|
@@ -1,12 +1,11 @@
|
|
|
package org.jeecg.modules.ProdPlan.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
-import org.apache.poi.util.Units;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFPicture;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.jeecg.modules.Contact.entity.Contact;
|
|
@@ -87,9 +86,9 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
} else {
|
|
|
throw new IllegalArgumentException("不支持的文件格式,请使用.xlsx或.xls文件");
|
|
|
}
|
|
|
- //第一张表
|
|
|
+ Sheet sheet = null;
|
|
|
for(int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum ++) {
|
|
|
- Sheet sheet = workbook.getSheetAt(sheetNum);
|
|
|
+ sheet = workbook.getSheetAt(sheetNum);
|
|
|
//第二行为表头
|
|
|
Row headerRow = sheet.getRow(1);
|
|
|
if (headerRow == null) {
|
|
@@ -115,7 +114,7 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
List<DestRule> destRuleList = destRuleService.list();
|
|
|
Map<String, String> destRules = destRuleList.stream().collect(Collectors.toMap(DestRule::getDestination, DestRule::getSchedule));
|
|
|
List<ReasonRule> reasonRuleList = reasonRuleService.list();
|
|
|
- Map<String, String> reasonRules = reasonRuleList.stream().collect(Collectors.toMap(ReasonRule::getComment2, ReasonRule::getRemark));
|
|
|
+ Map<String, ReasonRule> reasonRules = reasonRuleList.stream().collect(Collectors.toMap(i-> i.getDept()+" "+i.getReason(), i->i));
|
|
|
|
|
|
// 清洗数据,按规则匹配规定交付时间,计算超出时间,并转换延期原因
|
|
|
for (int i = 0; i < delayProducts.size(); i++) {
|
|
@@ -149,11 +148,12 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
String week = "W" + delayProduct.getDueDate().get(WeekFields.ISO.weekOfYear());
|
|
|
delayProduct.setWeek(week);
|
|
|
|
|
|
- reasonRules.forEach((reason,remark)->{
|
|
|
+ reasonRules.forEach((reason,rule)->{
|
|
|
Pattern pattern = Pattern.compile("^"+reason+"$");
|
|
|
- Matcher matcher = pattern.matcher(delayProduct.getComment2());
|
|
|
+ Matcher matcher = pattern.matcher(delayProduct.getComment1());
|
|
|
if (matcher.matches()) {
|
|
|
- String newRemark = matcher.replaceAll(remark);
|
|
|
+ delayProduct.setDept(rule.getDept());
|
|
|
+ String newRemark = matcher.replaceAll(rule.getRemark());
|
|
|
delayProduct.setRemark(newRemark);
|
|
|
}
|
|
|
});
|
|
@@ -161,28 +161,24 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
//没匹配到,且商品为延期商品,置部门及原因为OTHER
|
|
|
if(delayProduct.getRemark() == null && delayProduct.getOverdueDays() != null && delayProduct.getOverdueDays() > 0) {
|
|
|
delayProduct.setRemark("OTHER");
|
|
|
- delayProduct.setComment1("OTHER");
|
|
|
- delayProduct.setComment2("OTHER");
|
|
|
+ delayProduct.setDept("OTHER");
|
|
|
}
|
|
|
}
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
|
|
|
- List<DelayProduct> overDueList = delayProducts.stream().filter(i -> i.getRemark()!=null && i.getOverdueDays()!=null && i.getOverdueDays() > 0).collect(Collectors.toList());
|
|
|
-
|
|
|
- try {
|
|
|
- remarkDelayProduct(overDueList, filePath);
|
|
|
- }catch (Exception e) {
|
|
|
- log.error("源文件标注出错", e);
|
|
|
- }
|
|
|
+ List<DelayProduct> overDueList = delayProducts.stream().filter(i -> i.getRemark()!=null && i.getOverdueDays()!=null && i.getOverdueDays() > 0).collect(Collectors.toList());
|
|
|
|
|
|
- return overDueList;
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return null;
|
|
|
- }
|
|
|
+ remarkDelayProduct(overDueList, filePath);
|
|
|
+ delayProducts=null;
|
|
|
+ return overDueList;
|
|
|
}
|
|
|
|
|
|
- private void remarkDelayProduct(List<DelayProduct> overDueList, String filePath) throws Exception{
|
|
|
- Map<String, String> delayProduct = overDueList.stream().collect(Collectors.toMap(DelayProduct::getDemandId, DelayProduct::getDemandId));
|
|
|
+ private void remarkDelayProduct(List<DelayProduct> overDueList, String filePath){
|
|
|
+ Map<String, List<DelayProduct>> delayProduct = overDueList.stream().collect(Collectors.groupingBy(DelayProduct::getDemandId, Collectors.toList()));
|
|
|
try (FileInputStream fis = new FileInputStream(filePath)) {
|
|
|
Workbook workbook;
|
|
|
// 根据文件扩展名选择合适的工作簿类型
|
|
@@ -193,9 +189,9 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
} else {
|
|
|
throw new IllegalArgumentException("不支持的文件格式,请使用.xlsx或.xls文件");
|
|
|
}
|
|
|
-
|
|
|
+ Sheet sheet = null;
|
|
|
for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
|
|
|
- Sheet sheet = workbook.getSheetAt(sheetNum);
|
|
|
+ sheet = workbook.getSheetAt(sheetNum);
|
|
|
//第二行为表头
|
|
|
Row headerRow = sheet.getRow(1);
|
|
|
if (headerRow == null) {
|
|
@@ -205,8 +201,6 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
Map<String, Integer> columnIndices = parseHeadRow(headerRow);
|
|
|
|
|
|
CellStyle cellStyle = workbook.createCellStyle();
|
|
|
- cellStyle.setFillForegroundColor(IndexedColors.RED1.getIndex());
|
|
|
- cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
//从第三行开始读取数据
|
|
|
for (int i = 2; i <= sheet.getLastRowNum(); i++) {
|
|
|
Row row = sheet.getRow(i);
|
|
@@ -216,6 +210,9 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
if (delayProduct.containsKey(demandId)) {
|
|
|
for(int cellNum = 0; cellNum < row.getLastCellNum(); cellNum ++) {
|
|
|
Cell cell = row.getCell(cellNum);
|
|
|
+ cellStyle.cloneStyleFrom( cell.getCellStyle());
|
|
|
+ cellStyle.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.getIndex());
|
|
|
+ cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
cell.setCellStyle(cellStyle);
|
|
|
}
|
|
|
}
|
|
@@ -226,6 +223,10 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("源文件标注出错", e);
|
|
|
+ }finally {
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -401,63 +402,19 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public XSSFWorkbook report(String id, byte[] pie) {
|
|
|
+ public XSSFWorkbook report(String id, byte[] pie, byte[] barLine) {
|
|
|
ProdPlan prodPlan = this.getById(id);
|
|
|
int currentWeek = prodPlan.getPlanDate().get(WeekFields.ISO.weekOfYear());
|
|
|
List<ReportDetailVo> detailVos = new ArrayList<>();
|
|
|
- // TODO 根据计划日期增加当前周期查询条件
|
|
|
- List<DelayProduct> delayProductList = this.delayProductService.list();
|
|
|
- delayProductList.forEach(delayProduct -> {
|
|
|
- ReportDetailVo detailVo = new ReportDetailVo();
|
|
|
- BeanUtils.copyProperties(delayProduct, detailVo);
|
|
|
- detailVo.setPst(delayProduct.getPst().format(DateTimeFormatter.ofPattern("MM/dd")));
|
|
|
- detailVo.setDueDate(delayProduct.getDueDate().format(DateTimeFormatter.ofPattern("MM/dd")));
|
|
|
- LocalDate endDate = delayProduct.getPst();
|
|
|
- LocalDate startDate = delayProduct.getDueDate();
|
|
|
- while(endDate.isAfter(startDate)){
|
|
|
- int startWeek = startDate.get(WeekFields.ISO.weekOfYear());
|
|
|
- if(startWeek==currentWeek-3){
|
|
|
- detailVo.setWeek1(detailVo.getPo());
|
|
|
- } else if (startWeek==currentWeek-2) {
|
|
|
- detailVo.setWeek2(detailVo.getPo());
|
|
|
- } else if (startWeek==currentWeek-1) {
|
|
|
- detailVo.setWeek3(detailVo.getPo());
|
|
|
- } else if (startWeek==currentWeek) {
|
|
|
- detailVo.setWeek4(detailVo.getPo());
|
|
|
- } else if (startWeek==currentWeek+1) {
|
|
|
- detailVo.setWeek5(detailVo.getPo());
|
|
|
- } else if (startWeek==currentWeek+2) {
|
|
|
- detailVo.setWeek6(detailVo.getPo());
|
|
|
- }
|
|
|
- startDate = startDate.plusWeeks(1l);
|
|
|
- }
|
|
|
- detailVos.add(detailVo);
|
|
|
- });
|
|
|
|
|
|
- List<DefectiveProduct> defectiveProductList = this.defectiveProductService.list();
|
|
|
- defectiveProductList.forEach(defectiveProduct -> {
|
|
|
- ReportDetailVo detailVo = new ReportDetailVo();
|
|
|
- BeanUtils.copyProperties(defectiveProduct, detailVo);
|
|
|
- detailVo.setPo(defectiveProduct.getPo());
|
|
|
- detailVo.setDueDate(defectiveProduct.getDueDate().format(DateTimeFormatter.ofPattern("MM/dd")));
|
|
|
- int week = Integer.valueOf(defectiveProduct.getWeek().substring(1));
|
|
|
- if(week==currentWeek-3){
|
|
|
- detailVo.setWeek1(detailVo.getPo());
|
|
|
- } else if (week==currentWeek-2) {
|
|
|
- detailVo.setWeek2(detailVo.getPo());
|
|
|
- } else if (week==currentWeek-1) {
|
|
|
- detailVo.setWeek3(detailVo.getPo());
|
|
|
- } else if (week==currentWeek) {
|
|
|
- detailVo.setWeek4(detailVo.getPo());
|
|
|
- } else if (week==currentWeek+1) {
|
|
|
- detailVo.setWeek5(detailVo.getPo());
|
|
|
- } else if (week==currentWeek+2) {
|
|
|
- detailVo.setWeek6(detailVo.getPo());
|
|
|
- }
|
|
|
- detailVos.add(detailVo);
|
|
|
- });
|
|
|
+ List<ReportDetailVo> detailVoList = getReportDetailVos(prodPlan, currentWeek);
|
|
|
+
|
|
|
+ // 以第四周为当前周,过滤影响前一周及后两周周的数据
|
|
|
+ detailVos = detailVoList.stream().filter(i->{
|
|
|
+ return i.getWeek3()!=null||i.getWeek4()!=null||i.getWeek5()!=null||i.getWeek6()!=null;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
List<DeliveredQuantity> deliveredQuantityList = this.deliveredQuantityService.list();
|
|
|
- // TODO 按照计划日期,过滤影响到当前周的数据
|
|
|
|
|
|
|
|
|
XSSFWorkbook workbook=new XSSFWorkbook();
|
|
@@ -467,7 +424,8 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
sheet.setPrintGridlines(false);
|
|
|
sheet.setDefaultRowHeightInPoints(20f);
|
|
|
try {
|
|
|
- insertImageToSheetAtPosition(workbook,sheet,pie,"pie",0,0);
|
|
|
+ insertImageToSheetAtPosition(workbook,sheet,pie,"pie",0,0,6,17);
|
|
|
+ insertImageToSheetAtPosition(workbook,sheet,barLine,"barLine",0,7,10,18);
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
@@ -482,7 +440,7 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
CellStyle totalStyle = createTotalStyle(workbook);
|
|
|
CellStyle groupStyle = createGroupStyle(workbook);
|
|
|
|
|
|
- int currentRow = 30;
|
|
|
+ int currentRow = 18;
|
|
|
int startColumn = 1;
|
|
|
|
|
|
// 第一部分:原因部门数据
|
|
@@ -490,12 +448,12 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
dataStyle, percentStyle, totalStyle, groupStyle);
|
|
|
List<ReportDetailVo> sumDetailVos = new ArrayList<>();
|
|
|
ReportDetailVo totalVo = getSummaryDetailVo(detailVos);
|
|
|
- totalVo.setComment1("合计");
|
|
|
+ totalVo.setDept("合计");
|
|
|
|
|
|
- Map<String, List<ReportDetailVo>> deptMap = detailVos.stream().collect(Collectors.groupingBy(ReportDetailVo::getComment1, Collectors.toList()));
|
|
|
+ Map<String, List<ReportDetailVo>> deptMap = detailVos.stream().collect(Collectors.groupingBy(ReportDetailVo::getDept, Collectors.toList()));
|
|
|
deptMap.forEach((dept,deptList)->{
|
|
|
ReportDetailVo subTotalVo = getSummaryDetailVo(deptList);
|
|
|
- subTotalVo.setComment1(dept);
|
|
|
+ subTotalVo.setDept(dept);
|
|
|
subTotalVo.setLine("小计");
|
|
|
subTotalVo.setPercent((double)subTotalVo.getPo()/totalVo.getPo());
|
|
|
|
|
@@ -503,7 +461,7 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
lineMap.forEach((line,toolMap)->{
|
|
|
toolMap.forEach((tool,toolList)->{
|
|
|
ReportDetailVo toolVo = getSummaryDetailVo(toolList);
|
|
|
- toolVo.setComment1(dept);
|
|
|
+ toolVo.setDept(dept);
|
|
|
toolVo.setLine(line);
|
|
|
toolVo.setTool(tool);
|
|
|
toolVo.setPercent((double)toolVo.getPo()/subTotalVo.getPo());
|
|
@@ -523,7 +481,7 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
int lineStartRow = currentRow;
|
|
|
CellStyle cellStyle = dataStyle;
|
|
|
for(ReportDetailVo detailVo:sumDetailVos){
|
|
|
- if("合计".equals(detailVo.getComment1())) {
|
|
|
+ if("合计".equals(detailVo.getDept())) {
|
|
|
cellStyle = totalStyle;
|
|
|
}else if("小计".equals(detailVo.getLine())) {
|
|
|
cellStyle = subtotalStyle;
|
|
@@ -532,17 +490,17 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
}
|
|
|
Row dataRow = sheet.createRow(currentRow++);
|
|
|
int currentColumn = startColumn;
|
|
|
- createCell(dataRow,currentColumn++,detailVo.getComment1(),cellStyle);
|
|
|
+ createCell(dataRow,currentColumn++,detailVo.getDept(),cellStyle);
|
|
|
createCell(dataRow,currentColumn++,"",cellStyle);
|
|
|
createCell(dataRow,currentColumn++,"",cellStyle);
|
|
|
- if (!currentDept.equals(detailVo.getComment1())) {
|
|
|
+ if (!currentDept.equals(detailVo.getDept())) {
|
|
|
if (!currentDept.isEmpty()) {
|
|
|
sheet.addMergedRegion(new CellRangeAddress(deptStartRow, currentRow-2, startColumn, startColumn+2));
|
|
|
}
|
|
|
- currentDept = detailVo.getComment1();
|
|
|
+ currentDept = detailVo.getDept();
|
|
|
deptStartRow = currentRow-1;
|
|
|
}
|
|
|
- if("合计".equals(detailVo.getComment1())){
|
|
|
+ if("合计".equals(detailVo.getDept())){
|
|
|
sheet.addMergedRegion(new CellRangeAddress(currentRow-1, currentRow-1, startColumn, startColumn+2));
|
|
|
}
|
|
|
|
|
@@ -561,7 +519,7 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
createCell(dataRow,currentColumn++,detailVo.getWeek5()==null?0:detailVo.getWeek5(),cellStyle);
|
|
|
createCell(dataRow,currentColumn++,detailVo.getWeek6()==null?0:detailVo.getWeek6(),cellStyle);
|
|
|
|
|
|
- if("合计".equals(detailVo.getComment1())) {
|
|
|
+ if("合计".equals(detailVo.getDept())) {
|
|
|
createCell(dataRow,currentColumn++,detailVo.getPercent()==null?0:detailVo.getPercent(),cellStyle);
|
|
|
}else if("小计".equals(detailVo.getLine())) {
|
|
|
createCell(dataRow,currentColumn++,detailVo.getPercent()==null?0:detailVo.getPercent(),redPercentStyle);
|
|
@@ -677,7 +635,7 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
createCell(dataRow,currentColumn++,detailVo.getPst(),cellStyle);
|
|
|
createCell(dataRow,currentColumn++,detailVo.getDueDate(),cellStyle);
|
|
|
createCell(dataRow,currentColumn++,detailVo.getOverdueDays()==null?0:detailVo.getOverdueDays(),cellStyle);
|
|
|
- createCell(dataRow,currentColumn++,detailVo.getComment1(),cellStyle);
|
|
|
+ createCell(dataRow,currentColumn++,detailVo.getDept(),cellStyle);
|
|
|
createCell(dataRow,currentColumn++,detailVo.getRemark(),cellStyle);
|
|
|
}
|
|
|
|
|
@@ -686,6 +644,66 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
return workbook;
|
|
|
}
|
|
|
|
|
|
+ @NotNull
|
|
|
+ private List<ReportDetailVo> getReportDetailVos(ProdPlan prodPlan, int currentWeek) {
|
|
|
+ QueryWrapper<DelayProduct> delayProductQueryWrapper = new QueryWrapper<>();
|
|
|
+ delayProductQueryWrapper.between("pst", prodPlan.getPlanDate().minusWeeks(4), prodPlan.getPlanDate().plusWeeks(3));
|
|
|
+ List<DelayProduct> delayProductList = this.delayProductService.list(delayProductQueryWrapper);
|
|
|
+ List<ReportDetailVo> detailVoList = new ArrayList<>();
|
|
|
+ delayProductList.forEach(delayProduct -> {
|
|
|
+ ReportDetailVo detailVo = new ReportDetailVo();
|
|
|
+ BeanUtils.copyProperties(delayProduct, detailVo);
|
|
|
+ detailVo.setPst(delayProduct.getPst().format(DateTimeFormatter.ofPattern("MM/dd")));
|
|
|
+ detailVo.setDueDate(delayProduct.getDueDate().format(DateTimeFormatter.ofPattern("MM/dd")));
|
|
|
+ LocalDate endDate = delayProduct.getPst();
|
|
|
+ LocalDate startDate = delayProduct.getDueDate();
|
|
|
+ while(endDate.isAfter(startDate)){
|
|
|
+ int startWeek = startDate.get(WeekFields.ISO.weekOfYear());
|
|
|
+ if(startWeek== currentWeek -3){
|
|
|
+ detailVo.setWeek1(detailVo.getPo());
|
|
|
+ } else if (startWeek== currentWeek -2) {
|
|
|
+ detailVo.setWeek2(detailVo.getPo());
|
|
|
+ } else if (startWeek== currentWeek -1) {
|
|
|
+ detailVo.setWeek3(detailVo.getPo());
|
|
|
+ } else if (startWeek== currentWeek) {
|
|
|
+ detailVo.setWeek4(detailVo.getPo());
|
|
|
+ } else if (startWeek== currentWeek +1) {
|
|
|
+ detailVo.setWeek5(detailVo.getPo());
|
|
|
+ } else if (startWeek== currentWeek +2) {
|
|
|
+ detailVo.setWeek6(detailVo.getPo());
|
|
|
+ }
|
|
|
+ startDate = startDate.plusWeeks(1l);
|
|
|
+ }
|
|
|
+ detailVoList.add(detailVo);
|
|
|
+ });
|
|
|
+
|
|
|
+ QueryWrapper<DefectiveProduct> defectiveProductQueryWrapper = new QueryWrapper<>();
|
|
|
+ delayProductQueryWrapper.between("due_date", prodPlan.getPlanDate().minusWeeks(4), prodPlan.getPlanDate().plusWeeks(3));
|
|
|
+ List<DefectiveProduct> defectiveProductList = this.defectiveProductService.list(defectiveProductQueryWrapper);
|
|
|
+ defectiveProductList.forEach(defectiveProduct -> {
|
|
|
+ ReportDetailVo detailVo = new ReportDetailVo();
|
|
|
+ BeanUtils.copyProperties(defectiveProduct, detailVo);
|
|
|
+ detailVo.setPo(defectiveProduct.getPo());
|
|
|
+ detailVo.setDueDate(defectiveProduct.getDueDate().format(DateTimeFormatter.ofPattern("MM/dd")));
|
|
|
+ int week = Integer.valueOf(defectiveProduct.getWeek().substring(1));
|
|
|
+ if(week== currentWeek -3){
|
|
|
+ detailVo.setWeek1(detailVo.getPo());
|
|
|
+ } else if (week== currentWeek -2) {
|
|
|
+ detailVo.setWeek2(detailVo.getPo());
|
|
|
+ } else if (week== currentWeek -1) {
|
|
|
+ detailVo.setWeek3(detailVo.getPo());
|
|
|
+ } else if (week== currentWeek) {
|
|
|
+ detailVo.setWeek4(detailVo.getPo());
|
|
|
+ } else if (week== currentWeek +1) {
|
|
|
+ detailVo.setWeek5(detailVo.getPo());
|
|
|
+ } else if (week== currentWeek +2) {
|
|
|
+ detailVo.setWeek6(detailVo.getPo());
|
|
|
+ }
|
|
|
+ detailVoList.add(detailVo);
|
|
|
+ });
|
|
|
+ return detailVoList;
|
|
|
+ }
|
|
|
+
|
|
|
@NotNull
|
|
|
private ReportDetailVo getSummaryDetailVo(List<ReportDetailVo> detailVos) {
|
|
|
Integer poQty = detailVos.stream().map(ReportDetailVo::getPo).filter(Objects::nonNull).reduce(0, Integer::sum);
|
|
@@ -706,7 +724,7 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
return totalVo;
|
|
|
}
|
|
|
private void insertImageToSheetAtPosition(Workbook workbook, Sheet sheet, byte[] imageBytes,
|
|
|
- String fileName, int startRow, int startCol) throws Exception {
|
|
|
+ String fileName, int startRow, int startCol, int scaleX, int scaleY) throws Exception {
|
|
|
int pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_PNG);
|
|
|
Drawing drawing = sheet.createDrawingPatriarch();
|
|
|
ClientAnchor anchor = workbook.getCreationHelper().createClientAnchor();
|
|
@@ -717,7 +735,7 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
|
|
|
|
|
|
XSSFPicture picture = (XSSFPicture)drawing.createPicture(anchor, pictureIdx);
|
|
|
- picture.resize(16, 30);
|
|
|
+ picture.resize(scaleX, scaleY);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -989,8 +1007,8 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
sheet.autoSizeColumn(i);
|
|
|
// 设置最小和最大宽度
|
|
|
int currentWidth = sheet.getColumnWidth(i);
|
|
|
- if (currentWidth < 2000) {
|
|
|
- sheet.setColumnWidth(i, 2000); // 最小宽度
|
|
|
+ if (currentWidth < 2500) {
|
|
|
+ sheet.setColumnWidth(i, 2500); // 最小宽度
|
|
|
} else if (currentWidth > 8000) {
|
|
|
sheet.setColumnWidth(i, 8000); // 最大宽度
|
|
|
}
|
|
@@ -1000,7 +1018,7 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Boolean sendEmail(String id, byte[] pie) {
|
|
|
+ public Boolean sendEmail(String id, byte[] pie, byte[] barLine) {
|
|
|
ProdPlan prodPlan = this.getById(id);
|
|
|
String date = prodPlan.getPlanDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
|
@@ -1008,14 +1026,14 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
List<String> contactsTO = list.stream().filter(i -> "Y".equals(i.getIsActive()) && "TO".equals(i.getRecType())).map(Contact::getEmail).collect(Collectors.toList());
|
|
|
List<String> contactsCC = list.stream().filter(i -> "Y".equals(i.getIsActive()) && "CC".equals(i.getRecType())).map(Contact::getEmail).collect(Collectors.toList());
|
|
|
|
|
|
- Workbook workbook = this.report(id, pie);
|
|
|
+ Workbook workbook = this.report(id, pie, barLine);
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
byte[] excelBytes = null;
|
|
|
try {
|
|
|
workbook.write(outputStream);
|
|
|
excelBytes = outputStream.toByteArray();
|
|
|
workbook.close();
|
|
|
- Boolean success = EmailUtil.sendEmailWithPicAndExcelAttachment(contactsTO, contactsCC, "生产异常追踪表_" + date, "生产异常追踪表_" + date, pie, excelBytes);
|
|
|
+ Boolean success = EmailUtil.sendEmailWithPicAndExcelAttachment(contactsTO, contactsCC, "生产异常追踪表_" + date, "生产异常追踪表_" + date, pie, barLine, excelBytes);
|
|
|
if(success) {
|
|
|
prodPlan.setSendState(1);
|
|
|
this.updateById(prodPlan);
|
|
@@ -1025,4 +1043,190 @@ public class ProdPlanServiceImpl extends ServiceImpl<ProdPlanMapper, ProdPlan> i
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject getChartData(ProdPlan prodPlan) {
|
|
|
+ int currentWeek = prodPlan.getPlanDate().get(WeekFields.ISO.weekOfYear());
|
|
|
+
|
|
|
+ List<ReportDetailVo> detailVoList = getReportDetailVos(prodPlan, currentWeek);
|
|
|
+
|
|
|
+ List<ReportDetailVo> detailVos = new ArrayList<>();
|
|
|
+ // 以第四周为当前周,过滤影响前一周及后两周周的数据
|
|
|
+ detailVos = detailVoList.stream().filter(i->{
|
|
|
+ return i.getWeek3()!=null||i.getWeek4()!=null||i.getWeek5()!=null||i.getWeek6()!=null;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<JSONObject> pieInside = new ArrayList<>();
|
|
|
+ List<JSONObject> pieOutside = new ArrayList<>();
|
|
|
+ Map<String, List<ReportDetailVo>> deptMap = detailVos.stream().collect(Collectors.groupingBy(ReportDetailVo::getDept, Collectors.toList()));
|
|
|
+ int colorIndex = 0;
|
|
|
+// deptMap.forEach((dept,deptList)->{
|
|
|
+ for (String dept : deptMap.keySet()) {
|
|
|
+ List<ReportDetailVo> deptList = deptMap.get(dept);
|
|
|
+ String[] colors = COLOR_ARRAY[colorIndex++];
|
|
|
+ ReportDetailVo subTotalVo = getSummaryDetailVo(deptList);
|
|
|
+ JSONObject pieIn = new JSONObject();
|
|
|
+ pieIn.put("name",dept);
|
|
|
+ pieIn.put("value",subTotalVo.getPo());
|
|
|
+ int colorSubIndex = 0;
|
|
|
+ pieIn.put("color",colors[colorSubIndex++]);
|
|
|
+ pieInside.add(pieIn);
|
|
|
+
|
|
|
+ Map<String, List<ReportDetailVo>> remarkMap = deptList.stream().collect(Collectors.groupingBy(ReportDetailVo::getRemark, Collectors.toList()));
|
|
|
+// remarkMap.forEach((remark,remarkList)->{
|
|
|
+ for (String remark : remarkMap.keySet()) {
|
|
|
+ List<ReportDetailVo> remarkList = remarkMap.get(remark);
|
|
|
+ ReportDetailVo remarkVo = getSummaryDetailVo(remarkList);
|
|
|
+ JSONObject pieOut = new JSONObject();
|
|
|
+ pieOut.put("name",remark);
|
|
|
+ pieOut.put("value",remarkVo.getPo());
|
|
|
+ pieOut.put("color",colors[colorSubIndex++]);
|
|
|
+ pieOutside.add(pieOut);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<JSONObject> bars = new ArrayList<>();
|
|
|
+ // 以第四周为当前周,过滤影响前三周及后两周周的数据
|
|
|
+ detailVos = detailVoList.stream().filter(i->{
|
|
|
+ return i.getWeek1()!=null||i.getWeek2()!=null||i.getWeek3()!=null||i.getWeek4()!=null||i.getWeek5()!=null||i.getWeek6()!=null;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ deptMap = detailVos.stream().collect(Collectors.groupingBy(ReportDetailVo::getDept, Collectors.toList()));
|
|
|
+ colorIndex = 0;
|
|
|
+// deptMap.forEach((dept,deptList)->{
|
|
|
+ for (String dept : deptMap.keySet()) {
|
|
|
+ List<ReportDetailVo> deptList = deptMap.get(dept);
|
|
|
+ ReportDetailVo subTotalVo = getSummaryDetailVo(deptList);
|
|
|
+ JSONObject bar = new JSONObject();
|
|
|
+ bar.put("name",dept);
|
|
|
+ List<Integer> data = new ArrayList<>();
|
|
|
+ data.add(subTotalVo.getWeek1());
|
|
|
+ data.add(subTotalVo.getWeek2());
|
|
|
+ data.add(subTotalVo.getWeek3());
|
|
|
+ data.add(subTotalVo.getWeek4());
|
|
|
+ data.add(subTotalVo.getWeek5());
|
|
|
+ data.add(subTotalVo.getWeek6());
|
|
|
+ bar.put("data",data);
|
|
|
+ bar.put("color",COLOR_ARRAY[colorIndex++][0]);
|
|
|
+ bars.add(bar);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> weeks = new ArrayList<>();
|
|
|
+ for(int i= currentWeek-3;i<currentWeek+3;i++) {
|
|
|
+ weeks.add("W" + i);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> lineData = new ArrayList<>();
|
|
|
+ List<DeliveredQuantity> deliveredQuantityList = this.deliveredQuantityService.list();
|
|
|
+ Map<String, Integer> deliveredQuantityMap = deliveredQuantityList.stream().collect(Collectors.toMap(DeliveredQuantity::getWeek, DeliveredQuantity::getQuantity));
|
|
|
+ ReportDetailVo totalVo = getSummaryDetailVo(detailVos);
|
|
|
+ if(totalVo.getWeek1()!=null && deliveredQuantityMap.get(weeks.get(0))!=null && deliveredQuantityMap.get(weeks.get(0))>0) {
|
|
|
+ String lossCellValue = String.valueOf((double)totalVo.getWeek1()/ deliveredQuantityMap.get(weeks.get(0))*100);
|
|
|
+ lineData.add(lossCellValue);
|
|
|
+ }else{
|
|
|
+ lineData.add("");
|
|
|
+ }
|
|
|
+ if(totalVo.getWeek2()!=null && deliveredQuantityMap.get(weeks.get(1))!=null && deliveredQuantityMap.get(weeks.get(1))>0) {
|
|
|
+ String lossCellValue = String.valueOf((double)totalVo.getWeek2()/ deliveredQuantityMap.get(weeks.get(1))*100);
|
|
|
+ lineData.add(lossCellValue);
|
|
|
+ } else{
|
|
|
+ lineData.add("");
|
|
|
+ }
|
|
|
+ if(totalVo.getWeek3()!=null && deliveredQuantityMap.get(weeks.get(2))!=null && deliveredQuantityMap.get(weeks.get(2))>0) {
|
|
|
+ String lossCellValue = String.valueOf((double)totalVo.getWeek3()/ deliveredQuantityMap.get(weeks.get(2))*100);
|
|
|
+ lineData.add(lossCellValue);
|
|
|
+ } else{
|
|
|
+ lineData.add("");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(totalVo.getWeek4()!=null && deliveredQuantityMap.get(weeks.get(3))!=null && deliveredQuantityMap.get(weeks.get(3))>0) {
|
|
|
+ String lossCellValue = String.valueOf((double)totalVo.getWeek4()/ deliveredQuantityMap.get(weeks.get(3))*100);
|
|
|
+ lineData.add(lossCellValue);
|
|
|
+ } else{
|
|
|
+ lineData.add("");
|
|
|
+ }
|
|
|
+ if(totalVo.getWeek5()!=null && deliveredQuantityMap.get(weeks.get(4))!=null && deliveredQuantityMap.get(weeks.get(4))>0) {
|
|
|
+ String lossCellValue = String.valueOf((double)totalVo.getWeek5()/ deliveredQuantityMap.get(weeks.get(4))*100);
|
|
|
+ lineData.add(lossCellValue);
|
|
|
+ } else{
|
|
|
+ lineData.add("");
|
|
|
+ }
|
|
|
+ if(totalVo.getWeek6()!=null && deliveredQuantityMap.get(weeks.get(5))!=null && deliveredQuantityMap.get(weeks.get(5))>0) {
|
|
|
+ String lossCellValue = String.valueOf((double)totalVo.getWeek6()/ deliveredQuantityMap.get(weeks.get(5))*100);
|
|
|
+ lineData.add(lossCellValue);
|
|
|
+ } else{
|
|
|
+ lineData.add("");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("pieInside",pieInside);
|
|
|
+ result.put("pieOutside",pieOutside);
|
|
|
+ result.put("bars",bars);
|
|
|
+ result.put("weeks",weeks);
|
|
|
+ result.put("lineData",lineData);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static final String[][] COLOR_ARRAY = {
|
|
|
+ // 深蓝色系
|
|
|
+ {
|
|
|
+ "#1A3F5C", "#25557B", "#2F6B9A", "#4081B9", "#5197D8",
|
|
|
+ "#6FADF7", "#8BC3FF", "#A7D9FF", "#C3EFFF", "#DFFFFF"
|
|
|
+ },
|
|
|
+
|
|
|
+ // 暖橙色系
|
|
|
+ {
|
|
|
+ "#E6582A", "#F26B3B", "#FC8251", "#FD9468", "#FEA67F",
|
|
|
+ "#FEB896", "#FECAAD", "#FFDCC4", "#FFEEDB", "#FFF7F2"
|
|
|
+ },
|
|
|
+
|
|
|
+ // 亮蓝色系
|
|
|
+ {
|
|
|
+ "#0F6BB8", "#1C8BDF", "#2FA0F2", "#4BB5FF", "#67CAFF",
|
|
|
+ "#83DFFF", "#9FF4FF", "#BBFFFF", "#D7FFFF", "#F3FFFF"
|
|
|
+ },
|
|
|
+
|
|
|
+ // 青绿色系
|
|
|
+ {
|
|
|
+ "#4A8265", "#5B9276", "#6CA287", "#78AE96", "#8BC4A5",
|
|
|
+ "#9EDAB4", "#B1F0C3", "#C4FFD2", "#D7FFE1", "#EAFFF0"
|
|
|
+ },
|
|
|
+
|
|
|
+ // 深红色系
|
|
|
+ {
|
|
|
+ "#A01B15", "#C22721", "#E4332D", "#FF4F39", "#FF6B45",
|
|
|
+ "#FF8751", "#FFA35D", "#FFBF69", "#FFDB75", "#FFF781"
|
|
|
+ },
|
|
|
+
|
|
|
+ // 深紫蓝色系
|
|
|
+ {
|
|
|
+ "#2B4A66", "#3A5A7A", "#496A8E", "#587AA2", "#678AB6",
|
|
|
+ "#769ACA", "#85AADE", "#94BAF2", "#A3CAFF", "#B2DAFF"
|
|
|
+ },
|
|
|
+
|
|
|
+ // 深橙棕色系
|
|
|
+ {
|
|
|
+ "#B8542C", "#D46240", "#F07054", "#FF7E68", "#FF8C7C",
|
|
|
+ "#FF9A90", "#FFA8A4", "#FFB6B8", "#FFC4CC", "#FFD2E0"
|
|
|
+ },
|
|
|
+
|
|
|
+ // 深天蓝色系
|
|
|
+ {
|
|
|
+ "#1B7AB8", "#2B8AC8", "#3B9AD8", "#4BAAE8", "#5BBAF8",
|
|
|
+ "#6BCAFF", "#7BDAFF", "#8BEAFF", "#9BFAFF", "#ABFFFF"
|
|
|
+ },
|
|
|
+
|
|
|
+ // 深绿色系
|
|
|
+ {
|
|
|
+ "#5A8570", "#6A9580", "#7AA590", "#8AB5A0", "#9AC5B0",
|
|
|
+ "#AAD5C0", "#BAE5D0", "#CAF5E0", "#DAFFF0", "#EAFFFF"
|
|
|
+ },
|
|
|
+
|
|
|
+ // 深酒红色系
|
|
|
+ {
|
|
|
+ "#9B1F1A", "#B52F2A", "#CF3F3A", "#E94F4A", "#FF5F5A",
|
|
|
+ "#FF6F6A", "#FF7F7A", "#FF8F8A", "#FF9F9A", "#FFAFAA"
|
|
|
+ }
|
|
|
+ };
|
|
|
}
|