This commit is contained in:
马三炮 2025-09-15 09:46:49 +08:00
parent 610c290d1f
commit e7228b3177
6 changed files with 682 additions and 0 deletions

View File

@ -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<SysDept> getDemandUnit(DevInfoVo devInfoVo);
int updateTypeLeasePrice(DevInfo devInfo);
Integer getTotalEquipment(DevInfoReq devInfoReq);
BigDecimal getTotalValue(DevInfoReq devInfoReq);
int getLineNum(DevInfoReq devInfoReq);
BigDecimal getLinePrice(DevInfoReq devInfoReq);
List<String> getLineProductionDateList(DevInfoReq devInfoReq);
List<com.bonus.material.equipment.domain.SysDept> getUnitEquipmentConfiguration();
BigDecimal getPrice(Long deptId);
int getEquipmentStatus(String changeStatus);
int getChangeNum();
int getTurnoverRate();
}

View File

@ -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<String,Object> res = provinceScreenService.getTotalEquipment();
return AjaxResult.success(res);
} catch (Exception e) {
return AjaxResult.error("装备总量,总价值异常");
}
}
/**
*线路装备变电装备电缆装备
* @return
*/
@ApiOperation("线路装备,变电装备,电缆装备")
@GetMapping("/getTotalEquipment")
public AjaxResult getEquipmentClassification() {
try {
Map<String,Object> res = provinceScreenService.getEquipmentClassification();
return AjaxResult.success(res);
} catch (Exception e) {
return AjaxResult.error("线路装备,变电装备,电缆装备异常");
}
}
/**
* 单位装备配置
* @return
*/
@ApiOperation("单位装备配置")
@GetMapping("/getUnitEquipmentConfiguration")
public AjaxResult getUnitEquipmentConfiguration() {
try {
List<Map<String,Object>> res = provinceScreenService.getUnitEquipmentConfiguration();
return AjaxResult.success(res);
} catch (Exception e) {
return AjaxResult.error("单位装备配置异常");
}
}
/**
* 装备状态
* @return
*/
@ApiOperation("装备状态")
@GetMapping("/getEquipmentStatus")
public AjaxResult getEquipmentStatus() {
try {
List<Map<String,Object>> res = provinceScreenService.getEquipmentStatus();
return AjaxResult.success(res);
} catch (Exception e) {
return AjaxResult.error("装备状态异常");
}
}
/**
* 项目装备
* @return
*/
@ApiOperation("项目装备")
@GetMapping("/getProjectEquipment")
public AjaxResult getProjectEquipment() {
try {
Map<String,Object> res = provinceScreenService.getProjectEquipment();
return AjaxResult.success(res);
} catch (Exception e) {
return AjaxResult.error("项目装备异常");
}
}
/**
* 各单位装备在用率情况
* @return
*/
@ApiOperation("各单位装备在用率情况")
@GetMapping("/getDeptEquipment")
public AjaxResult getDeptEquipment() {
try {
List<Map<String,Object>> res = provinceScreenService.getDeptEquipment();
return AjaxResult.success(res);
} catch (Exception e) {
return AjaxResult.error("项目装备异常");
}
}
/**
* 工程在用装备情况
* @return
*/
@ApiOperation("工程在用装备情况")
@GetMapping("/getEquipmentUse")
public AjaxResult getEquipmentUse() {
try {
List<Map<String,Object>> res = provinceScreenService.getEquipmentUse();
for (int i = 0; i < 10; i++) {
Map<String,Object> 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<Map<String,Object>> res = provinceScreenService.getUsageStatistics();
for (int i = 0; i < 10; i++) {
Map<String,Object> 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("装备在用率统计异常");
}
}
}

View File

@ -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入库 23 出库(2是自用 3共享) 4退役 5维修
*/
public String changeStatus;
}

View File

