Browse Source

生产日报excel导入

develop
bobol 11 months ago
parent
commit
4389a24ae1
  1. 1
      lzbi-module/pom.xml
  2. 25
      lzbi-module/src/main/java/com/lzbi/bill/service/DcBusiMonthPlanBillMasterService.java
  3. 16
      lzbi-module/src/main/java/com/lzbi/draft/controller/ReportController.java
  4. 27
      lzbi-module/src/main/java/com/lzbi/draft/domain/req/ProductionDailySheetReq.java
  5. 27
      lzbi-module/src/main/java/com/lzbi/draft/domain/vo/ProductionDailySheetVO.java
  6. 72
      lzbi-module/src/main/java/com/lzbi/draft/service/ReportService.java

1
lzbi-module/pom.xml

@ -52,7 +52,6 @@
<version>3.3.2</version> <version>3.3.2</version>
</dependency> </dependency>
<!-- Mysql驱动包 --> <!-- Mysql驱动包 -->
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>mysql</groupId>--> <!-- <groupId>mysql</groupId>-->

25
lzbi-module/src/main/java/com/lzbi/bill/service/DcBusiMonthPlanBillMasterService.java

@ -244,31 +244,6 @@ public class DcBusiMonthPlanBillMasterService extends ServiceImpl<DcBusiMonthPla
if ("1".equals(master.getCheckStatus())) { if ("1".equals(master.getCheckStatus())) {
throw new RuntimeException("反审核失败,单据未审核通过"); throw new RuntimeException("反审核失败,单据未审核通过");
} }
// 如果单据状态为已审核状态,需要把底稿表数据恢复
if ("2".equals(master.getCheckStatus())) {
// 查询子表数据
DcBusiMonthPlanBillSub subParams = new DcBusiMonthPlanBillSub();
subParams.setBillNo(billNo);
List<DcBusiMonthPlanBillSub> subList = dcBusiMonthPlanBillSubMapper.selectDcBusiMonthPlanBillSubList(subParams);
DcBusiTargetDraftMonth dcBusiTargetDraftMonth;
for (int i = 0, len = subList.size(); i < len; i++) {
dcBusiTargetDraftMonth = new DcBusiTargetDraftMonth();
dcBusiTargetDraftMonth.setCompanyId(master.getCompanyId());
dcBusiTargetDraftMonth.setOrgId(master.getOragnizeId());
dcBusiTargetDraftMonth.setFieldCode(subList.get(i).getFieldCode());
dcBusiTargetDraftMonth.setAssetCode(subList.get(i).getAssetCode());
dcBusiTargetDraftMonth.setTargetCode(subList.get(i).getTargetCode());
dcBusiTargetDraftMonth.setCountYear(subList.get(i).getDateYear());
dcBusiTargetDraftMonth.setCountMonth(subList.get(i).getDateMonth());
List<DcBusiTargetDraftMonth> dcBusiTargetDraftMonthList = dcBusiTargetDraftMonthMapper.selectDcBusiTargetDraftMonthList(dcBusiTargetDraftMonth);
// 如果底稿表数据不为空,则减去计划值
if (!CollectionUtils.isEmpty(dcBusiTargetDraftMonthList)) {
dcBusiTargetDraftMonth = dcBusiTargetDraftMonthList.get(0);
dcBusiTargetDraftMonth.setValPlan(dcBusiTargetDraftMonth.getValPlan().subtract(subList.get(i).getPlanValue()));
dcBusiTargetDraftMonthMapper.updateDcBusiTargetDraftMonth(dcBusiTargetDraftMonth);
}
}
}
master.setUpdatedBy(SecurityUtils.getUsername()); master.setUpdatedBy(SecurityUtils.getUsername());
master.setCreatedTime(DateUtils.getNowDate()); master.setCreatedTime(DateUtils.getNowDate());
master.setBillNo(billNo); master.setBillNo(billNo);

16
lzbi-module/src/main/java/com/lzbi/draft/controller/ReportController.java

