add:车间质量统计分析

This commit is contained in:
zhangzhiqiang
2023-10-10 16:41:52 +08:00
parent e33ca3fae9
commit 24ed153a81
10 changed files with 377 additions and 65 deletions

View File

@@ -12,7 +12,6 @@ import lombok.extern.slf4j.Slf4j;
import org.nl.common.TableDataInfo;
import org.nl.common.anno.Log;
import org.nl.common.domain.query.PageQuery;
import org.nl.wms.analysis_manage.productCapacity.dto.ProductCapQuery;
import org.nl.wms.product_manage.service.workorder.IPdmProduceWorkorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -20,6 +19,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.nl.wms.analysis_manage.productCapacity.service.dto.ProductCapQuery;
import java.util.List;
import java.util.Map;

View File

@@ -1,4 +1,4 @@
package org.nl.wms.analysis_manage.productCapacity.dto;
package org.nl.wms.analysis_manage.productCapacity.service.dto;
import lombok.Data;

View File

@@ -0,0 +1,189 @@
package org.nl.wms.analysis_manage.qlmanage.controller;
/*
* @author ZZQ
* @Date 2023/10/8 10:24
*/
import cn.hutool.core.date.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.nl.common.TableDataInfo;
import org.nl.common.anno.Log;
import org.nl.common.domain.query.PageQuery;
import org.nl.common.utils.MapOf;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.wms.analysis_manage.qlmanage.dto.QualityQuery;
import org.nl.wms.product_manage.service.workorder.IPdmProduceWorkorderService;
import org.nl.wms.product_manage.service.workprocedure.IPdmBiWorkprocedureService;
import org.nl.wms.product_manage.service.workprocedure.dao.PdmBiWorkprocedure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.spring.web.json.Json;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/api/qualityanalysis")
@Slf4j
public class QualityController {
@Autowired
private IPdmProduceWorkorderService workorderService;
@Autowired
private IPdmBiWorkprocedureService workprocedureService;
@GetMapping()
@Log("查询质量分析")
public ResponseEntity<Object> byMaterial(QualityQuery query, PageQuery page) {
long between = 30;
between = checkDateLimit(query, between);
QueryWrapper<PdmBiWorkprocedure> wrapper = new QueryWrapper<>();
if (StringUtils.isEmpty(query.getProduct_area())){
query.setProduct_area("A1");
}
wrapper.eq("product_area",query.getProduct_area());
if (!StringUtils.isEmpty(query.getWorkprocedure_id())){
wrapper.eq("workprocedure_id",query.getWorkprocedure_id());
}
Page<Map<String, Object>> page1 = workprocedureService.pageMaps(page.build(PdmBiWorkprocedure.class), wrapper);
String collect = page1.getRecords().stream().map(a->String.valueOf(a.get("workprocedure_id"))).collect(Collectors.joining("','"));
query.setWorkprocedure_id("('"+collect+"')");
List<Map> list = workorderService.qualityAna(query);
if (!CollectionUtils.isEmpty(list)){
System.out.println("有数据了!!!!"+list.size());
}
Map<String, List<Map>> workprocedure_idMap = list.stream().collect(Collectors.groupingBy(map -> String.valueOf(map.get("workprocedure_id"))));
//数据封装
List<Map<String,Object>> result = new ArrayList<>();
String time = query.getStart_time();
String mo =DatePattern.NORM_MONTH_FORMAT.format(DateUtil.parse(query.getStart_time()));
int minWeek = DateUtil.weekOfYear(DateUtil.parse(query.getStart_time()));
int minYear = DateUtil.year(DateUtil.parse(query.getStart_time()));
for (Map record : page1.getRecords()) {
Map<String, Object> item = new HashMap<>();
List<Map> maps = workprocedure_idMap.get(record.get("workprocedure_id"));
item.put("workprocedure_id",record.get("workprocedure_id"));
item.put("workprocedure_name",record.get("workprocedure_name"));
item.put("workprocedure_code",record.get("workprocedure_code"));
item.put("product_area",record.get("product_area"));
Map<String, Map> collectByAnalysis = new HashMap<>();
if (!CollectionUtils.isEmpty(maps)){
collectByAnalysis = maps.stream().collect(HashMap::new, (k, v) -> k.put(String.valueOf(v.get(query.getAnalysis())), v), HashMap::putAll);
}else {
maps = new ArrayList<>();
}
String weektime = minYear+"_"+minWeek;
String motime = mo;
String datetime = time;
for (int i = 1; i <= between; i++) {
switch (query.getAnalysis()){
case "1":
Map itemData = collectByAnalysis.get(datetime);
if (itemData==null){
maps.add(MapOf.of("order_count", "0", "plan_qty", "0", "real_qty", "0", "nok_qty", "0","nok_rate",0,"header",datetime,"sort",i));
}else {
itemData.put("sort",i);
itemData.put("header",datetime);
}
datetime = DatePattern.NORM_DATE_FORMAT.format(DateUtil.offset(DateUtil.parse(query.getStart_time()),DateField.DAY_OF_MONTH,i));
break;
case "2":
Map weekData = collectByAnalysis.get(weektime);
if (weekData==null){
maps.add(MapOf.of("order_count", "0", "plan_qty", "0", "real_qty", "0", "nok_qty", "0","nok_rate",0,"header",weektime,"sort",i));
}else {
weekData.put("sort",i);
weekData.put("header",weektime);
}
DateTime offset = DateUtil.offset(DateUtil.parse(query.getStart_time()), DateField.WEEK_OF_YEAR, i);
weektime = DateUtil.year(offset)+"_"+DateUtil.weekOfYear(offset);
break;
case "3":
Map moDAta = collectByAnalysis.get(motime);
if (moDAta==null){
maps.add(MapOf.of("order_count", "0", "plan_qty", "0", "real_qty", "0", "nok_qty", "0","nok_rate",0,"header",motime,"sort",i));
}else {
moDAta.put("header",motime);
moDAta.put("sort",i);
}
motime = DatePattern.NORM_MONTH_FORMAT.format(DateUtil.offset(DateUtil.parse(query.getStart_time()),DateField.MONTH,i));
break;
default:throw new BadRequestException("统计周期未定义");
}
}
maps.removeIf(map -> map.get("sort")==null);
maps.sort(Comparator.comparing(a->(int)a.get("sort")));
item.put("item",maps);
item.put("viewData",maps.stream().map(a->a.get("nok_rate")).collect(Collectors.toList()));
item.put("header",maps.stream().map(a->a.get("header")).collect(Collectors.toList()));
item.put("total_real_qty",maps.stream().mapToLong(a->Long.valueOf(String.valueOf(a.get("real_qty")))).sum());
item.put("total_nok_qty",maps.stream().mapToLong(a->Long.valueOf(String.valueOf(a.get("nok_qty")))).sum());
item.put("total_order_count",maps.stream().mapToLong(a->Long.valueOf(String.valueOf(a.get("order_count")))).sum());
result.add(item);
}
page1.setRecords(result);
System.out.println(list.size());
return new ResponseEntity<>(TableDataInfo.build(page1), HttpStatus.OK);
}
private long checkDateLimit(QualityQuery query, long between) {
if (StringUtils.isEmpty(query.getAnalysis())){
query.setAnalysis("1");
}
if (query.getAnalysis().equals("1")){
if (query.getStart_time()!=null){
between = DateUtil.between(DateUtil.parse(query.getStart_time()), DateUtil.parse(query.getEnd_time()), DateUnit.DAY);
if (between >30){
throw new BadRequestException("日汇总请选择时间周期为一个月之内");
}
}else {
query.setEnd_time(DateUtil.today());
query.setStart_time(DatePattern.NORM_DATE_FORMAT.format(DateUtil.lastMonth()));
}
}
if (query.getAnalysis().equals("2")){
if (query.getStart_time()!=null){
between = DateUtil.between(DateUtil.parse(query.getStart_time()), DateUtil.parse(query.getEnd_time()), DateUnit.WEEK);
if (between >30){
throw new BadRequestException("日汇总请选择时间周期为一个月之内");
}
}else {
query.setEnd_time(DateUtil.today());
query.setStart_time(DatePattern.NORM_DATE_FORMAT.format(DateUtil.offset(new Date(), DateField.WEEK_OF_MONTH, -30)));
}
}
if (query.getAnalysis().equals("3")){
if (query.getStart_time()!=null){
between = DateUtil.betweenMonth(DateUtil.parse(query.getStart_time()), DateUtil.parse(query.getEnd_time()),true)+1;
if (between >24){
throw new BadRequestException("月汇总请选择时间周期为2年之内");
}
}else {
query.setEnd_time(DateUtil.today());
query.setStart_time(DatePattern.NORM_DATE_FORMAT.format(DateUtil.offset(new Date(), DateField.MONTH, -24)));
between =24;
}
}
return between;
}
}

