Skip to content

Commit

Permalink
物料批次按照标准数量分批
Browse files Browse the repository at this point in the history
  • Loading branch information
adomguo committed Apr 6, 2021
1 parent 12c52c7 commit aa1e61a
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.newbiest.mms.rest.materiallot.split.standard;

import com.newbiest.base.rest.AbstractRestController;
import com.newbiest.mms.model.MaterialLot;
import com.newbiest.mms.service.MmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mms")
@Slf4j
@Api(value="/mms", tags="MaterialManagerSystem", description = "物料管理相关")
public class SplitStandardMaterialLotController extends AbstractRestController {

@Autowired
MmsService mmsService;

@ApiOperation(value = "物料批次按数量分批")
@ApiImplicitParam(name="request", value="request", required = true, dataType = "SplitStandardMaterialLotRequest")
@RequestMapping(value = "/splitStandardMaterialLot", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
public SplitStandardMaterialLotResponse execute(@RequestBody SplitStandardMaterialLotRequest request) throws Exception {
SplitStandardMaterialLotResponse response = new SplitStandardMaterialLotResponse();
response.getHeader().setTransactionId(request.getHeader().getTransactionId());
SplitStandardMaterialLotResponseBody responseBody = new SplitStandardMaterialLotResponseBody();
SplitStandardMaterialLotRequestBody requestBody = request.getBody();

List<MaterialLot> subMaterialLots = mmsService.splitStandardMLot(requestBody.getMaterialLotAction().getMaterialLotId(), requestBody.getMaterialLotAction().getTransQty());
responseBody.setSubMaterialLots(subMaterialLots);
response.setBody(responseBody);
return response;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.newbiest.mms.rest.materiallot.split.standard;

import com.newbiest.base.msg.Request;
import io.swagger.annotations.ApiModel;
import lombok.Data;

@Data
@ApiModel
public class SplitStandardMaterialLotRequest extends Request {

private static final long serialVersionUID = 1L;

public static final String MESSAGE_NAME = "SplitStandardMaterialLot";

private SplitStandardMaterialLotRequestBody body;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.newbiest.mms.rest.materiallot.split.standard;

import com.newbiest.base.msg.RequestBody;
import com.newbiest.mms.dto.MaterialLotAction;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.math.BigDecimal;

@Data
@ApiModel("具体请求操作信息")
public class SplitStandardMaterialLotRequestBody extends RequestBody {

private static final long serialVersionUID = 1L;

private MaterialLotAction materialLotAction;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.newbiest.mms.rest.materiallot.split.standard;

import com.newbiest.base.msg.Response;
import lombok.Data;

@Data
public class SplitStandardMaterialLotResponse extends Response {

private static final long serialVersionUID = 1L;

private SplitStandardMaterialLotResponseBody body;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.newbiest.mms.rest.materiallot.split.standard;

import com.newbiest.base.msg.ResponseBody;
import com.newbiest.mms.model.MaterialLot;
import lombok.Data;

import java.util.List;

@Data
public class SplitStandardMaterialLotResponseBody extends ResponseBody {

private static final long serialVersionUID = 1L;

private List<MaterialLot> subMaterialLots;

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public interface MmsService {
void releaseMaterialLot(List<MaterialLotHold> materialLotHolds, MaterialLotAction releaseLotAction) throws ClientException;
void releaseMaterialLot(String materialLotId, List<MaterialLotHold> materialLotHolds, MaterialLotAction releaseLotAction) throws ClientException;

List<MaterialLot> splitStandardMLot(String parentMaterialLotId, BigDecimal standardQty) throws ClientException;

MaterialLot splitMLot(String parentMaterialLotId, MaterialLotAction materialLotAction) throws ClientException;

// rawMaterial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,35 @@ public MaterialLot returnMLot(MaterialLot materialLot) throws ClientException {
}
}

/**
* 根据标准数量将物料批次分批
* @param parentMaterialLotId
* @param standardQty
* @return
* @throws ClientException
*/
@Override
public List<MaterialLot> splitStandardMLot(String parentMaterialLotId, BigDecimal standardQty) throws ClientException {
try {
List<MaterialLot> subMaterialLots = Lists.newArrayList();
MaterialLot parentMaterialLot = getMLotByMLotId(parentMaterialLotId, true);
if (parentMaterialLot.getCurrentQty().compareTo(standardQty) <= 0){
throw new ClientParameterException(MmsException.MM_MATERIAL_LOT_QTY_CANT_LESS_THEN_ZERO);
}
BigDecimal currentQty = parentMaterialLot.getCurrentQty();
MaterialLotAction materialLotAction = new MaterialLotAction();
materialLotAction.setTransQty(standardQty);
while (currentQty.compareTo(standardQty) > 0) {
MaterialLot subMaterialLot = splitMLot(parentMaterialLotId, materialLotAction);
subMaterialLots.add(subMaterialLot);
currentQty = currentQty.subtract(standardQty);
}
return subMaterialLots;
} catch (Exception e) {
throw ExceptionManager.handleException(e, log);
}
}

/**
* 物料批次分批
* @param parentMaterialLotId 母批的物料批次号
Expand All @@ -208,25 +237,26 @@ public MaterialLot returnMLot(MaterialLot materialLot) throws ClientException {
*/
public MaterialLot splitMLot(String parentMaterialLotId, MaterialLotAction materialLotAction) throws ClientException {
try {
MaterialLot materialLot = getMLotByMLotId(parentMaterialLotId, true);
MaterialLot parentMaterialLot = getMLotByMLotId(parentMaterialLotId, true);
BigDecimal splitQty = materialLotAction.getTransQty();
if (materialLot.getCurrentQty().compareTo(splitQty) <= 0){
if (parentMaterialLot.getCurrentQty().compareTo(splitQty) <= 0){
throw new ClientParameterException(MmsException.MM_MATERIAL_LOT_QTY_CANT_LESS_THEN_ZERO);
}
materialLot.setCurrentQty(materialLot.getCurrentQty().subtract(splitQty));
materialLot.setReceiveQty(materialLot.getReceiveQty().subtract(splitQty));
if (materialLot.getCurrentQty().compareTo(BigDecimal.ZERO) == 0) {
materialLot.setStatusCategory(MaterialStatusCategory.STATUS_CATEGORY_FIN);
materialLot.setStatus(MaterialStatus.STATUS_SPLIT);
parentMaterialLot.setCurrentQty(parentMaterialLot.getCurrentQty().subtract(splitQty));
parentMaterialLot.setReceiveQty(parentMaterialLot.getReceiveQty().subtract(splitQty));
if (parentMaterialLot.getCurrentQty().compareTo(BigDecimal.ZERO) == 0) {
parentMaterialLot.setStatusCategory(MaterialStatusCategory.STATUS_CATEGORY_FIN);
parentMaterialLot.setStatus(MaterialStatus.STATUS_SPLIT);
}
baseService.saveEntity(materialLot, MaterialLotHistory.TRANS_TYPE_SPLIT, materialLotAction);
baseService.saveEntity(parentMaterialLot, MaterialLotHistory.TRANS_TYPE_SPLIT, materialLotAction);

String subMLotId = generatorSubMLotId(MaterialLot.GENERATOR_SUB_MATERIAL_LOT_ID_RULE, materialLot);
MaterialLot subMaterialLot = (MaterialLot) materialLot.clone();
String subMLotId = generatorSubMLotId(MaterialLot.GENERATOR_SUB_MATERIAL_LOT_ID_RULE, parentMaterialLot);
MaterialLot subMaterialLot = (MaterialLot) parentMaterialLot.clone();
subMaterialLot.setMaterialLotId(subMLotId);
subMaterialLot.setCurrentQty(splitQty);
subMaterialLot.setReceiveQty(splitQty);
subMaterialLot.setParentMaterialLot(materialLot);
subMaterialLot.setIncomingQty(BigDecimal.ZERO);
subMaterialLot.setParentMaterialLot(parentMaterialLot);
baseService.saveEntity(subMaterialLot, MaterialLotHistory.TRANS_TYPE_SPLIT_CREATE, materialLotAction);
return subMaterialLot;
} catch (Exception e) {
Expand Down

0 comments on commit aa1e61a

Please sign in to comment.