浏览代码

柴油使用管理 excel 上传

huangpeng 1 年之前
父节点
当前提交
15701fce2a

+ 84 - 0
cx-equipment/cx-equipment-common/src/main/java/com/rongwei/bscommon/sys/config/EquDieseloilUseManagementListener.java

@@ -0,0 +1,84 @@
+package com.rongwei.bscommon.sys.config;
+
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.rongwei.bscommon.sys.excel.EquDieseloilUseManagementTemplate;
+import com.rongwei.bsentity.domain.EquDieseloilUseManagementDo;
+import com.rongwei.bsentity.domain.EquMaintenanceStandardDo;
+import com.rongwei.bsentity.enums.MaintenanceTypeEnum;
+import com.rongwei.bsentity.enums.PlantEnum;
+import com.rongwei.rwcommon.utils.SecurityUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.h2.engine.User;
+import org.springframework.beans.BeanUtils;
+
+import java.lang.reflect.Field;
+import java.util.*;
+
+/**
+ * @author shangmi
+ * @title ExcelListener
+ * @date 2023/12/7 16:09
+ * @description EquMaintenanceStandard监听器
+ */
+@Slf4j
+public class EquDieseloilUseManagementListener extends AnalysisEventListener<EquDieseloilUseManagementTemplate> {
+
+    private static final String[] NON_SET = {"dieseldate","dieselnametype"};
+
+    private List<EquDieseloilUseManagementDo> dieseloilUseManagementDoList = new ArrayList<>();
+
+    private List<String> errorData = new ArrayList<>();
+
+    @Override
+    public void invoke(EquDieseloilUseManagementTemplate dieseloilUseManagementTemplate, AnalysisContext analysisContext) {
+
+
+        try {
+            log.info("解析到一条数据:{}", dieseloilUseManagementTemplate);
+            for (Field field : dieseloilUseManagementTemplate.getClass().getDeclaredFields()) {
+                field.setAccessible(true);
+                String name = field.getName();
+                if (Objects.isNull(field.get(dieseloilUseManagementTemplate)) && Arrays.asList(NON_SET).contains(name)) {
+                    errorData.add((analysisContext.readRowHolder().getRowIndex() + 1) + "行存在必填数据为空的情况,请填写完整!");
+                }
+            }
+            EquDieseloilUseManagementDo e = migrateDate(dieseloilUseManagementTemplate);
+            dieseloilUseManagementDoList.add(e);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+    }
+
+
+
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+
+    }
+
+    public List<EquDieseloilUseManagementDo> getDieseloilUseManagementDoList() {
+        return this.dieseloilUseManagementDoList;
+    }
+
+
+    public List<String> getErrorData() {
+        return this.errorData;
+    }
+
+
+    /**
+     * 数据转换
+     *
+     * @param equMaintenanceStandardTemplate
+     * @return {@link EquMaintenanceStandardDo}
+     * @date 2023/12/8 10:14
+     * @author shangmi
+     */
+
+    private EquDieseloilUseManagementDo migrateDate(EquDieseloilUseManagementTemplate equMaintenanceStandardTemplate) {
+        EquDieseloilUseManagementDo equDieseloilUseManagementDo = new EquDieseloilUseManagementDo();
+        BeanUtils.copyProperties(equMaintenanceStandardTemplate, equDieseloilUseManagementDo);
+        return equDieseloilUseManagementDo;
+    }
+}

+ 8 - 0
cx-equipment/cx-equipment-common/src/main/java/com/rongwei/bscommon/sys/dao/EquDieseloilUseManagementDao.java

@@ -0,0 +1,8 @@
+package com.rongwei.bscommon.sys.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.rongwei.bsentity.domain.EquDieseloilUseManagementDo;
+
+public interface EquDieseloilUseManagementDao extends BaseMapper<EquDieseloilUseManagementDo> {
+
+}

+ 121 - 0
cx-equipment/cx-equipment-common/src/main/java/com/rongwei/bscommon/sys/excel/EquDieseloilUseManagementTemplate.java