@ -6,24 +6,26 @@ import com.alibaba.excel.write.metadata.WriteSheet;
import com.lzbi.common.config.RuoYiConfig; import com.lzbi.common.config.RuoYiConfig;
import com.lzbi.common.core.controller.BaseController; import com.lzbi.common.core.controller.BaseController;
import com.lzbi.common.core.domain.AjaxResult; import com.lzbi.common.core.domain.AjaxResult;
import com.lzbi.draft.domain.req.ProductionDailySheetReq;
import com.lzbi.draft.entity.req.TargetDraftMonthReportReq; import com.lzbi.draft.entity.req.TargetDraftMonthReportReq;
import com.lzbi.draft.entity.vo.TargetDraftMonthReportVO; import com.lzbi.draft.entity.vo.TargetDraftMonthReportVO;
import com.lzbi.draft.service.ReportService; import com.lzbi.draft.service.ReportService;
import com.lzbi.task.domain.*; import com.lzbi.task.domain.*;
import com.lzbi.task.service.WorkParamReadService; import com.lzbi.task.service.WorkParamReadService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -195,4 +197,14 @@ public class ReportController extends BaseController {
public List<ThourWeatherVO> getThourWeather(@Validated ReadQueryReq readQueryReq) { public List<ThourWeatherVO> getThourWeather(@Validated ReadQueryReq readQueryReq) {
return workParamReadService.getThourWeather(readQueryReq); return workParamReadService.getThourWeather(readQueryReq);
} }
@PostMapping("/upload/production/daily")
public AjaxResult uploadProductionDaily(MultipartFile file) {
return reportService.uploadProductionDaily(file);
}
@PostMapping("/save/production/daily")
public AjaxResult saveProductionDaily(@RequestBody List<ProductionDailySheetReq> list) {
return reportService.saveProductionDaily(list);
}
} }

27
lzbi-module/src/main/java/com/lzbi/draft/domain/req/ProductionDailySheetReq.java

@ -0,0 +1,27 @@
package com.lzbi.draft.domain.req;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProductionDailySheetReq {
/**
* sheet页序号
*/
private int index;
/**
* sheet页名称
*/
private String name;
/**
* 数据
*/
private List<List<String>> data;
}

27
lzbi-module/src/main/java/com/lzbi/draft/domain/vo/ProductionDailySheetVO.java

@ -0,0 +1,27 @@
package com.lzbi.draft.domain.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProductionDailySheetVO {
/**
* sheet页序号
*/
private int index;
/**
* sheet页名称
*/
private String name;
/**
* 数据
*/
private List<List<String>> data;
}

72
lzbi-module/src/main/java/com/lzbi/draft/service/ReportService.java

@ -1,17 +1,31 @@
package com.lzbi.draft.service; package com.lzbi.draft.service;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.lzbi.common.core.domain.AjaxResult;
import com.lzbi.draft.domain.req.ProductionDailySheetReq;
import com.lzbi.draft.domain.vo.ProductionDailySheetVO;
import com.lzbi.draft.entity.dto.TargetDraftMonthReportValueDTO; import com.lzbi.draft.entity.dto.TargetDraftMonthReportValueDTO;
import com.lzbi.draft.entity.req.TargetDraftMonthReportReq; import com.lzbi.draft.entity.req.TargetDraftMonthReportReq;
import com.lzbi.draft.entity.vo.TargetDraftMonthReportVO; import com.lzbi.draft.entity.vo.TargetDraftMonthReportVO;
import com.lzbi.draft.mapper.DcBusiTargetDraftDayMapper; import com.lzbi.draft.mapper.DcBusiTargetDraftDayMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.IteratorUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -65,4 +79,62 @@ public class ReportService {
return list; return list;
} }
public AjaxResult uploadProductionDaily(MultipartFile file) {
List<ProductionDailySheetVO> list = new ArrayList<>();
InputStream inputStream = null;
try {
inputStream = file.getInputStream();
XSSFWorkbook hssfWorkbook = new XSSFWorkbook(inputStream);
int numberOfSheets = hssfWorkbook.getNumberOfSheets();
DataFormatter formatter = new DataFormatter();
for (int j = 0; j < numberOfSheets; j++) {
XSSFSheet sheetAt = hssfWorkbook.getSheetAt(j);
String sheetName = sheetAt.getSheetName();
//获取数据总行数
int rows = sheetAt.getPhysicalNumberOfRows();
List<List<String>> data = new ArrayList<>();
//每行数据处理
for (int i = 0; i < rows; i++) {
//获取一行数据
XSSFRow row = sheetAt.getRow(i);
if (null != row) {
List<Cell> cells = IteratorUtils.toList(row.cellIterator());
List<String> cellList = new ArrayList<>();
for (int i1 = 0, len1 = cells.size(); i1 < len1; i1++) {
cellList.add(formatter.formatCellValue(cells.get(i1)));
}
data.add(cellList);
}
}
list.add(new ProductionDailySheetVO(j, sheetName, data));
}
return AjaxResult.success(list);
} catch (Exception e) {
log.error("文件解析异常", e);
return AjaxResult.error();
} finally {
try {
if (null != inputStream) {
inputStream.close();
}
} catch (IOException e) {
log.error("文件解析异常", e);
}
}
}
public AjaxResult saveProductionDaily(List<ProductionDailySheetReq> list) {
if (CollectionUtils.isEmpty(list)) {
return AjaxResult.error("请选择需要保存的热源数据");
}
for (ProductionDailySheetReq productionDailySheetReq : list) {
String name = productionDailySheetReq.getName();
if (name.contains("(") && name.contains(")")) {
} else {
return AjaxResult.error("所选sheet页中存在非热源数据");
}
}
return null;
}
} }

Loading…
Cancel
Save