From 5cdcfd24600dd07a321ff92654eb614df4619a2d Mon Sep 17 00:00:00 2001 From: jiang Date: Fri, 28 Nov 2025 17:38:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MaDevInfoController.java | 209 +-------- .../devchange/domain/MaDevInfoXlsx.java | 407 +++++++++++++++--- .../devchange/mapper/MaDevInfoMapper.java | 2 + .../devchange/service/MaDevInfoService.java | 7 +- .../service/MaDevInfoServiceImpl.java | 15 +- .../device/controller/DevMergeController.java | 20 + .../material/device/mapper/DevInfoMapper.java | 24 +- .../device/mapper/DevMergeMapper.java | 2 + .../device/service/DevMergeService.java | 3 + .../service/impl/DevMergeServiceImpl.java | 85 ++++ .../impl/ProvinceScreenServiceImpl.java | 2 +- .../toolLedger/domain/ToolLedgerEntity.java | 3 +- .../service/Impl/ToolLedgerServiceImpl.java | 8 +- .../material/devchange/MaDevInfoMapper.xml | 108 +++++ .../mapper/material/device/DevInfoMapper.xml | 2 +- .../mapper/material/device/DevMergeMapper.xml | 52 +++ 16 files changed, 664 insertions(+), 285 deletions(-) diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/controller/MaDevInfoController.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/controller/MaDevInfoController.java index b7c4cd9..8f31c65 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/controller/MaDevInfoController.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/controller/MaDevInfoController.java @@ -5,20 +5,25 @@ import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ReflectUtil; -import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelWriter; +import com.bonus.common.core.utils.poi.ExcelUtil; import com.bonus.common.core.web.controller.BaseController; import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.log.annotation.SysLog; +import com.bonus.common.log.enums.OperaType; +import com.bonus.common.security.utils.SecurityUtils; import com.bonus.material.contract.domain.BmContract; import com.bonus.material.devchange.domain.*; import com.bonus.material.devchange.service.MaDevInfoService; import com.bonus.material.devchange.service.MaDevInfoServiceImpl; import com.bonus.material.device.domain.vo.DevInfoPropertyVo; import com.bonus.material.device.domain.vo.DevMergeVo; +import com.bonus.system.api.domain.SysUser; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.ServletOutputStream; @@ -171,207 +176,11 @@ public class MaDevInfoController extends BaseController { @PostMapping("/export") public void export(MaDevInfo o, HttpServletResponse response) throws IOException { // 1. 查询所有符合条件的数据(忽略分页) - List dataList = service.export(o); - - // 2. 转换数据为导出格式(处理特殊字段) - List> exportData = dataList.stream() - .map(this::convertToExportMap) - .collect(Collectors.toList()); - - // 生成Excel时,按 headerMap 的顺序添加表头 - ExcelWriter writer = ExcelUtil.getWriter(); - Map headerMap = getExportHeaderMap(); - // 按 headerMap 的顺序添加别名(LinkedHashMap保证顺序) - headerMap.forEach((prop, label) -> writer.addHeaderAlias(prop, label)); - // 显式设置导出的字段顺序(与表头一致) - writer.setOnlyAlias(true); // 只导出有别名的字段 - writer.write(exportData, true); - - // 5. 设置响应头,触发下载 - response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); - String fileName = URLEncoder.encode("设备信息表_" + System.currentTimeMillis(), "UTF-8"); - response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx"); - - // 6. 输出流写入 - try (ServletOutputStream out = response.getOutputStream()) { - writer.flush(out, true); - } finally { - writer.close(); - } + List dataList = service.export(o); + com.bonus.common.core.utils.poi.ExcelUtil util = new ExcelUtil(MaDevInfoXlsx.class); + util.exportExcel(response, dataList, "装备台账"); } - /** - * 转换设备信息为导出Map(处理特殊字段) - */ - private Map convertToExportMap(MaDevInfo item) { - Set headerProps = getExportHeaderMap().keySet(); - // 使用 LinkedHashMap 保持顺序 - Map map = new LinkedHashMap<>(); - - // 1. 先添加表头中定义的字段(确保顺序与表头一致) - for (String prop : headerProps) { - // 从对象中获取字段值(忽略不存在的字段) - Object value = BeanUtil.getProperty(item, prop); - map.put(prop, value); - } - - map.put("process", item.getMainProcess() + ">" + item.getSubProcess()); - map.put("devType", item.getMainCategory() + ">" + item.getSubCategory() + ">" + item.getBranch()); - Object productionDate = item.getProductionDate(); - if (productionDate != null) { - map.put("productionDate", formatDateToYmd(productionDate)); - } - - // 格式化采购日期(purchaseDate):只保留年月日 - Object purchaseDate = item.getPurchaseDate(); - if (purchaseDate != null) { - map.put("purchaseDate", formatDateToYmd(purchaseDate)); - } - - // 格式化采购日期(purchaseDate):只保留年月日 - Object nextMaintenanceDate = item.getNextMaintenanceDate(); - if (purchaseDate != null) { - map.put("nextMaintenanceDate", formatDateToYmd(nextMaintenanceDate)); - } - - - // 格式化采购日期(purchaseDate):只保留年月日 - Object expirationTime = item.getExpirationTime(); - if (purchaseDate != null) { - map.put("expirationTime", formatDateToYmd(expirationTime)); - } - - - - - map.put("status", convertStatusToText(Integer.valueOf(item.getStatus()))); - map.put("upDownStatus", convertUpDownStatusToText(Integer.valueOf(item.getUpDownStatus()))); - - List propertyVoList = item.getPropertyVoList(); - if (CollUtil.isNotEmpty(propertyVoList)) { - for (int i = 0; i < propertyVoList.size() && i < 9; i++) { - DevInfoPropertyVo property = propertyVoList.get(i); - int index = i + 1; - map.put("featureItem" + index, property.getPropertyName()); - map.put("featureValue" + index, property.getPropertyValue()); - } - } - for (int i = 1; i <= 9; i++) { - map.putIfAbsent("featureItem" + i, ""); - map.putIfAbsent("featureValue" + i, ""); - } - - // 4. 最终过滤:确保只保留表头中的字段(防止处理过程中新增多余字段) - map.keySet().retainAll(headerProps); - - return map; - } - - - /** - * 工具方法:将时间对象格式化为 "yyyy-MM-dd"(兼容Date和LocalDate) - */ - private String formatDateToYmd(Object dateObj) { - if (dateObj == null) { - return ""; - } - // 处理java.util.Date类型 - if (dateObj instanceof Date) { - return DateUtil.format((Date) dateObj, "yyyy-MM-dd"); - } - // 处理java.time.LocalDate类型 - if (dateObj instanceof LocalDate) { - return ((LocalDate) dateObj).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); - } - // 处理java.time.LocalDateTime类型(截取日期部分) - if (dateObj instanceof LocalDateTime) { - return ((LocalDateTime) dateObj).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); - } - // 其他类型直接返回字符串(避免转换失败) - return dateObj.toString(); - } - - /** - * 导出表头映射(prop -> label)- 兼容 Java 8 - */ - private Map getExportHeaderMap() { - Map headerMap = new LinkedHashMap<>(); - // 1. 基础字段映射(已有部分,保持不变) - headerMap.put("province", "所属省份"); - headerMap.put("propertyUnit", "产权单位"); - headerMap.put("major", "专业"); - headerMap.put("process", "工序"); - headerMap.put("devType", "装备类目"); - headerMap.put("name", "类型分支"); - headerMap.put("specificationModel", "规格型号"); - headerMap.put("code", "装备编码"); - headerMap.put("status", "装备状态"); - headerMap.put("upDownStatus", "上下架状态"); - headerMap.put("serviceLife", "使用年限"); - headerMap.put("usingProject", "使用项目"); - headerMap.put("expirationTime", "使用到期时间"); - headerMap.put("usageCount", "使用次数"); - headerMap.put("repairCount", "维修次数"); - headerMap.put("originalCode", "装备原始编码"); - headerMap.put("unit", "计量单位"); - headerMap.put("manufacturer", "生产厂家"); - headerMap.put("productionDate", "出厂日期"); - headerMap.put("purchaseDate", "采购日期"); - headerMap.put("originalValue", "资产原值(元)"); - headerMap.put("maxServiceLifeYears", "最大使用年限(年)"); - headerMap.put("nextMaintenanceDate", "下次维保日期"); - - // 2. 补全特征项和特征值的中文映射(关键补充) - for (int i = 1; i <= 9; i++) { - headerMap.put("featureItem" + i, "特征项" + i); // 如featureItem1→"特征项1" - headerMap.put("featureValue" + i, "特征值" + i); // 如featureValue1→"特征值1" - } - return headerMap; - } - - /** - * 装备状态枚举转文本(根据实际枚举实现) - */ - /** - * 装备状态枚举转文本(兼容 Java 8) - */ - private String convertStatusToText(Integer status) { - if (status == null) { - return ""; - } - // 传统 switch 语句(Java 8 支持) - String statusText; - switch (status) { - case 1: - statusText = "在库"; - break; - case 2: - statusText = "自用"; - break; - case 3: - statusText = "共享"; - break; - case 4: - statusText = "退役"; - break; - case 5: - statusText = "维修"; - break; - default: - statusText = "未知"; - break; - } - return statusText; - } - - /** - * 上下架状态枚举转文本(根据实际枚举实现) - */ - private String convertUpDownStatusToText(Integer upDownStatus) { - if (upDownStatus == null) return ""; - // 示例:实际项目中替换为枚举映射 - return upDownStatus == 1 ? "上架" : "下架"; - } } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/domain/MaDevInfoXlsx.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/domain/MaDevInfoXlsx.java index 5404e09..e4f304e 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/domain/MaDevInfoXlsx.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/domain/MaDevInfoXlsx.java @@ -7,210 +7,497 @@ import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import org.apache.commons.collections4.CollectionUtils; import java.math.BigDecimal; import java.util.Date; import java.util.List; /** - * 装备实体类 - * 存储装备的详细信息,包括基本属性、状态、使用情况、文档资料等 + * 装备Excel导出实体类 + * 存储装备导出所需的详细信息,含固定9组特征项 */ @Data @AllArgsConstructor @NoArgsConstructor public class MaDevInfoXlsx { /** - * 设备id(不导出,无注解) + * 设备id(不导出) */ + @ApiModelProperty(value = "设备ID") private Integer maId; + /** * 所属省份 */ - @Excel(name = "所属省份") // 对应headerMap的key=province + @Excel(name = "所属省份") + @ApiModelProperty(value = "所属省份") private String province; + /** * 专业 */ - @Excel(name = "专业") // 对应headerMap的key=major + @Excel(name = "专业") + @ApiModelProperty(value = "专业") private String major; + /** - * 工序(用子工序映射,可根据实际调整) + * 工序(子工序) */ - @Excel(name = "工序") // 对应headerMap的key=process + @Excel(name = "工序") + @ApiModelProperty(value = "工序") private String subProcess; + /** - * 装备类目(用小类目映射) + * 装备类目(小类目) */ - @Excel(name = "装备类目") // 对应headerMap的key=devType + @Excel(name = "装备类目") + @ApiModelProperty(value = "装备类目") private String subCategory; + /** - * 类型分支(用装备分支映射) + * 类型分支(装备分支) */ - @Excel(name = "类型分支") // 对应headerMap的key=name + @Excel(name = "类型分支") + @ApiModelProperty(value = "类型分支") private String branch; + /** * 规格型号 */ - @Excel(name = "规格型号") // 对应headerMap的key=specificationModel + @Excel(name = "规格型号") + @ApiModelProperty(value = "规格型号") private String specificationModel; + /** * 装备编码 */ - @Excel(name = "装备编码") // 对应headerMap的key=code + @Excel(name = "装备编码") + @ApiModelProperty(value = "装备编码") private String code; + /** * 装备状态 */ - @Excel(name = "装备状态") // 对应headerMap的key=status + @Excel(name = "装备状态", readConverterExp = "1=在库,2=自用,3=共享,4=退役,5=维修", // 核心:配置转换规则 + defaultValue = "在库") // 空值默认显示「下架」) + @ApiModelProperty(value = "装备状态") private String status; /** - * 上下架状态 + * 上下架状态:通过 readConverterExp 配置映射规则(1=上架,0=下架) */ - @Excel(name = "上下架状态") // 对应headerMap的key=upDownStatus - private String upDownStatus; + @Excel( + name = "上下架状态", + readConverterExp = "1=上架,0=下架", // 核心:配置转换规则 + defaultValue = "下架" // 空值默认显示「下架」 + ) + @ApiModelProperty(value = "上下架状态") + private String upDownStatus; // 字段类型:String/Integer均可 + /** * 使用年限 */ - @Excel(name = "使用年限") // 对应headerMap的key=serviceLife + @Excel(name = "使用年限") + @ApiModelProperty(value = "使用年限") private String serviceLife; + /** + * 使用项目ID(不导出) + */ + @ApiModelProperty(value = "使用项目ID") private String usingProjectId; + /** * 使用项目 */ - @Excel(name = "使用项目") // 对应headerMap的key=usingProject + @Excel(name = "使用项目") + @ApiModelProperty(value = "使用项目") private String usingProject; + /** - * 使用到期时间(Hutool会自动格式化日期) + * 使用到期时间 */ - @Excel(name = "使用到期时间") // 对应headerMap的key=expirationTime + @Excel(name = "使用到期时间", dateFormat = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @ApiModelProperty(value = "使用到期时间(yyyy-MM-dd)") private Date expirationTime; + /** * 使用次数 */ - @Excel(name = "使用次数") // 对应headerMap的key=usageCount + @Excel(name = "使用次数") + @ApiModelProperty(value = "使用次数") private Integer usageCount; + /** * 维修次数 */ - @Excel(name = "维修次数") // 对应headerMap的key=repairCount + @Excel(name = "维修次数") + @ApiModelProperty(value = "维修次数") private Integer repairCount; + /** * 装备原始编码 */ - @Excel(name = "装备原始编码") // 对应headerMap的key=originalCode + @Excel(name = "装备原始编码") + @ApiModelProperty(value = "装备原始编码") private String originalCode; + /** * 计量单位 */ - @Excel(name = "计量单位") // 对应headerMap的key=unit + @Excel(name = "计量单位") + @ApiModelProperty(value = "计量单位") private String unit; + /** + * 生产厂家ID(不导出) + */ + @ApiModelProperty(value = "生产厂家ID") private Integer manufacturerId; + /** * 生产厂家 */ - @Excel(name = "生产厂家") // 对应headerMap的key=manufacturer + @Excel(name = "生产厂家") + @ApiModelProperty(value = "生产厂家") private String manufacturer; + /** * 出厂日期 */ - @Excel(name = "出厂日期") // 对应headerMap的key=productionDate + @Excel(name = "出厂日期", dateFormat = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @ApiModelProperty(value = "出厂日期(yyyy-MM-dd)") private Date productionDate; /** * 采购日期 */ - @Excel(name = "采购日期") // 对应headerMap的key=purchaseDate + @Excel(name = "采购日期", dateFormat = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @ApiModelProperty(value = "采购日期(yyyy-MM-dd)") private Date purchaseDate; + /** * 资产原值(元) */ - @Excel(name = "资产原值(元)") // 对应headerMap的key=originalValue + @Excel(name = "资产原值(元)") + @ApiModelProperty(value = "资产原值(元)") private BigDecimal originalValue; + /** * 最大使用年限(年) */ - @Excel(name = "最大使用年限(年)") // 对应headerMap的key=maxServiceLifeYears + @Excel(name = "最大使用年限(年)") + @ApiModelProperty(value = "最大使用年限(年)") private Integer maxServiceLifeYears; + /** * 下次维保日期 */ - @Excel(name = "下次维保日期") // 对应headerMap的key=nextMaintenanceDate + @Excel(name = "下次维保日期", dateFormat = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @ApiModelProperty(value = "下次维保日期(yyyy-MM-dd)") private Date nextMaintenanceDate; + /** * 产权单位 */ - @Excel(name = "产权单位") // 对应headerMap的key=propertyUnit + @Excel(name = "产权单位") + @ApiModelProperty(value = "产权单位") private String propertyUnit; + // 固定9组特征项+特征值 @Excel(name = "特征项1") + @ApiModelProperty(value = "特征项1") private String propertyName1; - /** - * 属性值 - */ + @Excel(name = "特征值1") + @ApiModelProperty(value = "特征值1") private String propertyValue1; @Excel(name = "特征项2") + @ApiModelProperty(value = "特征项2") private String propertyName2; - /** - * 属性值 - */ + @Excel(name = "特征值2") + @ApiModelProperty(value = "特征值2") private String propertyValue2; + @Excel(name = "特征项3") + @ApiModelProperty(value = "特征项3") private String propertyName3; - /** - * 属性值 - */ + @Excel(name = "特征值3") + @ApiModelProperty(value = "特征值3") private String propertyValue3; + @Excel(name = "特征项4") + @ApiModelProperty(value = "特征项4") private String propertyName4; - /** - * 属性值 - */ + @Excel(name = "特征值4") + @ApiModelProperty(value = "特征值4") private String propertyValue4; + @Excel(name = "特征项5") + @ApiModelProperty(value = "特征项5") private String propertyName5; - /** - * 属性值 - */ + @Excel(name = "特征值5") + @ApiModelProperty(value = "特征值5") private String propertyValue5; + @Excel(name = "特征项6") + @ApiModelProperty(value = "特征项6") private String propertyName6; - /** - * 属性值 - */ + @Excel(name = "特征值6") + @ApiModelProperty(value = "特征值6") private String propertyValue6; + @Excel(name = "特征项7") + @ApiModelProperty(value = "特征项7") private String propertyName7; - /** - * 属性值 - */ + @Excel(name = "特征值7") + @ApiModelProperty(value = "特征值7") private String propertyValue7; + @Excel(name = "特征项8") + @ApiModelProperty(value = "特征项8") private String propertyName8; - /** - * 属性值 - */ + @Excel(name = "特征值8") + @ApiModelProperty(value = "特征值8") private String propertyValue8; + @Excel(name = "特征项9") + @ApiModelProperty(value = "特征项9") private String propertyName9; - /** - * 属性值 - */ + @Excel(name = "特征值9") + @ApiModelProperty(value = "特征值9") private String propertyValue9; -} + + + private Integer devId; + /** + * 类型id + */ + private Integer typeId; + /** + * 订单id + */ + private Integer orderId; + + /** + * 专业Id + * 说明:装备所属的专业领域(如机械、电子、建筑等) + */ + private Integer majorId; + + /** + * 管理模式 + */ + private String manageType; + /** + * 数量 + */ + private Integer count; + /** + * 主工序id + */ + private Integer mainProcessId; + /** + * 主工序 + * 说明:装备主要参与的工序环节 + */ + private String mainProcess; + /** + * 子工序id + * 说明:装备参与的具体子工序 + */ + private Integer subProcessId; + + + /** + * 装备大类目id + * 说明:装备所属的一级分类(如工程机械、仪器仪表等) + */ + private Integer mainCategoryId; + /** + * 装备大类目 + * 说明:装备所属的一级分类(如工程机械、仪器仪表等) + */ + private String mainCategory; + /** + * 装备小类目id + * 说明:装备所属的二级分类,主类目下的细分分类 + */ + private Integer subCategoryId; + + /** + * 装备分支id + * 说明:小类目下的更细分类,代表具体的装备类型分支 + */ + private Integer branchId; + + + /** + * 装备名称 + * 说明:装备的具体名称,用于标识和展示 + */ + private String name; + + + // 新增:开始出厂时间(查询条件,用于筛选 >= 该日期的记录) + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date startProductionDate; + + // 新增:结束出厂时间(查询条件,用于筛选 <= 该日期的记录) + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date endProductionDate; + + + /** + * 开始采购日期 + * 说明:装备被采购入库的日期 + */ + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date startPurchaseDate; + /** + * 结束采购日期 + * 说明:装备被采购入库的日期 + */ + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date endPurchaseDate; + + + /** + * 最小资产原值(元) + * 说明:装备的原始采购价值,以元为单位 + */ + private BigDecimal minOriginalValue; + + + /** + * 最大资产原值(元) + * 说明:装备的原始采购价值,以元为单位 + */ + private BigDecimal maxOriginalValue; + + + /** + * 产权单位id + * 说明:装备的所有权所属单位 + */ + private Integer propertyUnitId; + + + /** + * 装备外观 + * 说明:装备外观图片的URL列表,存储装备的外观照片 + */ + private List appearanceImages; + + /** + * 合格证 + * 说明:装备合格证的URL列表,存储合格证扫描件或照片 + */ + private List certificates; + + /** + * 定期检验报告 + * 说明:装备定期检验报告的URL列表 + */ + private List inspectionReports; + + /** + * 采购发票 + * 说明:装备采购发票的URL列表,存储发票扫描件或照片 + */ + private List purchaseInvoices; + + /** + * 订单编号 + */ + private String orderNumber; + /** + * 订单创建人 + */ + private String orderCreateUser; + /** + * 订单时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date orderCreateTime; + + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date startOrderCreateTime; + + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date endOrderCreateTime; + /** + * 订单时间 + */ + + private String orderStatus; + + private String daysDiff; + + private String remainingDays; + + private String remainingYears; + + private String yearsDiff; + + private String expirationYears; + + private String actualStartYear; + + private String remainingStartYear; + + private String isWarn; + private String entryStatus; + + private String remainingStopYear; + + private String actualStopYear; + + /** + * 特征项列表(不导出,用于映射到上述9组字段) + */ + @ApiModelProperty(value = "特征项列表") + private List propertyVoList; + + /** + * 自动填充特征项到9组固定字段(核心优化:避免手动赋值) + * 调用时机:propertyVoList设置后执行 + */ + public void fillPropertyFields() { + if (CollectionUtils.isEmpty(propertyVoList)) { + return; // 无特征项,直接返回 + } + + // 循环处理前9个特征项(超过9个则忽略,符合Excel固定列设计) + for (int i = 0; i < Math.min(propertyVoList.size(), 9); i++) { + DevInfoPropertyVo property = propertyVoList.get(i); + int index = i + 1; // 特征项序号(1~9) + + // 根据序号设置对应的特征项名称和值(通过反射简化重复代码) + try { + // 设置特征项名称(propertyName1~9) + this.getClass().getDeclaredField("propertyName" + index) + .set(this, property.getPropertyName()); // 假设DevInfoPropertyVo的特征项名称字段是propertyKey + // 设置特征值(propertyValue1~9) + this.getClass().getDeclaredField("propertyValue" + index) + .set(this, property.getPropertyValue()); // 假设特征值字段是propertyValue + } catch (Exception e) { + // 反射异常时跳过该特征项,不影响整体导出 + e.printStackTrace(); + } + } + } +} \ No newline at end of file diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/mapper/MaDevInfoMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/mapper/MaDevInfoMapper.java index d6ea88b..ca91b49 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/mapper/MaDevInfoMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/mapper/MaDevInfoMapper.java @@ -50,5 +50,7 @@ public interface MaDevInfoMapper { Integer selectTotalDeviceCount(); List batchGetProperties( @Param("mainIds") List mainIds); + + List listXlsx(MaDevInfo o); } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoService.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoService.java index 15fc5ab..a1f1002 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoService.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoService.java @@ -1,10 +1,7 @@ package com.bonus.material.devchange.service; import com.bonus.common.core.web.domain.AjaxResult; -import com.bonus.material.devchange.domain.DeviceCountBean; -import com.bonus.material.devchange.domain.DeviceTreeBean; -import com.bonus.material.devchange.domain.MaDevInfo; -import com.bonus.material.devchange.domain.MapBean; +import com.bonus.material.devchange.domain.*; import com.bonus.material.device.domain.vo.DevMergeVo; import java.util.List; @@ -31,5 +28,5 @@ public interface MaDevInfoService { AjaxResult getDeviceByMaIds(String maIds); - List export(MaDevInfo o); + List export(MaDevInfo o); } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoServiceImpl.java index 16f2afe..0395dbb 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/MaDevInfoServiceImpl.java @@ -3,10 +3,7 @@ package com.bonus.material.devchange.service; import com.bonus.common.core.utils.StringUtils; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.security.utils.SecurityUtils; -import com.bonus.material.devchange.domain.DeviceCountBean; -import com.bonus.material.devchange.domain.DeviceTreeBean; -import com.bonus.material.devchange.domain.MaDevInfo; -import com.bonus.material.devchange.domain.MapBean; +import com.bonus.material.devchange.domain.*; import com.bonus.material.devchange.mapper.MaDevInfoMapper; import com.bonus.material.device.domain.vo.DevInfoPropertyVo; import com.bonus.material.device.domain.vo.DevMergeVo; @@ -125,18 +122,16 @@ public class MaDevInfoServiceImpl implements MaDevInfoService { * @return */ @Override - public List export(MaDevInfo o) { - /* Long thisLoginUserDeptId = SecurityUtils.getLoginUser().getSysUser().getDeptId(); - o.setPropertyUnitId(Math.toIntExact(thisLoginUserDeptId));*/ + public List export(MaDevInfo o) { // 1. 一次性查询所有主表数据(1次查询) - List mainList = mapper.list(o); + List mainList = mapper.listXlsx(o); if (mainList.isEmpty()) { return Collections.emptyList(); // 空数据直接返回,避免后续无效操作 } // 2. 收集所有主表ID(用于批量查关联属性) List mainIds = mainList.stream() - .map(MaDevInfo::getMaId) // 假设主表主键是id(Long类型,根据实际字段调整) + .map(MaDevInfoXlsx::getMaId) // 假设主表主键是id(Long类型,根据实际字段调整) .filter(Objects::nonNull) // 过滤空ID,防止查询异常 .collect(Collectors.toList()); @@ -152,6 +147,8 @@ public class MaDevInfoServiceImpl implements MaDevInfoService { // 若主表ID无对应属性,返回空集合(避免null) List properties = propertyMap.getOrDefault(main.getMaId(), Collections.emptyList()); main.setPropertyVoList(properties); + // 自动填充 propertyName1~9 和 propertyValue1~9(适配Excel导出) + main.fillPropertyFields(); }); return mainList; diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/controller/DevMergeController.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/controller/DevMergeController.java index 947ecc5..da3b573 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/controller/DevMergeController.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/controller/DevMergeController.java @@ -7,7 +7,11 @@ import com.bonus.common.core.utils.poi.ExcelUtil; import com.bonus.common.core.web.controller.BaseController; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.core.web.page.TableDataInfo; +import com.bonus.common.log.annotation.SysLog; +import com.bonus.common.log.enums.OperaType; +import com.bonus.common.security.utils.SecurityUtils; import com.bonus.material.devchange.domain.MaDevInfo; +import com.bonus.material.devchange.domain.MaDevInfoXlsx; import com.bonus.material.device.domain.DevInfo; import com.bonus.material.device.domain.dto.InfoMotionDto; import com.bonus.material.device.domain.vo.DevInfoVo; @@ -16,6 +20,7 @@ import com.bonus.material.device.service.DevInfoService; import com.bonus.material.device.service.DevMergeService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -266,4 +271,19 @@ public class DevMergeController extends BaseController { } + @PostMapping("/importData") + @SysLog(title = "用户管理", businessType = OperaType.IMPORT, logType = 0, module = "系统管理->用户管理", details = "导入用户信息") + public AjaxResult importData(MultipartFile file, String orderId) throws Exception { + try { + ExcelUtil util = new ExcelUtil(MaDevInfoXlsx.class); + List list = util.importExcel(file.getInputStream()); + return service.importData(list, orderId); + } catch (Exception e) { + logger.error(e.toString(), e); + return error(e.getMessage()); + } + + } + + } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevInfoMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevInfoMapper.java index 6f3f394..473a558 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevInfoMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevInfoMapper.java @@ -41,6 +41,7 @@ public interface DevInfoMapper { /** * 判断设备名称是否重复 + * * @param deviceName 物资名称 * @return 条数 */ @@ -60,6 +61,7 @@ public interface DevInfoMapper { /** * 获取企业设备浏览量 + * * @param companyId * @return */ @@ -87,6 +89,7 @@ public interface DevInfoMapper { /** * 保存草稿 + * * @param devInfo 设备信息 */ int insertDraft(DevInfo devInfo); @@ -102,7 +105,7 @@ public interface DevInfoMapper { /** * 删除设备信息 -- 逻辑删除 -- 限制状态删除 * - * @param maId 设备信息主键 + * @param maId 设备信息主键 * @param statusCode 状态码 * @return 结果 */ @@ -133,16 +136,17 @@ public interface DevInfoMapper { List selectDevInfoLists(DevInfoVo devInfo); - List selectDevInfoProperties(@Param("maId")Long maId); + List selectDevInfoProperties(@Param("maId") Long maId); - int deleteDevInfoProperties(@Param("maId")Long maId); + int deleteDevInfoProperties(@Param("maId") Long maId); - int batchDeleteDevInfoProperties(@Param("maIds")Long[] maIds); + int batchDeleteDevInfoProperties(@Param("maIds") Long[] maIds); - int insertDevInfoProperties(@Param("maId")Long maId, @Param("list") List list); + int insertDevInfoProperties(@Param("maId") Long maId, @Param("list") List list); /** * 查询企业信息 + * * @param obj * @return */ @@ -154,6 +158,7 @@ public interface DevInfoMapper { /** * 查询预约车详情 + * * @param maId * @param userId * @return @@ -162,6 +167,7 @@ public interface DevInfoMapper { /** * 查询企业上架装备数 + * * @param companyId * @return */ @@ -169,6 +175,7 @@ public interface DevInfoMapper { /** * 查询该设备的出租记录 + * * @param maId * @return */ @@ -180,6 +187,7 @@ public interface DevInfoMapper { /** * 查询企业信息 + * * @param companyId * @return */ @@ -188,6 +196,7 @@ public interface DevInfoMapper { String getCodeByMaId(Long maId); Integer updateDevInfoIsQc(MaDevQc maDevQc); + Integer updateDevInfoIsSafeBook(SafeBookInfo safeBookInfo); List selectAssociationList(DevInfoVo devInfo); @@ -230,6 +239,7 @@ public interface DevInfoMapper { /** * 在租装备信息查询 + * * @param devInfo * @return */ @@ -238,6 +248,7 @@ public interface DevInfoMapper { /** * 查询装备对应所属公司 + * * @return */ List getCompanyNum(); @@ -252,6 +263,7 @@ public interface DevInfoMapper { /** * 根据装备类型名称查询 + * * @param typeName * @return */ @@ -295,7 +307,7 @@ public interface DevInfoMapper { int getEquipmentStatus(String changeStatus); - int getChangeNum(); + Integer getChangeNum(); int getTurnoverRate(); diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevMergeMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevMergeMapper.java index 5b94985..cf27c80 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevMergeMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/mapper/DevMergeMapper.java @@ -6,6 +6,7 @@ import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.material.book.domain.BookCarInfoDto; import com.bonus.material.devchange.domain.MaDevFile; import com.bonus.material.devchange.domain.MaDevInfo; +import com.bonus.material.devchange.domain.MaDevInfoXlsx; import com.bonus.material.devchange.domain.MapBean; import com.bonus.material.device.domain.DevInfo; import com.bonus.material.device.domain.MaDevQc; @@ -73,6 +74,7 @@ public interface DevMergeMapper { Integer interDevice(MaDevInfo maDevInfo); + Integer interDeviceXlsx(MaDevInfoXlsx maDevInfo); List getDevice(MaDevInfo o); diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/DevMergeService.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/DevMergeService.java index f61ebae..f935238 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/DevMergeService.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/DevMergeService.java @@ -4,6 +4,7 @@ package com.bonus.material.device.service; import com.bonus.common.biz.domain.BmCompanyInfo; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.material.devchange.domain.MaDevInfo; +import com.bonus.material.devchange.domain.MaDevInfoXlsx; import com.bonus.material.device.domain.DevInfo; import com.bonus.material.device.domain.dto.DevInfoImpDto; import com.bonus.material.device.domain.dto.InfoMotionDto; @@ -69,4 +70,6 @@ public interface DevMergeService { List getDeviceByOrderId(MaDevInfo o); AjaxResult updateDevice(MaDevInfo maDevInfo); + + AjaxResult importData(List list, String orderId); } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/impl/DevMergeServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/impl/DevMergeServiceImpl.java index ad4f421..302b6c0 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/impl/DevMergeServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/device/service/impl/DevMergeServiceImpl.java @@ -18,6 +18,7 @@ import com.bonus.common.security.utils.SecurityUtils; import com.bonus.material.book.domain.BookCarInfoDto; import com.bonus.material.devchange.domain.MaDevFile; import com.bonus.material.devchange.domain.MaDevInfo; +import com.bonus.material.devchange.domain.MaDevInfoXlsx; import com.bonus.material.devchange.domain.MapBean; import com.bonus.material.devchange.mapper.MaDevInfoMapper; import com.bonus.material.device.domain.DevInfo; @@ -415,6 +416,90 @@ public class DevMergeServiceImpl implements DevMergeService { } } + /** + * @param list + * @param orderId + * @return + */ + @Override + public AjaxResult importData(List list, String orderId) { + if (Objects.isNull(list) || list.isEmpty()) { + return AjaxResult.error("表格内没有数据"); + } + + if (Objects.isNull(orderId)) { + DevMergeVo o = new DevMergeVo(); + o.setCreateUser(SecurityUtils.getLoginUser().getSysUser().getNickName()); + o.setOrderNumber(generate()); + devMergeMapper.addOrder(o); + orderId = o.getId(); + } + + for (MaDevInfoXlsx maDevInfo : list) { + + } + for (MaDevInfoXlsx maDevInfo : list) { + maDevInfo.setOrderId(Integer.valueOf(orderId)); + try { + Long thisLoginUserDeptId = SecurityUtils.getLoginUser().getSysUser().getDeptId(); + maDevInfo.setPropertyUnitId(Math.toIntExact(thisLoginUserDeptId)); + maDevInfo.setCode(getString()); + Integer i = devMergeMapper.interDeviceXlsx(maDevInfo); + if (i > 0) { + devInfoMapper.deleteDevInfoProperties(Long.valueOf(maDevInfo.getMaId())); + MaDevQc maDevQc = new MaDevQc(); + maDevQc.setMaId(maDevInfo.getMaId()); + maDevQc.setQcCode(maDevInfo.getCode()); + maDevQc.setCreateBy(String.valueOf(SecurityUtils.getUserId())); + maDevQc.setCreateTime(DateUtils.getNowDate()); + maDevQc.setQcCom(Optional.ofNullable(SecurityUtils.getLoginUser().getSysUser().getCompanyId()).orElse(SecurityUtils.getLoginUser().getSysUser().getDeptId()).toString()); + maDevQc.setNextCheckTime(maDevInfo.getNextMaintenanceDate()); + qcMapper.insertDevQc(maDevQc); + if (!CollectionUtils.isEmpty(maDevInfo.getPropertyVoList())) { + devInfoMapper.insertDevInfoProperties(Long.valueOf(maDevInfo.getMaId()), maDevInfo.getPropertyVoList()); + } + devMergeMapper.insertOrderDevReal(String.valueOf(maDevInfo.getOrderId()), Long.valueOf(maDevInfo.getMaId())); + maDevInfo.getAppearanceImages().forEach(item -> { + // 这里编写对每个 image 的处理逻辑,比如打印、处理等 + item.setFileType(1); + item.setMaId(maDevInfo.getMaId()); + item.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid())); + devMergeMapper.interFile(item); + }); + + maDevInfo.getCertificates().forEach(item -> { + // 这里编写对每个 image 的处理逻辑,比如打印、处理等 + item.setFileType(2); + item.setMaId(maDevInfo.getMaId()); + item.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid())); + devMergeMapper.interFile(item); + }); + + maDevInfo.getInspectionReports().forEach(item -> { + // 这里编写对每个 image 的处理逻辑,比如打印、处理等 + item.setFileType(3); + item.setMaId(maDevInfo.getMaId()); + item.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid())); + devMergeMapper.interFile(item); + }); + + maDevInfo.getPurchaseInvoices().forEach(item -> { + // 这里编写对每个 image 的处理逻辑,比如打印、处理等 + item.setFileType(4); + item.setMaId(maDevInfo.getMaId()); + item.setCreator(Math.toIntExact(SecurityUtils.getLoginUser().getUserid())); + devMergeMapper.interFile(item); + }); + } + return i > 0 ? AjaxResult.success() : AjaxResult.error(); + } catch (Exception e) { + log.error(e.getMessage()); + return AjaxResult.error(); + } + } + return null; + } + private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyMMdd"); private static final String SEPARATOR = "-"; diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/impl/ProvinceScreenServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/impl/ProvinceScreenServiceImpl.java index f002d24..eaa648a 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/impl/ProvinceScreenServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/impl/ProvinceScreenServiceImpl.java @@ -223,7 +223,7 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); res.put("proportion", totalEquipmentQuantity > 0 ? ((inUse + share) * 100) / totalEquipmentQuantity : 0 + "%"); //周转率 - int devNum = devInfoMapper.getChangeNum(); + Integer devNum = devInfoMapper.getChangeNum(); res.put("turnoverRate", totalEquipmentQuantity > 0 ? (devNum * 100) / totalEquipmentQuantity : 0 + "%"); return res; } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerEntity.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerEntity.java index ef1300d..0542ff0 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerEntity.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/domain/ToolLedgerEntity.java @@ -10,6 +10,7 @@ import java.io.Serializable; import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; @Data @@ -190,7 +191,7 @@ public class ToolLedgerEntity implements Serializable { */ private String fileList; - private List propertyVoList; + private List propertyVoList = new ArrayList<>(); private String proName; } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/Impl/ToolLedgerServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/Impl/ToolLedgerServiceImpl.java index ae25ec6..8d3024c 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/Impl/ToolLedgerServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/toolLedger/service/Impl/ToolLedgerServiceImpl.java @@ -1,5 +1,6 @@ package com.bonus.material.toolLedger.service.Impl; +import cn.hutool.core.util.ObjectUtil; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.material.device.domain.vo.DevInfoPropertyVo; import com.bonus.material.toolLedger.domain.ToolLedgerEntity; @@ -57,8 +58,11 @@ public class ToolLedgerServiceImpl implements ToolLedgerService { public AjaxResult updateById(ToolLedgerEntity entity) { try { Integer num = mapper.updateById(entity); - mapper.delProperties(entity.getId()); - mapper.insertDevInfoProperties(entity.getPropertyVoList(), entity.getId()); + + if(!entity.getPropertyVoList().isEmpty()){ + mapper.delProperties(entity.getId()); + mapper.insertDevInfoProperties(entity.getPropertyVoList(), entity.getId()); + } return num > 0 ? AjaxResult.success("修改成功") : AjaxResult.error("修改失败"); } catch (Exception e) { log.error(e.getMessage()); diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devchange/MaDevInfoMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devchange/MaDevInfoMapper.xml index 44eb0b7..e80116a 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devchange/MaDevInfoMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devchange/MaDevInfoMapper.xml @@ -495,5 +495,113 @@ #{id} + diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevInfoMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevInfoMapper.xml index 7afd64b..6e291bd 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevInfoMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevInfoMapper.xml @@ -1459,7 +1459,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(1) from ma_dev_info where is_active ='1' and change_status = #{changeStatus}