@@ -0,0 +1,121 @@
+package com.rongwei.bscommon.sys.excel;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author  huangpeng
+ * @create 2024-05-13 13:35
+ * 柴油使用管理 导出模板
+ */
+
+@Data
+public class EquDieseloilUseManagementTemplate {
+
+
+
+	/**
+	 * table name:DIESELNAMETYPE
+	 * table type:varchar(200)
+	 * table comment:柴油名称型号
+	 */
+	@ColumnWidth(20)
+	@ExcelProperty(value = "柴油名称型号",index = 0)
+	private String dieselnametype;
+
+	/**
+	 * table name:DIESELDATE
+	 * table type:datetime
+	 * table comment:日期
+	 */
+	@ExcelProperty(value = "日期",index = 1)
+	private Date dieseldate;
+
+	/**
+	 * table name:CASTROLLINGONE
+	 * table type:decimal(18,6)
+	 * table comment:铸轧一
+	 */
+	@ExcelProperty(value = "铸轧一",index = 2)
+	private BigDecimal castrollingone;
+
+	/**
+	 * table name:CASTROLLINGTWO
+	 * table type:decimal(18,6)
+	 * table comment:铸轧二
+	 */
+	@ExcelProperty(value = "铸轧二",index = 3)
+	private BigDecimal castrollingtwo;
+
+	/**
+	 * table name:CASTROLLINGTHREE
+	 * table type:decimal(18)
+	 * table comment:铸轧三
+	 */
+	@ExcelProperty(value = "铸轧三",index = 4)
+	private BigDecimal castrollingthree;
+
+	/**
+	 * table name:COLDROLLINGONE
+	 * table type:decimal(18)
+	 * table comment:冷轧一
+	 */
+	@ExcelProperty(value = "冷轧一",index = 5)
+	private BigDecimal coldrollingone;
+
+	/**
+	 * table name:COLDROLLINGTWO
+	 * table type:decimal(18)
+	 * table comment:冷轧二
+	 */
+	@ExcelProperty(value = "冷轧二",index = 6)
+	private BigDecimal coldrollingtwo;
+
+	/**
+	 * table name:STASH
+	 * table type:decimal(18)
+	 * table comment:仓库
+	 */
+	@ExcelProperty(value = "仓库",index = 7)
+	private BigDecimal stash;
+
+	/**
+	 * table name:CART
+	 * table type:decimal(18)
+	 * table comment:大车
+	 */
+	@ExcelProperty(value = "大车",index = 8)
+	private BigDecimal cart;
+
+	/**
+	 * table name:MAINTENANCEAERIALWORK
+	 * table type:decimal(18)
+	 * table comment:维修/高空作业
+	 */
+	@ExcelProperty(value = "维修/高空作业",index = 9)
+	private BigDecimal maintenanceaerialwork;
+
+	/**
+	 * table name:ALUMINUMFOILBRANCHFACTORY
+	 * table type:decimal(18)
+	 * table comment:铝箔分厂
+	 */
+	@ExcelProperty(value = "铝箔分厂",index = 10)
+	private BigDecimal aluminumfoilbranchfactory;
+
+	/**
+	 * table name:HOTROLLINGBRANCHFACTORY
+	 * table type:decimal(18)
+	 * table comment:热轧分厂
+	 */
+	@ExcelProperty(value = "热轧分厂",index = 11)
+	private BigDecimal hotrollingbranchfactory;
+
+}

+ 20 - 0
cx-equipment/cx-equipment-common/src/main/java/com/rongwei/bscommon/sys/service/EquDieseloilUseManagementService.java

@@ -0,0 +1,20 @@
+package com.rongwei.bscommon.sys.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.rongwei.bsentity.domain.EquDieseloilUseManagementDo;
+import com.rongwei.rwcommon.base.R;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.List;
+
+public interface EquDieseloilUseManagementService  extends IService<EquDieseloilUseManagementDo> {
+    /**
+     * 导入 柴油使用管理 excel
+     * @param multipartFile
+     * @return
+     */
+    R uploadDieseloil(MultipartFile multipartFile) throws IOException;
+
+    R checkOneDateAndTenantid(List<EquDieseloilUseManagementDo> equDieseloilUseManagementDos);
+}

+ 145 - 0
cx-equipment/cx-equipment-common/src/main/java/com/rongwei/bscommon/sys/service/impl/EquDieseloilUseManagementServiceImpl.java