View File

@@ -0,0 +1,41 @@
package org.nl.wms.analysis_manage.qlmanage.dto;
import cn.hutool.core.date.DateUtil;
import lombok.Data;
import java.util.Date;
/*
* @author ZZQ
* @Date 2023/10/8 10:25
*/
@Data
public class QualityQuery {
/**
* 分析时间1日2周3月
*/
private String analysis;
/**
* 工序id
*/
private String workprocedure_id;
/**
* 车间
*/
private String product_area;
/**
* 日期
*/
private String[] create_time;
private String start_time;
private String end_time;
public void setCreate_time(String[] create_time) {
this.create_time = create_time;
if (create_time!=null && create_time.length == 2){
this.start_time = create_time[0];
this.end_time =create_time[1];
}
}
}

View File

@@ -5,7 +5,8 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import org.nl.common.TableDataInfo;
import org.nl.common.domain.query.PageQuery;
import org.nl.wms.analysis_manage.productCapacity.dto.ProductCapQuery;
import org.nl.wms.analysis_manage.productCapacity.service.dto.ProductCapQuery;
import org.nl.wms.analysis_manage.qlmanage.dto.QualityQuery;
import org.nl.wms.analysis_manage.scrapRate.service.dto.ScrapRateQuery;
import org.nl.wms.analysis_manage.workingGoods.service.dto.ByProcessQuery;
import org.nl.wms.product_manage.service.workorder.dao.PdmProduceWorkorder;
@@ -178,6 +179,13 @@ public interface IPdmProduceWorkorderService extends IService<PdmProduceWorkorde
*/
List<Map> productCap(ProductCapQuery query);
/**
* 不合格品分析
* @param query
* @return
*/
List<Map> qualityAna(QualityQuery query);
void download(Map map, HttpServletResponse response)
throws IOException;
}

