|
|
|
|
@ -6,26 +6,34 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanStatusEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.producereport.vo.ProduceReportDetailPageReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.producereport.vo.ProduceReportDetailRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.producereport.vo.ProduceReportDetailSaveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.producereport.vo.ReportStatusEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.WorkReportPlanSaveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.organization.OrganizationDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.producereport.ProduceReportDetailDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.producereport.ProduceReportDetailMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.service.organization.OrganizationService;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.service.plan.PlanService;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.service.workreportplan.WorkReportPlanService;
|
|
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.math.MathContext;
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
|
|
|
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PLAN_NOT_EXISTS;
|
|
|
|
|
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PRODUCE_REPORT_DETAIL_NOT_EXISTS;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -91,6 +99,10 @@ public class ProduceReportDetailServiceImpl implements ProduceReportDetailServic
|
|
|
|
|
private ErpProductService productService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ProduceReportService reportService;
|
|
|
|
|
@Resource
|
|
|
|
|
private PlanService planService;
|
|
|
|
|
@Resource
|
|
|
|
|
private WorkReportPlanService workReportPlanService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<ProduceReportDetailRespVO> buildVOList(List<ProduceReportDetailDO> list){
|
|
|
|
|
@ -116,4 +128,64 @@ public class ProduceReportDetailServiceImpl implements ProduceReportDetailServic
|
|
|
|
|
pro -> item.setProductName(pro.getName()));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**更改报工单状态***/
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void updateStatus(Long id, Integer status) {
|
|
|
|
|
ProduceReportDetailDO reportDetailDO = produceReportDetailMapper.selectById(id);
|
|
|
|
|
reportDetailDO.setReportStatus(status);
|
|
|
|
|
produceReportDetailMapper.updateById(reportDetailDO);
|
|
|
|
|
|
|
|
|
|
if(status.equals(ReportStatusEnum.通过.getValue())){
|
|
|
|
|
//分配给开工中的计划
|
|
|
|
|
List<Integer> statusList = new ArrayList<>();
|
|
|
|
|
statusList.add(PlanStatusEnum.开工.getValue());
|
|
|
|
|
List<PlanDO> planList = planService.getPlanByStatusAndProduct(statusList,reportDetailDO.getProductId());
|
|
|
|
|
if(planList!=null && planList.size()>0){
|
|
|
|
|
//该种产品只有一个计划在开工
|
|
|
|
|
if(planList.size()==1){
|
|
|
|
|
WorkReportPlanSaveReqVO saveReqVO = new WorkReportPlanSaveReqVO()
|
|
|
|
|
.setReportId(id).setPlanId(planList.get(0).getId())
|
|
|
|
|
.setProductId(reportDetailDO.getProductId())
|
|
|
|
|
.setQualityNumberPlan(reportDetailDO.getQualityNumber())
|
|
|
|
|
.setWasteNumberPlan(reportDetailDO.getWasteNumber())
|
|
|
|
|
.setReportTimePlan(reportDetailDO.getReportTime())
|
|
|
|
|
.setTotalTimePlan(reportDetailDO.getTotalTime());
|
|
|
|
|
workReportPlanService.createWorkReportPlan(saveReqVO);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
MathContext mc = new MathContext(0, RoundingMode.HALF_UP);
|
|
|
|
|
long totalNeed = 0;
|
|
|
|
|
Map<Long, Long> planDOMap = new HashMap<>();
|
|
|
|
|
for (PlanDO plan : planList) {
|
|
|
|
|
BigDecimal finishNumber = workReportPlanService.selectSumBy(plan.getId(),reportDetailDO.getOrgType());
|
|
|
|
|
long planNeed = plan.getPlanNumber() > finishNumber.longValue() ? plan.getPlanNumber() - finishNumber.longValue(): 0;
|
|
|
|
|
totalNeed += planNeed;
|
|
|
|
|
planDOMap.put(plan.getId(), planNeed);
|
|
|
|
|
}
|
|
|
|
|
//根据计划各自的需求比例分配给计划
|
|
|
|
|
for (Long planId : planDOMap.keySet()) {
|
|
|
|
|
Long planNeed = planDOMap.get(planId);
|
|
|
|
|
if(planNeed>0){
|
|
|
|
|
BigDecimal planNumber = reportDetailDO.getQualityNumber().multiply(BigDecimal.valueOf(planNeed/totalNeed),mc);
|
|
|
|
|
BigDecimal wasteNumber = reportDetailDO.getWasteNumber().multiply(BigDecimal.valueOf(planNeed/totalNeed),mc);
|
|
|
|
|
BigDecimal totalTime = reportDetailDO.getTotalTime().multiply(BigDecimal.valueOf(planNeed/totalNeed),mc);
|
|
|
|
|
|
|
|
|
|
WorkReportPlanSaveReqVO saveReqVO = new WorkReportPlanSaveReqVO()
|
|
|
|
|
.setReportId(id).setPlanId(planId)
|
|
|
|
|
.setProductId(reportDetailDO.getProductId())
|
|
|
|
|
.setQualityNumberPlan(planNumber)
|
|
|
|
|
.setWasteNumberPlan(wasteNumber)
|
|
|
|
|
.setReportTimePlan(reportDetailDO.getReportTime())
|
|
|
|
|
.setTotalTimePlan(totalTime);
|
|
|
|
|
workReportPlanService.createWorkReportPlan(saveReqVO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else throw exception(PLAN_NOT_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|