1.数据单位管理

2.谐波模块-excel和word报告数据单位调整
3.监测点权重管理
This commit is contained in:
wr
2023-08-24 15:07:12 +08:00
parent 5d288a6720
commit df51123872
26 changed files with 1477 additions and 44 deletions

View File

@@ -0,0 +1,85 @@
package com.njcn.device.pq.controller;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pq.pojo.po.PqsDeviceUnit;
import com.njcn.device.pq.pojo.vo.PqsDeviceUnitVo;
import com.njcn.device.pq.service.IPqsDeviceUnitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.njcn.web.controller.BaseController;
import java.util.List;
/**
* <p>
* 数据单位管理
* </p>
*
* @author wr
* @since 2023-08-21
*/
@RestController
@Api(tags = "数据单位管理")
@RequestMapping("/pq/pqsDeviceUnit")
@RequiredArgsConstructor
public class PqsDeviceUnitController extends BaseController {
private final IPqsDeviceUnitService iPqsDeviceUnitService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/nodeTree")
@ApiOperation("数据单位查询树")
@ApiImplicitParam(name = "devFlag", value = "实体", required = true)
public HttpResult<List<PqsDeviceUnitVo>> nodeTree(String devFlag) {
String methodDescribe = getMethodDescribe("nodeTree");
List<PqsDeviceUnitVo> pqsDeviceUnitVos = iPqsDeviceUnitService.nodeList(devFlag);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqsDeviceUnitVos, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/saveDeviceUnit")
@ApiOperation("数据单位修改")
@ApiImplicitParam(name = "unit", value = "实体", required = true)
public HttpResult<Boolean> saveDeviceUnit(@RequestBody PqsDeviceUnit unit) {
String methodDescribe = getMethodDescribe("saveDeviceUnit");
Boolean aBoolean = iPqsDeviceUnitService.saveDeviceUnit(unit);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, aBoolean, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/lineUnitDetail")
@ApiOperation("根据监测点id获取数据单位")
@ApiImplicitParam(name = "lineID", value = "实体", required = true)
public HttpResult<PqsDeviceUnit> lineUnitDetail(@RequestParam("lineID") String lineID) {
String methodDescribe = getMethodDescribe("lineUnitDetail");
PqsDeviceUnit pqsDeviceUnit = iPqsDeviceUnitService.lineUnitDetail(lineID);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqsDeviceUnit, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/devUnitDetail")
@ApiOperation("根据终端id获取数据单位")
@ApiImplicitParam(name = "devID", value = "实体", required = true)
public HttpResult<PqsDeviceUnit> devUnitDetail(@RequestParam("devID") String devID) {
String methodDescribe = getMethodDescribe("devUnitDetail");
PqsDeviceUnit pqsDeviceUnit = iPqsDeviceUnitService.devUnitDetail(devID);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqsDeviceUnit, methodDescribe);
}
}

View File

@@ -0,0 +1,78 @@
package com.njcn.device.pq.controller;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pq.pojo.po.PqsLineWeight;
import com.njcn.device.pq.pojo.vo.PqsLineWeightVo;
import com.njcn.device.pq.service.IPqsLineWeightService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.InputStreamResource;
import org.springframework.web.bind.annotation.*;
import com.njcn.web.controller.BaseController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
/**
* <p>
* 监测点评分权重
* </p>
*
* @author wr
* @since 2023-08-24
*/
@RestController
@RequestMapping("/LineWeight")
@Api(tags = "监测点评分权重")
@RequiredArgsConstructor
public class PqsLineWeightController extends BaseController {
private final IPqsLineWeightService iPqsLineWeightService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/LineWeightList")
@ApiOperation("查询监测点权重")
public HttpResult<List<PqsLineWeightVo>> LineWeightList() {
String methodDescribe = getMethodDescribe("nodeTree");
List<PqsLineWeightVo> pqsLineWeightVos = iPqsLineWeightService.LineWeightList();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqsLineWeightVos, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/addLineWeight")
@ApiOperation("监测点评分权重修改")
public HttpResult<Boolean> LineWeightList(@RequestBody PqsLineWeight lineWeight) {
String methodDescribe = getMethodDescribe("nodeTree");
Boolean aBoolean = iPqsLineWeightService.addLineWeight(lineWeight);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, aBoolean, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/export")
@ApiOperation("监测点评分权重模板导出")
public InputStreamResource export() throws IOException {
return iPqsLineWeightService.exportTemplate();
}
@PostMapping(value = "/batchWeight")
@ApiOperation("批量导入监测点评分权重")
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
public HttpResult<String> batchTerminal(@ApiParam(value = "文件", required = true) @RequestPart("file") MultipartFile file, HttpServletResponse response) {
String methodDescribe = getMethodDescribe("batchTerminal");
iPqsLineWeightService.batchWeight(file, response);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -0,0 +1,39 @@
package com.njcn.device.pq.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.device.pq.pojo.po.PqsDeviceUnit;
import com.njcn.device.pq.pojo.vo.PqsDeviceUnitVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* <p>
* Mapper 接口
* </p>
*
* @author wr
* @since 2023-08-21
*/
public interface PqsDeviceUnitMapper extends BaseMapper<PqsDeviceUnit> {
/**
* @Description: 查询终端单位信息
* @param devFlag
* @return: java.util.List<com.njcn.device.pq.pojo.vo.PqsDeviceUnitVo.DeviceUnit>
* @Author: wr
* @Date: 2023/8/21 14:17
*/
List<PqsDeviceUnitVo.DeviceUnit> deviceUnitList(@Param("devFlag") String devFlag);
/**
* @Description: 根据监测点信息查询
* @param ids
* @return: java.util.List<com.njcn.device.pq.pojo.po.PqsDeviceUnit>
* @Author: wr
* @Date: 2023/8/21 14:17
*/
PqsDeviceUnit deviceUnitByID(@Param("ids") String ids);
}

View File

@@ -0,0 +1,40 @@
package com.njcn.device.pq.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.device.pq.pojo.param.TerminalMainQueryParam;
import com.njcn.device.pq.pojo.po.PqsLineWeight;
import com.njcn.device.pq.pojo.vo.PqsLineWeightVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author wr
* @since 2023-08-24
*/
public interface PqsLineWeightMapper extends BaseMapper<PqsLineWeight> {
/**
* @Description: 查询监测点权重
* @param
* @return: java.util.List<com.njcn.device.pq.pojo.vo.PqsLineWeightVo>
* @Author: wr
* @Date: 2023/8/24 10:45
*/
List<PqsLineWeightVo> selectWeight();
/**
* @Description: 根据区域/供电公司/终端等查询监测点id
* @param param
* @return: java.lang.String
* @Author: wr
* @Date: 2023/8/24 13:50
*/
String getLineID( @Param("param") PqsLineWeightVo.WeightExcel param);
}

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.device.pq.mapper.PqsDeviceUnitMapper">
<select id="deviceUnitList" resultType="com.njcn.device.pq.pojo.vo.PqsDeviceUnitVo$DeviceUnit">
SELECT
dev.id as id,
dev.pid as pid,
dev.NAME as `name`,
pd.Run_Flag as devFlag,
b.*
FROM
pq_line dev
INNER JOIN pq_device pd ON dev.id = pd.id and dev.State = 1
LEFT JOIN pqs_device_unit b ON dev.id = b.dev_index
<where>
<if test="devFlag!=null and devFlag!='' ">
pd.Run_Flag = #{devFlag}
</if>
</where>
</select>
<select id="deviceUnitByID" resultType="com.njcn.device.pq.pojo.po.PqsDeviceUnit">
SELECT
unit.*
FROM
pq_line line
INNER JOIN pq_line vo ON vo.id = line.pid
INNER JOIN pq_line dev ON dev.id = vo.pid
INNER JOIN pq_device pd ON pd.id = dev.id
LEFT JOIN pqs_device_unit unit ON unit.DEV_INDEX = dev.id
<where>
line.State = 1
<if test="ids!=null and ids!='' ">
and line.id = #{ids}
</if>
</where>
</select>
</mapper>

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.device.pq.mapper.PqsLineWeightMapper">
<select id="selectWeight" resultType="com.njcn.device.pq.pojo.vo.PqsLineWeightVo">
SELECT
area.id AS areaName,
gd.NAME AS gbName,
sub.NAME AS subName,
dev.NAME AS devName,
line.NAME AS lineName,
pd.Run_Flag AS runFlag,
pld.Line_Grade AS lineGrade,
line.id AS lineIndex,
COMMUN_FEE_MARK,
SERVICE_MARK,
AGENT_MARK,
COMPANY_MARK,
USER_MARK,
LINE_TYPE_MARK,
BUSINESS_MARK
FROM
pq_line line
INNER JOIN pq_line_detail pld ON line.Id = pld.Id
INNER JOIN pq_line vol ON vol.Id = line.Pid
INNER JOIN pq_line dev ON dev.Id = vol.Pid
INNER JOIN pq_device pd ON pd.Id = dev.Id
INNER JOIN pq_line sub ON sub.Id = dev.Pid
INNER JOIN pq_line gd ON gd.Id = sub.Pid
INNER JOIN pq_line area ON area.Id = gd.Pid
LEFT JOIN pqs_line_weight plw ON line.Id = plw.LINE_INDEX
where line.State = 1
</select>
<select id="getLineID" resultType="java.lang.String">
SELECT
line.id
FROM
pq_line line
INNER JOIN pq_line vol ON vol.Id = line.Pid
INNER JOIN pq_line dev ON dev.Id = vol.Pid
INNER JOIN pq_line sub ON sub.Id = dev.Pid
INNER JOIN pq_line gd ON gd.Id = sub.Pid
INNER JOIN pq_line area ON area.Id = gd.Pid
where
line.name = #{param.lineName}
and dev.name = #{param.devName}
and sub.name = #{param.subName}
and gd.name = #{param.gbName}
and area.id = #{param.areaName}
</select>
</mapper>

View File

@@ -0,0 +1,55 @@
package com.njcn.device.pq.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.device.pq.pojo.po.PqsDeviceUnit;
import com.njcn.device.pq.pojo.vo.PqsDeviceUnitVo;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author wr
* @since 2023-08-21
*/
public interface IPqsDeviceUnitService extends IService<PqsDeviceUnit> {
/**
* @param devFlag
* @Description: 查询数据单位树
* @return: java.util.List<com.njcn.device.pq.pojo.vo.PqsDeviceUnitVo>
* @Author: wr
* @Date: 2023/8/21 13:58
*/
List<PqsDeviceUnitVo> nodeList(String devFlag);
/**
* @param unit
* @Description: 添加数据终端
* @return: java.lang.Boolean
* @Author: wr
* @Date: 2023/8/21 14:01
*/
Boolean saveDeviceUnit(PqsDeviceUnit unit);
/**
* @param lineID
* @Description: 根据监测点id查询数据单位
* @return: com.njcn.device.pq.pojo.po.PqsDeviceUnit
* @Author: wr
* @Date: 2023/8/21 14:02
*/
PqsDeviceUnit lineUnitDetail(String lineID);
/**
* @param devID
* @Description: 根据终端id查询数据单位
* @return: com.njcn.device.pq.pojo.po.PqsDeviceUnit
* @Author: wr
* @Date: 2023/8/21 14:02
*/
PqsDeviceUnit devUnitDetail(String devID);
}

View File

@@ -0,0 +1,59 @@
package com.njcn.device.pq.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.device.pq.pojo.po.PqsLineWeight;
import com.njcn.device.pq.pojo.vo.PqsLineWeightVo;
import org.springframework.core.io.InputStreamResource;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author wr
* @since 2023-08-24
*/
public interface IPqsLineWeightService extends IService<PqsLineWeight> {
/**
* @Description: 监测点评分权重修改
* @param lineWeight
* @return: java.lang.Boolean
* @Author: wr
* @Date: 2023/8/24 10:16
*/
Boolean addLineWeight(PqsLineWeight lineWeight);
/***
* @Description: 查询监测点权重
* @param
* @return: java.util.List<com.njcn.device.pq.pojo.vo.PqsLineWeightVo>
* @Author: wr
* @Date: 2023/8/24 10:44
*/
List<PqsLineWeightVo> LineWeightList();
/**
* @Description: 导出模板
* @param
* @return: org.springframework.core.io.InputStreamResource
* @Author: wr
* @Date: 2023/8/24 11:47
*/
InputStreamResource exportTemplate() throws IOException;
/**
* @Description: 批量导入监测点权重
* @param file
* @param response
* @Author: wr
* @Date: 2023/8/24 15:00
*/
void batchWeight(MultipartFile file, HttpServletResponse response);
}

View File

@@ -0,0 +1,119 @@
package com.njcn.device.pq.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.device.pq.enums.LineBaseEnum;
import com.njcn.device.pq.mapper.LineMapper;
import com.njcn.device.pq.mapper.PqsDeviceUnitMapper;
import com.njcn.device.pq.pojo.po.Line;
import com.njcn.device.pq.pojo.po.PqsDeviceUnit;
import com.njcn.device.pq.pojo.vo.PqsDeviceUnitVo;
import com.njcn.device.pq.pojo.vo.TerminalTree;
import com.njcn.device.pq.service.IPqsDeviceUnitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
* 服务实现类
* </p>
*
* @author wr
* @since 2023-08-21
*/
@Service
@RequiredArgsConstructor
public class PqsDeviceUnitServiceImpl extends ServiceImpl<PqsDeviceUnitMapper, PqsDeviceUnit> implements IPqsDeviceUnitService {
private final LineMapper lineMapper;
@Override
public List<PqsDeviceUnitVo> nodeList(String devFlag) {
List<Line> lines = lineMapper.selectList(new LambdaQueryWrapper<Line>()
.in(Line::getLevel, Arrays.asList(0, 1, 2, 3))
.eq(Line::getState, 1)
);
List<PqsDeviceUnitVo.DeviceUnit> deviceUnits = this.baseMapper.deviceUnitList(devFlag);
List<TerminalTree> provinceList = lineMapper.getProvinceList(null, 0);
Map<String, String> areaMap = provinceList.stream().collect(Collectors.toMap(TerminalTree::getId, TerminalTree::getName));
lines.stream().filter(x -> x.getLevel().equals(LineBaseEnum.PROVINCE_LEVEL.getCode())).forEach(x -> {
if (areaMap.containsKey(x.getId())) {
x.setName(areaMap.get(x.getId()));
}
}
);
List<PqsDeviceUnitVo> pqsDeviceUnitVos = recursionSelectList("0", lines, deviceUnits);
return pqsDeviceUnitVos;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean saveDeviceUnit(PqsDeviceUnit unit) {
PqsDeviceUnit byId = this.getById(unit.getDevIndex());
if (ObjectUtil.isNotNull(byId)) {
return this.updateById(unit);
}
return this.save(unit);
}
@Override
public PqsDeviceUnit lineUnitDetail(String lineID) {
PqsDeviceUnit pqsDeviceUnit = this.baseMapper.deviceUnitByID(lineID);
if(ObjectUtil.isNotNull(pqsDeviceUnit)){
return pqsDeviceUnit;
}
return new PqsDeviceUnit();
}
@Override
public PqsDeviceUnit devUnitDetail(String devID) {
PqsDeviceUnit byId = this.getById(devID);
if(ObjectUtil.isNotNull(byId)){
return byId;
}
return new PqsDeviceUnit();
}
/***
* 递归生成树
* @param id 父节点id
* @param deptInfos
* @param deviceUnits
* @return
*/
private static List<PqsDeviceUnitVo> recursionSelectList(String id, List<Line> deptInfos, List<PqsDeviceUnitVo.DeviceUnit> deviceUnits) {
List<PqsDeviceUnitVo> menuSelectList = new ArrayList<>();
Optional.ofNullable(deptInfos).ifPresent(customers -> customers.stream()
.filter(x -> x.getPid().equals(id))
.forEach(dto -> {
PqsDeviceUnitVo tree = new PqsDeviceUnitVo();
tree.setId(dto.getId());
tree.setName(dto.getName());
if (dto.getLevel().equals(LineBaseEnum.SUB_LEVEL.getCode())) {
List<PqsDeviceUnitVo.DeviceUnit> unit = getUnit(dto.getId(), deviceUnits);
tree.setChildren(unit);
} else {
tree.setChildren(recursionSelectList(dto.getId(), deptInfos, deviceUnits));
}
menuSelectList.add(tree);
}));
return menuSelectList;
}
/**
* 查询数据单位终端信息集合
*
* @param id
* @param deviceUnits
* @return
*/
private static List<PqsDeviceUnitVo.DeviceUnit> getUnit(String id, List<PqsDeviceUnitVo.DeviceUnit> deviceUnits) {
return deviceUnits.stream().filter(x -> x.getPid().equals(id)).collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,148 @@
package com.njcn.device.pq.service.impl;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.device.pq.mapper.LineMapper;
import com.njcn.device.pq.mapper.PqsLineWeightMapper;
import com.njcn.device.pq.pojo.po.PqsLineWeight;
import com.njcn.device.pq.pojo.vo.PqsLineWeightVo;
import com.njcn.device.pq.pojo.vo.TerminalTree;
import com.njcn.device.pq.service.IPqsLineWeightService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.device.pq.utils.ExcelStyleUtil;
import com.njcn.poi.excel.ExcelUtil;
import com.njcn.poi.util.PoiUtil;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.core.io.InputStreamResource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* <p>
* 服务实现类
* </p>
*
* @author wr
* @since 2023-08-24
*/
@Service
@RequiredArgsConstructor
public class PqsLineWeightServiceImpl extends ServiceImpl<PqsLineWeightMapper, PqsLineWeight> implements IPqsLineWeightService {
private final LineMapper lineMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean addLineWeight(PqsLineWeight lineWeight) {
PqsLineWeight weight = this.getById(lineWeight.getLineIndex());
if (ObjectUtil.isNotNull(weight)) {
return this.updateById(lineWeight);
}
return this.save(lineWeight);
}
@Override
public List<PqsLineWeightVo> LineWeightList() {
List<PqsLineWeightVo> lines = this.baseMapper.selectWeight();
List<TerminalTree> provinceList = lineMapper.getProvinceList(null, 0);
Map<String, String> areaMap = provinceList.stream().collect(Collectors.toMap(TerminalTree::getId, TerminalTree::getName));
lines.stream().forEach(x -> {
if (areaMap.containsKey(x.getAreaName())) {
x.setAreaName(areaMap.get(x.getAreaName()));
}
}
);
return lines;
}
@Override
public InputStreamResource exportTemplate() throws IOException {
ExportParams exportParams = new ExportParams("批量导入模板(所有字段均是必填,请严格按照模板标准填入数据)", "终端入网检测录入信息");
exportParams.setStyle(ExcelStyleUtil.class);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, PqsLineWeightVo.WeightExcel.class, new ArrayList<PqsLineWeightVo.WeightExcel>());
//临时缓冲区
ByteArrayOutputStream out = new ByteArrayOutputStream();
//创建临时文件
workbook.write(out);
byte[] bookByteAry = out.toByteArray();
InputStream in = new ByteArrayInputStream(bookByteAry);
InputStreamResource inputStreamResource = new InputStreamResource(in);
return inputStreamResource;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void batchWeight(MultipartFile file, HttpServletResponse response) {
ImportParams params = new ImportParams();
params.setHeadRows(1);
params.setTitleRows(1);
params.setNeedVerify(true);
//第一个sheet为台账信息
params.setStartSheetIndex(0);
params.setSheetNum(1);
try {
ExcelImportResult<PqsLineWeightVo.WeightExcel> weightList = ExcelImportUtil.importExcelMore(file.getInputStream(), PqsLineWeightVo.WeightExcel.class, params);
//如果存在非法数据,将不合格的数据导出
if (weightList.isVerifyFail()) {
PoiUtil.exportFileByWorkbook(weightList.getFailWorkbook(), "非法监测点权重录入信息.xlsx", response);
} else {
saveWeightBase(weightList.getList());
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void saveWeightBase(List<PqsLineWeightVo.WeightExcel> weightList) {
List<PqsLineWeightVo.Msg> weightExcelMsg = new ArrayList<>();
List<PqsLineWeight> info = new ArrayList<>();
List<TerminalTree> provinceList = lineMapper.getProvinceList(null, 0);
Map<String, String> areaMap = provinceList.stream().collect(Collectors.toMap(TerminalTree::getName, TerminalTree::getId));
weightList.stream().forEach(x -> {
if (areaMap.containsKey(x.getAreaName())) {
x.setAreaName(areaMap.get(x.getAreaName()));
}
}
);
for (PqsLineWeightVo.WeightExcel weightExcel : weightList) {
String lineID = this.baseMapper.getLineID(weightExcel);
if(StrUtil.isNotBlank(lineID)){
PqsLineWeight weight = BeanUtil.copyProperties(weightExcel, PqsLineWeight.class);
weight.setLineIndex(lineID);
info.add(weight);
}else{
PqsLineWeightVo.Msg msg = BeanUtil.copyProperties(weightExcel, PqsLineWeightVo.Msg.class);
msg.setMsg("未匹配到监测点对象,请仔细请检查/区域/供电公司/变电站名称/装置名称/监测点名称,是否对应正确");
weightExcelMsg.add(msg);
}
}
if(CollUtil.isNotEmpty(info)){
this.saveOrUpdateBatch(info);
}
//错误信息不为空则以excel的形式输出到前台
if (CollectionUtil.isNotEmpty(weightExcelMsg)) {
ExcelUtil.exportExcel("失败列表.xlsx", PqsLineWeightVo.Msg.class, weightExcelMsg);
}
}
}