View File

@@ -1,9 +1,9 @@
package org.nl.wms.product_manage.service.workorder.dao.mapper;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.nl.wms.analysis_manage.productCapacity.dto.ProductCapQuery;
import org.nl.wms.analysis_manage.productCapacity.service.dto.ProductCapQuery;
import org.nl.wms.analysis_manage.qlmanage.dto.QualityQuery;
import org.nl.wms.analysis_manage.scrapRate.service.dto.ScrapRateQuery;
import org.nl.wms.analysis_manage.workingGoods.service.dto.ByProcessQuery;
import org.nl.wms.product_manage.service.workorder.dao.PdmProduceWorkorder;
@@ -61,5 +61,11 @@ public interface PdmProduceWorkorderMapper extends BaseMapper<PdmProduceWorkorde
* @return
*/
List<Map> productCap(ProductCapQuery query);
/**
* 工序质量统计
* @param query
* @return
*/
List<Map> qualityAnalysis(QualityQuery query);
}

View File

@@ -339,6 +339,46 @@
GROUP BY
device_code
</select>
<select id="qualityAnalysis" resultType="java.util.Map">
select COUNT(pdm_produce_workorder.workprocedure_id) order_count,
pdm_produce_workorder.workprocedure_id,
YEAR(pdm_produce_workorder.create_time) '4',
DATE_FORMAT(pdm_produce_workorder.create_time,'%Y-%m') '3',
CONCAT(YEAR(pdm_produce_workorder.create_time),"_",WEEK(pdm_produce_workorder.create_time)) '2',
DATE_FORMAT(pdm_produce_workorder.create_time,'%Y-%m-%d') '1',
sum(plan_qty) plan_qty,
SUM(real_qty) real_qty,
SUM(nok_qty) nok_qty,
IF( SUM(real_qty) > 0, sum( nok_qty )*100 / sum( real_qty ), 0 ) AS nok_rate
from pdm_produce_workorder
LEFT JOIN pdm_bi_workprocedure ON pdm_bi_workprocedure.workprocedure_id = pdm_produce_workorder.workprocedure_id
where workorder_status in ('6','7')
<if test="workprocedure_id != null and workprocedure_id != ''">
and pdm_produce_workorder.workprocedure_id in ${workprocedure_id}
</if>
<if test="start_time != null and start_time != ''">
and pdm_produce_workorder.create_time >= #{start_time}
</if>
<if test="product_area != null and product_area != ''">
and pdm_produce_workorder.product_area >= #{product_area}
</if>
<if test="end_time != null and end_time != ''">
and #{end_time} >= pdm_produce_workorder.create_time
</if>
GROUP BY pdm_produce_workorder.workprocedure_id
<choose>
<when test='analysis == "2"'>
,CONCAT(YEAR(pdm_produce_workorder.create_time),"_",WEEK(pdm_produce_workorder.create_time))
</when>
<when test='analysis == "3"'>
,DATE_FORMAT(pdm_produce_workorder.create_time,'%Y-%m')
</when>
<otherwise>
,DATE(pdm_produce_workorder.create_time)
</otherwise>
</choose>
</select>
</mapper>

