|  |  | 
 |  |  |         } | 
 |  |  |         return PageData.from(new PageInfo<>(result)); | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public  PageData<SalaryStatisticsListVO> salaryStatistic(PageWrap<QuerySalaryStatisticDTO> pageWrap) { | 
 |  |  |         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
 |  |  |         if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); | 
 |  |  |         } | 
 |  |  |         //只能查看当前根组织的数据 | 
 |  |  |         pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId()); | 
 |  |  |         PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); | 
 |  |  |         List<SalaryStatisticsListVO> result = workorderRecordExtMapper.salaryStatistic(pageWrap.getModel()); | 
 |  |  |         if(result!=null){ | 
 |  |  |             List<DepartmentExtListVO> allDepartList = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_DEPART_LIST_KEY+user.getCompany().getId(),ArrayList.class); | 
 |  |  |             for(SalaryStatisticsListVO model : result){ | 
 |  |  |                 //查询生产人员姓名 | 
 |  |  | //                model.setUserName(initProUser(user,model.getUserId(),allDepartList)); | 
 |  |  |                     model.setUserInfo(initProUser(user,model.getUserId(),allDepartList)); | 
 |  |  |                     model.setJijianSalary(model.getJijianSalary().divide(new BigDecimal("100"),2,BigDecimal.ROUND_HALF_UP)); | 
 |  |  |                     model.setJishiSalary(model.getJishiSalary().divide(new BigDecimal("100"),2,BigDecimal.ROUND_HALF_UP)); | 
 |  |  |                     model.setTotalSalary(model.getTotalSalary().divide(new BigDecimal("100"),2,BigDecimal.ROUND_HALF_UP)); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return PageData.from(new PageInfo<>(result)); | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public  PageData<UserSalaryListVO> userSalaryPage(PageWrap<QueryUserSalaryListDTO> pageWrap) { | 
 |  |  |         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
 |  |  |         if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); | 
 |  |  |         } | 
 |  |  |         //只能查看当前根组织的数据 | 
 |  |  |         pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId()); | 
 |  |  |         pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId()); | 
 |  |  |         PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); | 
 |  |  |  | 
 |  |  |         //数据权限 | 
 |  |  | //        List<Integer> dataPermission = user.getDepartPermissionList(); | 
 |  |  |         List<UserSalaryListVO> result = workorderRecordExtMapper.userSalaryPage(pageWrap.getModel()); | 
 |  |  |         if(result!=null){ | 
 |  |  |             List<DepartmentExtListVO> allDepartList = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_DEPART_LIST_KEY+user.getCompany().getId(),ArrayList.class); | 
 |  |  |             for(UserSalaryListVO model : result){ | 
 |  |  |                 //查询生产人员姓名 | 
 |  |  |                 model.setUserInfo(initProUser(user,model.getUserId(),allDepartList)); | 
 |  |  |                 if(Constants.formatBigdecimal4Float(model.getNum()).compareTo(new BigDecimal(0))>0){ | 
 |  |  |                     model.setRate(Constants.formatBigdecimal4Float(model.getQualifiedNum()).divide(model.getNum(),4).multiply(new BigDecimal(100))); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return PageData.from(new PageInfo<>(result)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void initProUser(LoginUserInfo user, WorkorderRecordExtListVO data, List<DepartmentExtListVO> allDepartList) { | 
 |  |  |         if(data.getCreateUser() ==null){ | 
 |  |  | 
 |  |  |             String dName =d==null?"":StringUtils.defaultString(d.getName(),""); | 
 |  |  |             data.setProcedureName(comp.getName()+"-"+dName); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |     private UserBaseInfoVO initProUser(LoginUserInfo user, Integer userId, List<DepartmentExtListVO> allDepartList) { | 
 |  |  |         if(userId ==null){ | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         CompanyUser query=new CompanyUser(); | 
 |  |  |         query.setUserId(userId); | 
 |  |  |         query.setRootDepartId(user.getRootDepartment().getId()); | 
 |  |  |         query.setDeleted(Constants.ZERO); | 
 |  |  |         CompanyUser comp= companyUserExtMapper.selectOne(new QueryWrapper<>(query).last(" limit 1")); | 
 |  |  |         if(comp!=null){ | 
 |  |  |             UserBaseInfoVO userinfo = new UserBaseInfoVO(); | 
 |  |  |             DepartmentExtListVO d = departmentExtService.getModelById(user.getCompany().getId(),comp.getDepartmentId(),allDepartList); | 
 |  |  |             String dName =d==null?"":StringUtils.defaultString(d.getName(),""); | 
 |  |  |             userinfo.setNameAndDepart (comp.getName()+"-"+dName); | 
 |  |  |             userinfo.setDepartId(d.getId()); | 
 |  |  |             userinfo.setUserId(userId); | 
 |  |  |             userinfo.setUserName(comp.getName()); | 
 |  |  |             userinfo.setDepartName(d.getName()); | 
 |  |  |             return  userinfo; | 
 |  |  |         } | 
 |  |  |         return null; | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public List<WorkorderRecordExtListVO> findAll(QueryWorkorderRecordExtDTO pageWrap) { | 
 |  |  | 
 |  |  |         } | 
 |  |  |         if(!Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.create) | 
 |  |  |                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.material) | 
 |  |  |                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.producing) | 
 |  |  |                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.check) | 
 |  |  |                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.done)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单状态已流转,不能进行该操作!"); | 
 |  |  | 
 |  |  |         } | 
 |  |  |         if(!Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.create) | 
 |  |  |                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.material) | 
 |  |  |                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.producing) | 
 |  |  |                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.check) | 
 |  |  |                 && !Constants.equalsInteger(model.getWorkorderStatus(),Constants.WORKORDER_STATUS.done)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单状态已流转,不能进行该操作!"); | 
 |  |  | 
 |  |  |                 if(!Constants.equalsInteger(tModel.getDoneType(),Constants.ZERO)){ | 
 |  |  |                     //如果不良,累计工单的不良产出 | 
 |  |  |                     mp.setUnqualifiedNum(Constants.formatIntegerNum(mp.getUnqualifiedNum())+(Constants.formatBigdecimal(tModel.getNum()).intValue())); | 
 |  |  | //                    mp.setUnqualifiedNum(mp.getUnqualifiedNum().add(tModel.getNum())); | 
 |  |  |                 }else{ | 
 |  |  |                     //如果是合格,累计工单的合格数量 | 
 |  |  |                     mp.setQualifiedNum(Constants.formatIntegerNum(mp.getQualifiedNum())+(Constants.formatBigdecimal(tModel.getNum()).intValue())); | 
 |  |  | //                    mp.setUnqualifiedNum(mp.getQualifiedNum().add(tModel.getNum())); | 
 |  |  |                 } | 
 |  |  |                 //检查篮筐是否被作为产出篮筐,如果是,则需要判断该篮筐是否投料余额为0 | 
 |  |  |                 Appliances curUpdateModel = getApplianceFromList(tModel.getAppliancesId(),updateApplianceList); | 
 |  |  | 
 |  |  |             order.setStatus(Constants.WORKORDER_STATUS.material); | 
 |  |  |         }else if(status ==Constants.WORKORDER_HISTORY_STATUS.done){ | 
 |  |  |             order.setStatus(Constants.WORKORDER_STATUS.done); | 
 |  |  |         }else if(status ==Constants.WORKORDER_HISTORY_STATUS.produce){ | 
 |  |  |             //投料操作 | 
 |  |  |             if(Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.create) | 
 |  |  |                     ||Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.material)){ | 
 |  |  |                 //如果是已创建或者已备料状态的工单,修改其状态为【生产中】 | 
 |  |  |                 order.setStatus(Constants.WORKORDER_STATUS.producing); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         workorderExtMapper.updateById(order); | 
 |  |  |         workorderHistoryExtMapper.insertBatch(whList); | 
 |  |  | 
 |  |  |         } | 
 |  |  |         if(!Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.create) | 
 |  |  |                 && !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.material) | 
 |  |  |                 && !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.producing) | 
 |  |  |                 && !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.check) | 
 |  |  |                 && !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.done)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单状态已流转,不能进行该操作!"); | 
 |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void exportUserSalary(PageWrap<QueryUserSalaryListDTO> pageWrap, HttpServletResponse response) { | 
 |  |  |         List<UserSalaryListVO> result=this.userSalaryPage(pageWrap).getRecords(); | 
 |  |  |         for(UserSalaryListVO model : result) { | 
 |  |  |             if(model.getUserInfo()!=null){ | 
 |  |  |                 model.setUserName(model.getUserInfo().getUserName()); | 
 |  |  |                 model.setDepartName(model.getUserInfo().getDepartName()); | 
 |  |  |                 model.setNum(Constants.formatBigdecimalFloat(model.getNum(),2)); | 
 |  |  |                 model.setQualifiedNum(Constants.formatBigdecimalFloat(model.getQualifiedNum(),2)); | 
 |  |  |                 model.setUnQualifiedNum(Constants.formatBigdecimalFloat(model.getUnQualifiedNum(),2)); | 
 |  |  |                 model.setRate(Constants.formatBigdecimalFloat(model.getRate(),2)); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         ExcelExporter.build(UserSalaryListVO.class).export(result, "员工绩效明细"+System.currentTimeMillis(), response); | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public void exportSalaryStatistics(PageWrap<QuerySalaryStatisticDTO> pageWrap, HttpServletResponse response){ | 
 |  |  |         List<SalaryStatisticsListVO> result=this.salaryStatistic(pageWrap).getRecords(); | 
 |  |  |         for(SalaryStatisticsListVO model : result) { | 
 |  |  |             if(model.getUserInfo()!=null){ | 
 |  |  |                 model.setUserName(model.getUserInfo().getUserName()); | 
 |  |  |                 model.setDepartName(model.getUserInfo().getDepartName()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         ExcelExporter.build(SalaryStatisticsListVO.class).export(result, "工资报表"+System.currentTimeMillis(), response); | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     public void exportExcel(PageWrap<QueryWorkorderRecordExtDTO> pageWrap, HttpServletResponse response) { | 
 |  |  |         List<WorkorderRecordExtListVO> result=this.findPage(pageWrap).getRecords(); | 
 |  |  |         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | 
 |  |  | 
 |  |  |                 unintname = re.getUmodel().getName(); | 
 |  |  |             } | 
 |  |  |             if (re.getPmodel() != null) { | 
 |  |  |                 Integer pmodelnum = re.getPmodel().getNum() != null ? re.getPmodel().getNum() : 0; | 
 |  |  |                 BigDecimal pmodelnum = re.getNum() != null ? re.getNum() : new BigDecimal("0"); | 
 |  |  |                // wreev.setPlanNum( new BigDecimal(pmodelnum).stripTrailingZeros().toPlainString() + unintname); | 
 |  |  |                 wreev.setPlanNum( new BigDecimal(pmodelnum).stripTrailingZeros().toPlainString() ); | 
 |  |  |             } | 
 |  |  |             if (re.getDoneType() != null) { | 
 |  |  |                 switch (re.getDoneType()) { | 
 |  |  |                     case 0: | 
 |  |  |                         wreev.setDoneType("合格"); | 
 |  |  |                         break; | 
 |  |  |                     case 1: | 
 |  |  |                         wreev.setDoneType("不良"); | 
 |  |  |                         break; | 
 |  |  |                     case 2: | 
 |  |  |                         wreev.setDoneType("报废"); | 
 |  |  |                         break; | 
 |  |  |                     default: | 
 |  |  |                         break; | 
 |  |  |                 } | 
 |  |  |                 wreev.setPlanNum( re.getNum().stripTrailingZeros().toPlainString()+unintname); | 
 |  |  |             } | 
 |  |  |                 wreev.setProcedureName(re.getProcedureName()); | 
 |  |  |                 wreev.setUnintname(unintname); | 
 |  |  |                 if(re.getNum()!=null){ | 
 |  |  |                     wreev.setAppliancenum(re.getNum().stripTrailingZeros().toPlainString() ); | 
 |  |  |                     wreev.setAppliancenum(re.getNum().stripTrailingZeros().toPlainString()+unintname ); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 wreev.setUnintname(unintname); | 
 |  |  |  | 
 |  |  |                 if (re.getAmodel() != null) { | 
 |  |  |                     wreev.setAppliancecode(re.getAmodel().getCode()); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 wreev.setDeviceCode(re.getDeviceCode()+"|"+re.getDeviceName()); | 
 |  |  |                 wreev.setCreateTime(format.format(re.getCreateTime())); | 
 |  |  |                 wreev.setQualifiedNum( (Objects.nonNull(re.getQualifiedNum()) ? re.getQualifiedNum() : 0)+unintname); | 
 |  |  |                 wreev.setUnqualifiedNum((Objects.nonNull(re.getUnqualifiedNum()) ? re.getUnqualifiedNum() : 0)+unintname); | 
 |  |  |                 Integer duration = re.getDuration(); | 
 |  |  |                 if (Objects.nonNull(duration)){ | 
 |  |  |                     Integer h = duration/3600; | 
 |  |  |                     Integer m = (duration%3600)/60; | 
 |  |  |                     Integer s = ((duration%3600)%60); | 
 |  |  |                     wreev.setDuration(h+"小时"+m+"分钟"+s+"秒"); | 
 |  |  |                 }else { | 
 |  |  |                     wreev.setDuration("-"); | 
 |  |  |                 } | 
 |  |  |                 wreev.setSalaryType(re.getSalaryType()); | 
 |  |  |                 wreev.setSalaryPrice(re.getSalaryYuan()); | 
 |  |  |                 list.add(wreev); | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |         ExcelExporter.build(WorkorderRecordExportExtListVO.class).export(list, "工单生产过程记录"+System.currentTimeMillis(), response); | 
 |  |  |         ExcelExporter.build(WorkorderRecordExportExtListVO.class).export(list, "生产产出明细"+System.currentTimeMillis(), response); | 
 |  |  |  | 
 |  |  |        // EasyExcelUtil.exportExcel(list, "工单生产过程记录","工单生产过程记录",WorkorderRecordExportExtListVO.class,"工单生产过程记录"+System.currentTimeMillis()+".xls", response); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void exportExcel2(PageWrap<QueryWorkorderRecordExtDTO> pageWrap, HttpServletResponse response) { | 
 |  |  |  | 
 |  |  |         List<WorkorderRecordExtListVO> result=this.findPage(pageWrap).getRecords(); | 
 |  |  |         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | 
 |  |  |         List<WorkorderRecordBathExportExtListVO> list=new ArrayList<>(); | 
 |  |  |         for(int i=0;i<result.size();i++) { | 
 |  |  |             WorkorderRecordExtListVO re = result.get(i); | 
 |  |  |             WorkorderRecordBathExportExtListVO wreev = new WorkorderRecordBathExportExtListVO(); | 
 |  |  |             if (re.getOmodel() != null) { | 
 |  |  |                 wreev.setWorkordercode(re.getOmodel().getCode()); | 
 |  |  |                 if (re.getOmodel().getStatus() != null) { | 
 |  |  |                     String status = Constants.WORKORDER_STATUS.getTitleByStatus(null, re.getOmodel().getStatus()); | 
 |  |  |                     wreev.setStatus(status); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             if (re.getMmodel() != null) { | 
 |  |  |                 wreev.setMaterialcode(re.getMmodel().getCode()); | 
 |  |  |                 wreev.setMaterialname(re.getMmodel().getName()); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             wreev.setBatch(re.getBatch()); | 
 |  |  |             if (re.getPromodel() != null) { | 
 |  |  |                 wreev.setProceduresname(re.getPromodel().getName()); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             String unintname = ""; | 
 |  |  |             if (re.getUmodel() != null) { | 
 |  |  |                 unintname = re.getUmodel().getName(); | 
 |  |  |             } | 
 |  |  |             if (re.getNum() != null) { | 
 |  |  |                 BigDecimal pmodelnum = re.getNum() != null ? re.getNum() : new BigDecimal("0"); | 
 |  |  |                 // wreev.setPlanNum( new BigDecimal(pmodelnum).stripTrailingZeros().toPlainString() + unintname); | 
 |  |  |                 wreev.setNum( pmodelnum.stripTrailingZeros().toPlainString()+unintname); | 
 |  |  |             } | 
 |  |  |             wreev.setProcedureName(re.getProcedureName()); | 
 |  |  |             wreev.setUnintname(unintname); | 
 |  |  |             if(re.getOmodel().getPlanNum() != null){ | 
 |  |  |                 wreev.setPlanNum(re.getOmodel().getPlanNum().toString() ); | 
 |  |  |             } | 
 |  |  |             wreev.setMaterialDonetype(re.getMaterialDonetype()); | 
 |  |  |             wreev.setDeviceCode(re.getDeviceCode()+"|"+re.getDeviceName()); | 
 |  |  |             wreev.setCreateTime(format.format(re.getCreateTime())); | 
 |  |  |             list.add(wreev); | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |         ExcelExporter.build(WorkorderRecordBathExportExtListVO.class).export(list, "生产投料明细"+System.currentTimeMillis(), response); | 
 |  |  |  | 
 |  |  |     } | 
 |  |  | } |