diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/OperDefectController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/OperDefectController.java index addc566..b1d5fac 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/OperDefectController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/OperDefectController.java @@ -143,17 +143,17 @@ public class OperDefectController extends BladeController { @OperationAnnotation(moduleName = "生产月报", title = "缺陷月报表", operatorType = OperatorType.MOBILE, businessType = BusinessType.GENCODE, action = "获取缺陷的统计月报") - public R> getDefectStatistics(@ApiParam(value = "month 格式:2021-01", required = true) @RequestParam String month) { - Map defectStatistics = defectService.getDefectStatistics(month); + public R> getDefectStatistics(@ApiParam(value = "month 格式:2021-01", required = true) @RequestParam String month, @RequestParam String deptId) { + Map defectStatistics = defectService.getDefectStatistics(month,deptId); return R.data(defectStatistics); } @ApiOperation(value = "缺陷月报表导出-Excel") @RequestMapping(value = "/exportFualtMonthExcel", method = {RequestMethod.GET, RequestMethod.POST}) - public void exportFualtMonthExcel(HttpServletResponse response, @ApiParam(value = "month 格式:2021-01", required = true) @RequestParam String month) { + public void exportFualtMonthExcel(HttpServletResponse response, @ApiParam(value = "month 格式:2021-01", required = true) @RequestParam String month,@ApiParam String deptId) { Map result = new HashMap<>(); try { - defectService.exportFualtMonthExcel(response, month); + defectService.exportFualtMonthExcel(response, month, deptId); result.put("success", "true"); } catch (IOException e) { result.put("success", "false"); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperDefectMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperDefectMapper.java index 8eb6960..dfe376f 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperDefectMapper.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperDefectMapper.java @@ -27,7 +27,7 @@ public interface OperDefectMapper extends UserDataScopeBaseMapper getStatisticByMonth(@Param("month") String month, - @Param("createDept") String createDept); + @Param("createDept") List createDept); /** * 当年1月 - 当前月获取缺陷等级统计数据 @@ -37,13 +37,13 @@ public interface OperDefectMapper extends UserDataScopeBaseMapper getStatisticBySeveralMonth(@Param("firstMonth") String firstMonth, @Param("endMonth") String endMonth, - @Param("createDept") String createDept); + @Param("createDept") List createDept); /** * 获取重复缺陷等级统计数据 * @return */ - List getRepetStatistics(@Param("createDept") String createDept); + List getRepetStatistics(@Param("createDept") List createDept); /** * 获取按月管理指标统计数据 @@ -52,7 +52,7 @@ public interface OperDefectMapper extends UserDataScopeBaseMapper getManageIndex(@Param("month") String month, - @Param("createDept") String createDept); + @Param("createDept") List createDept); List selectDefectList(String emCode,List list); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperDefectMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperDefectMapper.xml index 28d1911..35489b3 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperDefectMapper.xml +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperDefectMapper.xml @@ -8,8 +8,11 @@ hzims_oper_phenomenon P ON D.DEFECT_CODE = P.DEFECT_CODE WHERE DATE_FORMAT(D.CREATE_TIME,'%Y-%m') = #{month} - - AND D.CREATE_DEPT = #{createDept} + + and D.CREATE_DEPT in + + #{item} + GROUP BY P.DEFECT_LEVEL,D.HANDLE_STATUS ORDER BY P.DEFECT_LEVEL @@ -22,8 +25,11 @@ LEFT JOIN hzims_oper_phenomenon P ON D.DEFECT_CODE = P.DEFECT_CODE WHERE D.CREATE_TIME BETWEEN #{firstMonth} AND #{endMonth} - - AND D.CREATE_DEPT = #{createDept} + + and D.CREATE_DEPT in + + #{item} + GROUP BY P.DEFECT_LEVEL,D.HANDLE_STATUS ORDER BY P.DEFECT_LEVEL @@ -34,8 +40,11 @@ hzims_oper_phenomenon P ON D.DEFECT_CODE = P.DEFECT_CODE WHERE 1=1 - - AND D.CREATE_DEPT = #{createDept} + + and D.CREATE_DEPT in + + #{item} + GROUP BY P.DEFECT_LEVEL,P.FAULT_CODE @@ -47,8 +56,11 @@ WHERE DATE_FORMAT(D.CREATE_TIME,'%Y-%m') = #{month} AND D.HANDLE_STATUS = 1 AND D.ACT_END_TIME <= P.PLAN_END_TIME - - AND D.CREATE_DEPT = #{createDept} + + and D.CREATE_DEPT in + + #{item} + ) UNION ALL @@ -57,8 +69,11 @@ SELECT COUNT(D.ID) AS DEFECT_NUM from hzims_oper_defect D WHERE DATE_FORMAT(D.CREATE_TIME,'%Y-%m') = #{month} AND D.HANDLE_STATUS = 1 - - AND D.CREATE_DEPT = #{createDept} + + and D.CREATE_DEPT in + + #{item} + ) UNION ALL @@ -67,8 +82,11 @@ SELECT COUNT(D.ID) AS DEFECT_NUM from hzims_oper_defect D WHERE DATE_FORMAT(D.CREATE_TIME,'%Y-%m') = #{month} AND D.HANDLE_STATUS = 0 - - AND D.CREATE_DEPT = #{createDept} + + and D.CREATE_DEPT in + + #{item} + ) UNION ALL @@ -77,8 +95,11 @@ SELECT COUNT(D.ID) AS DEFECT_NUM from hzims_oper_defect D WHERE DATE_FORMAT(D.CREATE_TIME,'%Y-%m') < CONCAT(#{month}, '-01') AND D.HANDLE_STATUS = 0 - - AND D.CREATE_DEPT = #{createDept} + + and D.CREATE_DEPT in + + #{item} + ) UNION ALL @@ -86,8 +107,11 @@ ( SELECT COUNT(D.ID) AS DEFECT_NUM from hzims_oper_defect D WHERE DATE_FORMAT(D.CREATE_TIME,'%Y-%m') = #{month} - - AND D.CREATE_DEPT = #{createDept} + + and D.CREATE_DEPT in + + #{item} + ) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperDefectService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperDefectService.java index ede6661..98c5c30 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperDefectService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperDefectService.java @@ -43,7 +43,7 @@ public interface IOperDefectService extends BaseService { * 获取缺陷的统计月报 * @param month 格式:"2021-01" */ - Map getDefectStatistics(String month); + Map getDefectStatistics(String month,String deptId); /** * 导出缺陷统计月报报表 @@ -51,7 +51,7 @@ public interface IOperDefectService extends BaseService { * @param month 格式 "2021-01" * @throws IOException */ - void exportFualtMonthExcel(HttpServletResponse response, String month) throws IOException; + void exportFualtMonthExcel(HttpServletResponse response, String month,String deptId) throws IOException; List getDefectList(String emCode,List list); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperDefectServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperDefectServiceImpl.java index 83a2c6d..859102e 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperDefectServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperDefectServiceImpl.java @@ -50,6 +50,8 @@ import org.springblade.flow.core.feign.IFlowClient; import org.springblade.flow.core.utils.FlowUtil; import org.springblade.flow.core.vo.ComleteTask; import org.springblade.system.cache.DictCache; +import org.springblade.system.entity.Dept; +import org.springblade.system.feign.ISysClient; import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; @@ -57,6 +59,7 @@ import org.springframework.stereotype.Service; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; +import javax.xml.ws.WebServiceException; import java.io.IOException; import java.math.BigDecimal; import java.net.URLEncoder; @@ -85,6 +88,8 @@ public class OperDefectServiceImpl extends BaseServiceImpl getQueryWrapper(OperDefectVO defectVO) { LambdaQueryWrapper queryWrapper = Condition.getQueryWrapper(new OperDefectEntity(), defectVO); @@ -180,6 +186,7 @@ public class OperDefectServiceImpl extends BaseServiceImpl getDefectStatistics(String month) { + public Map getDefectStatistics(String month, String deptId) { Map re = new HashMap<>(); - re.put("currentMonth", getCurrentMonthStatic(month)); - re.put("severalMonths", getStatisticBySeveralMonth(month)); - re.put("manageIndex", getManageIndexStatistic(month)); - re.put("repeat", getRepeatStatistic(month)); + re.put("currentMonth", getCurrentMonthStatic(month, deptId)); + re.put("severalMonths", getStatisticBySeveralMonth(month, deptId)); + re.put("manageIndex", getManageIndexStatistic(month, deptId)); + re.put("repeat", getRepeatStatistic(deptId)); return re; } @Override - public void exportFualtMonthExcel(HttpServletResponse response, String month) throws IOException { + public void exportFualtMonthExcel(HttpServletResponse response, String month, String deptId) throws IOException { Map re = new HashMap<>(); - re = this.getDefectStatistics(month); + re = this.getDefectStatistics(month, deptId); //获取数据 List currentMonth = (List) re.get("currentMonth"); List severalMonths = (List) re.get("severalMonths"); @@ -785,8 +792,24 @@ public class OperDefectServiceImpl extends BaseServiceImpl getCurrentMonthStatic(String month) { - List statisticByMonth = this.baseMapper.getStatisticByMonth(month, AuthUtil.getDeptId()); + private List getCurrentMonthStatic(String month, String deptId) { + List createDeptList = new ArrayList<>(); + List deptList = new ArrayList<>(); + R> res = sysClient.getDeptByCurrentUser(); + if (res.isSuccess() && CollectionUtil.isNotEmpty(res.getData())) { + deptList = res.getData().stream().map(Dept::getId).map(s -> s.toString()).collect(Collectors.toList()); + } else { + throw new WebServiceException("该用户没有此权限"); + } + if (StringUtil.isNotBlank(deptId)) { + if (deptList.contains(deptId)) { + createDeptList.add(deptId); + } + } else { + //拿到用户当前及其以下的机构 + createDeptList.addAll(deptList); + } + List statisticByMonth = this.baseMapper.getStatisticByMonth(month, createDeptList); return getRatioStatic(statisticByMonth); } @@ -796,7 +819,7 @@ public class OperDefectServiceImpl extends BaseServiceImpl getStatisticBySeveralMonth(String month) { + private List getStatisticBySeveralMonth(String month, String deptId) { Integer intervalMonth = Integer.valueOf(month.split("-")[1]); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date; @@ -811,8 +834,23 @@ public class OperDefectServiceImpl extends BaseServiceImpl statisticBySeveralMonth = this.baseMapper.getStatisticBySeveralMonth(firstMonth, dateFormat.format(date), createDeptList); return getRatioStatic(statisticBySeveralMonth); } @@ -822,9 +860,25 @@ public class OperDefectServiceImpl extends BaseServiceImpl list = this.baseMapper.getManageIndex(month, AuthUtil.getDeptId()); + List createDeptList = new ArrayList<>(); + List deptList = new ArrayList<>(); + R> res = sysClient.getDeptByCurrentUser(); + if (res.isSuccess() && CollectionUtil.isNotEmpty(res.getData())) { + deptList = res.getData().stream().map(Dept::getId).map(s -> s.toString()).collect(Collectors.toList()); + } else { + throw new WebServiceException("该用户没有此权限"); + } + if (StringUtil.isNotBlank(deptId)) { + if (deptList.contains(deptId)) { + createDeptList.add(deptId); + } + } else { + //拿到用户当前及其以下的机构 + createDeptList.addAll(deptList); + } + List list = this.baseMapper.getManageIndex(month, createDeptList); manageIndex.setInTimeNum(list.get(0)); if (!list.get(1).equals(0)) { manageIndex.setInTimeRatio(list.get(0).equals(0) ? 0.0 : Double.valueOf(list.get(0)) / list.get(1)); @@ -840,50 +894,67 @@ public class OperDefectServiceImpl extends BaseServiceImpl getRepeatStatistic(String month) { + private List getRepeatStatistic(String deptId) { List re = new ArrayList<>(); - - List repetStatistics = this.baseMapper.getRepetStatistics(AuthUtil.getDeptId()); - //总缺陷数 - int total = repetStatistics.stream().mapToInt(OperDefectStatisticsCodeDTO::getDefectNum).sum(); - //总重复缺陷数 - int totalRepeat = repetStatistics.stream().filter(s -> s.getDefectNum() > 1 && s.getDefectLevel() != null).collect(Collectors.summingInt(OperDefectStatisticsCodeDTO::getDefectNum)); - //等级重复统计 - Map repeatList = repetStatistics.stream().filter(s -> s.getDefectNum() > 1 && s.getDefectLevel() != null).collect(Collectors.groupingBy(OperDefectStatisticsCodeDTO::getDefectLevel, Collectors.summarizingInt(OperDefectStatisticsCodeDTO::getDefectNum))); - - OperDefectRepeatRatioDTO one = new OperDefectRepeatRatioDTO(); - one.setDefectLevel(DefectConstant.DefectLevelEnum.ONE.getStatus()); - if (repeatList.get(one.getDefectLevel()) != null) { - one.setHappenNum(repeatList.get(one.getDefectLevel()).getSum()); - one.setHappenRatio(one.getHappenNum() / Double.valueOf(total)); - one.setRepeatRatio(one.getHappenNum() / Double.valueOf(totalRepeat)); + List createDeptList = new ArrayList<>(); + List deptList ; + R> res = sysClient.getDeptByCurrentUser(); + if (res.isSuccess() && CollectionUtil.isNotEmpty(res.getData())) { + deptList = res.getData().stream().map(Dept::getId).map(s -> s.toString()).collect(Collectors.toList()); + } else { + throw new WebServiceException("该用户没有此权限"); } - - OperDefectRepeatRatioDTO two = new OperDefectRepeatRatioDTO(); - two.setDefectLevel(DefectConstant.DefectLevelEnum.TWO.getStatus()); - if (repeatList.get(two.getDefectLevel()) != null) { - two.setHappenNum(repeatList.get(two.getDefectLevel()).getSum()); - two.setHappenRatio(two.getHappenNum() / Double.valueOf(total)); - two.setRepeatRatio(two.getHappenNum() / Double.valueOf(totalRepeat)); + if (StringUtil.isNotBlank(deptId)) { + if (deptList.contains(deptId)) { + createDeptList.add(deptId); + } + } else { + //拿到用户当前及其以下的机构 + createDeptList.addAll(deptList); } + if (CollectionUtil.isNotEmpty(createDeptList)) { + List repetStatistics = this.baseMapper.getRepetStatistics(createDeptList); + //总缺陷数 + int total = repetStatistics.stream().mapToInt(OperDefectStatisticsCodeDTO::getDefectNum).sum(); + //总重复缺陷数 + int totalRepeat = repetStatistics.stream().filter(s -> s.getDefectNum() > 1 && s.getDefectLevel() != null).collect(Collectors.summingInt(OperDefectStatisticsCodeDTO::getDefectNum)); + //等级重复统计 + Map repeatList = repetStatistics.stream().filter(s -> s.getDefectNum() > 1 && s.getDefectLevel() != null).collect(Collectors.groupingBy(OperDefectStatisticsCodeDTO::getDefectLevel, Collectors.summarizingInt(OperDefectStatisticsCodeDTO::getDefectNum))); + + OperDefectRepeatRatioDTO one = new OperDefectRepeatRatioDTO(); + one.setDefectLevel(DefectConstant.DefectLevelEnum.ONE.getStatus()); + if (repeatList.get(one.getDefectLevel()) != null) { + one.setHappenNum(repeatList.get(one.getDefectLevel()).getSum()); + one.setHappenRatio(one.getHappenNum() / Double.valueOf(total)); + one.setRepeatRatio(one.getHappenNum() / Double.valueOf(totalRepeat)); + } - OperDefectRepeatRatioDTO three = new OperDefectRepeatRatioDTO(); - three.setDefectLevel(DefectConstant.DefectLevelEnum.THREE.getStatus()); - if (repeatList.get(three.getDefectLevel()) != null) { - three.setHappenNum(repeatList.get(three.getDefectLevel()).getSum()); - three.setHappenRatio(three.getHappenNum() / Double.valueOf(total)); - three.setRepeatRatio(three.getHappenNum() / Double.valueOf(totalRepeat)); - } + OperDefectRepeatRatioDTO two = new OperDefectRepeatRatioDTO(); + two.setDefectLevel(DefectConstant.DefectLevelEnum.TWO.getStatus()); + if (repeatList.get(two.getDefectLevel()) != null) { + two.setHappenNum(repeatList.get(two.getDefectLevel()).getSum()); + two.setHappenRatio(two.getHappenNum() / Double.valueOf(total)); + two.setRepeatRatio(two.getHappenNum() / Double.valueOf(totalRepeat)); + } - OperDefectRepeatRatioDTO addUp = OperDefectRepeatRatioDTO.builder().defectLevel("合计").happenNum(one.getHappenNum() + two.getHappenNum() + three.getHappenNum()).happenRatio(one.getHappenRatio() + two.getHappenRatio() + three.getHappenRatio()).repeatRatio(1.00).build(); - if (addUp.getHappenNum().equals(0L)) { - addUp.setRepeatRatio(0.0); - } + OperDefectRepeatRatioDTO three = new OperDefectRepeatRatioDTO(); + three.setDefectLevel(DefectConstant.DefectLevelEnum.THREE.getStatus()); + if (repeatList.get(three.getDefectLevel()) != null) { + three.setHappenNum(repeatList.get(three.getDefectLevel()).getSum()); + three.setHappenRatio(three.getHappenNum() / Double.valueOf(total)); + three.setRepeatRatio(three.getHappenNum() / Double.valueOf(totalRepeat)); + } - re.addAll(Arrays.asList(one, two, three, addUp)); + OperDefectRepeatRatioDTO addUp = OperDefectRepeatRatioDTO.builder().defectLevel("合计").happenNum(one.getHappenNum() + two.getHappenNum() + three.getHappenNum()).happenRatio(one.getHappenRatio() + two.getHappenRatio() + three.getHappenRatio()).repeatRatio(1.00).build(); + if (addUp.getHappenNum().equals(0L)) { + addUp.setRepeatRatio(0.0); + } + + re.addAll(Arrays.asList(one, two, three, addUp)); + } return re; }