@ -0,0 +1,51 @@
package com.bonus.material.largeScreen.service;
import java.util.List;
import java.util.Map;
public interface ProvinceScreenService {
/**
* 装备总量总价值
* @return
*/
Map<String, Object> getTotalEquipment();
/**
*线路装备变电装备电缆装备
* @return
*/
Map<String, Object> getEquipmentClassification();
/**
* 单位装备配置
* @return
*/
List<Map<String,Object>> getUnitEquipmentConfiguration();
/**
* 装备状态
* @return
*/
List<Map<String,Object>> getEquipmentStatus();
/**
* 项目装备
* @return
*/
Map<String, Object> getProjectEquipment();
/**
* 各单位装备在用率情况
* @return
*/
List<Map<String, Object>> getDeptEquipment();
/**
* 工程在用装备情况
* @return
*/
List<Map<String, Object>> getEquipmentUse();
List<Map<String, Object>> getUsageStatistics();
}

View File

@ -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<String, Object> getTotalEquipment() {
Map<String,Object> 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<String, Object> getEquipmentClassification() {
Map<String,Object> res = new HashMap<>();
Map<String,Object> res1 = new HashMap<>();
Map<String,Object> res2 = new HashMap<>();
Map<String,Object> 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<String> 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<String> 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<String> 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<Map<String,Object>> getUnitEquipmentConfiguration() {
//获取所有单位 TODO 后期可能单位放到字典表这里要修改
SysDept sysDept = new SysDept();
DevInfoReq devInfoReq = new DevInfoReq();
List<SysDept> sysDeptList = sysDeptMapper.selectDeptList(sysDept);
List<Map<String,Object>> res = new ArrayList<>();
for (SysDept sysDeptNew:sysDeptList) {
Map<String,Object> 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<DeptConfigRateSummary> 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<Map<String,Object>> getEquipmentStatus() {
List<Map<String,Object>> res = new ArrayList<>();
Map<String,Object> res1 = new HashMap<>();
Map<String,Object> res2 = new HashMap<>();
Map<String,Object> res3 = new HashMap<>();
Map<String,Object> 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<String, Object> getProjectEquipment() {
Map<String, Object> 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<Map<String, Object>> getDeptEquipment() {
List<Map<String, Object>> res = new ArrayList<>();
SysDept sysDept = new SysDept();
List<SysDept> sysDeptList = sysDeptMapper.selectDeptList(sysDept);
for (SysDept sysDeptNew:sysDeptList) {
Map<String, Object> 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<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> map1, Map<String, Object> 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<Map<String, Object>> getEquipmentUse() {
List<Map<String, Object>> res = new ArrayList<>();
return res;
}
@Override
public List<Map<String, Object>> getUsageStatistics() {
return null;
}
/**
* 统计数量
*/
public void count(Map<String, Object> res,List<String> 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();
}
}

View File

@ -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
</select>
<select id="getTotalEquipment" resultType="java.lang.Integer">
select count(1) from ma_dev_info where is_active ='1'
<if test="ownCo != null ">
AND own_co = #{ownCo}
</if>
<if test="changeStatus != null ">
AND change_status = #{changeStatus}
</if>
</select>
<select id="getTotalValue" resultType="java.math.BigDecimal">
select SUM(buy_price) from ma_dev_info where is_active ='1'
<if test="ownCo != null ">
AND own_co = #{ownCo}
</if>
</select>
<select id="getLineNum" resultType="java.lang.Integer">
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'
</select>
<select id="getLinePrice" resultType="java.math.BigDecimal">
select sum(mdi.buy_price)
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'
</select>
<select id="getLineProductionDateList" resultType="java.lang.String">
select production_date
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'
</select>
<select id="getUnitEquipmentConfiguration" resultType="com.bonus.material.equipment.domain.SysDept">
select production_date
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 = #{id} and mdi.is_active ='1'
</select>
<select id="getPrice" resultType="java.math.BigDecimal">
select SUM(buy_price) from ma_dev_info where is_active ='1' and own_co = #{deptId}
</select>
<select id="getEquipmentStatus" resultType="java.lang.Integer">
select count(1) from ma_dev_info where is_active ='1' and change_status = #{changeStatus}
</select>
<select id="getChangeNum" resultType="java.lang.Integer">
select SUM(dev_num) from cs_device_change where del_flag ='0'
AND create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH);
</select>
<select id="getTurnoverRate" resultType="java.lang.Integer">
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
where cdcd.del_flag = '0'
AND cdc.create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH);
</select>
</mapper>