Commit 2b7da872 authored by 田涛's avatar 田涛

电力设备新增模板导出和导入功能

parent fbffe876
package com.yeejoin.amos.fas.business.controller;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.yeejoin.amos.fas.core.util.*;
import com.yeejoin.amos.fas.exception.YeeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.util.CollectionUtils;
......@@ -30,6 +33,9 @@ import com.yeejoin.amos.fas.dao.entity.PreplanPicture;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.typroject.tyboot.core.foundation.utils.Bean;
import javax.servlet.http.HttpServletResponse;
@RestController
@RequestMapping(value = "/api/impEquip")
......@@ -319,4 +325,30 @@ public class EquipmentController extends BaseController {
return CommonResponseUtil.success(iEquipService.findFireEquipDataByPointCode(code));
}
/**
* 模板下载
*
* @return
*/
@Permission
@RequestMapping(value = "/downTemplate")
@ApiOperation(httpMethod = "GET", value = "下载模板", notes = "下载模板")
public void downTemplate(HttpServletResponse response) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
iEquipService.downTemplate(response);
}
/**
* 电力设备信息导入
*
* @return
*/
@RequestMapping(value = "/uploadList")
@ApiOperation(httpMethod = "POST", value = "导入", notes = "导入")
public Object uploadList(MultipartFile file) {
iEquipService.uploadList(file, getOrgCode(getSelectedOrgInfo()));
return CommonResponseUtil.success();
}
}
......@@ -2,6 +2,7 @@ package com.yeejoin.amos.fas.business.dao.mapper;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.yeejoin.amos.fas.dao.dto.EquipmentDTO;
import org.apache.ibatis.annotations.Param;
......@@ -21,4 +22,6 @@ public interface ImpEquipMapper extends BaseMapper {
Long reservePageCount();
List<EquipmentDTO> reservePage(@Param("start") long start,@Param("length") int length);
Set<String> getAllCode();
}
......@@ -23,4 +23,6 @@ public interface IEquipmentDao extends BaseDao<Equipment, Long> {
@Query(value = "SELECT ss.equipment_specific_id FROM(SELECT si.equipment_specific_id, si.equipment_index_id FROM wl_equipment_specific_index si WHERE si.equipment_specific_id IN ( SELECT fe.fire_equipment_id FROM f_equipment_fire_equipment fe WHERE fe.equipment_id = ?1 ) ) ss LEFT JOIN wl_equipment_index ei ON ss.equipment_index_id = ei.id WHERE ei.type_code = ?2", nativeQuery = true)
List<Object> getReserveEquipById(Long id, String typeCode);
Optional<Equipment> findFirstByCodeIs(String code);
}
package com.yeejoin.amos.fas.business.feign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -15,4 +16,10 @@ public interface IEquipManageFeign {
*/
@PutMapping(value = "/equip/building/unbind/region")
void unbindRelation(@RequestParam(value ="instanceId") Long instanceId);
/**
* 查询建筑位置全路径
*/
@GetMapping(value = "/equip/building/getBuildingCodeKeyMap")
Object getBuildingCodeKey();
}
......@@ -6,6 +6,7 @@ import com.yeejoin.amos.fas.business.dao.mapper.*;
import com.yeejoin.amos.fas.business.dao.repository.IEquipmentDao;
import com.yeejoin.amos.fas.business.dao.repository.IEquipmentFireEquipmentDao;
import com.yeejoin.amos.fas.business.dao.repository.IPreplanPictureDao;
import com.yeejoin.amos.fas.business.feign.IEquipManageFeign;
import com.yeejoin.amos.fas.business.feign.RemoteSecurityService;
import com.yeejoin.amos.fas.business.param.ImgParam;
import com.yeejoin.amos.fas.business.service.intfc.IEquipmentService;
......@@ -22,6 +23,9 @@ import com.yeejoin.amos.fas.exception.YeeException;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import com.yeejoin.amos.feign.privilege.model.DepartmentModel;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -34,9 +38,13 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
@Service("equipService")
......@@ -44,6 +52,8 @@ public class EquipmentServiceImpl implements IEquipmentService {
private final Logger log = LoggerFactory.getLogger(EquipmentServiceImpl.class);
private final String[] docxTitle = {"设备编号", "设备名称", "所属区域", "位置"};
@Autowired
ImpEquipMapper impEquipMapper;
......@@ -72,6 +82,9 @@ public class EquipmentServiceImpl implements IEquipmentService {
@Autowired
private PlanEquipmentMapper planEquipmentMapper;
@Autowired
IEquipManageFeign iEquipManageFeign;
// @Autowired
// private IFmeaEquipmentPointDao iFmeaEquipmentPointDao;
......@@ -515,4 +528,113 @@ public class EquipmentServiceImpl implements IEquipmentService {
return iEquipmentDao.getReserveEquipById(id, typeCode);
}
@Override
public void downTemplate(HttpServletResponse response) {
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(0);
for (int i = 0; i < docxTitle.length; i++) {
Cell cell = row.createCell(i);
cell.setCellValue(docxTitle[i]);
}
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment;filename=" + URLEncoder.encode("电力设备批量导入模板.xls", "UTF-8"));
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
workbook.write(response.getOutputStream());
} catch (IOException e) {
//throw new NormalException(e.getMessage());
}
}
@Override
public void uploadList(MultipartFile file, String orgCode) {
if (null != file) {
try {
Workbook workbook = new HSSFWorkbook(file.getInputStream());
Sheet sheet = workbook.getSheetAt(0);
int lastRowNum = sheet.getLastRowNum();
if (lastRowNum >= 1) {
List<Equipment> equipmentList = new LinkedList<>();
// 获取所有的区域编码
Map<String, Object> res = (Map<String, Object>) iEquipManageFeign.getBuildingCodeKey();
if (((int)res.get("status")) != 200) {
throw new YeeException("解析位置编码失败");
}
Map<String, String> areaCodeIdMap = (Map<String, String>) res.getOrDefault("result", new HashMap<String, String>());
// 获取所有存在的重点设备编码
Set<String> equipCodeSet = impEquipMapper.getAllCode();
for (int i = 1; i <= lastRowNum; i++) {
Row row = sheet.getRow(i);
String equipCode = getCellValue(row.getCell(0));
String equipName = getCellValue(row.getCell(1));
String areaCode = getCellValue(row.getCell(2));
String position = getCellValue(row.getCell(3));
if (ValidationUtil.isEmpty(equipCode) || ValidationUtil.isEmpty(equipName) || ValidationUtil.isEmpty(areaCode)) {
throw new YeeException("错误行" + i + ":检查非空字段");
}
if (equipCodeSet.contains(equipCode.trim())) {
throw new YeeException("错误行" + i + ":重复的设备编号");
}
if (!areaCodeIdMap.containsKey(areaCode.trim())) {
throw new YeeException("错误行" + i + ":所属区域编号有误");
}
equipCodeSet.add(equipCode.trim());
Equipment equipment = new Equipment();
equipment.setName(equipName.trim());
equipment.setCode(equipCode.trim());
equipment.setRiskSourceId(Long.valueOf(areaCodeIdMap.get(areaCode.trim())));
if (!ValidationUtil.isEmpty(position)) {
equipment.setAddress(position);
}
equipment.setIsIndoor(false);
equipment.setOrgCode(orgCode);
equipmentList.add(equipment);
}
iEquipmentDao.saveAll(equipmentList);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String getCellValue(Cell cell) {
if (cell == null) {
return null;
}
String cellValue = "";
// 以下是判断数据的类型
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC: // 数字
if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
cellValue = sdf.format(org.apache.poi.ss.usermodel.DateUtil.getJavaDate(cell.getNumericCellValue())).toString();
} else {
DataFormatter dataFormatter = new DataFormatter();
cellValue = dataFormatter.formatCellValue(cell);
}
break;
case Cell.CELL_TYPE_STRING: // 字符串
cellValue = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_BOOLEAN: // Boolean
cellValue = cell.getBooleanCellValue() + "";
break;
case Cell.CELL_TYPE_FORMULA: // 公式
cellValue = cell.getCellFormula() + "";
break;
case Cell.CELL_TYPE_BLANK: // 空值
cellValue = "";
break;
case Cell.CELL_TYPE_ERROR: // 故障
cellValue = "";
break;
default:
cellValue = "";
break;
}
return cellValue;
}
}
package com.yeejoin.amos.fas.business.service.intfc;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yeejoin.amos.fas.business.param.ImgParam;
import com.yeejoin.amos.fas.business.vo.EquipCommunicationData;
import com.yeejoin.amos.fas.business.vo.EquipmentSpecificIndexVo;
import com.yeejoin.amos.fas.core.common.request.CommonPageable;
import com.yeejoin.amos.fas.core.common.response.EquipDetailsResponse;
import com.yeejoin.amos.fas.core.util.DaoCriteria;
......@@ -13,6 +11,7 @@ import com.yeejoin.amos.fas.dao.entity.PreplanPicture;
import org.springframework.data.domain.Page;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
......@@ -113,8 +112,20 @@ public interface IEquipmentService {
/**
* 获取重点设备绑定设备
* @param id
* @param firealarm
* @param typeCode
* @return
*/
List<Object> getReserveEquipById(Long id, String typeCode);
/**
* 下载导入模板
* @param response
*/
void downTemplate(HttpServletResponse response);
/**
* 导入数据
* @param file
*/
void uploadList(MultipartFile file, String orgCode);
}
......@@ -89,4 +89,8 @@
a.reserve_plan IS NOT NULL
AND a.reserve_plan != ''
</select>
<select id="getAllCode" resultType="string">
select distinct code from f_equipment
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment