|
@@ -1,12 +1,43 @@
|
|
|
package com.factory.web.service.impl;
|
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Drawing;
|
|
|
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.factory.base.entity.aggregates.ResponseBean;
|
|
|
-import com.factory.base.entity.constant.SystemConstant;
|
|
|
import com.factory.user.service.UserInfoService;
|
|
|
import com.factory.web.entity.excel.Utility;
|
|
|
import com.factory.web.entity.pm.OnsiteApprovalPlan;
|
|
|
import com.factory.web.entity.pm.OnsiteCalendar;
|
|
|
+import com.factory.web.entity.pm.OnsiteItem;
|
|
|
+import com.factory.web.entity.pm.OnsiteWorkshop;
|
|
|
import com.factory.web.entity.pm.req.SearchPmCheckRecordListReq;
|
|
|
import com.factory.web.entity.pm.req.SearchPmPlanReq;
|
|
|
import com.factory.web.entity.pm.res.PmCheckRecordItemListRes;
|
|
@@ -16,24 +47,6 @@ import com.factory.web.entity.pm.res.PmPlanRes;
|
|
|
import com.factory.web.mapper.FileMapper;
|
|
|
import com.factory.web.service.FileService;
|
|
|
import com.factory.web.service.pm.PreventMistakeService;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
-import org.apache.poi.ss.usermodel.*;
|
|
|
-import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import javax.imageio.ImageIO;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -53,6 +66,7 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
|
|
|
HashMap<Integer, String> nmMap = new HashMap<>();
|
|
|
SearchPmPlanReq req = SearchPmPlanReq.builder().bentelerPlanId(param.getBentelerPlanId()).build();
|
|
|
PmPlanRes plan = preventMistakeService.getPmPlan(req);
|
|
|
+
|
|
|
ResponseBean<List<PmCheckRecordListRes>> checks = preventMistakeService.getPmCheckRecordList(param);
|
|
|
ResponseBean<List<OnsiteApprovalPlan>> approve = preventMistakeService.getPmPlanApprovalList(req);
|
|
|
Workbook wb = new SXSSFWorkbook(500);
|
|
@@ -66,20 +80,34 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
|
|
|
bufferImg = ImageIO.read(inb);
|
|
|
inb.close();
|
|
|
}
|
|
|
- String[] data = getOnsiteTitle1Data();
|
|
|
+ //设置版本 生效时间和上一个版本生效时间
|
|
|
+ String[] data = getOnsiteTitle1Data(plan.getBentelerPlanId(),plan.getEffectiveDate(),plan.getPrevEffectiveDate());
|
|
|
+
|
|
|
createOnsiteTitle1(wb, sheet, cellStyle, 0, data, bufferImg);
|
|
|
+ //设置公司名称和计划名称
|
|
|
data = getOnsiteTitle2Data(plan);
|
|
|
createOnsiteTitle2(sheet, cellStyle, 1, data);
|
|
|
+ //设置点检人年月信息
|
|
|
data = getOnsiteTitle3Data(plan, param, iscontroll);
|
|
|
createOnsiteTitle3(sheet, cellStyle, 2, data);
|
|
|
+
|
|
|
+ //设置op和点检信息头信息
|
|
|
createItemInfoTitle(sheet, cellStyle, 3);
|
|
|
+
|
|
|
+ //设置op点检项
|
|
|
List<String[]> dsl = getItemInfoDate(plan, checks.getData(), param, iscontroll, nmMap);
|
|
|
int rowindex = createItemInfo(sheet, cellStyle, 4, dsl);
|
|
|
+
|
|
|
+ //对应日期点检人信息
|
|
|
data = getOperaterTitleData(nmMap);
|
|
|
createOperaterTitle(sheet, cellStyle, rowindex + 1, data);
|
|
|
+ //备注信息
|
|
|
data = getOnsiteTitle4Data();
|
|
|
createOnsiteTitle4(sheet, cellStyleLeft, rowindex + 2, data);
|
|
|
+
|
|
|
+ //设置创建人审批人信息
|
|
|
data = getOnsiteTitle5Data(plan, approve.getData());
|
|
|
+
|
|
|
createOnsiteTitle5(sheet, cellStyle, rowindex + 3, data);
|
|
|
return wb;
|
|
|
}
|
|
@@ -88,8 +116,25 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
|
|
|
private List<String[]> getItemInfoDate(PmPlanRes plan, List<PmCheckRecordListRes> check, SearchPmCheckRecordListReq param, boolean iscontroll, HashMap<Integer, String> nmMap) {
|
|
|
List<String[]> rs = new ArrayList<>();
|
|
|
if (iscontroll) {
|
|
|
- String[] datas = inidata();
|
|
|
- rs.add(datas);
|
|
|
+ plan.getOnsiteCalendarList().forEach(cal->{
|
|
|
+// String userNm = getUserName(cal.getUserId());
|
|
|
+ String[] datas = null;
|
|
|
+ List<OnsiteWorkshop> wl = plan.getOnsiteWorkshopList();
|
|
|
+ for (OnsiteWorkshop res : wl) {
|
|
|
+ for (OnsiteItem item : res.getOnsiteItemList()) {
|
|
|
+ if(!item.getTypeFlag().equals(cal.getTypeFlag())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ datas = inidata();
|
|
|
+ datas[0] = cal.getTypeFlag() == 0 ? "日" : cal.getTypeFlag() == 1 ? "周" : "月";
|
|
|
+ datas[1] = res.getWsName();
|
|
|
+ datas[2] = item.getItemContent();
|
|
|
+
|
|
|
+ rs.add(datas);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
} else {
|
|
|
Optional<OnsiteCalendar> cal = plan.getOnsiteCalendarList().stream().filter(s -> s.getTypeFlag().equals(param.getTypeFlag())).findFirst();
|
|
|
String userNm = getUserName(!cal.isPresent() ? null : cal.get().getUserId());
|
|
@@ -125,14 +170,7 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
|
|
|
}
|
|
|
|
|
|
private String getUserName(Long userid) {
|
|
|
- String userNm = SystemConstant.EMPTY_STRING;
|
|
|
- if (userid != null) {
|
|
|
- String name = userInfoService.getNameById(userid);
|
|
|
- if (name != null) {
|
|
|
- userNm = name;
|
|
|
- }
|
|
|
- }
|
|
|
- return userNm;
|
|
|
+ return userInfoService.getNameInfoById(userid);
|
|
|
}
|
|
|
|
|
|
private String[] getOnsiteTitle5Data(PmPlanRes plan, List<OnsiteApprovalPlan> approvals) {
|
|
@@ -165,18 +203,19 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
|
|
|
}
|
|
|
|
|
|
private String[] getOnsiteTitle3Data(PmPlanRes plan, SearchPmCheckRecordListReq param, boolean iscontroll) {
|
|
|
- Optional<OnsiteCalendar> cal = plan.getOnsiteCalendarList().stream().filter(s -> s.getTypeFlag().equals(param.getTypeFlag())).findFirst();
|
|
|
+ List<OnsiteCalendar> list = plan.getOnsiteCalendarList();
|
|
|
+ list = list.stream().filter(s -> (iscontroll||s.getTypeFlag().equals(param.getTypeFlag()))).collect(Collectors.toList());
|
|
|
+ String userName = list.stream().map(s->getUserName(s.getUserId())).collect(Collectors.joining(","));
|
|
|
+ String shift = list.stream().map(s->s.getShift()).findFirst().orElse("");
|
|
|
String[] dates = param.getYearMonth().split("\\-");
|
|
|
- String setter = String.format("Setter/Jumper:%s", "");
|
|
|
+ String setter = String.format("Setter/Jumper:%s", userName);
|
|
|
if (iscontroll) {
|
|
|
dates[0]="";
|
|
|
dates[1]="";
|
|
|
- }else {
|
|
|
- setter = String.format("Setter/Jumper:%s", getUserName(!cal.isPresent() ? null : cal.get().getUserId()));
|
|
|
}
|
|
|
return new String[]{
|
|
|
String.format("Production line:%s", plan.getOnsiteTitle() != null ? plan.getOnsiteTitle().getProductionLine() : ""),
|
|
|
- String.format("Shift:%s", !cal.isPresent() ? "" : cal.get().getShift()),
|
|
|
+ String.format("Shift:%s", shift),
|
|
|
setter,
|
|
|
String.format("Year:%s", dates[0]),
|
|
|
String.format("Month:%s", dates[1])
|
|
@@ -185,9 +224,7 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
|
|
|
|
|
|
private String[] getOnsiteTitle2Data(PmPlanRes plan) {
|
|
|
String[] data;
|
|
|
- data = new String[]{companyName,
|
|
|
- plan.getBentelerPlanName()
|
|
|
- };
|
|
|
+ data = new String[]{companyName,plan.getBentelerPlanName()};
|
|
|
return data;
|
|
|
}
|
|
|
|
|
@@ -334,15 +371,15 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- private String[] getOnsiteTitle1Data() {
|
|
|
+ private String[] getOnsiteTitle1Data(Long planId,LocalDate effectDate,LocalDate prevEffectDate) {
|
|
|
String[] data = new String[]{
|
|
|
"Benteler Automotive (shenyang) Co. , Ltd",
|
|
|
"Pokayoke Checking Sheet for Production",
|
|
|
"模板编号: T.0702.Eng.022.An.02\n" +
|
|
|
- "发布日期: 2020-10-26\n" +
|
|
|
- "模板版本: 11\n" +
|
|
|
+ "发布日期: "+(effectDate==null?"2020-10-26":effectDate.toString())+"\n" +
|
|
|
+ "模板版本: "+planId+"\n" +
|
|
|
"部门:工程部\n" +
|
|
|
- "上一版本: 2019-11-01"
|
|
|
+ "上一版本: "+(prevEffectDate==null?"2019-11-01":prevEffectDate.toString())
|
|
|
};
|
|
|
return data;
|
|
|
}
|