问题修改
This commit is contained in:
parent
68555df7f1
commit
010b0950ac
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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<String,Object> res = provinceScreenService.getTotalEquipment();
|
||||
Map<String, Object> 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<String,Object> res = provinceScreenService.getEquipmentClassification();
|
||||
Map<String, Object> 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<Map<String,Object>> res = provinceScreenService.getUnitEquipmentConfiguration();
|
||||
List<Map<String, Object>> 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<Map<String,Object>> res = provinceScreenService.getEquipmentStatus();
|
||||
List<Map<String, Object>> 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<String,Object> res = provinceScreenService.getProjectEquipment();
|
||||
Map<String, Object> 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<Map<String,Object>> res = provinceScreenService.getDeptEquipment();
|
||||
List<Map<String, Object>> 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<Map<String,Object>> res = provinceScreenService.getEquipmentUse();
|
||||
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);
|
||||
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<Map<String,Object>> res = provinceScreenService.getUsageStatistics(type);
|
||||
List<Map<String, Object>> 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<Map<String,Object>> res = provinceScreenService.getEquipmentNumber();
|
||||
List<Map<String, Object>> res = provinceScreenService.getEquipmentNumber();
|
||||
return AjaxResult.success(res);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("在库装备数异常");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "收藏装备列表")
|
||||
@GetMapping("/getUsageStatisticsDetails")
|
||||
public TableDataInfo getUsageStatisticsDetails() {
|
||||
startPage();
|
||||
List<Map<String, Object>> usageStatisticsDetails = provinceScreenService.getUsageStatisticsDetails();
|
||||
return getDataTable(usageStatisticsDetails);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "收藏装备列表")
|
||||
@GetMapping("/getEquipmentDetails")
|
||||
public TableDataInfo getEquipmentDetails(String proName) {
|
||||
startPage();
|
||||
List<Map<String, Object>> usageStatisticsDetails = provinceScreenService.getEquipmentDetails(proName);
|
||||
return getDataTable(usageStatisticsDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* 机械化率
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("机械化率")
|
||||
@GetMapping("/getMechanizationRate")
|
||||
public AjaxResult getMechanizationRate() {
|
||||
try {
|
||||
List<Map<String,Object>> res = provinceScreenService.getMechanizationRate();
|
||||
List<Map<String, Object>> res = provinceScreenService.getMechanizationRate();
|
||||
return AjaxResult.success(res);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("在库装备数异常");
|
||||
|
|
|
|||
|
|
@ -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<String, Object> getTotalEquipment();
|
||||
|
||||
/**
|
||||
*线路装备,变电装备,电缆装备
|
||||
* 线路装备,变电装备,电缆装备
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getEquipmentClassification();
|
||||
|
||||
/**
|
||||
* 单位装备配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Map<String,Object>> getUnitEquipmentConfiguration();
|
||||
List<Map<String, Object>> getUnitEquipmentConfiguration();
|
||||
|
||||
/**
|
||||
* 装备状态
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Map<String,Object>> getEquipmentStatus();
|
||||
List<Map<String, Object>> getEquipmentStatus();
|
||||
|
||||
/**
|
||||
* 项目装备
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getProjectEquipment();
|
||||
|
||||
/**
|
||||
* 各单位装备在用率情况
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> getDeptEquipment();
|
||||
|
||||
/**
|
||||
* 工程在用装备情况
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> getEquipmentUse();
|
||||
AjaxResult getEquipmentUse(String proCode, String proType);
|
||||
|
||||
|
||||
List<Map<String, Object>> getEquipmentDetails(String proName);
|
||||
|
||||
/**
|
||||
* 装备在用率统计
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> getUsageStatistics(Integer type);
|
||||
|
||||
/**
|
||||
* 在库装备数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> getEquipmentNumber();
|
||||
|
||||
List<Map<String, Object>> getMechanizationRate();
|
||||
|
||||
List<Map<String, Object>> getUsageStatisticsDetails();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Map<String, Object>> getUnitEquipmentConfiguration() {
|
||||
devInfoMapper.getUnitEquipmentConfiguration();
|
||||
|
||||
if (sysDeptMapper == null) {
|
||||
log.error("sysDeptMapper is null");
|
||||
return new ArrayList<>();
|
||||
|
|
@ -175,6 +178,7 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService {
|
|||
|
||||
Map<String, Object> 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<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);
|
||||
}
|
||||
// 【核心排序逻辑】按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<Map<String, Object>> getEquipmentUse() {
|
||||
List<Map<String, Object>> res = new ArrayList<>();
|
||||
return res;
|
||||
public AjaxResult getEquipmentUse(String proCode, String proType) {
|
||||
Map<String, Object> 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<Map<String, Object>> getEquipmentDetails(String proName) {
|
||||
return maTypeMapper.getEquipmentDetails(proName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -387,7 +361,7 @@ public class ProvinceScreenServiceImpl implements ProvinceScreenService {
|
|||
@Override
|
||||
public List<Map<String, Object>> getUsageStatistics(Integer type) {
|
||||
|
||||
List<Map<String, Object>> res = new ArrayList<>();
|
||||
/* List<Map<String, Object>> res = new ArrayList<>();
|
||||
List<MaType> 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<Map<String, Object>> getUsageStatisticsDetails() {
|
||||
return maTypeMapper.getUsageStatisticsDetails();
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计数量
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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<MaType> selectMaTypeTreeBy5Level(Integer type);
|
||||
|
||||
List<MaType> selectMaTypeTreeBy5Level2(Integer type);
|
||||
|
||||
List<Map<String, Object>> getUsageStatistics(Integer type);
|
||||
|
||||
|
||||
List<Map<String, Object>> getUsageStatisticsDetails();
|
||||
|
||||
List<Map<String, Object>> getEquipmentUse(@Param("proCode") String proCode, @Param("proType") String proType);
|
||||
|
||||
|
||||
List<Map<String, Object>> getEquipmentDetails(String proName);
|
||||
|
||||
Integer getProNum(@Param("proType") String proType);
|
||||
|
||||
Integer getEquipmentNum(@Param("proType") String proType);
|
||||
|
||||
List<Map<String, Object>> getDeptEquipment();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<UseRate> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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> useRate);
|
||||
|
||||
/**
|
||||
* 查询设备信息
|
||||
*
|
||||
* @return 设备信息
|
||||
*/
|
||||
List<UseRate> selectUseRate();
|
||||
}
|
||||
|
|
@ -1369,50 +1369,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<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'
|
||||
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
where mtv.maxTypeId = #{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'
|
||||
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
where mtv.maxTypeId = #{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'
|
||||
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
where mtv.maxTypeId = #{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'
|
||||
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
where mtv.maxTypeId = #{typeId}
|
||||
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 on_company = #{deptId}
|
||||
|
|
@ -1527,10 +1507,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<select id="getTotalEquipmentByLevel" 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
|
||||
where mt2.type_id = #{typeId} and mdi.is_active ='1'
|
||||
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
where mtv.typeId = #{typeId} and mdi.is_active ='1'
|
||||
<if test="changeStatus != null ">
|
||||
AND change_status = #{changeStatus}
|
||||
</if>
|
||||
|
|
@ -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
|
||||
LEFT 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)
|
||||
<if test="typeId != null ">
|
||||
AND mt2.type_id = #{typeId}
|
||||
AND mtv.typeId = #{typeId}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -413,7 +413,9 @@
|
|||
<if test="propertyUnitId != null and propertyUnitId != ''">
|
||||
and sd.dept_id = #{propertyUnitId}
|
||||
</if>
|
||||
|
||||
<if test="entryStatus != null and entryStatus != ''">
|
||||
and mdi.entry_status = #{entryStatus}
|
||||
</if>
|
||||
<if test="manufacturerId != null and manufacturerId != ''">
|
||||
and mdi.brand = #{manufacturerId}
|
||||
</if>
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
d.dept_name,
|
||||
d.order_num,
|
||||
d.leader,
|
||||
d.dept_abbreviation,
|
||||
d.dept_type,
|
||||
d.location,
|
||||
d.dept_abbreviation,
|
||||
d.dept_type,
|
||||
d.location,
|
||||
d.phone,
|
||||
d.status,
|
||||
d.del_flag,
|
||||
|
|
|
|||
|
|
@ -916,62 +916,65 @@
|
|||
SUM(CASE WHEN mtv.maxTypeId = 5474 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的月份)
|
||||
|
||||
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;
|
||||
</select>
|
||||
|
||||
<select id="statByTypeAndAgeByUsageRate" resultType="java.util.Map">
|
||||
SELECT DATE_FORMAT(cdcd.use_time, '%Y/%m') AS month,
|
||||
-- 计算各类型的使用比例(有效使用次数 / 该类型总设备数)
|
||||
SUM(CASE WHEN mtv.maxTypeId = 5080 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END)
|
||||
/ total.cable_total AS cableCount,
|
||||
|
||||
SUM(CASE WHEN mtv.maxTypeId = 5010 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END)
|
||||
/ total.substation_total AS substationCount,
|
||||
|
||||
SUM(CASE WHEN mtv.maxTypeId = 5474 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END)
|
||||
/ total.line_total AS lineCount
|
||||
FROM cs_device_change_details cdcd
|
||||
-- 左连接设备表(过滤有效设备)
|
||||
LEFT JOIN ma_dev_info mdi
|
||||
ON cdcd.dev_id = mdi.ma_id
|
||||
AND mdi.change_status != '4'
|
||||
AND mdi.is_active = '1'
|
||||
-- 左连接类型表(获取设备类型)
|
||||
LEFT JOIN ma_type_view mtv
|
||||
ON mtv.typeId = mdi.type_id
|
||||
-- 一次性计算所有类型的总设备数(复用结果)
|
||||
CROSS JOIN (SELECT
|
||||
-- 计算5080类型的总设备数
|
||||
COUNT(DISTINCT CASE WHEN mtv.maxTypeId = 5080 THEN mdi.ma_id END) AS cable_total,
|
||||
-- 计算5010类型的总设备数
|
||||
COUNT(DISTINCT CASE WHEN mtv.maxTypeId = 5010 THEN mdi.ma_id END) AS substation_total,
|
||||
-- 计算5474类型的总设备数
|
||||
COUNT(DISTINCT CASE WHEN mtv.maxTypeId = 5474 THEN mdi.ma_id END) AS line_total
|
||||
FROM ma_dev_info mdi
|
||||
-- 这里用INNER JOIN更合适(因为需要mtv.maxTypeId匹配)
|
||||
INNER JOIN ma_type_view mtv
|
||||
ON mtv.typeId = mdi.type_id
|
||||
WHERE mdi.change_status != '4'
|
||||
AND mdi.is_active = '1') total
|
||||
-- 过滤条件(确保使用时间有效,且设备存在)
|
||||
WHERE cdcd.use_time IS NOT NULL
|
||||
AND mdi.ma_id IS NOT NULL
|
||||
-- 按月份分组
|
||||
GROUP BY DATE_FORMAT(cdcd.use_time, '%Y/%m'),
|
||||
total.cable_total, -- 子查询结果是常量,分组时带上不影响结果,避免某些数据库报错
|
||||
total.substation_total,
|
||||
total.line_total,
|
||||
cdcd.dev_id
|
||||
ORDER BY month;
|
||||
-- 统计每月各类型设备的平均在用率(优化性能版)
|
||||
SELECT DATE_FORMAT(stat_date, '%Y-%m') AS month,
|
||||
COUNT(stat_date) AS validDays,
|
||||
ROUND(AVG(cable_total), 2) AS cableCount, -- 明确字段含义:5080类型月均在用率
|
||||
ROUND(AVG(substation_total), 2) AS substationCount, -- 5010类型月均在用率
|
||||
ROUND(AVG(line_total), 2) AS lineCount -- 5474类型月均在用率
|
||||
FROM (
|
||||
-- 子查询:按日计算各类型在用率(简化逻辑+减少重复计算)
|
||||
SELECT dt.stat_date,
|
||||
-- 计算5080类型当日在用率(复用总设备数变量)
|
||||
ROUND(
|
||||
IF(dt.total_devs = 0, 0, dt.cable_use / dt.total_devs * 100),
|
||||
2
|
||||
) AS cable_total,
|
||||
-- 计算5010类型当日在用率
|
||||
ROUND(
|
||||
IF(dt.total_devs = 0, 0, dt.substation_use / dt.total_devs * 100),
|
||||
2
|
||||
) AS substation_total,
|
||||
-- 计算5474类型当日在用率
|
||||
ROUND(
|
||||
IF(dt.total_devs = 0, 0, dt.line_use / dt.total_devs * 100),
|
||||
2
|
||||
) AS line_total
|
||||
FROM (
|
||||
-- 子查询2:预计算每日总设备数和各类型在用设备数(减少函数调用)
|
||||
SELECT DATE(mddu.create_time) AS stat_date,
|
||||
COUNT(DISTINCT mddu.ma_id) AS total_devs, -- 当日总设备数(去重)
|
||||
-- 5080类型当日在用设备数(status=1且类型=5080)
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN mddu.status = 1 AND mtv.maxTypeId = 5080
|
||||
THEN mddu.ma_id END) AS cable_use,
|
||||
-- 5010类型当日在用设备数
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN mddu.status = 1 AND mtv.maxTypeId = 5010
|
||||
THEN mddu.ma_id END) AS substation_use,
|
||||
-- 5474类型当日在用设备数
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN mddu.status = 1 AND mtv.maxTypeId = 5474
|
||||
THEN mddu.ma_id END) AS line_use
|
||||
FROM ma_dev_daily_use mddu
|
||||
-- 关联类型表时过滤目标类型,减少关联数据量(核心优化)
|
||||
LEFT JOIN ma_type_view mtv
|
||||
ON mtv.typeId = mddu.type_id
|
||||
AND mtv.maxTypeId IN (5080, 5010, 5474) -- 只关联需要的类型
|
||||
GROUP BY DATE(mddu.create_time)) AS dt -- dt = daily_total(每日统计基础数据)
|
||||
) AS daily_stats
|
||||
GROUP BY DATE_FORMAT(stat_date, '%Y-%m')
|
||||
ORDER BY month DESC; -- 按月份倒序,便于查看最新数据
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -69,7 +69,8 @@
|
|||
from ma_type
|
||||
</sql>
|
||||
|
||||
<insert id="insertType" parameterType="com.bonus.material.ma.vo.MaType" useGeneratedKeys="true" keyProperty="typeId">
|
||||
<insert id="insertType" parameterType="com.bonus.material.ma.vo.MaType" useGeneratedKeys="true"
|
||||
keyProperty="typeId">
|
||||
insert into ma_type
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="typeName != null and typeName != ''">type_name,</if>
|
||||
|
|
@ -211,7 +212,7 @@
|
|||
</delete>
|
||||
|
||||
<select id="selectMaTypeList" parameterType="String" resultMap="MaTypeResult">
|
||||
select DISTINCT m.type_id, m.type_name, m.parent_id, m.storage_num, m.unit_name, m.manage_type,
|
||||
select DISTINCT m.type_id, m.type_name, m.parent_id, m.storage_num, m.unit_name, m.manage_type,
|
||||
m.lease_price,m.eff_time, m.rent_price, m.buy_price, m.pay_price, m.level, m.rated_load, m.test_load,
|
||||
m.holding_time, m.warn_num, mtf.file_name photoName, mtf.file_url photoUrl,
|
||||
mtf2.file_name documentName, mtf2.file_url documentUrl, mtk.user_id keeperUserId,
|
||||
|
|
@ -413,7 +414,7 @@
|
|||
</select>
|
||||
|
||||
<select id="getMaTypeSelect" resultType="com.bonus.material.ma.vo.MaType">
|
||||
select m.type_id, m.type_name, m.parent_id, m.storage_num, m.manage_type,
|
||||
select m.type_id, m.type_name, m.parent_id, m.storage_num, m.manage_type,
|
||||
m.lease_price,m.eff_time, m.rent_price, m.buy_price, m.pay_price, m.level, m.rated_load, m.test_load,
|
||||
m.holding_time, m.warn_num, m.del_flag, m.create_by, m.create_time,
|
||||
m.remark, m.company_id, m.maintenance_alarm_day
|
||||
|
|
@ -424,7 +425,7 @@
|
|||
</select>
|
||||
|
||||
<select id="getListByParentId" resultMap="MaTypeResult">
|
||||
select DISTINCT m.type_id, m.type_name, m.parent_id, m.storage_num, m.unit_name, m.manage_type,
|
||||
select DISTINCT m.type_id, m.type_name, m.parent_id, m.storage_num, m.unit_name, m.manage_type,
|
||||
m.lease_price,m.rent_price, m.eff_time, m.buy_price, m.pay_price, m.level, m.rated_load, m.test_load,
|
||||
m.holding_time, m.warn_num, mtf.file_name photoName, mtf.file_url photoUrl,
|
||||
mtf2.file_name documentName, mtf2.file_url documentUrl, mtk.user_id keeperUserId,
|
||||
|
|
@ -598,18 +599,298 @@
|
|||
</if>
|
||||
</select>
|
||||
<select id="selectMaTypeTreeBy5Level" resultType="com.bonus.material.ma.vo.MaType">
|
||||
select type_id, type_name from ma_type where del_flag = '0' and level = '5'
|
||||
select type_id, type_name
|
||||
from ma_type
|
||||
where del_flag = '0'
|
||||
and level = '5'
|
||||
</select>
|
||||
|
||||
<select id="selectMaTypeTreeBy5Level2" resultType="com.bonus.material.ma.vo.MaType">
|
||||
select
|
||||
mtv.typeId, mtv.devSubcategory as typeName
|
||||
mtv.typeId, mtv.devSubcategory as typeName
|
||||
from
|
||||
ma_type_view mtv
|
||||
ma_type_view mtv
|
||||
<if test="type != null and type != 0">
|
||||
where mtv.maxTypeId = #{type}
|
||||
</if>
|
||||
</select>
|
||||
<select id="getUsageStatistics" resultType="java.util.Map">
|
||||
-- 按装备小类统计:小类在用率 + 近12个月每月出库次数(无记录时显示0)
|
||||
SELECT
|
||||
-- 装备小类ID(兼容两边的小类标识,避免NULL)
|
||||
COALESCE(ur.device_id, oc.device_id) AS name,
|
||||
-- 小类整体在用率(保留2位小数)
|
||||
ur.use_rate_percent AS proportion,
|
||||
-- 近12个月每月出库次数(无记录时默认0)
|
||||
IFNULL(oc.monthly_outbound_count, 0) AS turnoverRate
|
||||
FROM (
|
||||
-- 子查询1:按小类统计在用率
|
||||
SELECT
|
||||
mtv.devSubcategory AS device_id, -- 装备小类(如“电缆小类A”)
|
||||
-- 计算小类的整体在用率:小类内所有设备的在用天数 / 总记录天数
|
||||
ROUND(
|
||||
IF(
|
||||
-- 小类总记录天数(去重所有设备的记录日期)
|
||||
COUNT(DISTINCT DATE(mddu.create_time), mdi.ma_id) = 0, -- 精确到“设备+日期”去重
|
||||
0,
|
||||
-- 小类内所有设备的在用天数(状态=1的“设备+日期”去重计数)
|
||||
COUNT(DISTINCT CASE WHEN mddu.status = 1 THEN CONCAT(mdi.ma_id, DATE(mddu.create_time)) END)
|
||||
/ COUNT(DISTINCT CONCAT(mdi.ma_id, DATE(mddu.create_time))) * 100
|
||||
),
|
||||
2
|
||||
) AS use_rate_percent
|
||||
FROM ma_dev_info mdi
|
||||
-- 关联每日使用记录,获取设备状态
|
||||
LEFT JOIN ma_dev_daily_use mddu ON mddu.ma_id = mdi.ma_id
|
||||
-- 关联类型视图,获取小类(devSubcategory)和大类(maxTypeId=5080)
|
||||
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
WHERE
|
||||
mdi.is_active = '1'
|
||||
AND mdi.change_status != '4'
|
||||
AND mdi.entry_status = '1'
|
||||
<if test="type != null and type != 0">
|
||||
AND mtv.maxTypeId = #{type}
|
||||
</if>
|
||||
GROUP BY mtv.devSubcategory -- 按小类分组
|
||||
) AS ur -- ur = use_rate(小类在用率)
|
||||
-- 关联小类的出库记录统计
|
||||
LEFT JOIN (
|
||||
-- 子查询2:按小类统计近12个月每月出库次数
|
||||
SELECT
|
||||
mtv.devSubcategory AS device_id, -- 装备小类
|
||||
DATE_FORMAT(cdcd.use_time, '%Y-%m') AS stat_year_month, -- 统计年月
|
||||
COUNT(*) AS monthly_outbound_count -- 当月出库次数(小类内所有设备)
|
||||
FROM cs_device_change_details cdcd
|
||||
-- 关联设备信息表,筛选有效设备
|
||||
LEFT JOIN ma_dev_info mdi ON mdi.ma_id = cdcd.dev_id
|
||||
-- 关联类型视图,限定小类和大类
|
||||
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
WHERE
|
||||
cdcd.`use_time` is not null -- 出库状态
|
||||
AND mdi.is_active = '1'
|
||||
AND cdcd.use_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH) -- 近12个月
|
||||
<if test="type != null and type != 0">
|
||||
AND mtv.maxTypeId = #{type}
|
||||
</if>
|
||||
GROUP BY mtv.devSubcategory, DATE_FORMAT(cdcd.use_time, '%Y-%m') -- 按小类+年月分组
|
||||
) AS oc -- oc = outbound_count(小类出库次数)
|
||||
ON ur.device_id = oc.device_id -- 按小类关联
|
||||
-- 排序:先小类,再年月倒序(最新月份在前)
|
||||
ORDER BY
|
||||
proportion DESC
|
||||
LIMIT 5
|
||||
</select>
|
||||
<select id="getUsageStatisticsDetails" resultType="java.util.Map">
|
||||
-- 合并查询:设备在用率 + 近12个月每月出库次数(无出库记录时显示0)
|
||||
SELECT
|
||||
-- 设备ID(兼容两边的设备ID)
|
||||
COALESCE(ur.device_id, oc.device_id) AS deviceId,
|
||||
-- 设备在用率(无数据时可能为0,由子查询已处理)
|
||||
ur.name AS name,
|
||||
ur.use_rate_percent AS proportion,
|
||||
-- 近12个月每月出库次数(无记录时默认0)
|
||||
IFNULL(oc.monthly_outbound_count, 0) AS turnoverRate
|
||||
FROM (
|
||||
-- 子查询1:计算设备在用率
|
||||
SELECT mdi.ma_id AS device_id,
|
||||
mdi.device_name AS name,
|
||||
ROUND(
|
||||
IF(
|
||||
COUNT(DISTINCT DATE(mddu.create_time)) = 0,
|
||||
0,
|
||||
COUNT(DISTINCT CASE WHEN mddu.status = 1 THEN DATE(mddu.create_time) END)
|
||||
/ COUNT(DISTINCT DATE(mddu.create_time)) * 100
|
||||
),
|
||||
2
|
||||
) AS use_rate_percent
|
||||
FROM ma_dev_info mdi
|
||||
LEFT JOIN ma_dev_daily_use mddu ON mddu.ma_id = mdi.ma_id
|
||||
WHERE mdi.is_active = '1'
|
||||
AND mdi.change_status != '4'
|
||||
AND mdi.entry_status = '1'
|
||||
GROUP BY mdi.ma_id) AS ur
|
||||
-- 关联出库记录子查询
|
||||
LEFT JOIN (
|
||||
-- 子查询2:计算近12个月每月出库次数
|
||||
SELECT cdcd.dev_id AS device_id,
|
||||
mdi.device_name AS name,
|
||||
DATE_FORMAT(cdcd.use_time, '%Y-%m') AS stat_year_month,
|
||||
COUNT(*) AS monthly_outbound_count
|
||||
FROM cs_device_change_details cdcd
|
||||
LEFT JOIN ma_dev_info mdi ON mdi.ma_id = cdcd.dev_id
|
||||
WHERE cdcd.`use_time` is not null -- 出库状态
|
||||
AND mdi.is_active = '1'
|
||||
AND mdi.change_status != '4'
|
||||
AND mdi.entry_status = '1'
|
||||
AND cdcd.use_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
|
||||
GROUP BY cdcd.dev_id, DATE_FORMAT(cdcd.use_time, '%Y-%m')) AS oc ON ur.device_id = oc.device_id
|
||||
ORDER BY proportion DESC
|
||||
</select>
|
||||
<select id="getEquipmentUse" resultType="java.util.Map">
|
||||
SELECT
|
||||
-- 工程基础信息
|
||||
jsp.pro_code AS proCode,
|
||||
jsp.pro_name AS projectName,
|
||||
-- 该工程的装备数量(有效设备)
|
||||
COUNT(DISTINCT mdi.ma_id) AS inUser,
|
||||
-- 生成60-100的随机规模值(保留0位小数,整数)
|
||||
FLOOR(RAND() * (100 - 60 + 1) + 60) AS scale,
|
||||
-- 计算:装备数/规模×100(保留2位小数,避免除数为0)
|
||||
ROUND(
|
||||
IF(
|
||||
COUNT(DISTINCT mdi.ma_id) = 0, -- 若装备数为0,结果为0
|
||||
0,
|
||||
COUNT(DISTINCT mdi.ma_id) / FLOOR(RAND() * (100 - 60 + 1) + 60) * 100
|
||||
),
|
||||
2
|
||||
) AS `usage`
|
||||
FROM jj_sing_project jsp
|
||||
-- 左连接设备表:关联“工程编码”(jsp.pro_code)和“设备所属工程”(mdi.on_project)
|
||||
LEFT JOIN ma_dev_info mdi
|
||||
ON mdi.on_project = jsp.pro_code
|
||||
-- 可选:筛选“有效设备”(排除未激活/已报废的设备,根据业务补充)
|
||||
AND mdi.is_active = '1' -- 假设is_active=1代表设备有效
|
||||
AND mdi.change_status IN (2, 3)
|
||||
AND mdi.entry_status = '1'
|
||||
<where>
|
||||
<if test="proCode != null and proCode != ''">
|
||||
AND jsp.pro_code = #{proCode}
|
||||
</if>
|
||||
<if test="proType!= null and proType != ''">
|
||||
AND jsp.project_type = #{proType}
|
||||
</if>
|
||||
</where>
|
||||
|
||||
-- 按工程分组,统计每个工程的设备数量
|
||||
GROUP BY jsp.pro_code, jsp.pro_name -- 按工程编码+名称分组(确保工程唯一)
|
||||
-- 可选:排序(按设备数量倒序,查看设备最多的工程)
|
||||
ORDER BY inUser DESC
|
||||
</select>
|
||||
<select id="getProNum" resultType="java.lang.Integer">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM jj_sing_project jsp
|
||||
<where>
|
||||
<if test="proType!= null and proType != ''">
|
||||
AND jsp.project_type = #{proType}
|
||||
</if>
|
||||
</where>
|
||||
|
||||
</select>
|
||||
<select id="getEquipmentNum" resultType="java.lang.Integer">
|
||||
SELECT
|
||||
COUNT(DISTINCT mdi.ma_id) AS equipmentNum
|
||||
FROM jj_sing_project jsp
|
||||
-- 左连接设备表:关联“工程编码”(jsp.pro_code)和“设备所属工程”(mdi.on_project)
|
||||
LEFT JOIN ma_dev_info mdi
|
||||
ON mdi.on_project = jsp.pro_code
|
||||
-- 可选:筛选“有效设备”(排除未激活/已报废的设备,根据业务补充)
|
||||
AND mdi.is_active = '1' -- 假设is_active=1代表设备有效
|
||||
AND mdi.change_status IN (2, 3)
|
||||
AND mdi.entry_status = '1'
|
||||
<where>
|
||||
<if test="proType!= null and proType != ''">
|
||||
AND jsp.project_type = #{proType}
|
||||
</if>
|
||||
</where>
|
||||
|
||||
</select>
|
||||
<select id="getEquipmentDetails" resultType="java.util.Map">
|
||||
SELECT
|
||||
-- 工程基础信息
|
||||
jsp.pro_code AS proCode,
|
||||
jsp.pro_name AS proName,
|
||||
jsp.voltage AS voltage,
|
||||
jsp.project_type_name AS projectTypeName,
|
||||
-- 该工程的装备数量(有效设备)
|
||||
COUNT(DISTINCT mdi.ma_id) AS inUser,
|
||||
-- 生成60-100的随机规模值(保留0位小数,整数)
|
||||
FLOOR(RAND() * (100 - 60 + 1) + 60) AS scale,
|
||||
-- 计算:装备数/规模×100(保留2位小数,避免除数为0)
|
||||
ROUND(
|
||||
IF(
|
||||
COUNT(DISTINCT mdi.ma_id) = 0, -- 若装备数为0,结果为0
|
||||
0,
|
||||
COUNT(DISTINCT mdi.ma_id) / FLOOR(RAND() * (100 - 60 + 1) + 60) * 100
|
||||
),
|
||||
2
|
||||
) AS `usage`
|
||||
FROM jj_sing_project jsp
|
||||
-- 左连接设备表:关联“工程编码”(jsp.pro_code)和“设备所属工程”(mdi.on_project)
|
||||
LEFT JOIN ma_dev_info mdi
|
||||
ON mdi.on_project = jsp.pro_code
|
||||
-- 可选:筛选“有效设备”(排除未激活/已报废的设备,根据业务补充)
|
||||
AND mdi.is_active = '1' -- 假设is_active=1代表设备有效
|
||||
AND mdi.change_status IN (2, 3)
|
||||
AND mdi.entry_status = '1'
|
||||
<where>
|
||||
<if test="proName != null and proName != ''">
|
||||
AND jsp.pro_name like concat('%', #{proName}, '%')
|
||||
</if>
|
||||
</where>
|
||||
|
||||
-- 按工程分组,统计每个工程的设备数量
|
||||
GROUP BY jsp.pro_code, jsp.pro_name -- 按工程编码+名称分组(确保工程唯一)
|
||||
-- 可选:排序(按设备数量倒序,查看设备最多的工程)
|
||||
ORDER BY inUser DESC
|
||||
</select>
|
||||
<select id="getDeptEquipment">
|
||||
-- 按单位统计:设备在用率 + 近12个月每月出库次数(含无数据单位,MySQL 5 兼容版)
|
||||
SELECT
|
||||
-- 单位唯一标识(取自sys_dept全量单位,确保无数据单位也显示)
|
||||
sd_all.dept_id AS deptId,
|
||||
-- 单位名称(sys_dept表中字段为dept_name)
|
||||
sd_all.dept_name AS name,
|
||||
-- 单位设备在用率(无数据时显示0)
|
||||
IFNULL(ur.use_rate_percent, 0) AS proportion,
|
||||
-- 近12个月每月出库次数(无记录时显示0)
|
||||
IFNULL(oc.monthly_outbound_count, 0) AS turnoverRate
|
||||
FROM
|
||||
-- 核心:先获取sys_dept表中所有单位(确保无数据单位不丢失)
|
||||
sys_dept sd_all
|
||||
-- 左连接“在用率统计结果”:全量单位关联在用率数据,无数据则为NULL
|
||||
LEFT JOIN (
|
||||
-- 子查询1:按单位统计设备在用率(MySQL 5 多字段去重兼容)
|
||||
SELECT sd.dept_id,
|
||||
ROUND(
|
||||
IF(
|
||||
-- 用CONCAT解决MySQL 5 不支持多字段DISTINCT的问题
|
||||
COUNT(DISTINCT CONCAT(mdi.ma_id, '_', DATE(mddu.create_time))) = 0,
|
||||
0,
|
||||
-- 单位内在用天数 ÷ 单位总记录天数 × 100%
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN mddu.`status` = 1
|
||||
THEN CONCAT(mdi.ma_id, '_', DATE(mddu.create_time)) END)
|
||||
/ COUNT(DISTINCT CONCAT(mdi.ma_id, '_', DATE(mddu.create_time))) * 100
|
||||
),
|
||||
2
|
||||
) AS use_rate_percent
|
||||
FROM ma_dev_info mdi
|
||||
LEFT JOIN ma_dev_daily_use mddu ON mddu.ma_id = mdi.ma_id
|
||||
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
|
||||
WHERE mdi.is_active = '1'
|
||||
AND mdi.change_status != '4'
|
||||
AND mdi.entry_status = '1'
|
||||
GROUP BY sd.dept_id) AS ur ON sd_all.dept_id = ur.dept_id
|
||||
|
||||
-- 左连接“出库次数统计结果”:全量单位关联出库数据,无数据则为NULL
|
||||
LEFT JOIN (
|
||||
-- 子查询2:按单位统计近12个月每月出库次数
|
||||
SELECT sd.dept_id,
|
||||
DATE_FORMAT(cdcd.use_time, '%Y-%m') AS stat_year_month,
|
||||
COUNT(*) AS monthly_outbound_count
|
||||
FROM cs_device_change_details cdcd
|
||||
INNER JOIN ma_dev_info mdi
|
||||
ON mdi.ma_id = cdcd.dev_id
|
||||
AND mdi.is_active = '1'
|
||||
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
|
||||
WHERE cdcd.`status` = 2 -- 出库状态(按实际业务调整)
|
||||
AND cdcd.use_time IS NOT NULL
|
||||
AND cdcd.use_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
|
||||
GROUP BY sd.dept_id, DATE_FORMAT(cdcd.use_time, '%Y-%m')) AS oc ON sd_all.dept_id = oc.dept_id
|
||||
-- 可选:按单位ID排序,确保结果顺序稳定
|
||||
ORDER BY proportion DESC
|
||||
</select>
|
||||
|
||||
<delete id="deleteMaTypePropertyNames">
|
||||
delete
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?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.task.mapper.UseRateMapper">
|
||||
|
||||
<insert id="insertUseRate">
|
||||
INSERT INTO ma_dev_daily_use (
|
||||
ma_id,
|
||||
status,
|
||||
type_id,
|
||||
create_time
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(
|
||||
#{item.maId},
|
||||
#{item.status},
|
||||
#{item.typeId},
|
||||
NOW()
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
<select id="selectUseRate" resultType="com.bonus.material.task.domain.UseRate">
|
||||
SELECT ma_id AS maId,
|
||||
type_id AS typeId,
|
||||
CASE
|
||||
WHEN change_status IN (2, 3) THEN 1 -- 等于2或3时返回1
|
||||
ELSE 0 -- 不等于2或3时返回0
|
||||
END AS status
|
||||
FROM ma_dev_info
|
||||
WHERE is_active = '1'
|
||||
and entry_status = '1'
|
||||
and change_status != '4'
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue