Prechádzať zdrojové kódy

feature 特种设备导入功能

xiahan 1 rok pred
rodič
commit
ddf14c2639

+ 3 - 0
cx-safe-check/cx-save-check-common/src/main/java/com/rongwei/sfcommon/sys/service/CheckItemsService.java

@@ -7,6 +7,7 @@ import com.rongwe.scentity.domian.CheckItemsDo;
 import com.rongwei.rwcommon.base.R;
 
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -25,5 +26,7 @@ public interface CheckItemsService extends IService<CheckItemsDo> {
     void reportEquMessage();
 
     R stateUpdateScheduledTasks();
+
+    R importExcel(Map<String, String> queryParameter);
 }
 

+ 227 - 2
cx-safe-check/cx-save-check-common/src/main/java/com/rongwei/sfcommon/sys/service/impl/CheckItemsServiceImpl.java

@@ -1,5 +1,7 @@
 package com.rongwei.sfcommon.sys.service.impl;
 
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
+import cn.afterturn.easypoi.excel.entity.ImportParams;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -8,21 +10,33 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.rongwe.scentity.domian.CheckItemsDo;
 import com.rongwe.scentity.domian.PointCheckDo;
+import com.rongwe.scentity.vo.CheckAreaVo;
 import com.rongwe.scentity.vo.CheckItemsTypeVo;
+import com.rongwe.scentity.vo.ImportCheckItemsVo;
 import com.rongwe.scentity.vo.UserMailOrgVo;
 import com.rongwei.rwadmincommon.system.domain.SysDictDo;
 import com.rongwei.rwadmincommon.system.service.impl.SysDictServiceImpl;
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
 import com.rongwei.rwcommon.base.R;
+import com.rongwei.rwcommon.base.exception.CustomException;
+import com.rongwei.rwcommon.utils.SecurityUtil;
+import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
 import com.rongwei.safecommon.utils.CXCommonUtils;
 import com.rongwei.sfcommon.sys.dao.CheckItemsDao;
 import com.rongwei.sfcommon.sys.dao.SaveCheckCommonDao;
 import com.rongwei.sfcommon.sys.service.CheckItemsService;
 import com.rongwei.sfcommon.sys.service.PointCheckService;
+import com.rongwei.sfcommon.utils.ClassExcelVerifyHandler;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
-import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
+import java.io.File;
+import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.ZoneId;
 import java.time.temporal.ChronoUnit;
@@ -37,7 +51,6 @@ import static com.rongwei.safecommon.utils.SaveConstans.NotifyType.SPECIALEQUIPM
 
 @Service("checkItemsService")
 public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItemsDo> implements CheckItemsService {
-
     /**
      * 组织机构代码
      */
@@ -45,10 +58,28 @@ public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItems
         add("code-safe");
         add("role031");
     }};
+    // 设备使用状态数据字典
+    public static final String SBSYZT_DICT = "sbsyzt";
+    // 特种设备类别数据字典
+    public static final String TZSBLB_DICT = "tzsblb";
+    // 检验结论
+    public static final String JYJL_DICT = "jyjl";
+    // 设备类型
+    public static final String CHECK_ITEM_TYPE_DICT = "asp_check_item_type";
+
     /**
      * 特种设备管理员
      */
     public static final String SPECIAL_EQUIPMENT_ADMINISTRATOR = "role031";
+    public static final String EMPTY_ERROR_MSG = "第%s行 %s 为空";
+    public static final String DATE_FORMAT_ERROR_MSG = "第%s行 %s 时间格式不正确";
+    public static final List<SimpleDateFormat> DATE_FORMAT_LIST = new ArrayList<SimpleDateFormat>() {{
+        add(new SimpleDateFormat("yyyy-MM-dd"));
+        add(new SimpleDateFormat("yyyy/MM/dd"));
+        add(new SimpleDateFormat("yyyy.MM.dd"));
+        add(new SimpleDateFormat("yyyyMMdd"));
+    }};
+    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
     @Autowired
     @Lazy
     private PointCheckService pointCheckService;
