change - 自动下达MES工单

master
yinq 11 months ago
parent 6bea396415
commit 04bdc2125f

@ -4,9 +4,12 @@ import com.aucma.api.domain.dto.SAPBOMPortDto;
import com.aucma.api.domain.dto.SAPPortDto;
import com.aucma.api.domain.dto.WERKSDto;
import com.aucma.api.service.ISAPPortService;
import com.aucma.base.domain.BaseOrderInfo;
import com.aucma.base.service.IBaseOrderInfoService;
import com.aucma.common.utils.DateUtils;
import com.aucma.production.domain.BaseBomInfo;
import com.aucma.production.service.IBaseBomInfoService;
import com.aucma.production.service.IProductPlanInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -27,6 +30,12 @@ public class SAPTask {
@Autowired
private IBaseBomInfoService baseBomInfoService;
@Autowired
private IProductPlanInfoService productPlanInfoService;
@Autowired
private IBaseOrderInfoService orderInfoService;
/**
* SAP
* @param factoryCode
@ -87,6 +96,25 @@ public class SAPTask {
baseBomInfoService.addAutomaticSynchronizationBOM(new BaseBomInfo());
}
/**
* MES
*
*/
public void automaticReleaseOrderPlan() {
//查询未下达MES工单的SAP计划
BaseOrderInfo orderInfo = new BaseOrderInfo();
orderInfo.setIsRelease(1L);
List<BaseOrderInfo> baseOrderInfos = orderInfoService.selectBaseOrderInfoList(orderInfo);
for (BaseOrderInfo baseOrderInfo : baseOrderInfos) {
try {
productPlanInfoService.releaseOrderPlan(baseOrderInfo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* SAP

@ -133,6 +133,19 @@ public class BaseBomInfo extends TreeStringEntity {
*/
private String ancestors;
/**
* BOM(0=;1-)
*/
private Long isPlanToStation;
public Long getIsPlanToStation() {
return isPlanToStation;
}
public void setIsPlanToStation(Long isPlanToStation) {
this.isPlanToStation = isPlanToStation;
}
@Override
public String getAncestors() {
return ancestors;

@ -72,4 +72,12 @@ public interface IBaseBomInfoService
* @return
*/
List<BaseBomInfo> addAutomaticSynchronizationBOM(BaseBomInfo baseBomInfo);
/**
* BOM
*
* @param baseBomInfo
* @return baseBomInfo
*/
public BaseBomInfo recursionSelectBaseBomInfoList(BaseBomInfo baseBomInfo);
}

@ -57,49 +57,44 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService {
public List<BaseBomInfo> selectBaseBomInfoList(BaseBomInfo baseBomInfo) {
List<BaseBomInfo> baseBomInfos = new ArrayList<>();
//测试查看全部BOM关系
if (StringUtils.isNotEmpty(baseBomInfo.getAncestors()) && baseBomInfo.getAncestors().equals("0")){
baseBomInfo.setMaterialCode(baseBomInfo.getMaterialCode());
baseBomInfo.setAncestors(null);
baseBomInfos = baseBomInfoMapper.selectBaseBomInfoList(baseBomInfo);
if (StringUtils.isNotEmpty(baseBomInfo.getAncestors()) && baseBomInfo.getAncestors().equals("0")) {
baseBomInfos = baseBomInfoMapper.selectBaseBomInfoList(new BaseBomInfo());
return baseBomInfos;
}
//筛选子集BOM
if (StringUtils.isNotEmpty(baseBomInfo.getAncestors()) && baseBomInfo.getAncestors().startsWith("900")){
BaseBomInfo baseBomInfo1 = new BaseBomInfo();
baseBomInfo1.setParentId(baseBomInfo.getAncestors());
List<BaseBomInfo> baseBomInfos1 = baseBomInfoMapper.selectBaseBomInfoList(baseBomInfo1);
baseBomInfos.addAll(baseBomInfos1);
for (BaseBomInfo bomInfo : baseBomInfos1) {
BaseBomInfo baseBomInfo2 = new BaseBomInfo();
baseBomInfo2.setParentId(bomInfo.getMaterialCode());
List<BaseBomInfo> baseBomInfos2 = baseBomInfoMapper.selectBaseBomInfoList(baseBomInfo2);
baseBomInfos.addAll(baseBomInfos2);
for (BaseBomInfo info : baseBomInfos2) {
BaseBomInfo baseBomInfo4 = new BaseBomInfo();
baseBomInfo4.setParentId(info.getMaterialCode());
List<BaseBomInfo> baseBomInfos4 = baseBomInfoMapper.selectBaseBomInfoList(baseBomInfo4);
baseBomInfos.addAll(baseBomInfos4);
}
}
BaseBomInfo baseBomInfo3 = new BaseBomInfo();
baseBomInfo3.setMaterialCode(baseBomInfo.getAncestors());
List<BaseBomInfo> baseBomInfos3 = baseBomInfoMapper.selectBaseBomInfoList(baseBomInfo3);
baseBomInfos.addAll(baseBomInfos3);
return baseBomInfos;
}
if (StringUtils.isNotEmpty(baseBomInfo.getMaterialCode()) || StringUtils.isEmpty(baseBomInfo.getAncestors())){
baseBomInfo.setMaterialCode(baseBomInfo.getMaterialCode());
baseBomInfo.setAncestors(null);
if (StringUtils.isNotEmpty(baseBomInfo.getAncestors())) {
baseBomInfos = baseBomInfoMapper.selectBaseBomInfoList(baseBomInfo);
return baseBomInfos;
}
return baseBomInfos;
//筛选成品BOM
List<BaseBomInfo> cpBomInfos = baseBomInfoMapper.selectBaseBomInfoList(baseBomInfo);
for (BaseBomInfo bomInfo : cpBomInfos) {
this.recursionSelectBaseBomInfoList(bomInfo);
}
// private List<BaseBomInfo> recursionSelectBaseBomInfoList(List<BaseBomInfo> baseBomInfo) {
// return null;
//
// }
return cpBomInfos;
}
/**
* BOM
*
* @param baseBomInfo
* @return baseBomInfo
*/
public BaseBomInfo recursionSelectBaseBomInfoList(BaseBomInfo baseBomInfo) {
BaseBomInfo info = new BaseBomInfo();
info.setAncestors(baseBomInfo.getMaterialCode());
info.setMaterialType(MaterialConstants.COAMING_MATERIAL_TYPE);
List<BaseBomInfo> baseBomInfos = baseBomInfoMapper.selectBaseBomInfoList(info);
if (baseBomInfos.size() >= 1) {
baseBomInfo.setIsPlanToStation(0L);
} else {
baseBomInfo.setIsPlanToStation(1L);
}
return baseBomInfo;
}
/**
@ -221,7 +216,7 @@ public class BaseBomInfoServiceImpl implements IBaseBomInfoService {
BaseBomInfo bomInfo = new BaseBomInfo();
bomInfo.setMaterialCode(baseMaterialInfo.getMaterialCode());
List<BaseBomInfo> baseBomInfos = baseBomInfoMapper.selectBaseBomInfoList(bomInfo);
if (baseBomInfos.size() == 0){
if (baseBomInfos.size() == 0) {
BaseBomInfo info = new BaseBomInfo();
info.setBomCode(baseMaterialInfo.getMaterialCode());
info.setMaterialCode(baseMaterialInfo.getMaterialCode());

@ -28,8 +28,7 @@ import static com.aucma.common.utils.SecurityUtils.getUsername;
* @date 2023-10-07
*/
@Service
public class ProductPlanInfoServiceImpl implements IProductPlanInfoService
{
public class ProductPlanInfoServiceImpl implements IProductPlanInfoService {
@Autowired
private ProductPlanInfoMapper productPlanInfoMapper;
@ -46,8 +45,7 @@ public class ProductPlanInfoServiceImpl implements IProductPlanInfoService
* @return
*/
@Override
public ProductPlanInfo selectProductPlanInfoByObjId(Long objId)
{
public ProductPlanInfo selectProductPlanInfoByObjId(Long objId) {
return productPlanInfoMapper.selectProductPlanInfoByObjId(objId);
}
@ -58,8 +56,7 @@ public class ProductPlanInfoServiceImpl implements IProductPlanInfoService
* @return
*/
@Override
public List<ProductPlanInfo> selectProductPlanInfoList(ProductPlanInfo productPlanInfo)
{
public List<ProductPlanInfo> selectProductPlanInfoList(ProductPlanInfo productPlanInfo) {
return productPlanInfoMapper.selectProductPlanInfoList(productPlanInfo);
}
@ -70,11 +67,7 @@ public class ProductPlanInfoServiceImpl implements IProductPlanInfoService
* @return
*/
@Override
public int insertProductPlanInfo(ProductPlanInfo productPlanInfo)
{
if (StringUtils.isEmpty(productPlanInfo.getCreatedBy())){
productPlanInfo.setCreatedBy(getUsername());
}
public int insertProductPlanInfo(ProductPlanInfo productPlanInfo) {
productPlanInfo.setCreatedTime(DateUtils.getNowDate());
return productPlanInfoMapper.insertProductPlanInfo(productPlanInfo);
}
@ -86,8 +79,7 @@ public class ProductPlanInfoServiceImpl implements IProductPlanInfoService
* @return
*/
@Override
public int updateProductPlanInfo(ProductPlanInfo productPlanInfo)
{
public int updateProductPlanInfo(ProductPlanInfo productPlanInfo) {
productPlanInfo.setUpdatedTime(DateUtils.getNowDate());
return productPlanInfoMapper.updateProductPlanInfo(productPlanInfo);
}
@ -99,8 +91,7 @@ public class ProductPlanInfoServiceImpl implements IProductPlanInfoService
* @return
*/
@Override
public int deleteProductPlanInfoByObjIds(Long[] objIds)
{
public int deleteProductPlanInfoByObjIds(Long[] objIds) {
return productPlanInfoMapper.deleteProductPlanInfoByObjIds(objIds);
}
@ -111,37 +102,41 @@ public class ProductPlanInfoServiceImpl implements IProductPlanInfoService
* @return
*/
@Override
public int deleteProductPlanInfoByObjId(Long objId)
{
public int deleteProductPlanInfoByObjId(Long objId) {
return productPlanInfoMapper.deleteProductPlanInfoByObjId(objId);
}
/**
*
*
* @param baseOrderInfo
* @return
*/
@Override
public Boolean releaseOrderPlan(BaseOrderInfo baseOrderInfo) {
try {
String orderCode = baseOrderInfo.getOrderCode();
String saleOrderCode = baseOrderInfo.getSaleOrderCode();
String saleOrderLineNumber = baseOrderInfo.getSaleOrderLineNumber();
BigDecimal orderAmount = baseOrderInfo.getOrderAmount();
int i = orderAmount.compareTo(new BigDecimal(1));
if (orderAmount.compareTo(new BigDecimal(1)) < 0){
if (orderAmount.compareTo(new BigDecimal(1)) < 0) {
throw new BaseException("该工单计划数量不合法!");
}
//获取生产BOM信息
BaseBomInfo bomInfo = new BaseBomInfo();
bomInfo.setParentId(baseOrderInfo.getMaterialCode());
bomInfo.setAncestors(baseOrderInfo.getMaterialCode());
bomInfo.setIsPlanToStation(0L);
List<BaseBomInfo> baseBomInfoList = baseBomInfoService.selectBaseBomInfoList(bomInfo);
if (baseBomInfoList.size() == 0){
throw new BaseException("请先维护生产BOM信息");
//检查生产BOM是否满足下计划条件
if (baseBomInfoList.size() == 0) {
throw new ServiceException("生产BOM信息不完整请先维护生产BOM信息");
}
for (BaseBomInfo baseBomInfo : baseBomInfoList) {
if (baseBomInfo.getMaterialType().equals(MaterialConstants.BOX_MATERIAL_TYPE)){
bomInfo.setIsPlanToStation(null);
List<BaseBomInfo> baseBomInfos= baseBomInfoService.selectBaseBomInfoList(bomInfo);
try {
for (BaseBomInfo baseBomInfo : baseBomInfos) {
if (baseBomInfo.getMaterialType().equals(MaterialConstants.BOX_MATERIAL_TYPE)) {
ProductPlanInfo planInfo = new ProductPlanInfo();
planInfo.setPlanCode(PlanCodeUtils.getPlanCode());
planInfo.setOrderCode(orderCode);
@ -156,30 +151,19 @@ public class ProductPlanInfoServiceImpl implements IProductPlanInfoService
planInfo.setProductLineCode("1005");
this.insertProductPlanInfo(planInfo);
BaseBomInfo bomInfo1 = new BaseBomInfo();
bomInfo1.setParentId(baseBomInfo.getMaterialCode());
List<BaseBomInfo> baseBomInfos = baseBomInfoService.selectBaseBomInfoList(bomInfo1);
for (BaseBomInfo info : baseBomInfos) {
if (info.getMaterialType().equals(MaterialConstants.COAMING_MATERIAL_TYPE)){
if (baseBomInfo.getMaterialType().equals(MaterialConstants.COAMING_MATERIAL_TYPE)) {
planInfo.setPlanCode(PlanCodeUtils.getPlanCode());
planInfo.setOrderCode(orderCode);
planInfo.setSaleOrderCode(saleOrderCode);
planInfo.setSaleorderLinenumber(saleOrderLineNumber);
planInfo.setMaterialCode(info.getMaterialCode());
planInfo.setMaterialName(info.getMaterialName());
planInfo.setMaterialCode(baseBomInfo.getMaterialCode());
planInfo.setMaterialName(baseBomInfo.getMaterialName());
planInfo.setProductLineCode("1001");
planInfo.setPlanAmount(baseBomInfo.getStandardAmount().longValue() * orderAmount.longValue());
this.insertProductPlanInfo(planInfo);
}
}
}
}
//-- 若一个工单可下达多计划:则需要根据工单编号和物料编号去重
//检查生产BOM是否满足下计划条件
// baseBomInfoService.checkBomInfo(baseBomInfoList);
baseOrderInfo.setIsRelease(0L);
baseOrderInfoService.updateBaseOrderInfo(baseOrderInfo);
} catch (Exception e) {

@ -71,6 +71,16 @@
<if test="ancestors != null and ancestors != ''">and bb.ancestors like concat(concat('%', #{ancestors}),
'%')
</if>
<if test="isPlanToStation != null and isPlanToStation == 0L"> AND bb.MATERIAL_CODE IN (SELECT ANCESTORS
FROM base_bominfo
WHERE MATERIAL_TYPE = 400
GROUP BY ANCESTORS)
</if>
<if test="isPlanToStation != null and isPlanToStation == 1L"> AND bb.MATERIAL_CODE NOT IN (SELECT ANCESTORS
FROM base_bominfo
WHERE MATERIAL_TYPE = 400
GROUP BY ANCESTORS)
</if>
</where>
order by bb.created_time desc
</select>

Loading…
Cancel
Save