|  |  | 
 |  |  | import doumeemes.dao.business.WOutboundMapper; | 
 |  |  | import doumeemes.dao.business.WTransferMapper; | 
 |  |  | import doumeemes.dao.business.WorkorderMapper; | 
 |  |  | import doumeemes.dao.business.dto.statistics.StatisticsPlanDataModel; | 
 |  |  | import doumeemes.dao.business.dto.statistics.Unqualified7DayModel; | 
 |  |  | import doumeemes.dao.business.dto.statistics.UserProduceTopModel; | 
 |  |  | import doumeemes.dao.business.dto.statistics.*; | 
 |  |  | import doumeemes.dao.business.model.*; | 
 |  |  | import doumeemes.dao.ext.*; | 
 |  |  | import doumeemes.dao.ext.dto.QueryBarcodeParamExtDTO; | 
 |  |  | import doumeemes.dao.ext.dto.QueryCompanyExtDTO; | 
 |  |  | import doumeemes.dao.ext.dto.QueryWorkPlansDTO; | 
 |  |  | import doumeemes.dao.ext.dto.QueryWorkorderRecordExtDTO; | 
 |  |  | import doumeemes.dao.ext.vo.BarcodeParamContent; | 
 |  |  | import doumeemes.dao.ext.vo.BarcodeParamExtListVO; | 
 |  |  | import doumeemes.dao.ext.vo.CompanyExtListVO; | 
 |  |  | import doumeemes.dao.ext.vo.DepartmentExtListVO; | 
 |  |  | import doumeemes.service.ext.BarcodeParamExtService; | 
 |  |  | import doumeemes.service.ext.DepartmentExtService; | 
 |  |  | import doumeemes.service.ext.StatisticsService; | 
 |  |  | import doumeemes.dao.ext.dto.*; | 
 |  |  | import doumeemes.dao.ext.vo.*; | 
 |  |  | import doumeemes.service.ext.*; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  |  | 
 |  |  | import java.math.BigDecimal; | 
 |  |  | import java.time.LocalDate; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private WorkPlansExtMapper workPlansExtMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private WorkorderRecordExtMapper workorderRecordExtMapper; | 
 |  |  |     private CompanyExtService companyExtService; | 
 |  |  |     @Autowired | 
 |  |  |     private DepartmentExtService departmentExtService; | 
 |  |  |     @Autowired | 
 |  |  |     private RouteProcedureExtMapper routeProcedureExtMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private PlansExtMapper plansExtMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private WStockExtMapper stockExtMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private WorkorderRecordExtMapper workorderRecordExtMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private DeviceCheckExtService deviceCheckExtService; | 
 |  |  |     @Autowired | 
 |  |  |     private PlansExtService plansExtService; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public StatisticsPlanDataModel getPlansData(Integer companyId, Integer departId) { | 
 |  |  | 
 |  |  |         workPlans.setDepartId(departId); | 
 |  |  |         //查询统计结果 | 
 |  |  |         StatisticsPlanDataModel model = workPlansExtMapper.getPlansStaticticsData(workPlans); | 
 |  |  |         model.setUnqualifiedNum(new BigDecimal(0)); | 
 |  |  |         model.setUnqualifiedRate(new BigDecimal(0)); | 
 |  |  |         if(model.getDoneNUm() !=null && model.getDoneNUm().compareTo(new BigDecimal(0)) != 0){ | 
 |  |  |             //不良品率 | 
 |  |  |             model.setUnqualifiedRate(model.getUnqualifiedNum().divide(model.getDoneNUm(),4).multiply(new BigDecimal(100))); | 
 |  |  | 
 |  |  |         return  model; | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public List<UserProduceTopModel> getUserProduceTopData(Integer companyId, Integer departId) { | 
 |  |  |     public StatisticsPlanDataModel getProcedurePlanData(Integer companyId, Integer departId, Integer procedureId){ | 
 |  |  |         DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId); | 
 |  |  |         if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员"); | 
 |  |  |         } | 
 |  |  |         QueryPlansExtDTO param = new QueryPlansExtDTO(); | 
 |  |  |         param.setRootDepartId(department.getRootId()); | 
 |  |  |         param.setDepartId(departId); | 
 |  |  |         param.setProcedureId(procedureId); | 
 |  |  |         //查询统计结果 | 
 |  |  |         StatisticsPlanDataModel model = plansExtMapper.getPlansStaticticsData(param); | 
 |  |  |         model.setUnqualifiedRate(new BigDecimal(0)); | 
 |  |  |         if(model.getDoneNUm() !=null && model.getDoneNUm().compareTo(new BigDecimal(0)) != 0){ | 
 |  |  |             //不良品率 | 
 |  |  |             model.setUnqualifiedRate(model.getUnqualifiedNum().divide(model.getDoneNUm(),4).multiply(new BigDecimal(100))); | 
 |  |  |         } | 
 |  |  |         return  model; | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public List<UserProduceTopModel> getUserProduceTopData(Integer companyId, Integer departId, Integer procedureId) { | 
 |  |  |         DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId); | 
 |  |  |         if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员"); | 
 |  |  |         } | 
 |  |  |         QueryWorkorderRecordExtDTO param = new QueryWorkorderRecordExtDTO(); | 
 |  |  |         param.setRootDepartId(department.getRootId()); | 
 |  |  |         param.setProcedureId(procedureId); | 
 |  |  |         param.setDepartId(departId); | 
 |  |  |         //查询统计结果 | 
 |  |  |         List<UserProduceTopModel> model = workorderRecordExtMapper.getUserProduceTopData(param); | 
 |  |  | 
 |  |  |         return  model; | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public List<Unqualified7DayModel> getUnqualified7DayData(Integer companyId, Integer departId) { | 
 |  |  |     public List<ProcedureProcessModel> getProcedureProcessList(Integer companyId, Integer departId) { | 
 |  |  |         DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId); | 
 |  |  |         if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员"); | 
 |  |  |         } | 
 |  |  |         QueryPlansExtDTO param = new QueryPlansExtDTO(); | 
 |  |  |         param.setRootDepartId(department.getRootId()); | 
 |  |  |         param.setDepartId(departId); | 
 |  |  |         //查询统计结果 | 
 |  |  |         List<ProcedureProcessModel> result = plansExtMapper.selectProcedureProcessList(param); | 
 |  |  |         if(result !=null){ | 
 |  |  |             for(ProcedureProcessModel model : result){ | 
 |  |  |                 //未完成数 | 
 |  |  |                 BigDecimal doneNum =Constants.formatBigdecimal(model.getUnqualifiedNum()) | 
 |  |  |                         .add(Constants.formatBigdecimal(model.getQualifiedNum())); | 
 |  |  |                 model.setUndoneNum(Constants.formatBigdecimal(model.getNum()).subtract(doneNum)); | 
 |  |  |                 //不良品率 | 
 |  |  |                 if(doneNum.compareTo(new BigDecimal(0) )>0){ | 
 |  |  |                     model.setUnqualifiedRate(model.getUnqualifiedNum().divide(doneNum,4).multiply(new BigDecimal(100))); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return  result; | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public   List<StockDataModel> getStockList(Integer companyId, Integer departId){ | 
 |  |  |         DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId); | 
 |  |  |         if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员"); | 
 |  |  |         } | 
 |  |  |         QueryWStockExtDTO param = new QueryWStockExtDTO(); | 
 |  |  |         param.setRootDepartId(department.getRootId()); | 
 |  |  |         param.setWmodelDepartId(departId); | 
 |  |  |         //查询统计结果 | 
 |  |  |         List<StockDataModel> result = stockExtMapper.getStatisticsStockList(param); | 
 |  |  |         return  result; | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public  List<DepartmentExtListVO> getDepartmentList(Integer companyId){ | 
 |  |  |         CompanyExtListVO companyExtListVO = companyExtService.getModelById(companyId); | 
 |  |  |         if(companyExtListVO == null || Constants.equalsInteger(companyExtListVO.getDeleted(), Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员"); | 
 |  |  |         } | 
 |  |  |         QueryDepartmentExtDTO param = new QueryDepartmentExtDTO(); | 
 |  |  |         param.setDeleted(Constants.ZERO); | 
 |  |  |         param.setCompanyId(companyId); | 
 |  |  |         param.setType(Constants.DEPART_TYPE.com); | 
 |  |  |         List<DepartmentExtListVO> result = departmentExtService.findList(param); | 
 |  |  |         return  result; | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public List<Unqualified7DayModel> getUnqualified7DayData(Integer companyId, Integer departId, Integer procedureId) { | 
 |  |  |         DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId); | 
 |  |  |         if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员"); | 
 |  |  | 
 |  |  |         QueryWorkorderRecordExtDTO param = new QueryWorkorderRecordExtDTO(); | 
 |  |  |         param.setRootDepartId(department.getRootId()); | 
 |  |  |         param.setDepartId(departId); | 
 |  |  |         param.setProcedureId(procedureId); | 
 |  |  |         //查询统计结果 | 
 |  |  |         List<Unqualified7DayModel> model = workorderRecordExtMapper.getUnqualified7DayData(param); | 
 |  |  |         List<Unqualified7DayModel> result = new ArrayList<>(); | 
 |  |  |         Date date = DateUtil.getCurrentDate(); | 
 |  |  |         for (int i = 0; i < 7; i++) { | 
 |  |  |             Date td = DateUtil.addDaysToDate(date, 7-i); | 
 |  |  |             Date td = DateUtil.addDaysToDate(date, i-6); | 
 |  |  |             Unqualified7DayModel m = getReusltModelByDate(td,model); | 
 |  |  |             if(m == null){ | 
 |  |  |                 m = new Unqualified7DayModel(); | 
 |  |  | 
 |  |  |             result.add(m); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return  result; | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public List<UnqualifiedCateModel> getUnqualifiedCateData(Integer companyId, Integer departId, Integer procedureId) { | 
 |  |  |         DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId); | 
 |  |  |         if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员"); | 
 |  |  |         } | 
 |  |  |         QueryWorkorderRecordExtDTO param = new QueryWorkorderRecordExtDTO(); | 
 |  |  |         param.setRootDepartId(department.getRootId()); | 
 |  |  |         param.setDepartId(departId); | 
 |  |  |         param.setProcedureId(procedureId); | 
 |  |  |         //查询统计结果 | 
 |  |  |         List<UnqualifiedCateModel> model = workorderRecordExtMapper.getUnqualifiedCateData(param); | 
 |  |  |  | 
 |  |  |         return  model; | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public PageData<RecordLogModel> getRecordLogPage(Integer companyId, Integer departId, PageWrap<QueryWorkorderRecordExtDTO> pageWrap){ | 
 |  |  |         DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId); | 
 |  |  |         if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员"); | 
 |  |  |         } | 
 |  |  |         //只能查看当前根组织的数据 | 
 |  |  |         pageWrap.getModel().setRootDepartId(department.getRootId()); | 
 |  |  |         pageWrap.getModel().setDepartId(departId); | 
 |  |  |         PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); | 
 |  |  |         List<RecordLogModel> result = workorderRecordExtMapper.getRecordLog(pageWrap.getModel()); | 
 |  |  |         if(result!=null){ | 
 |  |  |             for(RecordLogModel model : result){ | 
 |  |  |                 model.setUnqualifiedRate(new BigDecimal(0)); | 
 |  |  |                 BigDecimal doneNum = Constants.formatBigdecimal(model.getUnqualifiedNum()).add(Constants.formatBigdecimal(model.getQualifiedNum())); | 
 |  |  |                 if(model.getUnqualifiedNum() !=null && doneNum.compareTo(new BigDecimal(0)) != 0){ | 
 |  |  |                     //不良品率 | 
 |  |  |                     model.setUnqualifiedRate(model.getUnqualifiedNum().divide(doneNum,4).multiply(new BigDecimal(100))); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return PageData.from(new PageInfo<>(result)); | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public   PageData<DeviceCheckExtListVO> getDeviceCheckPage(Integer companyId, Integer departId,PageWrap<QueryDeviceCheckExtDTO> pageWrap){ | 
 |  |  |         DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId); | 
 |  |  |         if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员"); | 
 |  |  |         } | 
 |  |  |         //只能查看当前根组织的数据 | 
 |  |  |         pageWrap.getModel().setRootDepartId(department.getRootId()); | 
 |  |  |         pageWrap.getModel().setComDepartId(departId); | 
 |  |  |         return deviceCheckExtService.getDeviceCheckPage(pageWrap); | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public    List<ProcedurePlansPageModel> getProcedurePlansPage(Integer companyId, Integer departId,Integer procedureId){ | 
 |  |  |         DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId); | 
 |  |  |         if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员"); | 
 |  |  |         } | 
 |  |  |         if(procedureId == null){ | 
 |  |  |            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"工序编码不能为空!"); | 
 |  |  |         } | 
 |  |  |         QueryPlansExtDTO param = new QueryPlansExtDTO(); | 
 |  |  |         param.setRootDepartId(department.getRootId()); | 
 |  |  |         param.setDepartId(departId); | 
 |  |  |         param.setProcedureId(procedureId); | 
 |  |  |  | 
 |  |  |         List<ProcedurePlansPageModel> result = plansExtMapper.selectStatisticsList(param); | 
 |  |  |  | 
 |  |  |         if(result != null){ | 
 |  |  |             for(ProcedurePlansPageModel model :result){ | 
 |  |  |                 model.setUnqualifiedRate(new BigDecimal(0)); | 
 |  |  |                 BigDecimal doneNum = Constants.formatBigdecimal(model.getQualifiedNum()).add(Constants.formatBigdecimal(model.getUnqualifiedNum())); | 
 |  |  |                 if(model.getUnqualifiedNum() !=null && doneNum.compareTo(new BigDecimal(0)) != 0){ | 
 |  |  |                     //不良品率 | 
 |  |  |                     model.setUnqualifiedRate(model.getUnqualifiedNum().divide(doneNum,4).multiply(new BigDecimal(100))); | 
 |  |  |                     model.setUndoneNum(Constants.formatBigdecimal(model.getNum()).subtract(doneNum)); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public   List<WorkPlansPageModel> getWorkPlansList(Integer companyId, Integer departId){ | 
 |  |  |         DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId); | 
 |  |  |         if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员"); | 
 |  |  |         } | 
 |  |  |         QueryWorkPlansExtDTO param = new QueryWorkPlansExtDTO(); | 
 |  |  |         param.setRootDepartId(department.getRootId()); | 
 |  |  |         param.setDepartId(departId); | 
 |  |  |         List<WorkPlansPageModel> result = workPlansExtMapper.selectStatisticsList(param); | 
 |  |  |         if(result != null){ | 
 |  |  |             for(WorkPlansPageModel model :result){ | 
 |  |  |                 if(model.getRouteId() ==null){ | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 //查询工序集合和完成情况 | 
 |  |  |                 QueryRouteProcedureExtDTO r = new QueryRouteProcedureExtDTO(); | 
 |  |  |                 r.setRouteId(model.getRouteId()); | 
 |  |  |                 r.setDeleted(Constants.ZERO); | 
 |  |  |                 r.setWorkPlanId(model.getId()); | 
 |  |  |                 List<RouteProcedureExtListVO> list = routeProcedureExtMapper.selectStatisticsList(r); | 
 |  |  |                 List<WorkPlansProcedureModel> rList = new ArrayList<>(); | 
 |  |  |                 if(list != null){ | 
 |  |  |                     for(RouteProcedureExtListVO t : list){ | 
 |  |  |                         WorkPlansProcedureModel tt = new WorkPlansProcedureModel(); | 
 |  |  |                         tt.setProcedureName(t.getProcedureName()); | 
 |  |  |                         tt.setProcedureId(t.getProcedureId()); | 
 |  |  |                         tt.setRate(new BigDecimal(0)); | 
 |  |  |                         if(  Constants.formatBigdecimal(t.getPlanNum()).compareTo(new BigDecimal(0)) >0){ | 
 |  |  |                             //完成率 | 
 |  |  |                             tt.setRate(Constants.formatBigdecimal(t.getQualifiedNum()).divide(t.getPlanNum(),4).multiply(new BigDecimal(100))); | 
 |  |  |                         } | 
 |  |  |                         tt.setPlanNum(Constants.formatBigdecimal(t.getPlanNum())); | 
 |  |  |                         tt.setDoneNum(Constants.formatBigdecimal(t.getQualifiedNum())); | 
 |  |  |                         rList.add(tt); | 
 |  |  |                         //最后一列的良品数/完工数:为当前产品最后一道工序的良品数/完工数 | 
 |  |  |                         model.setDoneNum(t.getDoneNum()); | 
 |  |  |                         model.setQualifiedNum(t.getQualifiedNum()); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 model.setProcedureList(rList); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private Unqualified7DayModel getReusltModelByDate(Date td, List<Unqualified7DayModel> model ) { | 
 |  |  |         if(model !=null){ | 
 |  |  |             for(Unqualified7DayModel m : model){ | 
 |  |  |                 if(StringUtils.equals(DateUtil.getShortTime(td),DateUtil.getShortTime(m.getCreateTime()))){ | 
 |  |  |                 String d1 = DateUtil.getShortTime(td); | 
 |  |  |                 String d2 = DateUtil.getShortTime(m.getCreateTime()); | 
 |  |  |                 if(StringUtils.equals(d1,d2)){ | 
 |  |  |                     return m; | 
 |  |  |                 } | 
 |  |  |             } |