@@ -58,6 +89,8 @@ public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItems
     private SaveCheckCommonDao saveCheckCommonDao;
     @Autowired
     private SysDictServiceImpl sysDictService;
+    @Autowired
+    private ClassExcelVerifyHandler verifyHandler;
 
     /**
      * 设备列表删除验证是否存在点检记录
@@ -207,4 +240,196 @@ public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItems
                     k.getId(), SPECIALEQUIPMENT, false);
         });
     }
+
+
+    @Override
+    public R importExcel(Map<String, String> queryParameter) {
+        String fileId = queryParameter.getOrDefault("fileId", "");
+        CXCommonUtils.parameterCheck(() -> StringUtils.isBlank(fileId), "请上传文件", "文件ID为空");
+        SysFileItemDo fileItemDo = saveCheckCommonDao.getFileItemByID(fileId);
+        CXCommonUtils.parameterCheck(() -> fileItemDo == null, "文件解析有误!请联系管理员", "无法根据文件ID:{},获取到文件信息", fileId);
+        String realPath = fileItemDo.getFullpath();
+        CXCommonUtils.parameterCheck(() -> StringUtils.isBlank(realPath), "文件解析有误!请联系管理员", "根据文件ID:{},无法获取到文件路径", fileId);
+        File file = new File(realPath);
+        CXCommonUtils.parameterCheck(() -> !file.exists(), "文件解析有误!请联系管理员", "根据文件地址:{},无法获取文件", realPath);
+        ImportParams params = new ImportParams();
+        params.setTitleRows(0);
+        params.setHeadRows(1);
+        params.setVerifyHandler(verifyHandler);
+        List<ImportCheckItemsVo> userList = ExcelImportUtil.importExcel(file, ImportCheckItemsVo.class, params);
+        log.info("userList:{}", userList);
+        // 存放异常数据
+        List<String> errorMsgList = new ArrayList<>();
+        // 解析后的数据
+        List<CheckItemsDo> saveList = new ArrayList<>();
+        ImportCheckItemsVo importCheckItemsVo;
+        SysUserVo currentUser = CXCommonUtils.getCurrentUser();
+        String tenantId = currentUser.getOrganizationDoList().get(0).getFullpid().split(",")[1];
+        //获取区域信息
+        Map<String, String> checkAreaMap = saveCheckCommonDao.getCheckArea(tenantId).stream().collect(Collectors.toMap(CheckAreaVo::getName, CheckAreaVo::getId, (v1, v2) -> v1));
+        // 获取组织机构信息
+        Map<String, String> orgMap = null;
+        //saveCheckCommonDao.getOrgByTenantId(tenantId).stream().collect(Collectors.toMap(SysOrganizationDo::getFullname, SysOrganizationDo::getId, (v1, v2) -> v1));
+        // 用户信息
+        Map<String, String> userMap = null;
+        // saveCheckCommonDao.getUserInfoByTenantId(tenantId).stream().collect(Collectors.toMap(SysUserDo::getName, SysUserDo::getId, (v1, v2) -> v1));
+        // 设备使用状态数据字典
+        Map<String, String> deviceStatusDict = sysDictService.getDictsByType(SBSYZT_DICT).stream().collect(Collectors.toMap(SysDictDo::getName, SysDictDo::getValue, (v1, v2) -> v1));
+        Map<String, String> deviceTypeDict = sysDictService.getDictsByType(TZSBLB_DICT).stream().collect(Collectors.toMap(SysDictDo::getName, SysDictDo::getValue, (v1, v2) -> v1));
+        Map<String, String> conclusionTypeDict = sysDictService.getDictsByType(JYJL_DICT).stream().collect(Collectors.toMap(SysDictDo::getName, SysDictDo::getValue, (v1, v2) -> v1));
+        Map<String, String> typeDict = sysDictService.getDictsByType(CHECK_ITEM_TYPE_DICT).stream().collect(Collectors.toMap(SysDictDo::getName, SysDictDo::getValue, (v1, v2) -> v1));
+
+        for (int i = 0; i < userList.size(); i++) {
+            importCheckItemsVo = userList.get(i);
+            // 数据格式校验
+            checkDataAccuracy(i + 1, importCheckItemsVo, errorMsgList);
+
+            if (StringUtils.isNotBlank(importCheckItemsVo.getTreeName()) && !checkAreaMap.containsKey(importCheckItemsVo.getTreeName())) {
+                errorMsgList.add("第" + (i + 1) + "行树表名称不存在");
+            }
+            if (errorMsgList.isEmpty()) {
+                saveList.add(voToDo(importCheckItemsVo, checkAreaMap, tenantId, deviceStatusDict,
+                        deviceTypeDict, conclusionTypeDict, typeDict));
+            }
+        }
+        if (!errorMsgList.isEmpty()) {
+            log.error("excel数据异常:{}", errorMsgList);
+            throw new CustomException(StringUtils.join(errorMsgList, ";"));
+        }
+        if (!saveList.isEmpty()) {
+            this.saveBatch(saveList, 100);
+        }
+
+        return R.ok();
+    }
+
+    private void checkDataAccuracy(int index, ImportCheckItemsVo checkItemsVo, List<String> errorMsgList) {
+        if (StringUtils.isBlank(checkItemsVo.getTreeName())) {
+            errorMsgList.add(String.format(EMPTY_ERROR_MSG, index, "左侧树表"));
+        }
+        if (StringUtils.isBlank(checkItemsVo.getCheckitemname())) {
+            errorMsgList.add(String.format(EMPTY_ERROR_MSG, index, "设备名称"));
+        }
+        if (StringUtils.isBlank(checkItemsVo.getCheckitemtype())) {
+            errorMsgList.add(String.format(EMPTY_ERROR_MSG, index, "设备类型"));
+        }
+        if (StringUtils.isBlank(checkItemsVo.getDevicecheckstr())) {
+            errorMsgList.add(String.format(EMPTY_ERROR_MSG, index, "检验日期"));
+        }
+        if (StringUtils.isBlank(checkItemsVo.getNextcheckstr())) {
+            errorMsgList.add(String.format(EMPTY_ERROR_MSG, index, "下次检验日期"));
+        }
+        if (StringUtils.isBlank(checkItemsVo.getWarnstr())) {
+            errorMsgList.add(String.format(EMPTY_ERROR_MSG, index, "预计提醒日期"));
+        }
+        // 校验时间格式是否正确
+        if (StringUtils.isNotBlank(checkItemsVo.getDevicecheckstr()) && dateFormatValidation(checkItemsVo.getDevicecheckstr()) == null) {
+            errorMsgList.add(String.format(DATE_FORMAT_ERROR_MSG, index, "检验日期"));
+        }
+        // 校验时间格式是否正确
+        if (StringUtils.isNotBlank(checkItemsVo.getNextcheckstr()) && dateFormatValidation(checkItemsVo.getNextcheckstr()) == null) {
+            errorMsgList.add(String.format(DATE_FORMAT_ERROR_MSG, index, "下次检验日期"));
+        }
+        // 校验时间格式是否正确
+        if (StringUtils.isNotBlank(checkItemsVo.getWarnstr()) && dateFormatValidation(checkItemsVo.getWarnstr()) == null) {
+            errorMsgList.add(String.format(DATE_FORMAT_ERROR_MSG, index, "预计提醒日期"));
+        }
+        // 校验时间格式是否正确
+        if (StringUtils.isNotBlank(checkItemsVo.getDevicecreatestr()) && dateFormatValidation(checkItemsVo.getDevicecreatestr()) == null) {
+            errorMsgList.add(String.format(DATE_FORMAT_ERROR_MSG, index, "设备制造日期"));
+        }
+        // 校验时间格式是否正确
+        if (StringUtils.isNotBlank(checkItemsVo.getDeviceinstallstr()) && dateFormatValidation(checkItemsVo.getDeviceinstallstr()) == null) {
+            errorMsgList.add(String.format(DATE_FORMAT_ERROR_MSG, index, "设备安装日期"));
+        }
+        // 校验时间格式是否正确
+        if (StringUtils.isNotBlank(checkItemsVo.getDevicestartstr()) && dateFormatValidation(checkItemsVo.getDevicestartstr()) == null) {
+            errorMsgList.add(String.format(DATE_FORMAT_ERROR_MSG, index, "开始使用日期"));
+        }
+    }
+
+    private Date dateFormatValidation(String strDate) {
+        Date date = null;
+        for (SimpleDateFormat simpleDateFormat : DATE_FORMAT_LIST) {
+            try {
+                date = simpleDateFormat.parse(strDate);
+                break;
+            } catch (Exception e) {
+                log.info("时间格式不正确");
+            }
+        }
+        return date;
+    }
+
+    /**
+     * vo 转 do
+     *
+     * @param checkArea
+     * @param vo
+     * @return
+     */
+    private CheckItemsDo voToDo(ImportCheckItemsVo vo,
+                                Map<String, String> checkAreaMap,
+                                String tenantId,
+                                Map<String, String> deviceStatusDict,
+                                Map<String, String> deviceTypeDict,
+                                Map<String, String> conclusionTypeDict,
+                                Map<String, String> typeDict) {
+        CheckItemsDo checkItemsDo = new CheckItemsDo();
+        BeanUtils.copyProperties(vo, checkItemsDo);
+        checkItemsDo.setId(SecurityUtil.getUUID());
+        checkItemsDo.setTenantid(tenantId);
+        checkItemsDo.setCreatedate(new Date());
+        checkItemsDo.setCheckitemareaid(checkAreaMap.get(vo.getTreeName()));
+        checkItemsDo.setSource("1");
+        if (StringUtils.isNotBlank(vo.getCheckitemtype())) {
+            checkItemsDo.setCheckitemtype(typeDict.get(vo.getCheckitemtype()));
+        }
+        if (StringUtils.isNotBlank(vo.getDevicestatus())) {
+            checkItemsDo.setDevicestatus(deviceStatusDict.get(vo.getDevicestatus()));
+        }
+        if (StringUtils.isNotBlank(vo.getCategory())) {
+            checkItemsDo.setCategory(deviceTypeDict.get(vo.getCategory()));
+        }
+        if (StringUtils.isNotBlank(vo.getInspectresult())) {
+            checkItemsDo.setInspectresult(conclusionTypeDict.get(vo.getInspectresult()));
+        }
+
+        if (StringUtils.isNotBlank(vo.getNextcheckstr())) {
+            checkItemsDo.setNextcheckdate(dateFormatValidation(vo.getNextcheckstr()));
+        }
+        // 校验时间格式是否正确
+        if (StringUtils.isNotBlank(vo.getWarnstr())) {
+            checkItemsDo.setWarndate(dateFormatValidation(vo.getWarnstr()));
+        }
+        // 校验时间格式是否正确
+        if (StringUtils.isNotBlank(vo.getDevicecreatestr())) {
+            checkItemsDo.setDevicecreatedate(dateFormatValidation(vo.getDevicecreatestr()));
+        }
+        // 校验时间格式是否正确
+        if (StringUtils.isNotBlank(vo.getDeviceinstallstr())) {
+            checkItemsDo.setDeviceinstalldate(dateFormatValidation(vo.getDeviceinstallstr()));
+        }
+        // 校验时间格式是否正确
+        if (StringUtils.isNotBlank(vo.getDevicestartstr())) {
+            checkItemsDo.setDevicestartdate(dateFormatValidation(vo.getDevicestartstr()));
+        }
+        // 校验时间格式是否正确
+        if (StringUtils.isNotBlank(vo.getDevicecheckstr())) {
+            checkItemsDo.setDevicecheckdate(dateFormatValidation(vo.getDevicecheckstr()));
+        }
+
+        LocalDate date1 = checkItemsDo.getNextcheckdate().toInstant()
+                .atZone(ZoneId.systemDefault())
+                .toLocalDate();
+        long daysBetween = ChronoUnit.DAYS.between(LocalDate.now(), date1);
+        if (daysBetween <= 30) {
+            checkItemsDo.setReminderstate(HIGH);
+        } else if (daysBetween <= 90) {
+            checkItemsDo.setReminderstate(MIDDLE);
+        } else {
+            checkItemsDo.setReminderstate(LOW);
+        }
+        return checkItemsDo;
+    }
 }

