Browse Source

月度缺陷统计增加机构筛选项

zhongwei
ty 11 months ago
parent
commit
8107228ce5
  1. 8
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/OperDefectController.java
  2. 8
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperDefectMapper.java
  3. 56
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperDefectMapper.xml
  4. 4
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperDefectService.java
  5. 171
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperDefectServiceImpl.java

8
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<Map<String, Object>> getDefectStatistics(@ApiParam(value = "month 格式:2021-01", required = true) @RequestParam String month) {
Map<String, Object> defectStatistics = defectService.getDefectStatistics(month);
public R<Map<String, Object>> getDefectStatistics(@ApiParam(value = "month 格式:2021-01", required = true) @RequestParam String month, @RequestParam String deptId) {
Map<String, Object> 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<String, Object> result = new HashMap<>();
try {
defectService.exportFualtMonthExcel(response, month);
defectService.exportFualtMonthExcel(response, month, deptId);
result.put("success", "true");
} catch (IOException e) {
result.put("success", "false");

8
hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/mapper/OperDefectMapper.java

@ -27,7 +27,7 @@ public interface OperDefectMapper extends UserDataScopeBaseMapper<OperDefectEnti
* @return
*/
List<OperDefectStatisticsStatusDTO> getStatisticByMonth(@Param("month") String month,
@Param("createDept") String createDept);
@Param("createDept") List<String> createDept);
/**
* 当年1月 - 当前月获取缺陷等级统计数据
@ -37,13 +37,13 @@ public interface OperDefectMapper extends UserDataScopeBaseMapper<OperDefectEnti
*/
List<OperDefectStatisticsStatusDTO> getStatisticBySeveralMonth(@Param("firstMonth") String firstMonth,
@Param("endMonth") String endMonth,
@Param("createDept") String createDept);
@Param("createDept") List<String> createDept);
/**
* 获取重复缺陷等级统计数据
* @return
*/
List<OperDefectStatisticsCodeDTO> getRepetStatistics(@Param("createDept") String createDept);
List<OperDefectStatisticsCodeDTO> getRepetStatistics(@Param("createDept") List<String> createDept);
/**
* 获取按月管理指标统计数据
@ -52,7 +52,7 @@ public interface OperDefectMapper extends UserDataScopeBaseMapper<OperDefectEnti
* @return
*/
List<Integer> getManageIndex(@Param("month") String month,
@Param("createDept") String createDept);
@Param("createDept") List<String> createDept);
List<OperDefectEntity> selectDefectList(String emCode,List<String> list);

56
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}
<if test="createDept != null and createDept != ''">
AND D.CREATE_DEPT = #{createDept}
<if test="createDept != null and createDept.size > 0">
and D.CREATE_DEPT in
<foreach collection="createDept" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
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}
<if test="createDept != null and createDept != ''">
AND D.CREATE_DEPT = #{createDept}
<if test="createDept != null and createDept.size > 0">
and D.CREATE_DEPT in
<foreach collection="createDept" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
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
<if test="createDept != null and createDept != ''">
AND D.CREATE_DEPT = #{createDept}
<if test="createDept != null and createDept.size > 0">
and D.CREATE_DEPT in
<foreach collection="createDept" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
GROUP BY P.DEFECT_LEVEL,P.FAULT_CODE
</select>
@ -47,8 +56,11 @@
WHERE DATE_FORMAT(D.CREATE_TIME,'%Y-%m') = #{month}
AND D.HANDLE_STATUS = 1
AND D.ACT_END_TIME &lt;= P.PLAN_END_TIME
<if test="createDept != null and createDept != ''">
AND D.CREATE_DEPT = #{createDept}
<if test="createDept != null and createDept.size > 0">
and D.CREATE_DEPT in
<foreach collection="createDept" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
)
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
<if test="createDept != null and createDept != ''">
AND D.CREATE_DEPT = #{createDept}
<if test="createDept != null and createDept.size > 0">
and D.CREATE_DEPT in
<foreach collection="createDept" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
)
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
<if test="createDept != null and createDept != ''">
AND D.CREATE_DEPT = #{createDept}
<if test="createDept != null and createDept.size > 0">
and D.CREATE_DEPT in
<foreach collection="createDept" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
)
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') &lt; CONCAT(#{month}, '-01')
AND D.HANDLE_STATUS = 0
<if test="createDept != null and createDept != ''">
AND D.CREATE_DEPT = #{createDept}
<if test="createDept != null and createDept.size > 0">
and D.CREATE_DEPT in
<foreach collection="createDept" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
)
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}
<if test="createDept != null and createDept != ''">
AND D.CREATE_DEPT = #{createDept}
<if test="createDept != null and createDept.size > 0">
and D.CREATE_DEPT in
<foreach collection="createDept" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
)
</select>

4
hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperDefectService.java

@ -43,7 +43,7 @@ public interface IOperDefectService extends BaseService<OperDefectEntity> {
* 获取缺陷的统计月报
* @param month 格式"2021-01"
*/
Map<String, Object> getDefectStatistics(String month);
Map<String, Object> getDefectStatistics(String month,String deptId);
/**
* 导出缺陷统计月报报表
@ -51,7 +51,7 @@ public interface IOperDefectService extends BaseService<OperDefectEntity> {
* @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<OperDefectEntity> getDefectList(String emCode,List<String> list);

171
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<OperDefectMapper, Ope
private final IUserClient userClient;
private final ISysClient sysClient;
private final OperPhenomenonMapper operPhenomenonMapper;
/**
@ -118,6 +123,7 @@ public class OperDefectServiceImpl extends BaseServiceImpl<OperDefectMapper, Ope
}
}
@Override
public LambdaQueryWrapper<OperDefectEntity> getQueryWrapper(OperDefectVO defectVO) {
LambdaQueryWrapper<OperDefectEntity> queryWrapper = Condition.getQueryWrapper(new OperDefectEntity(), defectVO);
@ -180,6 +186,7 @@ public class OperDefectServiceImpl extends BaseServiceImpl<OperDefectMapper, Ope
queryWrapper.orderByDesc(OperDefectEntity::getCreateTime);
return queryWrapper;
}
/**
* 处理问题
*
@ -238,19 +245,19 @@ public class OperDefectServiceImpl extends BaseServiceImpl<OperDefectMapper, Ope
* @param month 格式"2021-01"
*/
@Override
public Map<String, Object> getDefectStatistics(String month) {
public Map<String, Object> getDefectStatistics(String month, String deptId) {
Map<String, Object> 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<String, Object> re = new HashMap<>();
re = this.getDefectStatistics(month);
re = this.getDefectStatistics(month, deptId);
//获取数据
List<OperDefectRatioDTO> currentMonth = (List<OperDefectRatioDTO>) re.get("currentMonth");
List<OperDefectRatioDTO> severalMonths = (List<OperDefectRatioDTO>) re.get("severalMonths");
@ -785,8 +792,24 @@ public class OperDefectServiceImpl extends BaseServiceImpl<OperDefectMapper, Ope
* @param month
* @return
*/
private List<OperDefectRatioDTO> getCurrentMonthStatic(String month) {
List<OperDefectStatisticsStatusDTO> statisticByMonth = this.baseMapper.getStatisticByMonth(month, AuthUtil.getDeptId());
private List<OperDefectRatioDTO> getCurrentMonthStatic(String month, String deptId) {
List<String> createDeptList = new ArrayList<>();
List<String> deptList = new ArrayList<>();
R<List<Dept>> 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<OperDefectStatisticsStatusDTO> statisticByMonth = this.baseMapper.getStatisticByMonth(month, createDeptList);
return getRatioStatic(statisticByMonth);
}
@ -796,7 +819,7 @@ public class OperDefectServiceImpl extends BaseServiceImpl<OperDefectMapper, Ope
* @param month "2021-01"
* @return
*/
private List<OperDefectRatioDTO> getStatisticBySeveralMonth(String month) {
private List<OperDefectRatioDTO> 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<OperDefectMapper, Ope
throw new ServiceException("日期转换失败");
}
log.error("firstMonth:" + firstMonth + "; end=" + dateFormat.format(date));
List<OperDefectStatisticsStatusDTO> statisticBySeveralMonth = this.baseMapper.getStatisticBySeveralMonth(firstMonth, dateFormat.format(date), AuthUtil.getDeptId());
List<String> createDeptList = new ArrayList<>();
List<String> deptList = new ArrayList<>();
R<List<Dept>> 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<OperDefectStatisticsStatusDTO> statisticBySeveralMonth = this.baseMapper.getStatisticBySeveralMonth(firstMonth, dateFormat.format(date), createDeptList);
return getRatioStatic(statisticBySeveralMonth);
}
@ -822,9 +860,25 @@ public class OperDefectServiceImpl extends BaseServiceImpl<OperDefectMapper, Ope
* @param month
* @return
*/
private OperDefectManageIndexDTO getManageIndexStatistic(String month) {
private OperDefectManageIndexDTO getManageIndexStatistic(String month, String deptId) {
OperDefectManageIndexDTO manageIndex = new OperDefectManageIndexDTO();
List<Integer> list = this.baseMapper.getManageIndex(month, AuthUtil.getDeptId());
List<String> createDeptList = new ArrayList<>();
List<String> deptList = new ArrayList<>();
R<List<Dept>> 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<Integer> 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<OperDefectMapper, Ope
/**
* 获取重复缺陷等级统计数据
*
* @param month
* @param deptId
* @return
*/
private List<OperDefectRepeatRatioDTO> getRepeatStatistic(String month) {
private List<OperDefectRepeatRatioDTO> getRepeatStatistic(String deptId) {
List<OperDefectRepeatRatioDTO> re = new ArrayList<>();
List<OperDefectStatisticsCodeDTO> 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<String, IntSummaryStatistics> 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<String> createDeptList = new ArrayList<>();
List<String> deptList ;
R<List<Dept>> 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<OperDefectStatisticsCodeDTO> 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<String, IntSummaryStatistics> 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;
}

Loading…
Cancel
Save