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 75e1f97..d8be7f5 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 @@ -10,10 +10,12 @@ import com.bonus.material.device.domain.dto.InfoMotionDto; import com.bonus.material.device.domain.vo.DevInfoPropertyVo; import com.bonus.material.device.domain.vo.DevInfoVo; import com.bonus.material.device.domain.vo.LeaseVo; +import com.bonus.material.largeScreen.entity.DevInfoReq; import com.bonus.material.largeScreen.entity.LeaseInfo; import com.bonus.material.largeScreen.entity.RentInfo; import org.apache.ibatis.annotations.Param; +import java.math.BigDecimal; import java.util.Date; import java.util.List; @@ -276,5 +278,25 @@ public interface DevInfoMapper { List getDemandUnit(DevInfoVo devInfoVo); int updateTypeLeasePrice(DevInfo devInfo); + + Integer getTotalEquipment(DevInfoReq devInfoReq); + + BigDecimal getTotalValue(DevInfoReq devInfoReq); + + int getLineNum(DevInfoReq devInfoReq); + + BigDecimal getLinePrice(DevInfoReq devInfoReq); + + List getLineProductionDateList(DevInfoReq devInfoReq); + + List getUnitEquipmentConfiguration(); + + BigDecimal getPrice(Long deptId); + + int getEquipmentStatus(String changeStatus); + + int getChangeNum(); + + int getTurnoverRate(); } 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 new file mode 100644 index 0000000..87acf9c --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/controller/ProvinceScreenController.java @@ -0,0 +1,161 @@ +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.material.device.domain.DevInfo; +import com.bonus.material.largeScreen.service.ProvinceScreenService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author 马三炮 + * @date 2025/9/14 + */ +@Api(value = "网省大屏", tags = {"网省大屏"}) +@RestController +@RequestMapping("/provinceScreen") +public class ProvinceScreenController extends BaseController { + + @Resource + private ProvinceScreenService provinceScreenService; + + /** + * 装备总量,总价值 + * @return + */ + @ApiOperation("装备总量,总价值") + @GetMapping("/getTotalEquipment") + public AjaxResult getTotalEquipment() { + try { + Map res = provinceScreenService.getTotalEquipment(); + return AjaxResult.success(res); + } catch (Exception e) { + return AjaxResult.error("装备总量,总价值异常"); + } + } + + /** + *线路装备,变电装备,电缆装备 + * @return + */ + @ApiOperation("线路装备,变电装备,电缆装备") + @GetMapping("/getTotalEquipment") + public AjaxResult getEquipmentClassification() { + try { + Map res = provinceScreenService.getEquipmentClassification(); + return AjaxResult.success(res); + } catch (Exception e) { + return AjaxResult.error("线路装备,变电装备,电缆装备异常"); + } + } + + /** + * 单位装备配置 + * @return + */ + @ApiOperation("单位装备配置") + @GetMapping("/getUnitEquipmentConfiguration") + public AjaxResult getUnitEquipmentConfiguration() { + try { + List> res = provinceScreenService.getUnitEquipmentConfiguration(); + return AjaxResult.success(res); + } catch (Exception e) { + return AjaxResult.error("单位装备配置异常"); + } + } + + /** + * 装备状态 + * @return + */ + @ApiOperation("装备状态") + @GetMapping("/getEquipmentStatus") + public AjaxResult getEquipmentStatus() { + try { + List> res = provinceScreenService.getEquipmentStatus(); + return AjaxResult.success(res); + } catch (Exception e) { + return AjaxResult.error("装备状态异常"); + } + } + + /** + * 项目装备 + * @return + */ + @ApiOperation("项目装备") + @GetMapping("/getProjectEquipment") + public AjaxResult getProjectEquipment() { + try { + Map res = provinceScreenService.getProjectEquipment(); + return AjaxResult.success(res); + } catch (Exception e) { + return AjaxResult.error("项目装备异常"); + } + } + + /** + * 各单位装备在用率情况 + * @return + */ + @ApiOperation("各单位装备在用率情况") + @GetMapping("/getDeptEquipment") + public AjaxResult getDeptEquipment() { + try { + List> res = provinceScreenService.getDeptEquipment(); + return AjaxResult.success(res); + } catch (Exception e) { + return AjaxResult.error("项目装备异常"); + } + } + + /** + * 工程在用装备情况 + * @return + */ + @ApiOperation("工程在用装备情况") + @GetMapping("/getEquipmentUse") + public AjaxResult getEquipmentUse() { + try { + List> res = provinceScreenService.getEquipmentUse(); + for (int i = 0; i < 10; i++) { + 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); + } + return AjaxResult.success(res); + } catch (Exception e) { + return AjaxResult.error("工程在用装备情况异常"); + } + } + + @ApiOperation("装备在用率统计") + @GetMapping("/getUsageStatistics") + public AjaxResult getUsageStatistics() { + try { + List> res = provinceScreenService.getUsageStatistics(); + for (int i = 0; i < 10; i++) { + 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); + } + 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/entity/DevInfoReq.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/entity/DevInfoReq.java new file mode 100644 index 0000000..cc96ea4 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/entity/DevInfoReq.java @@ -0,0 +1,26 @@ +package com.bonus.material.largeScreen.entity; + +import lombok.Data; + +/** + * @author 马三炮 + * @date 2025/9/14 + */ +@Data +public class DevInfoReq { + + /** + * 设备所属公司 + */ + public Integer ownCo; + + /** + * 类型id + */ + public Integer typeId; + + /** + *默认 1 变更状态 变更类型 1入库 2、3 出库(2是自用 3共享) 4退役 5维修 + */ + public String changeStatus; +} 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 new file mode 100644 index 0000000..2c5d555 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/ProvinceScreenService.java @@ -0,0 +1,51 @@ +package com.bonus.material.largeScreen.service; + +import java.util.List; +import java.util.Map; + +public interface ProvinceScreenService { + + /** + * 装备总量,总价值 + * @return + */ + Map getTotalEquipment(); + + /** + *线路装备,变电装备,电缆装备 + * @return + */ + Map getEquipmentClassification(); + + /** + * 单位装备配置 + * @return + */ + List> getUnitEquipmentConfiguration(); + + /** + * 装备状态 + * @return + */ + List> getEquipmentStatus(); + + /** + * 项目装备 + * @return + */ + Map getProjectEquipment(); + + /** + * 各单位装备在用率情况 + * @return + */ + List> getDeptEquipment(); + + /** + * 工程在用装备情况 + * @return + */ + List> getEquipmentUse(); + + List> getUsageStatistics(); +} 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 new file mode 100644 index 0000000..623db9f --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/largeScreen/service/impl/ProvinceScreenServiceImpl.java @@ -0,0 +1,342 @@ +package com.bonus.material.largeScreen.service.impl; + +import com.bonus.common.core.utils.DateUtils; +import com.bonus.material.device.domain.DevInfo; +import com.bonus.material.device.mapper.DevInfoMapper; +import com.bonus.material.equipment.domain.DeptConfigRateSummary; +import com.bonus.material.equipment.mapper.SysDeptMapper; +import com.bonus.material.equipment.service.ISysDeptService; +import com.bonus.material.equipment.service.impl.SysDeptServiceImpl; +import com.bonus.material.largeScreen.entity.DevInfoReq; +import com.bonus.material.largeScreen.service.ProvinceScreenService; +import com.bonus.system.api.domain.SysDept; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.Period; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.*; + +/** + * @author 马三炮 + * @date 2025/9/14 + */ +@Service +@Slf4j +public class ProvinceScreenServiceImpl implements ProvinceScreenService { + + @Resource + private DevInfoMapper devInfoMapper; + + @Resource + private SysDeptMapper sysDeptMapper; + + @Resource + private ISysDeptService sysDeptService; + + /** + * 装备总量,总价值 + * @return + */ + @Override + public Map getTotalEquipment() { + Map res = new HashMap<>(); + DevInfoReq devInfoReq = new DevInfoReq(); + //装备总量 + Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); + res.put("totalEquipmentQuantity",totalEquipmentQuantity); + //总价值 + BigDecimal totalValue = devInfoMapper.getTotalValue(devInfoReq); + res.put("totalValue",totalValue); + return res; + } + + /** + *线路装备,变电装备,电缆装备 + * @return + */ + @Override + public Map getEquipmentClassification() { + Map res = new HashMap<>(); + Map res1 = new HashMap<>(); + Map res2 = new HashMap<>(); + Map res3 = new HashMap<>(); + DevInfoReq devInfoReq = new DevInfoReq(); + //线路装备 + //装备数 + devInfoReq.setTypeId(1); + int lineNum = devInfoMapper.getLineNum(devInfoReq); + res1.put("num",lineNum); + BigDecimal linePrice = devInfoMapper.getLinePrice(devInfoReq); + res1.put("price",linePrice); + List lineProductionDateList = devInfoMapper.getLineProductionDateList(devInfoReq); + count(res1,lineProductionDateList); + //变电装备 + //装备数 + devInfoReq.setTypeId(2); + int substationNum = devInfoMapper.getLineNum(devInfoReq); + res2.put("num",substationNum); + BigDecimal substationPrice = devInfoMapper.getLinePrice(devInfoReq); + res2.put("price",substationPrice); + List substationProductionDateList = devInfoMapper.getLineProductionDateList(devInfoReq); + count(res2,substationProductionDateList); + //电缆装备 + //装备数 + devInfoReq.setTypeId(3); + int cableNum = devInfoMapper.getLineNum(devInfoReq); + res3.put("num",cableNum); + BigDecimal cablePrice = devInfoMapper.getLinePrice(devInfoReq); + res3.put("price",cablePrice); + List cableProductionDateList = devInfoMapper.getLineProductionDateList(devInfoReq); + count(res3,cableProductionDateList); + + res.put("line",res1); + res.put("substation",res2); + res.put("cable",res3); + return res; + } + + /** + * 单位装备配置 + * @return + */ + @Override + public List> getUnitEquipmentConfiguration() { + //获取所有单位 TODO 后期可能单位放到字典表这里要修改 + SysDept sysDept = new SysDept(); + DevInfoReq devInfoReq = new DevInfoReq(); + List sysDeptList = sysDeptMapper.selectDeptList(sysDept); + List> res = new ArrayList<>(); + for (SysDept sysDeptNew:sysDeptList) { + Map dept = new HashMap<>(); + dept.put("deptName",sysDeptNew.getDeptName()); + devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId())); + //装备价值 + BigDecimal totalValue = devInfoMapper.getTotalValue(devInfoReq); + dept.put("totalValue",totalValue); + //装备总数 + Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); + dept.put("totalEquipmentQuantity",totalEquipmentQuantity); + //线路 + devInfoReq.setTypeId(1); + int lineNum = devInfoMapper.getLineNum(devInfoReq); + dept.put("lineNum",lineNum); + //变电 + devInfoReq.setTypeId(2); + int substationNum = devInfoMapper.getLineNum(devInfoReq); + dept.put("substationNum",substationNum); + //电缆 + devInfoReq.setTypeId(3); + int cableNum = devInfoMapper.getLineNum(devInfoReq); + dept.put("cableNum",cableNum); + // 获取装备转换率 + DeptConfigRateSummary user = new DeptConfigRateSummary(); + List list = sysDeptService.selectDeptConfigRatePivot(user); + for (DeptConfigRateSummary deptConfigRateSummary: list) { + if (deptConfigRateSummary.getDeptId().equals(sysDeptNew.getDeptId())){ + //总数 + dept.put("configRate",deptConfigRateSummary.getConfigRate()); + //线路 + dept.put("valueA",deptConfigRateSummary.getValueA()); + //变电 + dept.put("valueA",deptConfigRateSummary.getValueB()); + //电缆 + dept.put("valueA",deptConfigRateSummary.getValueC()); + } + } + res.add(dept); + } + return res; + } + + /** + * 装备状态 + * @return + */ + @Override + public List> getEquipmentStatus() { + List> res = new ArrayList<>(); + Map res1 = new HashMap<>(); + Map res2 = new HashMap<>(); + Map res3 = new HashMap<>(); + Map res4 = new HashMap<>(); + //在库--1 + int inStock = devInfoMapper.getEquipmentStatus("1"); + res1.put("name","在库"); + res1.put("num",inStock); + //自用--2 + int inUse = devInfoMapper.getEquipmentStatus("2"); + //共享--3 + int share = devInfoMapper.getEquipmentStatus("3"); + res2.put("name","在用"); + res2.put("num",inUse+share); + //维修--5 + int repair = devInfoMapper.getEquipmentStatus("5"); + res3.put("name","在修"); + res3.put("num",repair); + + res4.put("name","共享"); + res4.put("num",share); + int count = inStock+inUse+share+repair; + res1.put("proportion",count > 0 ? (inStock * 100) / count : 0+"%"); + res2.put("proportion",count > 0 ? ((inUse+share) * 100) / count : 0+"%"); + res3.put("proportion",count > 0 ? (repair * 100) / count : 0+"%"); + res4.put("proportion",0); + res.add(res1); + res.add(res2); + res.add(res3); + res.add(res4); + return null; + } + + /** + * 项目装备 + * @return + */ + @Override + public Map getProjectEquipment() { + + Map res = new HashMap<>(); + //年度总投资额 TODO 输入的 + res.put("annualTotal","140.6"); + //在建工程数 TODO e基建2.0获取 + res.put("projectNUm",50); + //在用装备数 + //自用--2 + int inUse = devInfoMapper.getEquipmentStatus("2"); + //共享--3 + int share = devInfoMapper.getEquipmentStatus("3"); + res.put("num",inUse+share); + //在用率 + DevInfoReq devInfoReq = new DevInfoReq(); + Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq); + res.put("proportion",totalEquipmentQuantity > 0 ? ((inUse+share) * 100) / totalEquipmentQuantity : 0+"%"); + //周转率 + int devNum = devInfoMapper.getChangeNum(); + res.put("turnoverRate",totalEquipmentQuantity > 0 ? (devNum * 100) / totalEquipmentQuantity : 0+"%"); + return res; + } + + /** + * 各单位装备在用率情况 + * @return + */ + @Override + public List> getDeptEquipment() { + List> res = new ArrayList<>(); + SysDept sysDept = new SysDept(); + List sysDeptList = sysDeptMapper.selectDeptList(sysDept); + for (SysDept 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数值降序排序(高在用率优先) + Collections.sort(res, new Comparator>() { + @Override + public int compare(Map map1, Map 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 + */ + @Override + public List> getEquipmentUse() { + List> res = new ArrayList<>(); + return res; + } + + @Override + public List> getUsageStatistics() { + return null; + } + + /** + * 统计数量 + */ + public void count(Map res,List lineProductionDateList){ + int five = 0; + int fiveOrTen = 0; + int ten = 0; + if (lineProductionDateList.size()>0){ + for (String date :lineProductionDateList){ + int yearDiff = calculateYearDifferenceWithJava8(date); + if (yearDiff<5){ + five++; + }else if(yearDiff>10){ + ten++; + }else { + fiveOrTen++; + } + } + five = lineProductionDateList.size() > 0 ? (five * 100) / lineProductionDateList.size() : 0; + fiveOrTen = lineProductionDateList.size() > 0 ? (fiveOrTen * 100) / lineProductionDateList.size() : 0; + ten = lineProductionDateList.size() > 0 ? (ten * 100) / lineProductionDateList.size() : 0; + } + res.put("five",five+"%"); + res.put("fiveOrTen",fiveOrTen+"%"); + res.put("ten",ten+"%"); + } + + /** + * 计算当前日期与production_date的完整年数差(基于Java 8+ LocalDate) + * @param productionDateStr 生产日期字符串(格式:yyyy-MM-dd,如"2020-05-18") + * @return 年数差(正数:当前日期在production_date之后;负数:当前日期在production_date之前;0:同年) + * @throws DateTimeParseException 若日期字符串格式不符合要求,抛出解析异常 + */ + public static int calculateYearDifferenceWithJava8(String productionDateStr) throws DateTimeParseException { + // 1. 定义日期格式器(匹配输入的production_date字符串格式) + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + // 2. 将字符串类型的production_date解析为LocalDate对象 + LocalDate productionDate = LocalDate.parse(productionDateStr, formatter); + + // 3. 获取当前系统日期(仅日期,不含时间) + LocalDate currentDate = LocalDate.now(); + + // 4. 计算两个LocalDate之间的周期(Period包含年、月、日差) + Period period = Period.between(productionDate, currentDate); + + // 5. 返回完整年数差(Period的getYears()方法直接返回满1年的数量) + return period.getYears(); + } + + + +} 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 200ada2..3cb3fbe 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 @@ -1405,4 +1405,84 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ma_lease_info mli LEFT JOIN sys_dept sd ON mli.publish_company = sd.dept_id + + + + + + + + + +