diff --git a/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotController.java b/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotController.java new file mode 100644 index 000000000..e2f94e8d9 --- /dev/null +++ b/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotController.java @@ -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 subMaterialLots = mmsService.splitStandardMLot(requestBody.getMaterialLotAction().getMaterialLotId(), requestBody.getMaterialLotAction().getTransQty()); + responseBody.setSubMaterialLots(subMaterialLots); + response.setBody(responseBody); + return response; + } + +} diff --git a/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotRequest.java b/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotRequest.java new file mode 100644 index 000000000..f64278149 --- /dev/null +++ b/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotRequest.java @@ -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; + +} diff --git a/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotRequestBody.java b/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotRequestBody.java new file mode 100644 index 000000000..7c56b7380 --- /dev/null +++ b/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotRequestBody.java @@ -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; + +} diff --git a/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotResponse.java b/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotResponse.java new file mode 100644 index 000000000..5d64737d2 --- /dev/null +++ b/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotResponse.java @@ -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; + +} diff --git a/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotResponseBody.java b/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotResponseBody.java new file mode 100644 index 000000000..9bc0a5514 --- /dev/null +++ b/newbiest-mm/src/main/java/com/newbiest/mms/rest/materiallot/split/standard/SplitStandardMaterialLotResponseBody.java @@ -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 subMaterialLots; + +} diff --git a/newbiest-mm/src/main/java/com/newbiest/mms/service/MmsService.java b/newbiest-mm/src/main/java/com/newbiest/mms/service/MmsService.java index f7e33d45a..d4655089d 100644 --- a/newbiest-mm/src/main/java/com/newbiest/mms/service/MmsService.java +++ b/newbiest-mm/src/main/java/com/newbiest/mms/service/MmsService.java @@ -31,6 +31,8 @@ public interface MmsService { void releaseMaterialLot(List materialLotHolds, MaterialLotAction releaseLotAction) throws ClientException; void releaseMaterialLot(String materialLotId, List materialLotHolds, MaterialLotAction releaseLotAction) throws ClientException; + List splitStandardMLot(String parentMaterialLotId, BigDecimal standardQty) throws ClientException; + MaterialLot splitMLot(String parentMaterialLotId, MaterialLotAction materialLotAction) throws ClientException; // rawMaterial diff --git a/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/MmsServiceImpl.java b/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/MmsServiceImpl.java index a5819902b..e79fc2927 100644 --- a/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/MmsServiceImpl.java +++ b/newbiest-mm/src/main/java/com/newbiest/mms/service/impl/MmsServiceImpl.java @@ -199,6 +199,35 @@ public MaterialLot returnMLot(MaterialLot materialLot) throws ClientException { } } + /** + * 根据标准数量将物料批次分批 + * @param parentMaterialLotId + * @param standardQty + * @return + * @throws ClientException + */ + @Override + public List splitStandardMLot(String parentMaterialLotId, BigDecimal standardQty) throws ClientException { + try { + List 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 母批的物料批次号 @@ -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) {