@@ -0,0 +1,145 @@
+package com.rongwei.bscommon.sys.service.impl;
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.rongwei.bscommon.sys.config.EquDieseloilUseManagementListener;
+import com.rongwei.bscommon.sys.dao.EquDieseloilUseManagementDao;
+import com.rongwei.bscommon.sys.excel.EquDieseloilUseManagementTemplate;
+import com.rongwei.bscommon.sys.service.EquDieseloilUseManagementService;
+import com.rongwei.bsentity.domain.EquDieseloilUseManagementDo;
+import com.rongwei.rwcommon.base.R;
+import com.rongwei.rwcommon.utils.SecurityUtil;
+import com.rongwei.safecommon.utils.CXCommonUtils;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+import java.io.IOException;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.rongwei.safecommon.utils.SaveConstans.DatePattern.DATE_PATTERN_YMD;
+
+@Service
+public class EquDieseloilUseManagementServiceImpl extends ServiceImpl<EquDieseloilUseManagementDao, EquDieseloilUseManagementDo> implements EquDieseloilUseManagementService {
+
+    @Autowired
+    private EquDieseloilUseManagementDao equDieseloilUseManagementDao;
+
+
+    @Autowired
+    private EquDieseloilUseManagementService equDieseloilUseManagementService;
+    @Override
+    public R uploadDieseloil(MultipartFile multipartFile) throws IOException {
+        // 使用自定义的DataListener来读取数据
+        EquDieseloilUseManagementListener listener = new EquDieseloilUseManagementListener();
+        // 读取数据
+        EasyExcel.read(multipartFile.getInputStream(), EquDieseloilUseManagementTemplate.class, listener).sheet().headRowNumber(2).doRead();
+        // 解析有误信息
+        List<String> errorData = listener.getErrorData();
+        if (!errorData.isEmpty()) {
+            return R.error(JSON.toJSONString(errorData));
+        }
+        // 解析数据
+        List<EquDieseloilUseManagementDo> dieseloilUseManagementDoList = listener.getDieseloilUseManagementDoList();
+        // 唯一性数据
+        R r = checkOneDateAndTenantid(dieseloilUseManagementDoList);
+        if (r.getCode().equals("500")){
+            return r;
+        }
+        //保存数据
+        if (!dieseloilUseManagementDoList.isEmpty()) {
+            equDieseloilUseManagementService.saveBatch(dieseloilUseManagementDoList);
+        }
+        return R.ok("导入成功");
+    }
+
+    /**
+     * 通过  Tenantid 和  dieseldate 确认唯一值 做新增编辑
+     * @param dieseloilUseManagementDoList
+     */
+    public R checkOneDateAndTenantid(List<EquDieseloilUseManagementDo> dieseloilUseManagementDoList) {
+        String tenantid = "";StringBuilder builder = new StringBuilder();
+        String tokenTenantId = CXCommonUtils.getCurrentUser() != null ? CXCommonUtils.getCurrentUser().getTenantid() : "";
+        if (StringUtils.isNotBlank(tokenTenantId)) {
+            tenantid = tokenTenantId;
+        } else {
+            return R.error("token 失效,请联系管理员");
+        };
+
+        //设置查询条件
+        LambdaQueryWrapper<EquDieseloilUseManagementDo> queryWrapper = setqueryWrapper(dieseloilUseManagementDoList,tenantid);
+        List<EquDieseloilUseManagementDo> oldList = equDieseloilUseManagementDao.selectList(queryWrapper);
+
+        List<String> dieseldates = oldList.stream().map(info ->DateUtil.format(info.getDieseldate(),DATE_PATTERN_YMD) ).collect(Collectors.toList());
+
+        //通过时间判断是否有相同的数据
+        for (EquDieseloilUseManagementDo dieseloilUseManagementDo:dieseloilUseManagementDoList){
+            String dieseldate = DateUtil.format(dieseloilUseManagementDo.getDieseldate(), DATE_PATTERN_YMD);
+            if (dieseldates.contains(dieseldate)){
+                builder.append("日期"+dieseldate+"、");
+                continue;
+            };
+            Date date =new Date();
+            dieseloilUseManagementDo.setId(SecurityUtil.getUUID());
+            dieseloilUseManagementDo.setTenantid(tenantid);
+            dieseloilUseManagementDo.setCreatedate(date);
+            dieseloilUseManagementDo.setCreateuserid(CXCommonUtils.getCurrentUser().getId());
+            dieseloilUseManagementDo.setCreateusername(CXCommonUtils.getCurrentUser().getName());
+            dieseloilUseManagementDo.setModifydate(date);
+            dieseloilUseManagementDo.setModifyuserid(CXCommonUtils.getCurrentUser().getId());
+            dieseloilUseManagementDo.setModifyusername(CXCommonUtils.getCurrentUser().getName());
+        };
+
+        //数据拼接错误日志
+        if (StringUtils.isBlank(builder.toString())){
+            return R.ok();
+        }else {
+            builder.append("的使用记录已存在,不可重复导入");
+            String errMsg =builder.toString().replace("、的", "的");
+            return R.error(errMsg);
+        }
+
+    }
+
+    /**
+     * 设置查询条件,筛选出传入参数的最大,最小时间去数据库查询,避免全量查询
+     * @param dieseloilUseManagementDoList
+     * @param tenantid
+     * @return
+     */
+    private LambdaQueryWrapper<EquDieseloilUseManagementDo> setqueryWrapper(List<EquDieseloilUseManagementDo> dieseloilUseManagementDoList, String tenantid) {
+        //默认升序,那个最小最大时间
+        Collections.sort(dieseloilUseManagementDoList, Comparator.comparing(EquDieseloilUseManagementDo::getDieseldate));
+        Date minDate = dieseloilUseManagementDoList.get(0).getDieseldate();
+        Date maxDate = dieseloilUseManagementDoList.get(dieseloilUseManagementDoList.size()-1).getDieseldate();
+        //对时间的设置时分秒
+        Calendar instanceMin = Calendar.getInstance();
+        instanceMin.setTime(minDate);
+        // 设置时、分、秒
+        instanceMin.set(Calendar.HOUR_OF_DAY, 0); // 24小时制
+        instanceMin.set(Calendar.MINUTE, 0);
+        instanceMin.set(Calendar.SECOND, 0);
+        Date timemin = instanceMin.getTime();
+
+        //对时间的设置时分秒
+        Calendar instanceMax = Calendar.getInstance();
+        instanceMax.setTime(maxDate);
+        // 设置时、分、秒
+        instanceMax.set(Calendar.HOUR_OF_DAY, 23); // 24小时制
+        instanceMax.set(Calendar.MINUTE, 59);
+        instanceMax.set(Calendar.SECOND, 59);
+        Date timemax = instanceMax.getTime();
+
+        //系统中已存在的相同的 tenantid 数据
+        LambdaQueryWrapper<EquDieseloilUseManagementDo> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(EquDieseloilUseManagementDo::getTenantid,tenantid)
+                .eq(EquDieseloilUseManagementDo::getDeleted,"0")
+                .ge(EquDieseloilUseManagementDo::getDieseldate,timemin)
+                .le(EquDieseloilUseManagementDo::getDieseldate,timemax);
+        return queryWrapper;
+    }
+
+}