+ 28 - 0
cx-safe-check/cx-save-check-entity/src/main/java/com/rongwe/scentity/domian/CheckItemsDo.java

@@ -366,4 +366,32 @@ public class CheckItemsDo extends BaseDo implements Serializable {
 	 * 提醒状态
 	 */
 	private String reminderstate;
+	/**
+	 * 厂内车牌号
+	 */
+	private String plantnumber;
+	/**
+	 * 自重(单位T)
+	 */
+	private BigDecimal weight;
+	/**
+	 * 厂内编号
+	 */
+	private String plantcode;
+	/**
+	 * 设备位置
+	 */
+	private String equaddress;
+	/**
+	 * 额定起重量/高度(单位T/M)
+	 */
+	private String weigthorheight;
+	/**
+	 * 双限位
+	 */
+	private String doublelimitposition;
+	/**
+	 * 容积
+	 */
+	private String volume;
 }

+ 235 - 0
cx-safe-check/cx-save-check-entity/src/main/java/com/rongwe/scentity/vo/ImportCheckItemsVo.java

@@ -0,0 +1,235 @@
+package com.rongwe.scentity.vo;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * ImportCheckItemsVo class
+ *
+ * @author XH
+ * @date 2024/06/20
+ */
+@Data
+public class ImportCheckItemsVo implements Serializable {
+    /**
+     * 树名称
+     */
+    @Excel(name = "左侧树表", orderNum = "0")
+    private String treeName;
+
+    /**
+     *
+     */
+    @Excel(name = "设备名称", orderNum = "1")
+    private String checkitemname;
+
+    /**
+     * 设备类型
+     */
+    @Excel(name = "设备类型", orderNum = "2")
+    private String checkitemtype;
+
+    /**
+     * 规格型号
+     */
+    @Excel(name = "规格型号", orderNum = "3")
+    private String devicemodel;
+
+    /**
+     * 出厂编号
+     */
+    @Excel(name = "出厂编号", orderNum = "4")
+    private String deviceoutcode;
+    /**
+     * 安装地点
+     */
+    @Excel(name = "安装地点", orderNum = "5")
+    private String deviceaddress;
+
+    /**
+     * 设备编号
+     */
+    @Excel(name = "设备编号", orderNum = "6")
+    private String checkitemcode;
+
+    /**
+     * 设备代码
+     */
+    @Excel(name = "设备代码", orderNum = "7")
+    private String devicecode;
+
+    /**
+     * 注册代码
+     */
+    @Excel(name = "注册代码", orderNum = "8")
+    private String signupcode;
+
+    /**
+     * 制造单位名称
+     */
+    @Excel(name = "设备制造单位名称", orderNum = "9")
+    private String devicenakedname;
+
+    /**
+     * 设备制造日期
+     */
+    @Excel(name = "设备制造日期", orderNum = "10")
+    private String devicecreatestr;
+
+    /**
+     * 设备使用状态
+     */
+    @Excel(name = "设备使用状态", orderNum = "11")
+    private String devicestatus;
+    /**
+     * 使用登记证编号
+     */
+    @Excel(name = "使用登记证编号", orderNum = "12")
+    private String registrationno;
+    /**
+     * 环保号
+     */
+    @Excel(name = "环保号", orderNum = "13")
+    private String environmentalprotectionno;
+
+    /**
+     * 备案号
+     */
+    @Excel(name = "备案号", orderNum = "14")
+    private String filingno;
+    /**
+     * 设备安装日期
+     */
+    @Excel(name = "设备安装日期",orderNum = "15")
+    private String deviceinstallstr;
+
+    /**
+     * 设备开始使用日期
+     */
+    @Excel(name = "开始使用日期",orderNum = "16")
+    private String devicestartstr;
+
+    /**
+     * 类别
+     */
+    @Excel(name = "类别",orderNum = "17")
+    private String category;
+
+    /**
+     * 年限
+     */
+    @Excel(name = "年限",orderNum = "18")
+    private Integer life;
+    /**
+     * 检验日期
+     */
+    @Excel(name = "检验日期", orderNum = "19")
+    private String devicecheckstr;
+
+    /**
+     * 下次检验日期
+     */
+    @Excel(name = "下次检验日期", orderNum = "20")
+    private String nextcheckstr;
+
+    /**
+     * 检验结论
+     */
+    @Excel(name = "检验结论", orderNum = "21")
+    private String inspectresult;
+    /**
+     * 检验机构名称
+     */
+    @Excel(name = "检验机构名称",orderNum = "22")
+    private String inspectby;
+
+    /**
+     * 预计提醒日期
+     */
+    @Excel(name = "预计提醒日期",orderNum = "23")
+    private String warnstr;
+    /**
+     * 厂内车牌号
+     */
+    @Excel(name = "厂内车牌号",orderNum = "24")
+    private String plantnumber;
+    /**
+     * 自重(单位T)
+     */
+    @Excel(name = "自重(单位T)",orderNum = "25")
+    private BigDecimal weight;
+    /**
+     * 厂内编号
+     */
+    @Excel(name = "厂内编号",orderNum = "26")
+    private String plantcode;
+    /**
+     * 设备位置
+     */
+    @Excel(name = "设备位置",orderNum = "27")
+    private String equaddress;
+
+    /**
+     * 额定起重量/高度
+     */
+    @Excel(name = "额定起重量/高度",orderNum = "28")
+    private String weigthorheight;
+
+    /**
+     * 双限位
+     */
+    @Excel(name = "双限位",orderNum = "29")
+    private String doublelimitposition;
+
+    /**
+     * 公称直径(mm)
+     */
+    @Excel(name ="公称直径(mm)",orderNum = "30")
+    private String nominaldiameter;
+
+    /**
+     * 公称壁厚(mm)
+     */
+    @Excel(name ="公称壁厚(mm)",orderNum = "31")
+    private String nominalwallthickness;
+
+    /**
+     * 管道长度(m)
+     */
+    @Excel(name ="管道长度(m)",orderNum = "32")
+    private String pipelinelength;
+    /**
+     * 容积
+     */
+    @Excel(name ="容积",orderNum = "33")
+    private String volume;
+    /**
+     *压力(Mpa)
+     */
+    @Excel(name ="压力(Mpa)",orderNum = "34")
+    private String pressure;
+    /**
+     * 温度(℃)
+     */
+    @Excel(name ="温度(℃)",orderNum = "35")
+    private String temperature;
+    /**
+     * 介质
+     */
+    @Excel(name ="介质",orderNum = "36")
+    private String medium;
+    /**
+     * 设备用途
+     */
+    @Excel(name ="设备用途",orderNum = "37")
+    private String equipmentusage;
+    /**
+     * 备注
+     */
+    @Excel(name ="备注",orderNum = "38")
+    private String deviceremark;
+}

+ 7 - 0
cx-safe-check/cx-save-check-server/src/main/java/com/rongwei/savecheck/controller/CheckItemsController.java

@@ -60,4 +60,11 @@ public class CheckItemsController {
         log.info("安全附件定时任务,更改安全附件预警级别");
         return checkItemsService.stateUpdateScheduledTasks();
     }
+
+
+    @PostMapping("/import")
+    public R importExport(@RequestBody Map<String, String> queryParameter){
+        log.info("开始导入安全附件信息");
+        return  checkItemsService.importExcel(queryParameter);
+    }
 }