|
@@ -3,22 +3,38 @@ package com.management.platform.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.management.platform.entity.CompanyDingding;
|
|
|
-import com.management.platform.entity.ReportLog;
|
|
|
-import com.management.platform.entity.User;
|
|
|
-import com.management.platform.entity.WxCorpInfo;
|
|
|
-import com.management.platform.mapper.CompanyDingdingMapper;
|
|
|
-import com.management.platform.mapper.UserMapper;
|
|
|
-import com.management.platform.mapper.WxCorpInfoMapper;
|
|
|
+import com.management.platform.entity.*;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.ReportLogService;
|
|
|
import com.management.platform.service.ReportService;
|
|
|
+import com.management.platform.util.ExcelUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
+import com.management.platform.util.MessageUtils;
|
|
|
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.hamcrest.core.Is;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.*;
|
|
|
+import java.lang.reflect.Array;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -40,6 +56,16 @@ public class ReportLogController {
|
|
|
WxCorpInfoMapper wxCorpInfoMapper;
|
|
|
@Resource
|
|
|
private CompanyDingdingMapper companyDingdingMapper;
|
|
|
+ @Resource
|
|
|
+ private HttpServletRequest request;
|
|
|
+ @Resource
|
|
|
+ private ReportMapper reportMapper;
|
|
|
+ @Resource
|
|
|
+ private ProjectMapper projectMapper;
|
|
|
+ @Value(value = "${upload.path}")
|
|
|
+ private String path;
|
|
|
+ @Resource
|
|
|
+ private ReportService reportService;
|
|
|
|
|
|
@RequestMapping("/get")
|
|
|
public HttpRespMsg get(String creatorId, String createDate) {
|
|
@@ -66,5 +92,230 @@ public class ReportLogController {
|
|
|
msg.data = list;
|
|
|
return msg;
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping("/exportReportLog")
|
|
|
+ public HttpRespMsg exportReportLog(String startDate,String endDate){
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<ReportLog> list = reportLogService.list(new LambdaQueryWrapper<ReportLog>().eq(ReportLog::getCompanyId,companyId).between(ReportLog::getCreateDate, startDate,endDate));
|
|
|
+ list=list.stream().filter(l->l.getMsg().contains("审核通过了")).collect(Collectors.toList());
|
|
|
+ List<List<String>> dataList=new ArrayList<>();
|
|
|
+ List<String> titleList=new ArrayList<>();
|
|
|
+ titleList.add("编号(不可随意修改)");
|
|
|
+ titleList.add("姓名");
|
|
|
+ titleList.add("工号");
|
|
|
+ titleList.add("工作日期");
|
|
|
+ titleList.add("项目名称");
|
|
|
+ titleList.add("项目编号");
|
|
|
+ titleList.add("审核通过时间");
|
|
|
+ dataList.add(titleList);
|
|
|
+ List<String> reportIds = list.stream().map(ReportLog::getReportIds).collect(Collectors.toList());
|
|
|
+ List<Integer> reportIdList=new ArrayList<>();
|
|
|
+ reportIds.forEach(r->{
|
|
|
+ String[] split = r.split(",");
|
|
|
+ List<Integer> reportIdListSub = Arrays.asList(split).stream().map(i -> Integer.valueOf(i)).collect(Collectors.toList());
|
|
|
+ reportIdList.addAll(reportIdListSub);
|
|
|
+ });
|
|
|
+ reportIdList.add(-1);
|
|
|
+ List<Report> reportList = reportMapper.selectList(new LambdaQueryWrapper<Report>().in(Report::getId, reportIdList));
|
|
|
+ List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId,companyId));
|
|
|
+ List<Integer> projectIds= reportList.stream().map(Report::getProjectId).distinct().collect(Collectors.toList());
|
|
|
+ projectIds.add(-1);
|
|
|
+ List<Project> projectList = projectMapper.selectList(new LambdaQueryWrapper<Project>().in(Project::getId, projectIds));
|
|
|
+ for (ReportLog reportLog : list) {
|
|
|
+ List<String> item=new ArrayList<>();
|
|
|
+ item.add(String.valueOf(reportLog.getId()));
|
|
|
+ Optional<User> user = userList.stream().filter(u -> u.getId().equals(reportLog.getCreatorId())).findFirst();
|
|
|
+ if(user.isPresent()){
|
|
|
+ item.add(String.valueOf(user.get().getName()));
|
|
|
+ item.add(String.valueOf(user.get().getJobNumber()));
|
|
|
+ }else {
|
|
|
+ item.add("");
|
|
|
+ item.add("");
|
|
|
+ }
|
|
|
+ item.add(String.valueOf(df.format(reportLog.getCreateDate())));
|
|
|
+ String ids = reportLog.getReportIds();
|
|
|
+ String[] split = ids.split(",");
|
|
|
+ StringBuilder projectNames=new StringBuilder();
|
|
|
+ StringBuilder projectCodes=new StringBuilder();
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ String reportId = split[i];
|
|
|
+ Optional<Report> report = reportList.stream().filter(r -> r.getId().equals(Integer.valueOf(reportId))).findFirst();
|
|
|
+ if(report.isPresent()){
|
|
|
+ Optional<Project> first = projectList.stream().filter(p -> p.getId().equals(report.get().getProjectId())).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ if(i==0){
|
|
|
+ projectNames.append(first.get().getProjectName());
|
|
|
+ projectCodes.append((first.get().getProjectCode()==null?"":first.get().getProjectCode()));
|
|
|
+ }else {
|
|
|
+ projectNames.append(","+first.get().getProjectName());
|
|
|
+ projectCodes.append(","+(first.get().getProjectCode()==null?"":first.get().getProjectCode()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.add(projectNames.toString());
|
|
|
+ item.add(projectCodes.toString());
|
|
|
+ item.add(String.valueOf(df1.format(reportLog.getOperateDate())));
|
|
|
+ dataList.add(item);
|
|
|
+ }
|
|
|
+ String resp = ExcelUtil.exportGeneralExcelByTitleAndList("日报审核记录", dataList, path);
|
|
|
+ msg.setData(resp);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/importReportLogChange")
|
|
|
+ public HttpRespMsg importReportLogChange(MultipartFile multipartFile){
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ //然后处理文件
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ File file = new File(fileName == null ? "file" : fileName);
|
|
|
+ InputStream inputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = multipartFile.getInputStream();
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int temp = 0;
|
|
|
+ while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, temp);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ outputStream.close();
|
|
|
+ //然后解析表格
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(file);
|
|
|
+ //我们只需要第一个sheet
|
|
|
+ XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ List<Integer> reportLogIds=new ArrayList<>();
|
|
|
+ for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //跳过空行
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ XSSFCell numCell = row.getCell(0);
|
|
|
+ if (numCell != null) {
|
|
|
+ String code = numCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
+ if ((code.equals("编号(不可随意修改)")||(code.equals("编号(不可随意修改)")) && rowIndex == 0)){
|
|
|
+ //跳过第一行标题
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (numCell != null)numCell.setCellType(CellType.STRING);
|
|
|
+ Integer numCellValue = Integer.valueOf(numCell.getStringCellValue());
|
|
|
+ reportLogIds.add(numCellValue);
|
|
|
+ }
|
|
|
+ List<ReportLog> reportLogList = reportLogService.list(new LambdaQueryWrapper<ReportLog>().in(ReportLog::getId, reportLogIds));
|
|
|
+ List<String> reportIds = reportLogList.stream().map(ReportLog::getReportIds).collect(Collectors.toList());
|
|
|
+ List<Integer> reportIdList =new ArrayList<>();
|
|
|
+ reportIds.forEach(r->{
|
|
|
+ String[] split = r.split(",");
|
|
|
+ List<Integer> reportSubIds = Arrays.asList(split).stream().map(s -> Integer.valueOf(s)).collect(Collectors.toList());
|
|
|
+ reportIdList.addAll(reportSubIds);
|
|
|
+ });
|
|
|
+ List<Report> reportList = reportMapper.selectList(new LambdaQueryWrapper<Report>().in(Report::getId, reportIdList));
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ List<Report> needUpdateReportList=new ArrayList<>();
|
|
|
+ List<ReportLog> needUpdateReportLogList=new ArrayList<>();
|
|
|
+ for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //跳过空行
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ XSSFCell numCell = row.getCell(0);
|
|
|
+ XSSFCell nameCell = row.getCell(1);
|
|
|
+ XSSFCell jobNumCell = row.getCell(2);
|
|
|
+ XSSFCell createDateCell = row.getCell(3);
|
|
|
+ XSSFCell projectNameCell = row.getCell(4);
|
|
|
+ XSSFCell projectCodeCell = row.getCell(5);
|
|
|
+ XSSFCell auditDateCell = row.getCell(6);
|
|
|
+
|
|
|
+ if (numCell != null) {
|
|
|
+ String code = numCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
+ if ((code.equals("编号(不可随意修改)")||(code.equals("编号(不可随意修改)")) && rowIndex == 0)){
|
|
|
+ //跳过第一行标题
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (numCell != null)numCell.setCellType(CellType.STRING);
|
|
|
+ if (nameCell != null)nameCell.setCellType(CellType.STRING);
|
|
|
+ if (jobNumCell != null)jobNumCell.setCellType(CellType.STRING);
|
|
|
+ if (createDateCell != null)createDateCell.setCellType(CellType.STRING);
|
|
|
+ if (projectNameCell != null)projectNameCell.setCellType(CellType.STRING);
|
|
|
+ if (projectCodeCell != null)projectCodeCell.setCellType(CellType.STRING);
|
|
|
+ if (auditDateCell != null)auditDateCell.setCellType(CellType.STRING);
|
|
|
+
|
|
|
+ Integer numCellValue = Integer.valueOf(numCell.getStringCellValue());
|
|
|
+ String nameCellValue = nameCell.getStringCellValue();
|
|
|
+ String jobNumCellValue =jobNumCell.getStringCellValue();
|
|
|
+ String createDateCellValue = createDateCell.getStringCellValue();
|
|
|
+ String projectNameCellValue = projectNameCell.getStringCellValue();
|
|
|
+ String projectCodeCellValue = projectCodeCell.getStringCellValue();
|
|
|
+ String auditDateCellValue = auditDateCell.getStringCellValue();
|
|
|
+
|
|
|
+
|
|
|
+ Optional<ReportLog> first = reportLogList.stream().filter(r -> r.getId().equals(numCellValue)).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ ReportLog reportLog = first.get();
|
|
|
+ String reportIdSplit = reportLog.getReportIds();
|
|
|
+ List<Integer> ids = Arrays.asList(reportIdSplit.split(",")).stream().map(s -> Integer.valueOf(s)).collect(Collectors.toList());
|
|
|
+ List<Report> reports = reportList.stream().filter(r -> ids.contains(r.getId())).collect(Collectors.toList());
|
|
|
+ if(auditDateCellValue!=null){
|
|
|
+ LocalDateTime time = null;
|
|
|
+ try {
|
|
|
+ time = LocalDateTime.parse(auditDateCellValue, df);
|
|
|
+ }catch (Exception e){
|
|
|
+ msg.setError("第"+row+"行审核时间格式错误,请检查审核时间数据");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ reportLog.setOperateDate(time);
|
|
|
+ needUpdateReportLogList.add(reportLog);
|
|
|
+ LocalDateTime finalTime = time;
|
|
|
+ reports.forEach(r->{
|
|
|
+ r.setProjectAuditTime(finalTime);
|
|
|
+ });
|
|
|
+ needUpdateReportList.addAll(reports);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(sb.toString().length()==0){
|
|
|
+ sb.append(numCell);
|
|
|
+ }else {
|
|
|
+ sb.append(","+numCell);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(needUpdateReportList.size()>0){
|
|
|
+ reportService.updateBatchById(needUpdateReportList);
|
|
|
+ }
|
|
|
+ if(needUpdateReportLogList.size()>0){
|
|
|
+ reportLogService.updateBatchById(needUpdateReportLogList);
|
|
|
+ }
|
|
|
+ if(sb.length()>0){
|
|
|
+ msg.setMsg("更新完成,其中编号["+sb.toString()+"]的填报数据不存在");
|
|
|
+ }else {
|
|
|
+ msg.setMsg("更新完成");
|
|
|
+ }
|
|
|
+ }catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InvalidFormatException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
}
|
|
|
|