+ 190 - 0
cx-equipment/cx-equipment-entity/src/main/java/com/rongwei/bsentity/domain/EquDieseloilUseManagementDo.java

@@ -0,0 +1,190 @@
+package com.rongwei.bsentity.domain;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author  huangpeng
+ * @create 2024-05-13 13:35 
+ */
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@TableName("equ_dieseloil_use_management")
+public class EquDieseloilUseManagementDo {
+
+	/**
+	 * table name:ID
+	 * table type:varchar(36)
+	 * table comment:主键ID
+	 */
+	private String id;
+
+	/**
+	 * table name:TENANTID
+	 * table type:varchar(36)
+	 * table comment:租户ID
+	 */
+	private String tenantid;
+
+	/**
+	 * table name:ROPTION
+	 * table type:text
+	 * table comment:扩展json格式配置
+	 */
+	private String roption;
+
+	/**
+	 * table name:DELETED
+	 * table type:varchar(1)
+	 * table comment:是否删除Y/N
+	 */
+	private String deleted;
+
+	/**
+	 * table name:REMARK
+	 * table type:varchar(500)
+	 * table comment:备注
+	 */
+	private String remark;
+
+	/**
+	 * table name:CREATEDATE
+	 * table type:datetime
+	 * table comment:创建时间
+	 */
+	private Date createdate;
+
+	/**
+	 * table name:CREATEUSERID
+	 * table type:varchar(36)
+	 * table comment:创建用户ID
+	 */
+	private String createuserid;
+
+	/**
+	 * table name:MODIFYDATE
+	 * table type:datetime
+	 * table comment:修改日期
+	 */
+	private Date modifydate;
+
+	/**
+	 * table name:MODIFYUSERID
+	 * table type:varchar(36)
+	 * table comment:修改用户ID
+	 */
+	private String modifyuserid;
+
+	/**
+	 * table name:CREATEUSERNAME
+	 * table type:varchar(20)
+	 * table comment:创建人
+	 */
+	private String createusername;
+
+	/**
+	 * table name:MODIFYUSERNAME
+	 * table type:varchar(20)
+	 * table comment:修改人
+	 */
+	private String modifyusername;
+
+	/**
+	 * table name:BELONGFACTORY
+	 * table type:varchar(36)
+	 * table comment:所属工厂名称
+	 */
+	private String belongfactory;
+
+	/**
+	 * table name:DIESELNAMETYPE
+	 * table type:varchar(200)
+	 * table comment:柴油名称型号
+	 */
+	private String dieselnametype;
+
+	/**
+	 * table name:DIESELDATE
+	 * table type:datetime
+	 * table comment:日期
+	 */
+	private Date dieseldate;
+
+	/**
+	 * table name:CASTROLLINGONE
+	 * table type:decimal(18,6)
+	 * table comment:铸轧一
+	 */
+	private BigDecimal castrollingone;
+
+	/**
+	 * table name:CASTROLLINGTWO
+	 * table type:decimal(18,6)
+	 * table comment:铸轧二
+	 */
+	private BigDecimal castrollingtwo;
+
+	/**
+	 * table name:CASTROLLINGTHREE
+	 * table type:decimal(18)
+	 * table comment:铸轧三
+	 */
+	private BigDecimal castrollingthree;
+
+	/**
+	 * table name:COLDROLLINGONE
+	 * table type:decimal(18)
+	 * table comment:冷轧一
+	 */
+	private BigDecimal coldrollingone;
+
+	/**
+	 * table name:COLDROLLINGTWO
+	 * table type:decimal(18)
+	 * table comment:冷轧二
+	 */
+	private BigDecimal coldrollingtwo;
+
+	/**
+	 * table name:STASH
+	 * table type:decimal(18)
+	 * table comment:仓库
+	 */
+	private BigDecimal stash;
+
+	/**
+	 * table name:CART
+	 * table type:decimal(18)
+	 * table comment:大车
+	 */
+	private BigDecimal cart;
+
+	/**
+	 * table name:MAINTENANCEAERIALWORK
+	 * table type:decimal(18)
+	 * table comment:维修/高空作业
+	 */
+	private BigDecimal maintenanceaerialwork;
+
+	/**
+	 * table name:ALUMINUMFOILBRANCHFACTORY
+	 * table type:decimal(18)
+	 * table comment:铝箔分厂
+	 */
+	private BigDecimal aluminumfoilbranchfactory;
+
+	/**
+	 * table name:HOTROLLINGBRANCHFACTORY
+	 * table type:decimal(18)
+	 * table comment:热轧分厂
+	 */
+	private BigDecimal hotrollingbranchfactory;
+
+}

