73d00fac sonin

出库统计分析 物料/设备

1 个父辈 805c4dc5
......@@ -21,37 +21,28 @@ public class BusinessServiceImpl implements IBusinessService {
@Autowired
private IBaseService baseService;
/**
* table0 => (key0, value0)
*/
private static final Map<String, String[]> DICT_MAP = new HashMap<String, String[]>() {{
put("equipment_info", new String[]{"id", "equipment_name"});
put("sys_user", new String[]{"id", "realname"});
put("sys_struct_dict", new String[]{"id", "struct_name"});
put("equipment_category", new String[]{"id", "des"});
put("evaluate_score_desc", new String[]{"id", "score_desc"});
put("carbon_qualitative_desc", new String[]{"id", "qualitative_desc"});
put("sys_depart", new String[]{"id", "depart_name"});
put("equipment_sparepart_type", new String[]{"id", "item_text"});
}};
@Override
public Map<String, String> dictMap(String dictCode, Collection<?> inCol) {
String key0, value0, table0;
QueryWrapper<?> queryWrapper0 = new QueryWrapper<>();
if ("equipment_info".equals(dictCode)) {
key0 = "id";
value0 = "equipment_name";
table0 = dictCode;
} else if ("sys_user".equals(dictCode)) {
key0 = "id";
value0 = "realname";
table0 = dictCode;
} else if ("sys_struct_dict".equals(dictCode)) {
key0 = "id";
value0 = "struct_name";
table0 = dictCode;
} else if ("equipment_category".equals(dictCode)) {
key0 = "id";
value0 = "des";
table0 = dictCode;
} else if ("evaluate_score_desc".equals(dictCode)) {
key0 = "id";
value0 = "score_desc";
table0 = dictCode;
} else if ("carbon_qualitative_desc".equals(dictCode)) {
key0 = "id";
value0 = "qualitative_desc";
table0 = dictCode;
} else if ("sys_depart".equals(dictCode)) {
key0 = "id";
value0 = "depart_name";
if (DICT_MAP.containsKey(dictCode)) {
String[] dictArray = DICT_MAP.get(dictCode);
key0 = dictArray[0];
value0 = dictArray[1];
table0 = dictCode;
} else {
// 数据字典查询
......@@ -72,5 +63,4 @@ public class BusinessServiceImpl implements IBusinessService {
return dictMap;
}
}
......
......@@ -159,10 +159,16 @@ public class EquipmentOutController {
EquipmentOut equipmentOut = BeanExtUtils.bean2Bean(equipmentOutDTO, EquipmentOut.class);
QueryWrapper<EquipmentOut> queryWrapper = QueryGenerator.initQueryWrapper(equipmentOut, req.getParameterMap());
if (StringUtils.isNotEmpty(equipmentOutDTO.getStartTime())) {
queryWrapper.ge("out_date", equipmentOutDTO.getStartTime() + " 00:00:00");
if (equipmentOutDTO.getStartTime().length() == 10) {
equipmentOutDTO.setStartTime(equipmentOutDTO.getStartTime() + " 00:00:00");
}
queryWrapper.ge("out_date", equipmentOutDTO.getStartTime());
}
if (StringUtils.isNotEmpty(equipmentOutDTO.getEndTime())) {
queryWrapper.le("out_date", equipmentOutDTO.getEndTime() + " 23:59:59");
if (equipmentOutDTO.getEndTime().length() == 10) {
equipmentOutDTO.setEndTime(equipmentOutDTO.getEndTime() + " 23:59:59");
}
queryWrapper.le("out_date", equipmentOutDTO.getEndTime());
}
if (StringUtils.isNotEmpty(equipmentOutDTO.getSparepartId())) {
String sparepartId = equipmentOutDTO.getSparepartId();
......
package com.skua.modules.equipment.controller;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.aop.annotation.CustomExceptionAnno;
import com.skua.common.constant.BusinessConstant;
import com.skua.core.api.vo.Result;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.base.service.IBaseService;
import com.skua.modules.biz.IBusinessService;
import com.skua.modules.equipment.entity.EquipmentInfo;
import com.skua.modules.equipment.entity.EquipmentSparepart;
import com.skua.modules.equipment.service.IEquipmentInfoService;
import com.skua.modules.equipment.service.IEquipmentSparepartService;
import com.skua.tool.dfs.MapDFS;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author:sonin
* @Date:2025/4/21 14:07
*/
@Slf4j
@Api(tags = "设备统计")
@RestController
@RequestMapping("/equipmentStatistic")
public class EquipmentStatisticController {
@Autowired
private IBaseService baseService;
@Autowired
private IBusinessService businessService;
@Autowired
private IEquipmentSparepartService equipmentSparepartService;
@Autowired
private IEquipmentInfoService equipmentInfoService;
@GetMapping("/sparepartOut")
@CustomExceptionAnno(description = "物料-出库统计")
public Result<Object> sparepartOutCtrl(@RequestParam Map<String, Object> paramMap) {
// 请求参数
String sparepartType = ConvertUtils.getString(paramMap.get("sparepartType"));
String departId = ConvertUtils.getString(paramMap.get("departId"));
String sparepartName = ConvertUtils.getString(paramMap.get("sparepartName"));
String sparepartCode = ConvertUtils.getString(paramMap.get("sparepartCode"));
String startTime = ConvertUtils.getString(paramMap.get("startTime"));
String endTime = ConvertUtils.getString(paramMap.get("endTime"));
Integer pageNo = Integer.parseInt(ConvertUtils.getString(paramMap.getOrDefault("pageNo", "1")));
Integer pageSize = Integer.parseInt(ConvertUtils.getString(paramMap.getOrDefault("pageSize", "10")));
// 查询条件
Set<String> sparepartTypeSet = new HashSet<>();
if (StringUtils.isNotEmpty(sparepartType)) {
MapDFS mapDFS = new MapDFS();
List<Map<String, Object>> tree = mapDFS.buildTree(baseService.queryForList("select id, parent_id as parentId from equipment_sparepart_type", new QueryWrapper<>()));
LinkedList<LinkedList<Map<String, Object>>> routeList = mapDFS.getRouteList(tree);
for (LinkedList<Map<String, Object>> route : routeList) {
for (int i = 0; i < route.size(); i++) {
if (sparepartType.equals(route.get(i).get("id"))) {
for (int j = i; j < route.size(); j++) {
sparepartTypeSet.add(ConvertUtils.getString(route.get(j).get("id")));
}
}
}
}
}
Set<String> departIdSet = new HashSet<>();
if (StringUtils.isNotEmpty(departId)) {
MapDFS mapDFS = new MapDFS();
List<Map<String, Object>> tree = mapDFS.buildTree(baseService.queryForList("select id, parent_id as parentId from sys_depart", new QueryWrapper<>()));
LinkedList<LinkedList<Map<String, Object>>> routeList = mapDFS.getRouteList(tree);
for (LinkedList<Map<String, Object>> route : routeList) {
for (int i = 0; i < route.size(); i++) {
if (departId.equals(route.get(i).get("id"))) {
for (int j = i; j < route.size(); j++) {
departIdSet.add(ConvertUtils.getString(route.get(j).get("id")));
}
}
}
}
}
// 查询
QueryWrapper<EquipmentSparepart> queryWrapper0 = new QueryWrapper<>();
queryWrapper0.in(!sparepartTypeSet.isEmpty(), "sparepart_type", sparepartTypeSet)
.in(!departIdSet.isEmpty(), "depart_id", departIdSet)
.like(StringUtils.isNotEmpty(sparepartName), "sparepart_name", sparepartName)
.like(StringUtils.isNotEmpty(sparepartCode), "sparepart_code", sparepartCode);
// 备件查询信息
String inSql = "select distinct equipment_out_child.sparepart_id from equipment_out inner join equipment_out_child on equipment_out.id = equipment_out_child.out_id where 1=1";
if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
inSql += " and out_date >= '" + startTime + "' and out_date <= '" + endTime + "'";
if (!departIdSet.isEmpty()) {
List<String> departId2Set = departIdSet.stream().map(item -> "'" + item + "'").collect(Collectors.toList());
inSql += " and equipment_out.depart_id in (" + String.join(",", departId2Set) + ")";
}
}
queryWrapper0.inSql("supplies_id", inSql);
IPage<EquipmentSparepart> equipmentSparepartPage = equipmentSparepartService.page(new Page<>(pageNo, pageSize), queryWrapper0);
// 翻译
Map<String, String> sysDepartDictMap = businessService.dictMap("sys_depart", null);
Map<String, String> equipmentSparepartTypeDictMap = businessService.dictMap("equipment_sparepart_type", null);
// 封装结果集
Page<Map<String, Object>> mapPage = new Page<>(pageNo, pageSize);
mapPage.setTotal(equipmentSparepartPage.getTotal());
Set<String> sparepartIdSet = new HashSet<>();
mapPage.setRecords(equipmentSparepartPage.getRecords().stream().map(item -> {
sparepartIdSet.add(ConvertUtils.getString(item.getId()));
Map<String, Object> entityMap = BeanUtil.beanToMap(item, false, true);
entityMap.put("departName", sysDepartDictMap.get(item.getDepartId()));
entityMap.put("sparepartType_dictText", equipmentSparepartTypeDictMap.get(item.getSparepartType()));
entityMap.put("outNum", "0");
return entityMap;
}).collect(Collectors.toList()));
// 获取 物料出库 数量
if (!sparepartIdSet.isEmpty()) {
QueryWrapper<?> queryWrapper1 = new QueryWrapper<>();
if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
queryWrapper1.ge("out_date", startTime)
.le("out_date", endTime);
}
queryWrapper1.in(!departIdSet.isEmpty(), "equipment_out.depart_id", departIdSet);
queryWrapper1.groupBy("sparepart_id")
.in("sparepart_id", sparepartIdSet);
List<Map<String, Object>> queryMapList1 = baseService.queryForList("select equipment_out_child.sparepart_id as key0, sum(equipment_out_child.out_num) as value0 from equipment_out inner join equipment_out_child on equipment_out.id = equipment_out_child.out_id", queryWrapper1);
Map<String, String> outNumDictMap = queryMapList1.stream().collect(Collectors.toMap(item -> ConvertUtils.getString(item.get("key0")), item -> ConvertUtils.getString(item.get("value0"))));
mapPage.getRecords().forEach(item -> item.put("outNum", outNumDictMap.getOrDefault(ConvertUtils.getString(item.get("id")), "0")));
}
return Result.ok(mapPage);
}
/**
* 出库存的是suppliesId,维修存的是sparepartId
*
* @param paramMap
* @return
*/
@GetMapping("/sparepartOutDetail")
@CustomExceptionAnno(description = "物料-出库详情")
public Result<Object> sparepartOutDetailCtrl(@RequestParam Map<String, Object> paramMap) {
// 请求参数
String suppliesId = ConvertUtils.getString(paramMap.get("suppliesId"));
String startTime = ConvertUtils.getString(paramMap.get("startTime"));
String endTime = ConvertUtils.getString(paramMap.get("endTime"));
Integer pageNo = Integer.parseInt(ConvertUtils.getString(paramMap.getOrDefault("pageNo", "1")));
Integer pageSize = Integer.parseInt(ConvertUtils.getString(paramMap.getOrDefault("pageSize", "10")));
// 查询条件
QueryWrapper<?> queryWrapper0 = new QueryWrapper<>();
queryWrapper0.ge(StringUtils.isNotEmpty(startTime), "equipment_out.out_date", startTime)
.le(StringUtils.isNotEmpty(endTime), "equipment_out.out_date", endTime);
if (StringUtils.isNotEmpty(suppliesId)) {
queryWrapper0.in("equipment_out_child.sparepart_id", Arrays.asList(suppliesId.split(",")));
}
// 排序
queryWrapper0.orderByDesc("equipment_out_child.sparepart_id", "equipment_out.out_date");
// 翻译
Map<String, String> sysDepartDictMap = businessService.dictMap("sys_depart", null);
Map<String, String> ckTypeDictMap = businessService.dictMap("ckType", null);
// 查询字段
List<String> columnList = new ArrayList<String>() {{
add("equipment_out_child.sparepart_id as suppliesId");
add("equipment_sparepart.sparepart_name as sparepartName");
add("equipment_out.depart_id as departId");
add("equipment_out.out_type as outType");
add("equipment_out.out_order as outOrder");
add("equipment_out.out_date as outDate");
add("equipment_sparepart.measuring_unit as measuringUnit");
add("equipment_out_child.out_num as outNum");
add("equipment_out_child.use_position as usePosition");
add("equipment_out.id as outId");
}};
IPage<Map<String, Object>> mapPage = baseService.queryForPage(new Page<>(pageNo, pageSize), "select " + String.join(",", columnList) + " from equipment_out_child left join equipment_out on equipment_out_child.out_id = equipment_out.id left join equipment_sparepart on equipment_out_child.sparepart_id = equipment_sparepart.supplies_id", queryWrapper0);
mapPage.getRecords().forEach(item -> {
item.put("departName", sysDepartDictMap.get(item.get("departId")));
item.put("outType" + BusinessConstant.dictText, ckTypeDictMap.get(item.get("outType")));
});
return Result.ok(mapPage);
}
@GetMapping("/equipmentOut")
@CustomExceptionAnno(description = "设备-出库统计")
public Result<Object> equipmentOutCtrl(@RequestParam Map<String, Object> paramMap) {
// 请求参数
String departId = ConvertUtils.getString(paramMap.get(""));
String equipmentType = ConvertUtils.getString(paramMap.get("equipmentType"));
String equipmentName = ConvertUtils.getString(paramMap.get("equipmentName"));
String equipmentLevel = ConvertUtils.getString(paramMap.get("equipmentLevel"));
String startTime = ConvertUtils.getString(paramMap.get("startTime"));
String endTime = ConvertUtils.getString(paramMap.get("endTime"));
Integer pageNo = Integer.parseInt(ConvertUtils.getString(paramMap.getOrDefault("pageNo", "1")));
Integer pageSize = Integer.parseInt(ConvertUtils.getString(paramMap.getOrDefault("pageSize", "10")));
String energyLevel = ConvertUtils.getString(paramMap.get("energyLevel"));
String structures = ConvertUtils.getString(paramMap.get("structures"));
// 查询条件
Set<String> departIdSet = new HashSet<>();
if (StringUtils.isNotEmpty(departId)) {
MapDFS mapDFS = new MapDFS();
List<Map<String, Object>> tree = mapDFS.buildTree(baseService.queryForList("select id, parent_id as parentId from sys_depart", new QueryWrapper<>()));
LinkedList<LinkedList<Map<String, Object>>> routeList = mapDFS.getRouteList(tree);
for (LinkedList<Map<String, Object>> route : routeList) {
for (int i = 0; i < route.size(); i++) {
if (departId.equals(route.get(i).get("id"))) {
for (int j = i; j < route.size(); j++) {
departIdSet.add(ConvertUtils.getString(route.get(j).get("id")));
}
}
}
}
}
// 查询
QueryWrapper<EquipmentInfo> queryWrapper0 = new QueryWrapper<>();
queryWrapper0.in(!departIdSet.isEmpty(), "depart_id", departIdSet)
.like(StringUtils.isNotEmpty(equipmentType), "equipment_type_tree_path", equipmentType)
.like(StringUtils.isNotEmpty(equipmentName), "equipment_name", equipmentName)
.eq(StringUtils.isNotEmpty(equipmentLevel), "equipment_level", equipmentLevel)
.eq(StringUtils.isNotEmpty(energyLevel), "energy_level", energyLevel)
.eq(StringUtils.isNotEmpty(structures), "structures", structures);
// 备件数量需要>0
String sql0 = "select distinct equipment_repair.info_id from equipment_repair inner join equipment_repair_child on equipment_repair.id = equipment_repair_child.repair_id where equipment_repair_child.nums > 0";
// 出库时间范围
String inSql = "select equipment_sparepart.id from equipment_out_child left join equipment_out on equipment_out.id = equipment_out_child.out_id left join equipment_sparepart on equipment_sparepart.supplies_id = equipment_out_child.sparepart_id where 1=1";
if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
inSql += " and out_date >= '" + startTime + "' and out_date <= '" + endTime + "'";
if (!departIdSet.isEmpty()) {
List<String> departId2Set = departIdSet.stream().map(item -> "'" + item + "'").collect(Collectors.toList());
inSql += " and equipment_out.depart_id in (" + String.join(",", departId2Set) + ")";
}
sql0 += " and equipment_repair_child.sparepart_id in (" + inSql + ")";
}
// 备件数量需要>0
queryWrapper0.inSql("id", sql0);
IPage<EquipmentInfo> equipmentInfoIPage = equipmentInfoService.page(new Page<>(pageNo, pageSize), queryWrapper0);
// 翻译
Map<String, String> sysDepartDictMap = businessService.dictMap("sys_depart", null);
Map<String, String> equipmentCategoryDictMap = businessService.dictMap("equipment_category", null);
Map<String, String> equipmentStatusDictMap = businessService.dictMap("equipment-equipment_status", null);
Map<String, String> sparepartTypeDictMap = businessService.dictMap("equipment_sparepart_type", null);
// 封装结果集
Page<Map<String, Object>> mapPage = new Page<>(pageNo, pageSize);
mapPage.setTotal(equipmentInfoIPage.getTotal());
Set<String> equipmentInfoIdSet = new HashSet<>();
mapPage.setRecords(equipmentInfoIPage.getRecords().stream().map(item -> {
equipmentInfoIdSet.add(item.getId());
Map<String, Object> entityMap = BeanUtil.beanToMap(item, false, true);
entityMap.put("departName", sysDepartDictMap.get(item.getDepartId()));
entityMap.put("equipmentType_dictText", equipmentCategoryDictMap.get(item.getEquipmentType()));
entityMap.put("equipmentStatus_dictText", equipmentStatusDictMap.get(item.getEquipmentStatus()));
entityMap.put("outNum", "0");
entityMap.put("sparepartList", new ArrayList<>());
return entityMap;
}).collect(Collectors.toList()));
// 如果设备非空
if (!equipmentInfoIdSet.isEmpty()) {
QueryWrapper<?> queryWrapper1 = new QueryWrapper<>();
queryWrapper1.in("info_id", equipmentInfoIdSet)
.inSql("equipment_repair_child.sparepart_id", inSql);
List<String> columnList = new ArrayList<String>() {{
add("equipment_repair.info_id");
add("equipment_repair_child.sparepart_id");
add("equipment_repair_child.nums");
}};
List<Map<String, Object>> queryMapList1 = baseService.queryForList("select " + String.join(",", columnList) + " from equipment_repair inner join equipment_repair_child on equipment_repair.id = equipment_repair_child.repair_id", queryWrapper1);
Map<String, List<Map<String, Object>>> infoId2SparepartListMap = new HashMap<>();
Map<String, Double> infoId2NumsMap = new HashMap<>();
Set<String> sparepartIdSet = new HashSet<>();
for (Map<String, Object> item : queryMapList1) {
String infoId = ConvertUtils.getString(item.get("info_id"));
String sparepartId = ConvertUtils.getString(item.get("sparepart_id"));
Double nums = ConvertUtils.getDouble(item.get("nums"), 0D);
infoId2NumsMap.put(infoId, nums + infoId2NumsMap.getOrDefault(infoId, 0D));
infoId2SparepartListMap.putIfAbsent(infoId, new ArrayList<>());
infoId2SparepartListMap.get(infoId).add(new HashMap<String, Object>(2) {{
put("sparepartId", sparepartId);
put("nums", nums);
}});
sparepartIdSet.add(sparepartId);
}
List<EquipmentSparepart> equipmentSparepartList = equipmentSparepartService.list(new QueryWrapper<EquipmentSparepart>().in("id", sparepartIdSet));
Map<String, EquipmentSparepart> sparepartId2EntityMap = equipmentSparepartList.stream().collect(Collectors.toMap(EquipmentSparepart::getId, item -> item));
mapPage.getRecords().forEach(item -> {
String infoId = ConvertUtils.getString(item.get("id"));
item.put("outNum", infoId2NumsMap.getOrDefault(infoId, 0D));
List<Map<String, Object>> sparepartList = infoId2SparepartListMap.getOrDefault(infoId, new ArrayList<>());
for (Map<String, Object> sparepartItem : sparepartList) {
String sparepartId = ConvertUtils.getString(sparepartItem.get("sparepartId"));
EquipmentSparepart equipmentSparepart = sparepartId2EntityMap.get(sparepartId);
if (equipmentSparepart != null) {
sparepartItem.put("suppliesId", equipmentSparepart.getSuppliesId());
sparepartItem.put("sparepartName", equipmentSparepart.getSparepartName());
sparepartItem.put("sparepartType", equipmentSparepart.getSparepartType());
sparepartItem.put("sparepartType" + BusinessConstant.dictText, sparepartTypeDictMap.get(equipmentSparepart.getSparepartType()));
sparepartItem.put("measuringUnit", equipmentSparepart.getMeasuringUnit());
}
}
item.put("sparepartList", sparepartList);
});
}
return Result.ok(mapPage);
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!