View File

@@ -7,7 +7,6 @@ import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -28,7 +27,8 @@ import org.nl.common.utils.api.RestBusinessTemplate;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.FileUtil;
import org.nl.modules.system.util.CodeUtil;
import org.nl.wms.analysis_manage.productCapacity.dto.ProductCapQuery;
import org.nl.wms.analysis_manage.productCapacity.service.dto.ProductCapQuery;
import org.nl.wms.analysis_manage.qlmanage.dto.QualityQuery;
import org.nl.wms.analysis_manage.scrapRate.service.dto.ScrapRateQuery;
import org.nl.wms.analysis_manage.workingGoods.service.dto.ByProcessQuery;
import org.nl.wms.ext_manage.acs.service.WmsToAcsService;
@@ -36,7 +36,6 @@ import org.nl.wms.masterdata_manage.master.service.classstandard.IMdPbClassstand
import org.nl.wms.masterdata_manage.service.material.IMdMeMaterialbaseService;
import org.nl.wms.masterdata_manage.service.material.dao.MdMeMaterialbase;
import org.nl.wms.mps_manage.other.service.dto.ProduceshiftorderDto;
import org.nl.wms.mps_manage.saleorder.service.IMpsSaleOrderService;
import org.nl.wms.mps_manage.saleorder.service.dao.MpsSaleOrder;
import org.nl.wms.mps_manage.saleorder.service.impl.MpsSaleOrderServiceImpl;
import org.nl.wms.product_manage.service.workorder.dao.WorkorderRecord;
@@ -893,4 +892,10 @@ public class IPdmProduceWorkorderServiceImpl extends ServiceImpl<PdmProduceWorko
List<Map> maps = this.baseMapper.productCap(query);
return maps;
}
@Override
public List<Map> qualityAna(QualityQuery query) {
List<Map> maps = this.baseMapper.qualityAnalysis(query);
return maps;
}
}