+ 65 - 0
cx-equipment/cx-equipment-server/src/main/java/com/rongwei/bsserver/sys/controller/EquDieseloilUseManagementController.java

@@ -0,0 +1,65 @@
+package com.rongwei.bsserver.sys.controller;
+
+import com.rongwei.bscommon.sys.service.EquDieseloilUseManagementService;
+import com.rongwei.bscommon.sys.service.MaintenanceService;
+import com.rongwei.bscommon.sys.utils.ExceptionUtils;
+import com.rongwei.bsentity.domain.EquDieseloilUseManagementDo;
+import com.rongwei.bsentity.dto.EquipmentDisposeDTO;
+import com.rongwei.rwcommon.base.R;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+
+/**
+ * 柴油使用管理
+ */
+@RestController
+@RequestMapping("/equDieseloilUseManagement")
+public class EquDieseloilUseManagementController {
+
+    private final static Logger log = LoggerFactory.getLogger(EquDieseloilUseManagementController.class);
+
+    @Autowired
+    private EquDieseloilUseManagementService equDieseloilUseManagementService;
+
+
+    /**
+     * excel 上传
+     * @param multipartFile
+     * @return
+     */
+    @PostMapping("importDieseloil")
+    public R uploadDieseloil(@RequestParam("file") MultipartFile multipartFile){
+        try {
+            log.info("进入接口:/equDieseloilUseManagement/importDieseloil,入参:{}", multipartFile);
+            return equDieseloilUseManagementService.uploadDieseloil(multipartFile);
+            // return null;
+        }catch (Exception e){
+            ExceptionUtils.printExceptionDetail(e,"导入失败,请检查后再导入:");
+            return R.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 校验重复值
+     * @param equDieseloilUseManagementDos
+     * @return
+     */
+    @PostMapping("/checkOneDateAndTenantid")
+    public R checkOneDateAndTenantid(@RequestBody List<EquDieseloilUseManagementDo> equDieseloilUseManagementDos){
+        try {
+            log.info("进入接口:/equDieseloilUseManagement/checkOneDateAndTenantid,参数为:{}",equDieseloilUseManagementDos);
+            return equDieseloilUseManagementService.checkOneDateAndTenantid(equDieseloilUseManagementDos);
+        }catch (Exception e){
+            ExceptionUtils.printExceptionDetail(e,"校验失败,异常为:");
+            log.info(e.getMessage());
+            return R.error(e.getMessage());
+        }
+
+    }
+}
+