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 9a9220c..0f70f25 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 @@ -1,11 +1,19 @@ package com.bonus.material.devchange.controller; +import cn.hutool.core.bean.BeanUtil; +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.web.controller.BaseController; import com.bonus.common.core.web.domain.AjaxResult; 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 io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; @@ -13,8 +21,17 @@ import org.springframework.web.bind.annotation.*; import org.springframework.beans.factory.annotation.Autowired; import javax.annotation.Resource; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.util.List; +import java.lang.reflect.Field; +import java.net.URLEncoder; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; /** * 设备台账-总览表 @@ -44,6 +61,7 @@ public class MaDevInfoController extends BaseController { } } + @ApiOperation(value = "设备台账-上下架") @PostMapping("/updateDeviceStatus") public AjaxResult updateDeviceStatus(@RequestBody DevMergeVo o) { @@ -143,4 +161,218 @@ public class MaDevInfoController extends BaseController { } + /** + * 导出设备信息为Excel + * + * @param o 查询条件(同列表接口) + * @param response 响应对象 + */ + @ApiOperation("导出设备信息Excel") + @PostMapping("/export") + public void export(MaDevInfo o, HttpServletResponse response) throws IOException { + // 1. 查询所有符合条件的数据(忽略分页) + List dataList = service.list(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(); + } + } + + /** + * 转换设备信息为导出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/MaDevInfo.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/domain/MaDevInfo.java index 446830a..e7b65b1 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/domain/MaDevInfo.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/domain/MaDevInfo.java @@ -338,4 +338,6 @@ public class MaDevInfo { private String upDownStatus; + private String remainingStopYear; + } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/DevChangeServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/DevChangeServiceImpl.java index acf0f82..cdfce30 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/DevChangeServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devchange/service/DevChangeServiceImpl.java @@ -73,7 +73,7 @@ public class DevChangeServiceImpl implements DevChangeService { @Override public AjaxResult updateDevChangeInfo(CsDeviceChangeVo vo) { try { - String username = SecurityUtils.getLoginUser().getUsername(); + String username = SecurityUtils.getLoginUser().getSysUser().getNickName(); vo.setCreateUser(username); String proCode = vo.getProCode(); if (StringUtils.isBlank(proCode)) { @@ -149,7 +149,7 @@ public class DevChangeServiceImpl implements DevChangeService { @Override public AjaxResult updateDevChangeInfo3(CsDeviceChangeVo vo) { try { - String username = SecurityUtils.getLoginUser().getUsername(); + String username = SecurityUtils.getLoginUser().getSysUser().getNickName(); vo.setCreateUser(username); if (StringUtils.isBlank(vo.getType())) { return AjaxResult.error("请上传类型type:1入库 2出库 3 退役 4 维修"); @@ -206,7 +206,8 @@ public class DevChangeServiceImpl implements DevChangeService { @Override public AjaxResult updateDevChangeInfo2(CsDeviceChangeVo vo) { try { - String username = SecurityUtils.getLoginUser().getUsername(); + String username = SecurityUtils.getLoginUser().getSysUser().getNickName(); + vo.setCreateUser(username); if (StringUtils.isBlank(vo.getType())) { return AjaxResult.error("请上传类型type:1入库 2出库 3 退役 4 维修"); @@ -271,7 +272,7 @@ public class DevChangeServiceImpl implements DevChangeService { @Override public AjaxResult addChangeInfo(CsDeviceChangeVo vo) { try { - String username = SecurityUtils.getLoginUser().getUsername(); + String username = SecurityUtils.getLoginUser().getSysUser().getNickName(); vo.setCreateUser(username); String proCode = vo.getProCode(); if (StringUtils.isBlank(proCode)) { 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 b706500..ad4f421 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 @@ -246,8 +246,9 @@ public class DevMergeServiceImpl implements DevMergeService { maDevQc.setQcCom(Optional.ofNullable(SecurityUtils.getLoginUser().getSysUser().getCompanyId()).orElse(SecurityUtils.getLoginUser().getSysUser().getDeptId()).toString()); maDevQc.setNextCheckTime(maDevInfo.getNextMaintenanceDate()); qcMapper.insertDevQc(maDevQc); - - devInfoMapper.insertDevInfoProperties(Long.valueOf(maDevInfo.getMaId()), maDevInfo.getPropertyVoList()); + 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 的处理逻辑,比如打印、处理等 @@ -364,7 +365,9 @@ public class DevMergeServiceImpl implements DevMergeService { if (i > 0) { devInfoMapper.deleteDevInfoProperties(Long.valueOf(maDevInfo.getMaId())); devMergeMapper.delFile(maDevInfo.getMaId()); - devInfoMapper.insertDevInfoProperties(Long.valueOf(maDevInfo.getMaId()), maDevInfo.getPropertyVoList()); + if (!CollectionUtils.isEmpty(maDevInfo.getPropertyVoList())) { + devInfoMapper.insertDevInfoProperties(Long.valueOf(maDevInfo.getMaId()), maDevInfo.getPropertyVoList()); + } MaDevQc maDevQc = new MaDevQc(); maDevQc.setMaId(maDevInfo.getMaId()); maDevQc.setQcCode(maDevInfo.getCode()); diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/controller/ProvinceScreenController.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/controller/ProvinceScreenController.java index adb5a36..fb81594 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/controller/ProvinceScreenController.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/controller/ProvinceScreenController.java @@ -2,14 +2,14 @@ package com.bonus.material.largeScreen.controller; 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.material.device.domain.DevInfo; +import com.bonus.material.device.domain.vo.DevInfoVo; import com.bonus.material.largeScreen.service.ProvinceScreenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.ArrayList; @@ -32,13 +32,14 @@ public class ProvinceScreenController extends BaseController { /** * 装备总量,总价值 + * * @return */ @ApiOperation("装备总量,总价值") @GetMapping("/getTotalEquipment") public AjaxResult getTotalEquipment() { try { - Map res = provinceScreenService.getTotalEquipment(); + Map res = provinceScreenService.getTotalEquipment(); return AjaxResult.success(res); } catch (Exception e) { return AjaxResult.error("装备总量,总价值异常"); @@ -46,14 +47,15 @@ public class ProvinceScreenController extends BaseController { } /** - *线路装备,变电装备,电缆装备 + * 线路装备,变电装备,电缆装备 + * * @return */ @ApiOperation("线路装备,变电装备,电缆装备") @GetMapping("/getEquipmentClassification") public AjaxResult getEquipmentClassification() { try { - Map res = provinceScreenService.getEquipmentClassification(); + Map res = provinceScreenService.getEquipmentClassification(); return AjaxResult.success(res); } catch (Exception e) { log.error("错误", e); @@ -64,13 +66,14 @@ public class ProvinceScreenController extends BaseController { /** * 单位装备配置 + * * @return */ @ApiOperation("单位装备配置") @GetMapping("/getUnitEquipmentConfiguration") public AjaxResult getUnitEquipmentConfiguration() { try { - List> res = provinceScreenService.getUnitEquipmentConfiguration(); + List> res = provinceScreenService.getUnitEquipmentConfiguration(); if (res == null) { logger.warn("单位装备配置数据为空"); return AjaxResult.success(new ArrayList<>()); @@ -85,13 +88,14 @@ public class ProvinceScreenController extends BaseController { /** * 装备状态 + * * @return */ @ApiOperation("装备状态") @GetMapping("/getEquipmentStatus") public AjaxResult getEquipmentStatus() { try { - List> res = provinceScreenService.getEquipmentStatus(); + List> res = provinceScreenService.getEquipmentStatus(); return AjaxResult.success(res); } catch (Exception e) { return AjaxResult.error("装备状态异常"); @@ -100,13 +104,14 @@ public class ProvinceScreenController extends BaseController { /** * 项目装备 + * * @return */ @ApiOperation("项目装备") @GetMapping("/getProjectEquipment") public AjaxResult getProjectEquipment() { try { - Map res = provinceScreenService.getProjectEquipment(); + Map res = provinceScreenService.getProjectEquipment(); return AjaxResult.success(res); } catch (Exception e) { return AjaxResult.error("项目装备异常"); @@ -115,13 +120,14 @@ public class ProvinceScreenController extends BaseController { /** * 各单位装备在用率情况 + * * @return */ @ApiOperation("各单位装备在用率情况") @GetMapping("/getDeptEquipment") public AjaxResult getDeptEquipment() { try { - List> res = provinceScreenService.getDeptEquipment(); + List> res = provinceScreenService.getDeptEquipment(); return AjaxResult.success(res); } catch (Exception e) { return AjaxResult.error("项目装备异常"); @@ -130,44 +136,14 @@ public class ProvinceScreenController extends BaseController { /** * 工程在用装备情况 + * * @return */ @ApiOperation("工程在用装备情况") @GetMapping("/getEquipmentUse") - public AjaxResult getEquipmentUse() { + public AjaxResult getEquipmentUse(String proCode, String type) { try { - List> res = provinceScreenService.getEquipmentUse(); - Map map = new HashMap<>(); - map.put("projectName","石桥-大陇π入万济变、大陇-阳湖T接万济变 35kV架空线路工程"); - map.put("inUser","82"); - map.put("scale","172"); - map.put("usage","47.67"); - res.add(map); - map = new HashMap<>(); - map.put("projectName","淮南泥河110kV变电站新建工程"); - map.put("inUser","66"); - map.put("scale","170"); - map.put("usage","48.67"); - res.add(map); - map = new HashMap<>(); - map.put("projectName","安徽黄山市徽州区呈坎35kV变电站新建工程"); - map.put("inUser","68"); - map.put("scale","160"); - map.put("usage","49.67"); - res.add(map); - map = new HashMap<>(); - map.put("projectName","凌云220kV变电站新建工程"); - map.put("inUser","65"); - map.put("scale","175"); - map.put("usage","45.67"); - res.add(map); - map = new HashMap<>(); - map.put("projectName","东坡110kV变电站新建工程"); - map.put("inUser","68"); - map.put("scale","174"); - map.put("usage","49.67"); - res.add(map); - return AjaxResult.success(res); + return provinceScreenService.getEquipmentUse(proCode, type); } catch (Exception e) { return AjaxResult.error("工程在用装备情况异常"); } @@ -175,13 +151,14 @@ public class ProvinceScreenController extends BaseController { /** * 装备在用率统计 + * * @return */ @ApiOperation("装备在用率统计") @GetMapping("/getUsageStatistics") public AjaxResult getUsageStatistics(Integer type) { try { - List> res = provinceScreenService.getUsageStatistics(type); + List> res = provinceScreenService.getUsageStatistics(type); return AjaxResult.success(res); } catch (Exception e) { return AjaxResult.error("装备在用率统计异常"); @@ -190,28 +167,46 @@ public class ProvinceScreenController extends BaseController { /** * 在库装备数 + * * @return */ @ApiOperation("在库装备数") @GetMapping("/getEquipmentNumber") public AjaxResult getEquipmentNumber() { try { - List> res = provinceScreenService.getEquipmentNumber(); + List> res = provinceScreenService.getEquipmentNumber(); return AjaxResult.success(res); } catch (Exception e) { return AjaxResult.error("在库装备数异常"); } } + @ApiOperation(value = "收藏装备列表") + @GetMapping("/getUsageStatisticsDetails") + public TableDataInfo getUsageStatisticsDetails() { + startPage(); + List> usageStatisticsDetails = provinceScreenService.getUsageStatisticsDetails(); + return getDataTable(usageStatisticsDetails); + } + + @ApiOperation(value = "收藏装备列表") + @GetMapping("/getEquipmentDetails") + public TableDataInfo getEquipmentDetails(String proName) { + startPage(); + List> usageStatisticsDetails = provinceScreenService.getEquipmentDetails(proName); + return getDataTable(usageStatisticsDetails); + } + /** * 机械化率 + * * @return */ @ApiOperation("机械化率") @GetMapping("/getMechanizationRate") public AjaxResult getMechanizationRate() { try { - List> res = provinceScreenService.getMechanizationRate(); + List> res = provinceScreenService.getMechanizationRate(); return AjaxResult.success(res); } catch (Exception e) { return AjaxResult.error("在库装备数异常"); diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/ProvinceScreenService.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/ProvinceScreenService.java index 9e79986..f3f50fb 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/ProvinceScreenService.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/ProvinceScreenService.java @@ -1,5 +1,7 @@ package com.bonus.material.largeScreen.service; +import com.bonus.common.core.web.domain.AjaxResult; + import java.util.List; import java.util.Map; @@ -7,57 +9,71 @@ public interface ProvinceScreenService { /** * 装备总量,总价值 + * * @return */ Map getTotalEquipment(); /** - *线路装备,变电装备,电缆装备 + * 线路装备,变电装备,电缆装备 + * * @return */ Map getEquipmentClassification(); /** * 单位装备配置 + * * @return */ - List> getUnitEquipmentConfiguration(); + List> getUnitEquipmentConfiguration(); /** * 装备状态 + * * @return */ - List> getEquipmentStatus(); + List> getEquipmentStatus(); /** * 项目装备 + * * @return */ Map getProjectEquipment(); /** * 各单位装备在用率情况 + * * @return */ List> getDeptEquipment(); /** * 工程在用装备情况 + * * @return */ - List> getEquipmentUse(); + AjaxResult getEquipmentUse(String proCode, String proType); + + + List> getEquipmentDetails(String proName); /** * 装备在用率统计 + * * @return */ List> getUsageStatistics(Integer type); /** * 在库装备数 + * * @return */ List> getEquipmentNumber(); List> getMechanizationRate(); + + List> getUsageStatisticsDetails(); } 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 72fa9a0..f3744fd 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 @@ -1,6 +1,7 @@ package com.bonus.material.largeScreen.service.impl; import com.bonus.common.core.utils.StringUtils; +import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.material.basic.domain.SysDeptVO; import com.bonus.material.device.mapper.DevInfoMapper; import com.bonus.material.equipment.domain.DeptConfigRateSummary; @@ -149,6 +150,8 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { */ @Override public List> getUnitEquipmentConfiguration() { + devInfoMapper.getUnitEquipmentConfiguration(); + if (sysDeptMapper == null) { log.error("sysDeptMapper is null"); return new ArrayList<>(); @@ -175,6 +178,7 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { Map dept = new HashMap<>(); dept.put("deptName", sysDeptNew.getDeptName() != null ? sysDeptNew.getDeptName() : "未知部门"); + dept.put("deptAbbreviation", sysDeptNew.getDeptAbbreviation() != null ? sysDeptNew.getDeptAbbreviation() : "未知部门"); devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId())); // 部门定位 @@ -192,7 +196,6 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { devInfoReq.setTypeId(1); int lineNum = devInfoMapper.getLineNum(devInfoReq); dept.put("lineNum", lineNum); - // 变电 devInfoReq.setTypeId(2); int substationNum = devInfoMapper.getLineNum(devInfoReq); @@ -214,10 +217,7 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { if (list != null) { for (DeptConfigRateSummary deptConfigRateSummary : list) { - if (deptConfigRateSummary != null && - deptConfigRateSummary.getDeptId() != null && - deptConfigRateSummary.getDeptId().equals(sysDeptNew.getDeptId())) { - + if (deptConfigRateSummary != null) { // 总数 dept.put("configRate", deptConfigRateSummary.getConfigRate() != null ? deptConfigRateSummary.getConfigRate() : 0.0); @@ -326,46 +326,7 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { */ @Override public List> getDeptEquipment() { - List> res = new ArrayList<>(); - SysDept sysDept = new SysDept(); - List sysDeptList = sysDeptMapper.selectDeptVOList(sysDept); - for (SysDeptVO sysDeptNew : sysDeptList) { - Map dept = new HashMap<>(); - DevInfoReq devInfoReq = new DevInfoReq(); - devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId())); - //装备总数 - Integer sum = devInfoMapper.getTotalEquipment(devInfoReq); - //自用2 - devInfoReq.setChangeStatus("2"); - Integer inUse = devInfoMapper.getTotalEquipment(devInfoReq); - devInfoReq.setChangeStatus("3"); - Integer share = devInfoMapper.getTotalEquipment(devInfoReq); - inUse = inUse + share; - dept.put("name", sysDeptNew.getDeptName()); - //在用率 - dept.put("proportion", sum > 0 ? (inUse * 100) / sum : 0); - //周转率 - int turnoverRate = devInfoMapper.getTurnoverRate(); - dept.put("turnoverRate", sum > 0 ? (turnoverRate * 100) / sum : 0); - dept.put("inUse", inUse); - res.add(dept); - } - // 【核心排序逻辑】按proportion数值降序排序(高在用率优先) -// res.sort((map1, map2) -> { -// // 1. 提取两个map中的proportion字符串 -// String proportion1 = (String) map1.get("proportion"); -// String proportion2 = (String) map2.get("proportion"); -// // 2. 处理null值(默认视为0%) -// proportion1 = proportion1 == null ? "0%" : proportion1; -// proportion2 = proportion2 == null ? "0%" : proportion2; -// // 3. 去掉"%"符号,转为Integer数值(核心步骤) -// // 注意:若proportion含小数(如"83.5%"),需转为Double,此处按整数处理(适配原代码逻辑) -// int propValue1 = Integer.parseInt(proportion1.replace("%", "")); -// int propValue2 = Integer.parseInt(proportion2.replace("%", "")); -// // 4. 数值降序排序(高在用率在前);升序用:propValue1 - propValue2 -// return propValue2 - propValue1; -// }); - return res; + return maTypeMapper.getDeptEquipment(); } /** @@ -374,9 +335,22 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { * @return */ @Override - public List> getEquipmentUse() { - List> res = new ArrayList<>(); - return res; + public AjaxResult getEquipmentUse(String proCode, String proType) { + Map res = new HashMap<>(); + Integer proNum = maTypeMapper.getProNum(proType); + Integer equipmentNum = maTypeMapper.getEquipmentNum(proType); + res.put("proNum", proNum); + res.put("equipmentNum", equipmentNum); + res.put("equipmentUse", maTypeMapper.getEquipmentUse(proCode, proType)); + return AjaxResult.success(res); + } + + /** + * @return + */ + @Override + public List> getEquipmentDetails(String proName) { + return maTypeMapper.getEquipmentDetails(proName); } /** @@ -387,7 +361,7 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { @Override public List> getUsageStatistics(Integer type) { - List> res = new ArrayList<>(); + /* List> res = new ArrayList<>(); List maTypeList = new ArrayList<>(); //获取装备在用率 查询全部 if (StringUtils.isNull(type)) { @@ -431,8 +405,8 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { int propValue2 = Integer.parseInt(proportion2.replace("%", "")); // 4. 数值降序排序(高在用率在前);升序用:propValue1 - propValue2 return propValue2 - propValue1; - }); - return res.subList(0, 10); + });*/ + return maTypeMapper.getUsageStatistics(type); } /** @@ -455,6 +429,7 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { devInfoReq.setChangeStatus("1"); Integer inStock = devInfoMapper.getTotalEquipment(devInfoReq); dept.put("location", sysDeptNew.getLocation()); + dept.put("deptAbbreviation", sysDeptNew.getDeptAbbreviation() != null ? sysDeptNew.getDeptAbbreviation() : "未知部门"); dept.put("name", sysDeptNew.getDeptName()); dept.put("num", inStock); res.add(dept); @@ -467,6 +442,14 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService { return null; } + /** + * @return + */ + @Override + public List> getUsageStatisticsDetails() { + return maTypeMapper.getUsageStatisticsDetails(); + } + /** * 统计数量 */ diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/mapper/MaTypeMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/mapper/MaTypeMapper.java index 1b3e56c..d81edee 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/mapper/MaTypeMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/mapper/MaTypeMapper.java @@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param; import java.math.BigDecimal; import java.util.List; +import java.util.Map; /** * 工机具类型管理 数据层 @@ -100,4 +101,20 @@ public interface MaTypeMapper { List selectMaTypeTreeBy5Level(Integer type); List selectMaTypeTreeBy5Level2(Integer type); + + List> getUsageStatistics(Integer type); + + + List> getUsageStatisticsDetails(); + + List> getEquipmentUse(@Param("proCode") String proCode, @Param("proType") String proType); + + + List> getEquipmentDetails(String proName); + + Integer getProNum(@Param("proType") String proType); + + Integer getEquipmentNum(@Param("proType") String proType); + + List> getDeptEquipment(); } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/supplier/mapper/MaSupplierMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/supplier/mapper/MaSupplierMapper.java index daf6bf3..fea43f1 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/supplier/mapper/MaSupplierMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/supplier/mapper/MaSupplierMapper.java @@ -11,9 +11,7 @@ public interface MaSupplierMapper { MaSupplier selectById(@Param("supplierId") Long supplierId); - List list(@Param("supplierCode") String supplierCode, - @Param("supplierName") String supplierName, - @Param("status") Integer status); + List list(MaSupplier query); int insert(MaSupplier supplier); diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/supplier/service/impl/MaSupplierServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/supplier/service/impl/MaSupplierServiceImpl.java index a0937b6..e1df6f7 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/supplier/service/impl/MaSupplierServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/supplier/service/impl/MaSupplierServiceImpl.java @@ -21,7 +21,7 @@ public class MaSupplierServiceImpl implements MaSupplierService { @Override public List list(MaSupplier query) { - return maSupplierMapper.list(query.getSupplierCode(), query.getSupplierName(), query.getStatus()); + return maSupplierMapper.list(query); } @Override diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/task/UseRateTask.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/task/UseRateTask.java new file mode 100644 index 0000000..f9211bf --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/task/UseRateTask.java @@ -0,0 +1,57 @@ +package com.bonus.material.task; + +import com.bonus.material.task.domain.UseRate; +import com.bonus.material.task.mapper.UseRateMapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; + +@Slf4j +@Component +public class UseRateTask { + + @Resource + private UseRateMapper mapper; + + /** + * 每晚11点执行:统计并保存设备当日使用情况 + * 优化点:异常处理、日志记录、事务控制、空集合判断 + */ + @Scheduled(cron = "0 0 23 * * ?") + //@Scheduled(cron = "0/10 * * * * ?") // 每10秒执行 + @Transactional(rollbackFor = Exception.class) // 确保数据一致性,异常时回滚 + public void collectDailyDeviceUsage() { + log.info("【设备每日使用统计】任务开始执行"); + long startTime = System.currentTimeMillis(); + + try { + // 1. 查询待统计的设备数据 + List useRates = mapper.selectUseRate(); + log.info("【设备每日使用统计】查询到待处理设备数量:{}", useRates.size()); + + // 2. 空集合判断,避免无效插入 + if (useRates.isEmpty()) { + log.warn("【设备每日使用统计】未查询到设备数据,无需执行插入"); + return; + } + + // 3. 批量插入(优先使用批量插入,效率更高) + int insertCount = mapper.insertUseRate(useRates); // 改用之前定义的批量插入方法 + log.info("【设备每日使用统计】批量插入完成,成功插入 {} 条记录", insertCount); + + } catch (Exception e) { + // 4. 异常捕获与日志记录(避免任务中断) + log.error("【设备每日使用统计】任务执行失败", e); // 打印完整堆栈,便于排查 + throw e; // 若有事务,抛出异常触发回滚 + } finally { + // 5. 记录任务耗时 + long costTime = System.currentTimeMillis() - startTime; + log.info("【设备每日使用统计】任务执行结束,耗时:{}ms", costTime); + } + } + +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/task/domain/UseRate.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/task/domain/UseRate.java new file mode 100644 index 0000000..62e97d9 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/task/domain/UseRate.java @@ -0,0 +1,19 @@ +package com.bonus.material.task.domain; + +import lombok.Data; + +@Data +public class UseRate { + /** + * 设备id + */ + private Integer maId; + /** + * 设备状态 + */ + private Integer status; + /** + * 设备类型 + */ + private Integer typeId; +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/task/mapper/UseRateMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/task/mapper/UseRateMapper.java new file mode 100644 index 0000000..bf65732 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/task/mapper/UseRateMapper.java @@ -0,0 +1,24 @@ +package com.bonus.material.task.mapper; + +import com.bonus.material.task.domain.UseRate; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface UseRateMapper { + /** + * 插入每个设备的每天的在用状态 + * + * @param useRate 数据 + * @return 条数 + */ + Integer insertUseRate(List useRate); + + /** + * 查询设备信息 + * + * @return 设备信息 + */ + List selectUseRate(); +} diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/cityScreen/CityScreenMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/cityScreen/CityScreenMapper.xml index 7d2952c..f631435 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/cityScreen/CityScreenMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/cityScreen/CityScreenMapper.xml @@ -26,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ifnull(sum(mdi.buy_price * mdi.device_count),0) as totalValue, COUNT(1) as deviceQuantity from ma_dev_info mdi - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id where mdi.is_active = 1 and mtv.MaxTypeId = #{typeId} and mdi.on_company = #{companyId} and TIMESTAMPDIFF(YEAR,mdi.production_date, NOW()) 5 @@ -53,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mdi.change_status as status, mtv.maxTypeId as typeId from ma_dev_info mdi - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id where mdi.is_active = 1 and mdi.on_company = #{companyId} and mtv.MaxTypeId = #{typeId} @@ -80,7 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" when TIMESTAMPDIFF(DAY, NOW(),mdq.next_check_time) 0 then '已超期' else '未检' end as situation from ma_dev_info mdi - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id left join ma_dev_qc mdq on mdq.ma_id = mdi.ma_id where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 4 order by TIMESTAMPDIFF(YEAR, NOW(),mdq.next_check_time) @@ -89,7 +89,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(DISTINCT mdi.ma_id) from ma_dev_info mdi - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id left join ma_dev_qc mdq on mdq.ma_id = mdi.ma_id where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 4 @@ -99,7 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mtv.devCategory as procedureName, concat('差',TIMESTAMPDIFF(DAY, NOW(),mdi.expiration_time),'天退役') as situation from ma_dev_info mdi - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 4 order by TIMESTAMPDIFF(YEAR, NOW(),mdi.expiration_time) @@ -108,7 +108,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(DISTINCT mdi.ma_id) from ma_dev_info mdi - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 4 @@ -116,7 +116,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(1) from ma_dev_info mdi - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 3 @@ -128,7 +128,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mdi.device_name as deviceName, CONCAT(ROUND(count(cdcd.dev_id)/mdi.device_count, 2),'次/年') as turnoverRate from ma_dev_info mdi - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id left join cs_device_change_details cdcd on cdcd.dev_id = mdi.ma_id left join cs_device_change cdc on cdc.id = cdcd.change_id where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 4 and cdc.type = 2 and cdc.del_flag = 0 @@ -144,7 +144,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sum(mdi.buy_price * mdi.device_count) as investAmount from jj_sing_project jsp left join ma_dev_info mdi on mdi.on_project = jsp.id - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status in (2,3) and jsp.voltage = #{voltageLevel} @@ -161,7 +161,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select DISTINCT count(1) from jj_sing_project jsp left join ma_dev_info mdi on mdi.on_project = jsp.id - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status in (2, 3) @@ -182,7 +182,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select DISTINCT ifnull(sum(mdi.device_count),0) as num from jj_sing_project jsp left join ma_dev_info mdi on mdi.on_project = jsp.id - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status in (2, 3) @@ -206,7 +206,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sum(mdi.device_count) as useNum from jj_sing_project jsp left join ma_dev_info mdi on mdi.on_project = jsp.id - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id where mdi.is_active = 1 @@ -221,7 +221,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ifnull(sum(mdi.device_count),0) as useNum from jj_sing_project jsp left join ma_dev_info mdi on mdi.on_project = jsp.id - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id where mdi.is_active = 1 and mdi.change_status in (1,5) and jsp.city = #{city} @@ -233,7 +233,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" from (select DISTINCT ifnull(sum(mdi.device_count), 0) as useNum from jj_sing_project jsp left join ma_dev_info mdi on mdi.on_project = jsp.id - left join ma_type_view mtv on mtv.typeId = mdi.type_id + INNER join ma_type_view mtv on mtv.typeId = mdi.type_id where mdi.is_active = 1 and (mdi.change_status in (2, 3) or mdi.change_status is null) and jsp.city != #{city}) r diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/contract/BmContractMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/contract/BmContractMapper.xml index 4b5a661..db97aa1 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/contract/BmContractMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/contract/BmContractMapper.xml @@ -30,7 +30,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(1) from ma_dev_info mdi - left join ma_type mt on mdi.type_id = mt.type_id - left join ma_type mt1 on mt.parent_id = mt1.type_id - left join ma_type mt2 on mt1.parent_id = mt2.type_id - left join ma_type mt3 on mt2.parent_id = mt3.type_id - left join ma_type mt4 on mt3.parent_id = mt4.type_id - left join ma_type mt5 on mt4.parent_id = mt5.type_id - left join ma_type mt6 on mt5.parent_id = mt6.type_id - where mt6.type_id = #{typeId} and mdi.is_active ='1' + INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id + where mtv.maxTypeId = #{typeId} + and mdi.is_active = '1' select count(1) from ma_dev_info mdi - left join ma_type mt on mdi.type_id = mt.type_id - left join ma_type mt1 on mt.parent_id = mt1.type_id - left join ma_type mt2 on mt1.parent_id = mt2.type_id - where mt2.type_id = #{typeId} and mdi.is_active ='1' + INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id + where mtv.typeId = #{typeId} and mdi.is_active ='1' AND change_status = #{changeStatus} @@ -1539,13 +1517,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(1) from cs_device_change_details cdcd left join cs_device_change cdc on cdcd.change_id = cdc.id left join ma_dev_info mdi on mdi.ma_id = cdcd.dev_id - left join ma_type mt on mdi.type_id = mt.type_id - left join ma_type mt1 on mt.parent_id = mt1.type_id - left join ma_type mt2 on mt1.parent_id = mt2.type_id + INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id where cdcd.del_flag = '0' - AND cdc.create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH) + AND cdc.create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH) - AND mt2.type_id = #{typeId} + AND mtv.typeId = #{typeId} diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevMergeMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevMergeMapper.xml index 88f46e7..78c1482 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevMergeMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/DevMergeMapper.xml @@ -68,7 +68,7 @@ LEFT JOIN cs_device_status cds ON cdrd.cs_id = cds.id LEFT JOIN sys_dept sd ON d.on_company = sd.dept_id LEFT JOIN bm_company_info c ON sd.dept_id = c.company_id - LEFT JOIN ma_type_view mtv ON mtv.typeId = d.type_id + INNER JOIN ma_type_view mtv ON mtv.typeId = d.type_id and cdrd.cs_id = #{orderId} @@ -248,7 +248,7 @@ type_name AS label, parent_id AS parentId FROM ma_type - WHERE parent_id IS NULL + WHERE parent_id = '0' AND del_flag = '0'; -- 排除已删除的数据 @@ -325,7 +325,7 @@ AND t5.del_flag = '0' -- 五级 ) AS all_levels ON t.type_id = all_levels.type_id WHERE t1.type_id = #{firstLevelId} - AND t1.parent_id IS NULL -- 确保是一级类型 + AND t1.parent_id = '0' -- 确保是一级类型 AND t.del_flag = '0' SELECT DATE_FORMAT(cdcd.use_time, '%Y/%m') AS month,-- 月份 -- 统计不同类型设备的有效使用次数(status为2/3) - SUM(CASE WHEN mtv.maxTypeId = 5080 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS cableCount, - SUM(CASE WHEN mtv.maxTypeId = 5010 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS substationCount, - SUM(CASE WHEN mtv.maxTypeId = 5474 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS lineCount + SUM(CASE WHEN mtv.maxTypeId = 1 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS cableCount, + SUM(CASE WHEN mtv.maxTypeId = 3 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS substationCount, + SUM(CASE WHEN mtv.maxTypeId = 2 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS lineCount FROM cs_device_change_details cdcd -- 左连接设备表(过滤有效设备) LEFT JOIN ma_dev_info mdi ON cdcd.dev_id = mdi.ma_id -- 关联设备ID - AND mdi.change_status != '4' AND mdi.is_active = '1' -- 左连接类型表(获取设备类型) - LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id -- 过滤无效的使用时间(可选,避免NULL的月份) - + INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id -- 过滤无效的使用时间(可选,避免NULL的月份) WHERE cdcd.use_time IS NOT NULL AND mdi.ma_id IS NOT NULL -- 按「设备ID+月份」分组(核心修正) GROUP BY DATE_FORMAT(cdcd.use_time, '%Y/%m') -- 按月份和设备ID排序,结果更清晰 - ORDER BY month; diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml index 00ec04f..f0030be 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml @@ -69,7 +69,8 @@ from ma_type - + insert into ma_type type_name, @@ -211,7 +212,7 @@ + + + + + + + delete diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/order/OrderInfoMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/order/OrderInfoMapper.xml index ce4efc5..4d06e31 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/order/OrderInfoMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/order/OrderInfoMapper.xml @@ -148,10 +148,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mdi.on_company as sellerCompany, up.dept_name AS czcompanyName, mdi.person AS person, - mdi.person_phone AS personPhone, + sd.phone AS personPhone, su.phonenumber AS phoneNumber, su.nick_name as buyerName, - su2.nick_name as sellerName, + sd.dept_name as sellerName, moi.address, moi.order_id, dept.dept_name as companyName @@ -159,6 +159,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ma_order_details hh LEFT JOIN ma_order_info moi ON moi.order_id = hh.order_id LEFT JOIN ma_dev_info mdi ON hh.ma_id = mdi.ma_id + LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id LEFT JOIN sys_user su ON su.user_id = moi.buyer_id LEFT JOIN sys_user su2 ON su2.user_id = mdi.creator diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/supplier/MaSupplierMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/supplier/MaSupplierMapper.xml index 3d98b2a..e49f6fb 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/supplier/MaSupplierMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/supplier/MaSupplierMapper.xml @@ -49,6 +49,13 @@ and status = #{status} + + and contact_person like concat('%', #{contactPerson}, '%') + + + + and contact_phone like concat('%', #{contactPhone}, '%') + order by update_time desc diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/task/UseRateMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/task/UseRateMapper.xml new file mode 100644 index 0000000..21a170f --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/task/UseRateMapper.xml @@ -0,0 +1,34 @@ + + + + + + INSERT INTO ma_dev_daily_use ( + ma_id, + status, + type_id, + create_time + ) + VALUES + + ( + #{item.maId}, + #{item.status}, + #{item.typeId}, + NOW() + ) + + + + diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/user/UserMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/user/UserMapper.xml index 3772840..217aa40 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/user/UserMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/user/UserMapper.xml @@ -32,7 +32,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" d.order_num, d.leader, d.phone, - d.email, d.status, d.del_flag, d.create_by,