enhance equipment management with new SysDeptVO and improved error handling

This commit is contained in:
syruan 2025-09-17 18:10:01 +08:00
parent 1e1db1892d
commit a08a45b216
6 changed files with 494 additions and 421 deletions

View File

@ -0,0 +1,18 @@
package com.bonus.material.basic.domain;
import com.bonus.system.api.domain.SysDept;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = false)
@Data
public class SysDeptVO extends SysDept {
@ApiModelProperty(value = "经纬度定位信息")
private String location;
@ApiModelProperty(value = "单位类型: 省公司、地市公司、三方公司")
private String deptType;
}

View File

@ -1,5 +1,6 @@
package com.bonus.material.equipment.mapper;
import com.bonus.material.basic.domain.SysDeptVO;
import com.bonus.material.equipment.domain.ConfigEntity;
import com.bonus.material.equipment.domain.DeptEquipmentConfig;
import com.bonus.material.equipment.domain.DeptTreeSelect;
@ -14,8 +15,9 @@ public interface SysDeptMapper {
List<com.bonus.system.api.domain.SysDept> selectDeptList(com.bonus.system.api.domain.SysDept dept);
List<SysUser> selectUserList(DeptEquipmentConfig user);
List<SysDeptVO> selectDeptVOList(com.bonus.system.api.domain.SysDept dept);
List<SysUser> selectUserList(DeptEquipmentConfig user);
List<ConfigEntity> selectConfigList(DeptEquipmentConfig user);

View File

@ -1,6 +1,7 @@
package com.bonus.material.equipment.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.bonus.common.core.utils.SpringUtils;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.web.domain.AjaxResult;
@ -8,6 +9,7 @@ import com.bonus.common.core.web.domain.BaseEntity;
import com.bonus.common.datascope.annotation.DataScope;
import com.bonus.common.datascope.utils.CommonDataPermissionInfo;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.basic.domain.SysDeptVO;
import com.bonus.material.equipment.domain.*;
import com.bonus.material.equipment.mapper.SysDeptMapper;
import com.bonus.material.equipment.service.ISysDeptService;
@ -25,6 +27,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Function;
import javax.annotation.Resource;
import java.util.stream.Collectors;
@ -437,7 +440,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
}
public List<SysDept> buildDeptTree(List<SysDept> depts) {
List<SysDept> returnList = new ArrayList<SysDept>();
List<SysDept> returnList = new ArrayList<>();
List<Long> tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList());
for (SysDept dept : depts) {
// 如果是顶级节点, 遍历该父节点的所有子节点
@ -464,18 +467,16 @@ public class SysDeptServiceImpl implements ISysDeptService {
}
private List<SysDept> getChildList(List<SysDept> list, SysDept t) {
List<SysDept> tlist = new ArrayList<SysDept>();
Iterator<SysDept> it = list.iterator();
while (it.hasNext()) {
SysDept n = (SysDept) it.next();
List<SysDept> tlist = new ArrayList<>();
for (SysDept n : list) {
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) {
tlist.add(n);
tlist.add((SysDeptVO) n);
}
}
return tlist;
}
private boolean hasChild(List<SysDept> list, SysDept t) {
return getChildList(list, t).size() > 0 ? true : false;
return !getChildList(list, t).isEmpty();
}
}

View File

@ -56,6 +56,8 @@ public class ProvinceScreenController extends BaseController {
Map<String,Object> res = provinceScreenService.getEquipmentClassification();
return AjaxResult.success(res);
} catch (Exception e) {
log.error("错误", e);
System.err.println(e.getMessage());
return AjaxResult.error("线路装备,变电装备,电缆装备异常");
}
}

View File

@ -1,13 +1,11 @@
package com.bonus.material.largeScreen.service.impl;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.material.device.domain.DevInfo;
import com.bonus.material.basic.domain.SysDeptVO;
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.material.ma.mapper.MaTypeMapper;
@ -19,6 +17,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
@ -32,279 +31,321 @@ import java.util.*;
@Slf4j
public class ProvinceScreenServiceImpl implements ProvinceScreenService {
@Resource
private DevInfoMapper devInfoMapper;
@Resource
private DevInfoMapper devInfoMapper;
@Resource
private SysDeptMapper sysDeptMapper;
@Resource
private SysDeptMapper sysDeptMapper;
@Resource
private ISysDeptService sysDeptService;
@Resource
private ISysDeptService sysDeptService;
@Resource
private MaTypeMapper maTypeMapper;
@Resource
private MaTypeMapper maTypeMapper;
/**
* 装备总量总价值
* @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;
/**
* 计算当前日期与production_date的完整年数差基于Java 8+ LocalDate
* @param productionDateStr 生产日期字符串格式yyyy-MM-dd或yyyy-MM-dd HH:mm:ss
* @return 年数差正数当前日期在production_date之后负数当前日期在production_date之前0同年
* @throws DateTimeParseException 若日期字符串格式不符合要求抛出解析异常
*/
public static int calculateYearDifferenceWithJava8(String productionDateStr) throws DateTimeParseException {
LocalDate productionDate;
try {
// 首先尝试解析包含时间的格式
if (productionDateStr.length() > 10) {
DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
productionDate = LocalDateTime.parse(productionDateStr, fullFormatter).toLocalDate();
} else {
// 如果只有日期部分使用简单的日期格式
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
productionDate = LocalDate.parse(productionDateStr, dateFormatter);
}
} catch (DateTimeParseException e) {
// 如果解析失败尝试提取日期部分
if (productionDateStr.length() >= 10) {
String datePart = productionDateStr.substring(0, 10);
productionDate = LocalDate.parse(datePart, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
} else {
throw e;
}
}
/**
*线路装备变电装备电缆装备
* @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);
LocalDate currentDate = LocalDate.now();
return Period.between(productionDate, currentDate).getYears();
}
res.put("line",res1);
res.put("substation",res2);
res.put("cable",res3);
return res;
/**
* 装备总量总价值
* @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() {
if (sysDeptMapper == null) {
log.error("sysDeptMapper is null");
return new ArrayList<>();
}
/**
* 单位装备配置
* @return
*/
@Override
public List<Map<String,Object>> getUnitEquipmentConfiguration() {
if (sysDeptMapper == null) {
log.error("sysDeptMapper is null");
return new ArrayList<>();
SysDept sysDept = new SysDept();
DevInfoReq devInfoReq = new DevInfoReq();
List<SysDeptVO> sysDeptList = sysDeptMapper.selectDeptVOList(sysDept);
if (sysDeptList == null) {
log.error("未找到部门数据");
return new ArrayList<>();
}
sysDeptList.removeIf(item -> item.getDeptType() == null || !Objects.equals(item.getDeptType(),"地市公司"));
List<Map<String,Object>> res = new ArrayList<>();
for (SysDeptVO sysDeptNew : sysDeptList) {
if (sysDeptNew == null || sysDeptNew.getDeptId() == null) {
log.warn("跳过无效的部门数据");
continue;
}
SysDept sysDept = new SysDept();
DevInfoReq devInfoReq = new DevInfoReq();
List<SysDept> sysDeptList = sysDeptMapper.selectDeptList(sysDept);
Map<String,Object> dept = new HashMap<>();
dept.put("deptName", sysDeptNew.getDeptName() != null ? sysDeptNew.getDeptName() : "未知部门");
devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId()));
if (sysDeptList == null) {
log.error("未找到部门数据");
return new ArrayList<>();
}
// 部门定位
dept.put("location", Optional.ofNullable(sysDeptNew.getLocation()).orElse(""));
List<Map<String,Object>> res = new ArrayList<>();
for (SysDept sysDeptNew : sysDeptList) {
if (sysDeptNew == null || sysDeptNew.getDeptId() == null) {
log.warn("跳过无效的部门数据");
continue;
}
// 装备价值
BigDecimal totalValue = devInfoMapper.getTotalValue(devInfoReq);
dept.put("totalValue", totalValue != null ? totalValue : BigDecimal.ZERO);
Map<String,Object> dept = new HashMap<>();
dept.put("deptName", sysDeptNew.getDeptName() != null ? sysDeptNew.getDeptName() : "未知部门");
devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId()));
// 装备总数
Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq);
dept.put("totalEquipmentQuantity", totalEquipmentQuantity != null ? totalEquipmentQuantity : 0);
// 装备价值
BigDecimal totalValue = devInfoMapper.getTotalValue(devInfoReq);
dept.put("totalValue", totalValue != null ? totalValue : BigDecimal.ZERO);
// 线路
devInfoReq.setTypeId(1);
int lineNum = devInfoMapper.getLineNum(devInfoReq);
dept.put("lineNum", lineNum);
// 装备总数
Integer totalEquipmentQuantity = devInfoMapper.getTotalEquipment(devInfoReq);
dept.put("totalEquipmentQuantity", totalEquipmentQuantity != null ? totalEquipmentQuantity : 0);
// 变电
devInfoReq.setTypeId(2);
int substationNum = devInfoMapper.getLineNum(devInfoReq);
dept.put("substationNum", substationNum);
// 线路
devInfoReq.setTypeId(1);
int lineNum = devInfoMapper.getLineNum(devInfoReq);
dept.put("lineNum", lineNum);
// 电缆
devInfoReq.setTypeId(3);
int cableNum = devInfoMapper.getLineNum(devInfoReq);
dept.put("cableNum", cableNum);
// 变电
devInfoReq.setTypeId(2);
int substationNum = devInfoMapper.getLineNum(devInfoReq);
dept.put("substationNum", substationNum);
// 所在城市
String cityName = sysDeptMapper.getCityName(sysDeptNew.getCity());
dept.put("cityName", cityName != null ? cityName : "未知城市");
// 电缆
devInfoReq.setTypeId(3);
int cableNum = devInfoMapper.getLineNum(devInfoReq);
dept.put("cableNum", cableNum);
// 获取装备转换率
try {
DeptConfigRateSummary user = new DeptConfigRateSummary();
List<DeptConfigRateSummary> list = sysDeptService.selectDeptConfigRatePivot(user);
// 所在城市
String cityName = sysDeptMapper.getCityName(sysDeptNew.getCity());
dept.put("cityName", cityName != null ? cityName : "未知城市");
// 获取装备转换率
try {
DeptConfigRateSummary user = new DeptConfigRateSummary();
List<DeptConfigRateSummary> list = sysDeptService.selectDeptConfigRatePivot(user);
if (list != null) {
for (DeptConfigRateSummary deptConfigRateSummary : list) {
if (deptConfigRateSummary != null &&
if (list != null) {
for (DeptConfigRateSummary deptConfigRateSummary : list) {
if (deptConfigRateSummary != null &&
deptConfigRateSummary.getDeptId() != null &&
deptConfigRateSummary.getDeptId().equals(sysDeptNew.getDeptId()))
{
{
// 总数
dept.put("configRate", deptConfigRateSummary.getConfigRate() != null ?
deptConfigRateSummary.getConfigRate() : 0.0);
// 线路
dept.put("valueA", deptConfigRateSummary.getValueA() != null ?
deptConfigRateSummary.getValueA() : 0.0);
// 变电
dept.put("valueB", deptConfigRateSummary.getValueB() != null ?
deptConfigRateSummary.getValueB() : 0.0);
// 电缆
dept.put("valueC", deptConfigRateSummary.getValueC() != null ?
deptConfigRateSummary.getValueC() : 0.0);
break;
}
// 总数
dept.put("configRate", deptConfigRateSummary.getConfigRate() != null ?
deptConfigRateSummary.getConfigRate() : 0.0);
// 线路
dept.put("valueA", deptConfigRateSummary.getValueA() != null ?
deptConfigRateSummary.getValueA() : 0.0);
// 变电
dept.put("valueB", deptConfigRateSummary.getValueB() != null ?
deptConfigRateSummary.getValueB() : 0.0);
// 电缆
dept.put("valueC", deptConfigRateSummary.getValueC() != null ?
deptConfigRateSummary.getValueC() : 0.0);
break;
}
}
} catch (Exception e) {
log.error("获取装备转换率异常: " + e.getMessage(), e);
// 设置默认值
dept.put("configRate", 0.0);
dept.put("valueA", 0.0);
dept.put("valueB", 0.0);
dept.put("valueC", 0.0);
}
res.add(dept);
} catch (Exception e) {
log.error("获取装备转换率异常: " + e.getMessage(), e);
// 设置默认值
dept.put("configRate", 0.0);
dept.put("valueA", 0.0);
dept.put("valueB", 0.0);
dept.put("valueC", 0.0);
}
return res;
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);
/**
* 装备状态
* @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 res;
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 res;
}
/**
* 项目装备
* @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<SysDeptVO> sysDeptList = sysDeptMapper.selectDeptVOList(sysDept);
for (SysDeptVO 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);
}
/**
* 项目装备
* @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数值降序排序高在用率优先
// 核心排序逻辑按proportion数值降序排序高在用率优先
// res.sort((map1, map2) -> {
// // 1. 提取两个map中的proportion字符串
// String proportion1 = (String) map1.get("proportion");
@ -319,152 +360,131 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService {
// // 4. 数值降序排序高在用率在前升序用propValue1 - propValue2
// return propValue2 - propValue1;
// });
return res;
return res;
}
/**
* 工程在用装备情况
* @return
*/
@Override
public List<Map<String, Object>> getEquipmentUse() {
List<Map<String, Object>> res = new ArrayList<>();
return res;
}
/**
* 装备在用率统计
* @return
*/
@Override
public List<Map<String, Object>> getUsageStatistics(Integer type) {
List<Map<String, Object>> res = new ArrayList<>();
List<MaType> maTypeList = new ArrayList<>();
//获取装备在用率 查询全部
if (StringUtils.isNull(type)){
maTypeList = maTypeMapper.selectMaTypeTreeBy5Level(null);
} else {
maTypeList = maTypeMapper.selectMaTypeTreeBy5Level2(type);
}
/**
* 工程在用装备情况
* @return
*/
@Override
public List<Map<String, Object>> getEquipmentUse() {
List<Map<String, Object>> res = new ArrayList<>();
return res;
if (!maTypeList.isEmpty()) {
for (MaType maType:maTypeList) {
Map<String, Object> dev = new HashMap<>();
DevInfoReq devInfoReq = new DevInfoReq();
devInfoReq.setTypeId(Math.toIntExact(maType.getTypeId()));
//装备总数
Integer sum = devInfoMapper.getTotalEquipmentByLevel(devInfoReq);
//自用2
devInfoReq.setChangeStatus("2");
Integer inUse = devInfoMapper.getTotalEquipmentByLevel(devInfoReq);
devInfoReq.setChangeStatus("3");
Integer share = devInfoMapper.getTotalEquipmentByLevel(devInfoReq);
inUse = inUse+share;
dev.put("name",maType.getTypeName());
//在用率
dev.put("proportion",sum > 0 ? (inUse * 100) / sum : 0+"%");
//周转率
int turnoverRate = devInfoMapper.getTurnoverRateByLevel(devInfoReq);
dev.put("turnoverRate",sum > 0 ? (turnoverRate * 100) / sum : 0+"次/年");
res.add(dev);
}
}
// 核心排序逻辑按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.subList(0,10);
}
/**
* 装备在用率统计
* @return
*/
@Override
public List<Map<String, Object>> getUsageStatistics(Integer type) {
/**
* 在库装备数
* @return
*/
@Override
public List<Map<String, Object>> getEquipmentNumber() {
//在库装备数
List<Map<String, Object>> res = new ArrayList<>();
SysDept sysDept = new SysDept();
List<SysDeptVO> sysDeptList = sysDeptMapper.selectDeptVOList(sysDept);
sysDeptList.removeIf(item -> item.getDeptType() == null || !Objects.equals(item.getDeptType(),"地市公司"));
for (SysDeptVO sysDeptNew : sysDeptList) {
Map<String, Object> dept = new HashMap<>();
//入库1
DevInfoReq devInfoReq = new DevInfoReq();
devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId()));
devInfoReq.setChangeStatus("1");
Integer inStock = devInfoMapper.getTotalEquipment(devInfoReq);
dept.put("location", sysDeptNew.getLocation());
dept.put("name", sysDeptNew.getDeptName());
dept.put("num", inStock);
res.add(dept);
}
return res;
}
List<Map<String, Object>> res = new ArrayList<>();
List<MaType> maTypeList = new ArrayList<>();
//获取装备在用率 查询全部
if (StringUtils.isNull(type)){
maTypeList = maTypeMapper.selectMaTypeTreeBy5Level(null);
@Override
public List<Map<String, Object>> getMechanizationRate() {
return null;
}
/**
* 统计数量
*/
public void count(Map<String, Object> res,List<String> lineProductionDateList){
int five = 0;
int fiveOrTen = 0;
int ten = 0;
if (!lineProductionDateList.isEmpty()){
for (String date :lineProductionDateList){
int yearDiff = calculateYearDifferenceWithJava8(date);
if (yearDiff<5){
five++;
}else if(yearDiff>10){
ten++;
}else {
maTypeList = maTypeMapper.selectMaTypeTreeBy5Level2(type);
fiveOrTen++;
}
if (maTypeList.size()>0){
for (MaType maType:maTypeList) {
Map<String, Object> dev = new HashMap<>();
DevInfoReq devInfoReq = new DevInfoReq();
devInfoReq.setTypeId(Math.toIntExact(maType.getTypeId()));
//装备总数
Integer sum = devInfoMapper.getTotalEquipmentByLevel(devInfoReq);
//自用2
devInfoReq.setChangeStatus("2");
Integer inUse = devInfoMapper.getTotalEquipmentByLevel(devInfoReq);
devInfoReq.setChangeStatus("3");
Integer share = devInfoMapper.getTotalEquipmentByLevel(devInfoReq);
inUse = inUse+share;
dev.put("name",maType.getTypeName());
//在用率
dev.put("proportion",sum > 0 ? (inUse * 100) / sum : 0+"%");
//周转率
int turnoverRate = devInfoMapper.getTurnoverRateByLevel(devInfoReq);
dev.put("turnoverRate",sum > 0 ? (turnoverRate * 100) / sum : 0+"次/年");
res.add(dev);
}
}
// 核心排序逻辑按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.subList(0,10);
}
/**
* 在库装备数
* @return
*/
@Override
public List<Map<String, Object>> getEquipmentNumber() {
//在库装备数
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<>();
//入库1
DevInfoReq devInfoReq = new DevInfoReq();
devInfoReq.setOwnCo(Math.toIntExact(sysDeptNew.getDeptId()));
devInfoReq.setChangeStatus("1");
Integer inStock = devInfoMapper.getTotalEquipment(devInfoReq);
dept.put("name",sysDeptNew.getDeptName());
dept.put("num",inStock);
res.add(dept);
}
return res;
}
@Override
public List<Map<String, Object>> getMechanizationRate() {
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();
}
five = !lineProductionDateList.isEmpty() ? (five * 100) / lineProductionDateList.size() : 0;
fiveOrTen = !lineProductionDateList.isEmpty() ? (fiveOrTen * 100) / lineProductionDateList.size() : 0;
ten = !lineProductionDateList.isEmpty() ? (ten * 100) / lineProductionDateList.size() : 0;
}
res.put("five",five);
res.put("fiveOrTen",fiveOrTen);
res.put("ten",ten);
}

View File

@ -1,22 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.material.equipment.mapper.SysDeptMapper">
<sql id="selectDeptVo">
select d.dept_id,
d.parent_id,
d.ancestors,
d.dept_name,
d.order_num,
d.leader,
d.dept_abbreviation,
d.dept_type,
d.location,
d.phone,
d.email,
d.status,
d.del_flag,
d.create_by,
d.create_time,
d.city
from sys_dept d
</sql>
<resultMap type="com.bonus.system.api.domain.SysDept" id="SysDeptResult">
<id property="deptId" column="dept_id" />
<result property="parentId" column="parent_id" />
@ -44,18 +45,55 @@
<result property="adminUserId" column="admin_user_id" />
<result property="initPassword" column="init_password" />
</resultMap>
<select id="selectDeptTree" resultType="SysDept">
<resultMap type="com.bonus.material.basic.domain.SysDeptVO" id="SysDeptVOResult">
<id property="deptId" column="dept_id" />
<result property="parentId" column="parent_id" />
<result property="ancestors" column="ancestors" />
<result property="deptName" column="dept_name" />
<result property="orderNum" column="order_num" />
<result property="leader" column="leader" />
<result property="phone" column="phone" />
<result property="email" column="email" />
<result property="status" column="status" />
<result property="delFlag" column="del_flag" />
<result property="parentName" column="parent_name" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="menuTemplateId" column="menu_template_id" />
<result property="province" column="province" />
<result property="city" column="city" />
<result property="district" column="district" />
<result property="address" column="address" />
<result property="deptAbbreviation" column="dept_abbreviation" />
<result property="remark" column="remark" />
<result property="logo" column="logo" />
<result property="adminUserId" column="admin_user_id" />
<result property="initPassword" column="init_password" />
</resultMap>
<select id="selectDeptTree" resultType="com.bonus.material.equipment.domain.SysDept">
SELECT * FROM sys_dept WHERE del_flag = '0' ORDER BY parent_id, order_num
</select>
<select id="selectDeptList" parameterType="com.bonus.system.api.domain.SysDept" resultMap="SysDeptResult">
<include refid="selectDeptVo"/>
where d.del_flag = '0'
<if test="deptName != null and deptName != ''">
AND dept_name like concat('%', #{deptName}, '%')
</if>
</select>
<select id="selectDeptVOList" resultMap="SysDeptVOResult">
<include refid="selectDeptVo"/>
where d.del_flag = '0'
<if test="deptName != null and deptName != ''">
AND dept_name like concat('%', #{deptName}, '%')
</if>
</select>
<select id="selectUserList" resultType="com.bonus.material.equipment.domain.DeptEquipmentConfig">
SELECT
mt.type_id AS equipmentId,
@ -79,6 +117,7 @@
</if>
GROUP BY mt.type_id, mt2.type_name, mt.type_name
</select>
<select id="selectConfigList" resultType="com.bonus.material.equipment.domain.ConfigEntity">
SELECT
config_value AS basicConfig,
@ -89,21 +128,19 @@
WHERE dept_id = #{deptId}
AND type_id = #{typeId}
</select>
<select id="getTree" resultType="com.bonus.material.equipment.domain.DeptTreeSelect">
SELECT
mt.type_id AS id,
mt.type_name AS name
FROM ma_type mt
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
LEFT JOIN ma_dept_config mdc
ON mdc.type_id = mt.type_id
LEFT JOIN ma_dept_config mdc ON mdc.type_id = mt.type_id
WHERE mt.level = 3
GROUP BY mt.type_id, mt2.type_name, mt.type_name
</select>
<select id="selectDeptConfigRatePivot"
resultType="com.bonus.material.equipment.domain.DeptConfigRateSummary">
<select id="selectDeptConfigRatePivot" resultType="com.bonus.material.equipment.domain.DeptConfigRateSummary">
SELECT
my.type_name AS deptName,
my.type_id AS typeId,
@ -144,13 +181,9 @@
) order_stat
ON order_stat.dept_id = grouped.dept_id
AND order_stat.parent_type_id = grouped.type_id
WHERE 1 = 1
</select>
<select id="selectDeptConfigTypeSummary"
resultType="com.bonus.material.equipment.domain.DeptConfigTypeSummary">
<select id="selectDeptConfigTypeSummary" resultType="com.bonus.material.equipment.domain.DeptConfigTypeSummary">
SELECT mt1.type_name AS typeName,
mt2.type_name AS parentTypeName,
CAST(mdc.config_rate AS DECIMAL(10, 2)) AS configRate,
@ -160,6 +193,7 @@
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
WHERE mdc.dept_id = #{deptId}
</select>
<select id="detailsInfo" resultType="com.bonus.material.equipment.domain.EquipmentDetail">
SELECT
d.dept_id AS companyId,
@ -213,34 +247,30 @@
</if>
</otherwise>
</choose>
GROUP BY
d.dept_id,
d.config_type,
d.type_id
</select>
<select id="listFromDevInfo" resultType="com.bonus.material.equipment.domain.NewmydevInfo">
SELECT
md.own_co AS companyId,
mt2.type_id AS typeId,
mt2.type_name as typeName,
mt2.type_id AS typeId, mt2.type_name as typeName,
SUM( 1 ) AS ownCount
FROM
ma_dev_info md
LEFT JOIN ma_type mt ON mt.type_id = md.type_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
LEFT JOIN ma_type mt ON mt.type_id = md.type_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
WHERE
md.is_active = '1'
AND md.own_co = #{companyId}
md.is_active = '1' AND md.own_co = #{companyId}
GROUP BY
mt2.type_id
</select>
<select id="getCityName" resultType="java.lang.String">
select name
from base_address where code = #{city}
</select>
</mapper>