6a45629d 张雷

Merge remote-tracking branch 'origin/master' into master

2 个父辈 f2f342b3 10293212
正在显示 16 个修改的文件 包含 444 行增加29 行删除
package com.skua.tool.util;
import com.skua.common.constant.BusinessConstant;
import java.util.ArrayList;
import java.util.List;
/**
* 请求参数工具类
*
* @Author:sonin
* @Date:2025/3/6 15:05
*/
public class ParamUtils {
public static List<String> timeRangeParamFunc(String startTime, String endTime, String timeType) {
List<String> timeList = new ArrayList<>(), intervalTimeList;
if ("day".equalsIgnoreCase(timeType)) {
intervalTimeList = DateUtils.intervalByDay(startTime, endTime, BusinessConstant.dateFormat.substring(0, 10));
for (String intervalTime : intervalTimeList) {
timeList.add(intervalTime + BusinessConstant.startTimeSuffix + "~" + intervalTime + BusinessConstant.endTimeSuffix);
}
} else if ("month".equalsIgnoreCase(timeType)) {
intervalTimeList = DateUtils.intervalByMonth(startTime, endTime, BusinessConstant.dateFormat.substring(0, 7));
for (String intervalTime : intervalTimeList) {
String tmpStartTime = intervalTime + "-01" + BusinessConstant.startTimeSuffix;
int days = DateUtils.lengthOfSomeMonth(Integer.parseInt(intervalTime.split("-")[0]), Integer.parseInt(intervalTime.split("-")[1]));
String tmpEndTime = intervalTime + "-" + days + BusinessConstant.endTimeSuffix;
timeList.add(tmpStartTime + "~" + tmpEndTime);
}
} else if ("year".equalsIgnoreCase(timeType)) {
intervalTimeList = DateUtils.intervalByYear(startTime, endTime, BusinessConstant.dateFormat.substring(0, 4));
for (String intervalTime : intervalTimeList) {
String tmpStartTime = intervalTime + "-01-01" + BusinessConstant.startTimeSuffix;
String tmpEndTime = intervalTime + "-12-31" + BusinessConstant.endTimeSuffix;
timeList.add(tmpStartTime + "~" + tmpEndTime);
}
}
return timeList;
}
}
......@@ -89,7 +89,8 @@ public class CommandCentreServiceImpl implements ICommandCentreService {
sql += " left join sys_factory_info fi on fi.depart_id = aaa.depart_id";
sql += " left join sys_depart d on d.id = aaa.depart_id";
sql += " order by aaa.CSL desc ";*/
String sql = " select d.depart_name , bbb.* , f.pro_scale *10000 'pro_scale', ROUND( 100 * bbb.CSL/( f.pro_scale *10000 ) , 2 ) AS fhl from ( ";
int days = DateUtils.lengthOfSomeMonth(Integer.parseInt(startDate.split("-")[0]), Integer.parseInt(startDate.split("-")[1]));
String sql = " select d.depart_name , bbb.* , f.pro_scale *10000 'pro_scale', ROUND( 100 * bbb.CSL/( f.pro_scale *10000 *"+days+") , 2 ) AS fhl from ( ";
sql += " select sum(aaa.CSL) CSL, avg(aaa.CSL) dayCsl ,aaa.depart_id from "+dataViewName2119+ " aaa group by aaa.depart_id";
sql += " ) bbb LEFT JOIN sys_factory_info f ON f.depart_id = bbb.depart_id ";
sql += " left join sys_depart d on d.id = bbb.depart_id ";
......
......@@ -426,7 +426,6 @@ public class MaterialINController {
// queryWrapper.orderByDesc("arrive_time");
Page<MaterialINVO> page = new Page<MaterialINVO>(1, 10000);
if(StringUtils.isNotEmpty(request.getParameter("arriveTime_begin"))){
materialINVO.setStartTime( request.getParameter("arriveTime_begin") );
}
......@@ -438,11 +437,10 @@ public class MaterialINController {
}
materialINVO.setAuditStatus("3");
IPage<MaterialINVO> pageList = materialINService.arrivalRecordList(page, materialINVO);
List<MaterialINVO> materialINList = materialINService.arrivalRecordList2(materialINVO);
//Step.2 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
List<MaterialINVO> materialINList = pageList.getRecords();
List<MaterialINArrivalRecordVO> dataList = new ArrayList<>();
MaterialINArrivalRecordVO arrivalRecordVO = null;
......
......@@ -32,6 +32,8 @@ public interface MaterialINMapper extends BaseMapper<MaterialIN> {
List<MaterialIN> selectAuditMaterialINByPage(IPage<MaterialIN> page, @Param("materialIN") MaterialIN materialIN);
@Anonymous
List<MaterialINVO> arrivalRecordList(Page<MaterialINVO> page, @Param("param")MaterialINVO materialINVO);
List<MaterialINVO> arrivalRecordList2(@Param("param")MaterialINVO materialINVO);
@Anonymous
MaterialINVO queryById(@Param("id") String id);
......
......@@ -119,6 +119,47 @@
</if>
order by t.arrive_time desc
</select>
<select id="arrivalRecordList2" resultType="com.skua.modules.erp.vo.MaterialINVO">
select d.depart_name 'departName', ss.sparepart_code, st.item_text as 'sparepart_type_name',sm.supp_name as 'supplier_name',ss.sparepart_name, ss.specification,ss.measuring_unit,
pm.unit_price 'purchasePrice',
round(pm.unit_price * t.material_num,2) 'purchaseTotalPrice', round(dm.distribut_price * t.material_num,2) 'distributTotalPrice' ,round(dm.distribut_price * t.material_num ,2)'total_price',
dm.tax_amount,dm.distribut_price,t.distribut_material_id,t.sparepart_type,t.in_warehouse_id,
t.id,t.depart_id,t.project_name,t.in_order,t.purchase_contract_id,t.purchase_contract_code,t.distribut_contract_id,t.distribut_contract_code,t.arrive_time,t.receiver,t.sparepart_id,t.material_num,t.supplier_id,t.good_code,t.share_url,t.confirm_status,t.audit_status,t.approve_message,t.in_type
from erp_material_in t
left join sys_depart d on t.depart_id = d.id
left join erp_purchase_material pm on pm.good_code = t.good_code
left join equipment_sparepart_supplies ss on t.sparepart_id = ss.id
left join equipment_sparepart_type st on st.id = t.sparepart_type
left join ajh_supplier_manage sm on sm.id = t.supplier_id
left join erp_distribut_material dm on (dm.contract_id = t.distribut_contract_id and dm.good_code = t.good_code)
where t.audit_status = #{param.auditStatus}
<if test="param.departIds != null and param.departIds != ''">
and t.depart_id in(${param.departIds})
</if>
<if test="param.departId != null and param.departId != ''">
and t.depart_id = #{param.departId}
</if>
<if test="param.goodCode != null and param.goodCode != ''">
AND t.good_code like concat('%', #{param.goodCode}, '%')
</if>
<if test="param.startTime != null and param.startTime !='' ">
and t.arrive_time &gt;= #{param.startTime}
</if>
<if test="param.endTime != null and param.endTime != '' ">
and t.arrive_time &lt;= #{param.endTime}
</if>
<if test="param.supplierId != null and param.supplierId != ''">
and t.supplier_id = #{param.supplierId}
</if>
<if test="param.sparepartName != null and param.sparepartName != ''">
and ss.sparepart_name like concat('%', #{param.sparepartName}, '%')
</if>
order by t.arrive_time desc
</select>
<!-- 批量送审-->
<update id="batchSendAudit" >
update erp_material_in set audit_status = #{auditStatus} where id in (${ids}) and audit_status = '0'
......
......@@ -37,6 +37,8 @@ public interface IMaterialINService extends IService<MaterialIN> {
public IPage<MaterialIN> selectAuditMaterialINByPage(IPage<MaterialIN> page, MaterialIN materialIN) ;
IPage<MaterialINVO> arrivalRecordList(Page<MaterialINVO> page, MaterialINVO materialINVO);
List<MaterialINVO> arrivalRecordList2(MaterialINVO materialINVO);
/***
* 药剂入库
* @param materialINVO
......
......@@ -246,6 +246,10 @@ public class MaterialINServiceImpl extends ServiceImpl<MaterialINMapper, Materia
public IPage<MaterialINVO> arrivalRecordList(Page<MaterialINVO> page, MaterialINVO materialINVO){
return page.setRecords(baseMapper.arrivalRecordList(page, materialINVO));
}
public List<MaterialINVO> arrivalRecordList2(MaterialINVO materialINVO){
return baseMapper.arrivalRecordList2(materialINVO);
}
/***
* 药剂入库
* @param materialINVO
......
......@@ -307,9 +307,9 @@ public class WorkAnalysisController {
sql += " left join ( select t.depart_id , count(1) 'count' from equipment_maintain_task t where t.results_enforcement = '2' and t.real_start_time >='"+startTime+"' and t.real_end_time <='"+endTime+"' and DATEDIFF(t.real_end_time , t.end_time) < 2 group by t.depart_id) hhhh_2 on hhhh_2.depart_id = d.id";
//巡检任务
sql += " left join ( select t.depart_id , count(1) 'count' from inspection_task t where t.task_start_time >='"+startTime+"' and t.task_end_time <='"+endTime+"' group by t.depart_id) jj on jj.depart_id = d.id";
sql += " left join ( select t.depart_id , count(1) 'count' from inspection_task t where t.task_state = 2 and t.task_start_time >='"+startTime+"' and t.task_end_time <='"+endTime+"' group by t.depart_id) jjjj on jjjj.depart_id = d.id";
sql += " left join ( select t.depart_id , count(1) 'count' from inspection_task t where t.task_state = 2 and t.task_start_time >='"+startTime+"' and t.task_end_time <='"+endTime+"' and DATEDIFF(t.task_end_time , t.plan_end_date) < 2 group by t.depart_id) jjjj_2 on jjjj_2.depart_id = d.id";
sql += " left join ( select t.depart_id , count(1) 'count' from inspection_task t where t.inspection_cycle_start_date >='"+startTime+"' and t.inspection_cycle_start_date <='"+endTime+"' group by t.depart_id) jj on jj.depart_id = d.id";
sql += " left join ( select t.depart_id , count(1) 'count' from inspection_task t where t.task_state = 2 and t.inspection_cycle_start_date >='"+startTime+"' and t.inspection_cycle_start_date <='"+endTime+"' group by t.depart_id) jjjj on jjjj.depart_id = d.id";
sql += " left join ( select t.depart_id , count(1) 'count' from inspection_task t where t.task_state = 2 and t.inspection_cycle_start_date >='"+startTime+"' and t.inspection_cycle_start_date <='"+endTime+"' and DATEDIFF(t.task_end_time , t.plan_end_date) < 2 group by t.depart_id) jjjj_2 on jjjj_2.depart_id = d.id";
return sql ;
}
......
......@@ -156,7 +156,7 @@ public class FactoryOperateCenterServiceImpl implements IFactoryOperateCenterSer
map.put("nclsl",new HashMap<>());
Map<String, Object> nclslMap = new HashMap<>();
nclslMap.put("nsjsl", yearClsl);
nclslMap.put("nsjsl", yearClslMb);
// nclslMap.put("nsjsl", yearClslMb);
nclslMap.put("wcbfb", df.format(100*yearClsl/yearClslMb));
nclslMap.put("nmb", yearClslMb);
nclslMap.put("nmbTb", df.format((yearClslMb-yearTbClslMb)/yearClslMb));
......
......@@ -2,13 +2,18 @@ package com.skua.modules.equipment.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.common.constant.BusinessConstant;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.equipment.dto.ReportStatisticsDTO;
import com.skua.modules.equipment.service.IEquipmentAnalysisService;
import com.skua.modules.equipment.service.IProductionEquipmentService;
import com.skua.modules.equipment.vo.*;
import com.skua.modules.system.service.ISysDepartService;
import com.skua.tool.util.DateUtils;
import com.skua.tool.util.DigitalUtils;
import com.skua.tool.util.JSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -20,8 +25,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Api(tags = "设备中心")
......@@ -32,6 +37,8 @@ public class EquipmentCenterController {
private IProductionEquipmentService iProductionEquipmentService;
@Autowired
private ISysDepartService departService;
@Autowired
private IEquipmentAnalysisService equipmentAnalysisService;
@AutoLog(value = "设备中心-顶部总览")
@ApiOperation(value = "设备中心-顶部总览", notes = "设备中心-顶部总览")
......@@ -86,6 +93,9 @@ public class EquipmentCenterController {
Result<IPage<EquipmentStatisticsCountVO>> result = new Result<IPage<EquipmentStatisticsCountVO>>();
Page<EquipmentStatisticsCountVO> page = new Page<EquipmentStatisticsCountVO>(pageNo, pageSize);
setDepartIds(reportStatisticsDTO);//设置departIds
// bug11036:暂时先隐藏,不然和设备台账统计不一致
reportStatisticsDTO.setStartTime(null);
reportStatisticsDTO.setEndTime(null);
IPage<EquipmentStatisticsCountVO> pageList =iProductionEquipmentService.getEquipmentStatisticsDetailsNew(page, reportStatisticsDTO);
result.setSuccess(true);
result.setResult(pageList);
......@@ -128,9 +138,52 @@ public class EquipmentCenterController {
public Result<List<ContrastVO>> equipmentIntactRate(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<ContrastVO>> result = new Result<List<ContrastVO>>();
setDepartIds(reportStatisticsDTO);
List<ContrastVO> equipmentIntactRate = iProductionEquipmentService.getEquipmentIntactRate(reportStatisticsDTO);
// 当前时间
Date nowDate = new Date();
String nowDateStr = DateUtils.date2Str(nowDate, BusinessConstant.dateFormat);
Date startDate;
if (reportStatisticsDTO.getTimeUnit() == 6) {
startDate = DateUtils.someDate(nowDate, Calendar.MONTH, -6);
} else {
startDate = DateUtils.prevYear(nowDate);
}
String startTime = DateUtils.date2Str(startDate, BusinessConstant.dateFormat).substring(0, 7) + "-01" + BusinessConstant.startTimeSuffix;
int days = DateUtils.lengthOfSomeMonth(Integer.parseInt(nowDateStr.split("-")[0]), Integer.parseInt(nowDateStr.split("-")[1]));
String endTime = nowDateStr.substring(0, 7) + "-" + days + BusinessConstant.endTimeSuffix;
// 同比时间
String[] tbTimeArray = DateUtils.tbTime(startTime, endTime);
// departId删除''
String departId = Arrays.stream(reportStatisticsDTO.getDepartIds().split(",")).map(item -> item.replaceAll("'", "")).collect(Collectors.joining(","));
List<Map<String, Object>> entityList = equipmentAnalysisService.equipmentInTactRateByTime(new HashMap<String, Object>(){{
put("startTime", startTime);
put("endTime", endTime);
put("timeType", "month");
put("departId", departId);
}});
List<Map<String, Object>> entityListTb = equipmentAnalysisService.equipmentInTactRateByTime(new HashMap<String, Object>(){{
put("startTime", tbTimeArray[0]);
put("endTime", tbTimeArray[1]);
put("timeType", "month");
put("departId", departId);
}});
Map<String, String> tbTime2ValueMap = entityListTb.stream().collect(Collectors.toMap(item -> ConvertUtils.getString(item.get("time")).substring(0, 7), item -> DigitalUtils.nPoint(ConvertUtils.getDouble(item.get("intactRate"), 0D) * 100, 2) + "%"));
// 封装结果集
List<ContrastVO> resMapList = new ArrayList<>();
for (Map<String, Object> item: entityList) {
ContrastVO map = new ContrastVO();
String yearMonth = ConvertUtils.getString(item.get("time")).substring(0, 7);
map.setMonth(yearMonth);
// 完好率
map.setRepairNum(DigitalUtils.nPoint(ConvertUtils.getDouble(item.get("intactRate"), 0D) * 100, 2) + "%");
// 同比
String tbYearMonth = (Integer.parseInt(yearMonth.split("-")[0]) - 1) + "-" + yearMonth.split("-")[1];
map.setMaintainNum(tbTime2ValueMap.get(tbYearMonth));
resMapList.add(map);
}
result.setResult(resMapList);
// List<ContrastVO> equipmentIntactRate = iProductionEquipmentService.getEquipmentIntactRate(reportStatisticsDTO);
result.setSuccess(true);
result.setResult(equipmentIntactRate);
// result.setResult(equipmentIntactRate);
return result;
}
......@@ -152,9 +205,42 @@ public class EquipmentCenterController {
public Result<List<Map>> equipmentIntactRateDetailsNew(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<Map>> result = new Result<List<Map>>();
setDepartIds(reportStatisticsDTO);
List<Map> equipmentIntactRateDetails = iProductionEquipmentService.getEquipmentIntactRateDetailsNew(reportStatisticsDTO);
result.setResult(equipmentIntactRateDetails);
// List<Map> equipmentIntactRateDetails = iProductionEquipmentService.getEquipmentIntactRateDetailsNew(reportStatisticsDTO);
// result.setResult(equipmentIntactRateDetails);
// 请求参数
String startTime = reportStatisticsDTO.getStartTime();
String endTime = reportStatisticsDTO.getEndTime();
// endTime修改到本月月底
int days = DateUtils.lengthOfSomeMonth(Integer.parseInt(endTime.split("-")[0]), Integer.parseInt(endTime.split("-")[1]));
endTime = endTime.substring(0, 7) + "-" + days + BusinessConstant.endTimeSuffix;
String finalEndTime = endTime;
// 同比时间
String[] tbTimeArray = DateUtils.tbTime(startTime, endTime);
// departId删除''
String departId = Arrays.stream(reportStatisticsDTO.getDepartIds().split(",")).map(item -> item.replaceAll("'", "")).collect(Collectors.joining(","));
List<Map<String, Object>> entityList = equipmentAnalysisService.equipmentInTactRateByDepart(new HashMap<String, Object>(){{
put("startTime", startTime);
put("endTime", finalEndTime);
put("departId", departId);
}});
List<Map<String, Object>> entityListTb = equipmentAnalysisService.equipmentInTactRateByDepart(new HashMap<String, Object>(){{
put("startTime", tbTimeArray[0]);
put("endTime", tbTimeArray[1]);
put("departId", departId);
}});
Map<String, String> tbDepartId2intactRateMap = entityListTb.stream().collect(Collectors.toMap(item -> ConvertUtils.getString(item.get("departId")), item -> DigitalUtils.nPoint(ConvertUtils.getDouble(item.get("intactRate"), 0D) * 100, 2)));
// 封装结果集
List<Map> resMapList = new ArrayList<>();
for (Map<String, Object> item : entityList) {
Map<String, Object> map = new HashMap<>();
map.put("depart_id", item.get("departId"));
map.put("depart_name", item.get("departName"));
map.put("intact", DigitalUtils.nPoint(ConvertUtils.getDouble(item.get("intactRate"), 0) * 100, 2));
map.put("percentage", tbDepartId2intactRateMap.get(ConvertUtils.getString(item.get("departId"))));
resMapList.add(map);
}
result.setSuccess(true);
result.setResult(resMapList);
return result;
}
@AutoLog(value = "设备中心-MTTR&MTBF")
......
......@@ -226,7 +226,7 @@ public class EquipmentInfoMonthReportController {
sql += " left join (select depart_id, GROUP_CONCAT(plan_name,',') 'plan_name' ,(sum(ifnull(plan_cost,0))/10000) 'plan_cost' from equipment_maintain_plan where maintenance_type = 'dxjg' and release_status='1' and start_time >= '"+startDate+" 00:00:00' and end_time <='"+endDate+" 23:59:59' group by depart_id )aaa on aaa.depart_id = d.id ";
sql += " left join ( select emt.depart_id, sum(ifnull(maintenance_cost,0)) maintenance_cost from equipment_maintain_task emt ,equipment_maintain_plan emp where emt.plan_id = emp.id and emp.maintenance_type = 'dxjg' and emt.maintain_time >= '"+startDate+" 00:00:00' and emt.maintain_time <='"+endDate+" 23:59:59' group by emt.depart_id )bbb on bbb.depart_id = d.id ";
sql += " where d.depart_type = 1 ";*/
String sql = "select d.depart_name, t.depart_id, t.plan_name , (t.plan_cost/10000) 'plan_cost' ,round(ifnull(aaa.maintenance_cost,0) ,2)maintenance_cost , '' as 'reason' from equipment_maintain_plan t ";
String sql = "select d.depart_name, t.depart_id, t.plan_name , (t.plan_cost/10000) 'plan_cost' ,round(ifnull(aaa.maintenance_cost,0)/10000 ,2)maintenance_cost , '' as 'reason' from equipment_maintain_plan t ";
sql += " left join (select emt.plan_id, sum(ifnull(maintenance_cost,0)) maintenance_cost from equipment_maintain_task emt where emt.maintain_time >= '"+startDate+" 00:00:00' and emt.maintain_time <='"+endDate+" 23:59:59' group by emt.plan_id )aaa on aaa.plan_id = t.id ";
sql += " left join sys_depart d on t.depart_id = d.id ";
sql += " where t.maintenance_type = 'dxjg' and t.release_status='1' and t.start_time >= '"+startDate+" 00:00:00' and t.end_time <='"+endDate+" 23:59:59' ";
......
......@@ -14,6 +14,8 @@ 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.modules.supplies.entity.EquipmentSparepartSupplies;
import com.skua.modules.supplies.service.IEquipmentSparepartSuppliesService;
import com.skua.tool.dfs.MapDFS;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
......@@ -45,6 +47,8 @@ public class EquipmentStatisticController {
private IEquipmentSparepartService equipmentSparepartService;
@Autowired
private IEquipmentInfoService equipmentInfoService;
@Autowired
private IEquipmentSparepartSuppliesService equipmentSparepartSuppliesService;
@GetMapping("/sparepartOut")
@CustomExceptionAnno(description = "物料-出库统计")
......@@ -90,7 +94,7 @@ public class EquipmentStatisticController {
}
}
// 查询
QueryWrapper<EquipmentSparepart> queryWrapper0 = new QueryWrapper<>();
QueryWrapper<EquipmentSparepartSupplies> queryWrapper0 = new QueryWrapper<>();
queryWrapper0.in(!sparepartTypeSet.isEmpty(), "sparepart_type", sparepartTypeSet)
.in(!departIdSet.isEmpty(), "depart_id", departIdSet)
.like(StringUtils.isNotEmpty(sparepartName), "sparepart_name", sparepartName)
......@@ -104,25 +108,26 @@ public class EquipmentStatisticController {
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);
queryWrapper0.inSql("id", inSql);
IPage<EquipmentSparepartSupplies> equipmentSparepartSuppliesIPage = equipmentSparepartSuppliesService.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()));
mapPage.setTotal(equipmentSparepartSuppliesIPage.getTotal());
Set<String> suppliesIdSet = new HashSet<>();
mapPage.setRecords(equipmentSparepartSuppliesIPage.getRecords().stream().map(item -> {
suppliesIdSet.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");
entityMap.put("suppliesId", item.getId());
return entityMap;
}).collect(Collectors.toList()));
// 获取 物料出库 数量
if (!sparepartIdSet.isEmpty()) {
if (!suppliesIdSet.isEmpty()) {
QueryWrapper<?> queryWrapper1 = new QueryWrapper<>();
if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
queryWrapper1.ge("out_date", startTime)
......@@ -130,7 +135,7 @@ public class EquipmentStatisticController {
}
queryWrapper1.in(!departIdSet.isEmpty(), "equipment_out.depart_id", departIdSet);
queryWrapper1.groupBy("sparepart_id")
.in("sparepart_id", sparepartIdSet);
.in("sparepart_id", suppliesIdSet);
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")));
......@@ -149,17 +154,45 @@ public class EquipmentStatisticController {
public Result<Object> sparepartOutDetailCtrl(@RequestParam Map<String, Object> paramMap) {
// 请求参数
String suppliesId = ConvertUtils.getString(paramMap.get("suppliesId"));
String sparepartId = ConvertUtils.getString(paramMap.get("sparepartId"));
String equipmentId = ConvertUtils.getString(paramMap.get("equipmentId"));
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 departId = ConvertUtils.getString(paramMap.get("departId"));
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<?> queryWrapper0 = new QueryWrapper<>();
queryWrapper0.ge(StringUtils.isNotEmpty(startTime), "equipment_out.out_date", startTime)
.le(StringUtils.isNotEmpty(endTime), "equipment_out.out_date", endTime);
.le(StringUtils.isNotEmpty(endTime), "equipment_out.out_date", endTime)
.in(!departIdSet.isEmpty(), "equipment_out.depart_id", departIdSet)
.in(StringUtils.isNotEmpty(sparepartId), "equipment_sparepart.id", Arrays.asList(sparepartId.split(",")));
if (StringUtils.isNotEmpty(suppliesId)) {
queryWrapper0.in("equipment_out_child.sparepart_id", Arrays.asList(suppliesId.split(",")));
}
// 约束条件,设备维修和出库无关联关系,因此需要找约束条件
if (StringUtils.isNotEmpty(equipmentId)) {
String tmpSql = "select {param} from equipment_repair_child left join equipment_repair on equipment_repair_child.repair_id = equipment_repair.id where equipment_repair.info_id in ('" + equipmentId + "') and equipment_repair_child.nums > 0";
String tmpSql0 = tmpSql.replaceAll("\\{param}", "equipment_repair.maintenance_user");
queryWrapper0.inSql("equipment_out.use_by", tmpSql0);
String tmpSql1 = tmpSql.replaceAll("\\{param}", "DATE_FORMAT(equipment_repair_child.create_time, '%Y-%m-%d')");
queryWrapper0.inSql("DATE_FORMAT(equipment_out_child.create_time, '%Y-%m-%d')", tmpSql1);
}
// 排序
queryWrapper0.orderByDesc("equipment_out_child.sparepart_id", "equipment_out.out_date");
// 翻译
......@@ -282,7 +315,7 @@ public class EquipmentStatisticController {
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);
List<Map<String, Object>> queryMapList1 = baseService.queryForList("select " + String.join(",", columnList) + " from equipment_repair_child left join equipment_repair 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<>();
......
......@@ -80,7 +80,11 @@ public class ReportStatisticsDTO {
public String getTime() {
if(StringUtils.isEmpty(time)){//判断time如果为空,获取starttime的年份数据,否则获取当前年
if( StringUtils.isNotEmpty(startTime) ){
time = DateUtils.getDateYear(startTime)+"";
if (timeUnit == 3) {
time = startTime.substring(0, 7);
} else {
time = DateUtils.getDateYear(startTime)+"";
}
}else{
time = DateUtils.getCurrentYear()+"";
}
......
......@@ -127,8 +127,8 @@
from sys_depart d
left join (
select bbb.depart_id,
ifnull(sum(CASE WHEN equipment_level = '2421538a0286b491ffb863db92fe6cbf' THEN bbb.hour END),0) 'category_value1',
ifnull(sum(CASE WHEN equipment_level = '6bf727eb7e7cca6a95c694dab0036b2c' THEN bbb.hour END),0) 'category_value2',
ifnull(sum(CASE WHEN equipment_level = '6bf727eb7e7cca6a95c694dab0036b2c' THEN bbb.hour END),0) 'category_value1',
ifnull(sum(CASE WHEN equipment_level = '2421538a0286b491ffb863db92fe6cbf' THEN bbb.hour END),0) 'category_value2',
ifnull(sum(CASE WHEN equipment_level = 'a64bfc58110d2c105a6026e8bd02c232' THEN bbb.hour END),0) 'category_value3'
from (
......
package com.skua.modules.equipment.service;
import java.util.List;
import java.util.Map;
/**
* @Author:sonin
* @Date:2025/4/23 9:54
*/
public interface IEquipmentAnalysisService {
List<Map<String, Object>> equipmentInTactRateByDepart(Map<String, Object> paramMap);
List<Map<String, Object>> equipmentInTactRateByTime(Map<String, Object> paramMap);
}
package com.skua.modules.equipment.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.skua.common.constant.BusinessConstant;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.biz.IBusinessService;
import com.skua.modules.equipment.entity.EquipmentInfo;
import com.skua.modules.equipment.entity.EquipmentRepair;
import com.skua.modules.equipment.service.IEquipmentAnalysisService;
import com.skua.modules.equipment.service.IEquipmentInfoService;
import com.skua.modules.equipment.service.IEquipmentRepairService;
import com.skua.tool.util.DateUtils;
import com.skua.tool.util.ParamUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author:sonin
* @Date:2025/4/23 9:55
*/
@Service
public class EquipmentAnalysisServiceImpl implements IEquipmentAnalysisService {
@Autowired
private IEquipmentInfoService equipmentInfoService;
@Autowired
private IEquipmentRepairService equipmentRepairService;
@Autowired
private IBusinessService businessService;
@Override
public List<Map<String, Object>> equipmentInTactRateByDepart(Map<String, Object> paramMap) {
// 请求参数
String startTime = ConvertUtils.getString(paramMap.get("startTime"));
String endTime = ConvertUtils.getString(paramMap.get("endTime"));
Date startTime0 = DateUtils.str2Date(startTime, BusinessConstant.dateFormat);
Date endTime0 = DateUtils.str2Date(endTime, BusinessConstant.dateFormat);
// 时间差值,转换成秒
long interval = (endTime0.getTime() - startTime0.getTime()) / 1000 + 1;
String departId = ConvertUtils.getString(paramMap.get("departId"));
List<String> departIdList = Arrays.asList(departId.split(","));
// 查询设备信息
QueryWrapper<EquipmentInfo> queryWrapper0 = new QueryWrapper<>();
queryWrapper0.select("depart_id, count(*) as total")
.in(StringUtils.isNotEmpty(departId), "depart_id", departIdList)
.groupBy("depart_id");
List<Map<String, Object>> equipmentInfoList = equipmentInfoService.listMaps(queryWrapper0);
// 机构 => 设备数量
Map<String, Integer> departId2EquipCountMap = equipmentInfoList.stream().collect(Collectors.toMap(item -> ConvertUtils.getString(item.get("depart_id")), item -> Integer.parseInt(ConvertUtils.getString(item.get("total"))), (v1, v2) -> v2));
// 查询设备的故障时间
QueryWrapper<EquipmentRepair> queryWrapper1 = new QueryWrapper<>();
queryWrapper1.ge("create_time", startTime)
.le("create_time", endTime)
.in(StringUtils.isNotEmpty(departId), "depart_id", departIdList)
.isNotNull("reality_maintenance_end_time")
.isNotNull("repair_date")
.apply("reality_maintenance_end_time >= repair_date")
.inSql("info_id", "select id from equipment_info");
List<EquipmentRepair> equipmentRepairList = equipmentRepairService.list(queryWrapper1);
// 设备 => 故障时间
Map<String, Map<String, Long>> departId2Equip2FaultTimeMap = new LinkedHashMap<>();
for (EquipmentRepair item : equipmentRepairList) {
String equipId = item.getInfoId();
String tmpDepartId = item.getDepartId();
Date tmpStartTime = item.getRepairDate();
Date tmpEndTime = item.getRealityMaintenanceEndTime();
// 获取时间范围内的数据
if (startTime0.compareTo(tmpStartTime) > 0) {
tmpStartTime = startTime0;
}
if (endTime0.compareTo(tmpEndTime) < 0) {
tmpEndTime = endTime0;
}
long diff = 0L;
if (tmpStartTime.compareTo(tmpEndTime) <= 0) {
// 计算时间差(秒)
diff = (tmpEndTime.getTime() - tmpStartTime.getTime()) / 1000 + 1;
}
departId2Equip2FaultTimeMap.putIfAbsent(tmpDepartId, new HashMap<>());
departId2Equip2FaultTimeMap.get(tmpDepartId).putIfAbsent(equipId, 0L);
departId2Equip2FaultTimeMap.get(tmpDepartId).put(equipId, departId2Equip2FaultTimeMap.get(tmpDepartId).get(equipId) + diff);
}
// 翻译
Map<String, String> sysDepartDictMap = businessService.dictMap("sys_depart", null);
// 封装结果集
List<Map<String, Object>> resMapList = new ArrayList<>();
for (Map.Entry<String, Integer> entry : departId2EquipCountMap.entrySet()) {
String tmpDepartId = entry.getKey();
int equipCount = entry.getValue();
// 计算完好率
long value0 = departId2Equip2FaultTimeMap.getOrDefault(tmpDepartId, new HashMap<>()).values().stream().mapToLong(item -> item).sum();
long value1 = equipCount * interval;
double intactRate = 1 - 1.0 * value0 / value1;
String departName = sysDepartDictMap.get(tmpDepartId);
// 结果
Map<String, Object> resMap = new HashMap<>(4);
resMap.put("departId", tmpDepartId);
resMap.put("departName", departName);
resMap.put("intactRate", intactRate);
resMapList.add(resMap);
}
return resMapList;
}
@Override
public List<Map<String, Object>> equipmentInTactRateByTime(Map<String, Object> paramMap) {
// 请求参数
String startTime = ConvertUtils.getString(paramMap.get("startTime"));
String endTime = ConvertUtils.getString(paramMap.get("endTime"));
String departId = ConvertUtils.getString(paramMap.get("departId"));
List<String> departIdList = Arrays.asList(departId.split(","));
String timeType = ConvertUtils.getString(paramMap.getOrDefault("timeType", "month"));
List<String> timeRangeList = ParamUtils.timeRangeParamFunc(startTime, endTime, timeType);
// 查询设备总数
QueryWrapper<EquipmentInfo> queryWrapper0 = new QueryWrapper<>();
queryWrapper0.select("count(*) as total")
.in(StringUtils.isNotEmpty(departId), "depart_id", departIdList);
Map<String, Object> equipmentInfoMap = equipmentInfoService.getMap(queryWrapper0);
int equipTotal = Integer.parseInt(ConvertUtils.getString(equipmentInfoMap.get("total")));
// 查询设备的故障时间
QueryWrapper<EquipmentRepair> queryWrapper1 = new QueryWrapper<>();
queryWrapper1.ge("create_time", startTime)
.le("create_time", endTime)
.in(StringUtils.isNotEmpty(departId), "depart_id", departIdList)
.isNotNull("reality_maintenance_end_time")
.isNotNull("repair_date")
.apply("reality_maintenance_end_time >= repair_date")
.inSql("info_id", "select id from equipment_info");
List<EquipmentRepair> equipmentRepairList = equipmentRepairService.list(queryWrapper1);
// 时间范围 => 设备 => 故障时间
Map<String, Map<String, Long>> timeRange2Equip2FaultTimeMap = new LinkedHashMap<>();
for (String timeRange : timeRangeList) {
timeRange2Equip2FaultTimeMap.putIfAbsent(timeRange, new HashMap<>());
}
for (EquipmentRepair item : equipmentRepairList) {
String equipId = item.getInfoId();
Date tmpStartTime = item.getRepairDate();
Date tmpEndTime = item.getRealityMaintenanceEndTime();
String createTime = DateUtils.date2Str(item.getCreateTime(), BusinessConstant.dateFormat);
for (String timeRange : timeRangeList) {
String[] timeRangeArray = timeRange.split("~");
// 获取时间范围内的数据
if (createTime.compareTo(timeRangeArray[0]) >= 0 && createTime.compareTo(timeRangeArray[1]) <= 0) {
if (DateUtils.str2Date(timeRangeArray[0], BusinessConstant.dateFormat).compareTo(tmpStartTime) > 0) {
tmpStartTime = DateUtils.str2Date(timeRangeArray[0], BusinessConstant.dateFormat);
}
if (DateUtils.str2Date(timeRangeArray[1], BusinessConstant.dateFormat).compareTo(tmpEndTime) < 0) {
tmpEndTime = DateUtils.str2Date(timeRangeArray[1], BusinessConstant.dateFormat);
}
long diff = 0L;
if (tmpStartTime.compareTo(tmpEndTime) <= 0) {
// 计算时间差(秒)
diff = (tmpEndTime.getTime() - tmpStartTime.getTime()) / 1000 + 1;
}
timeRange2Equip2FaultTimeMap.get(timeRange).putIfAbsent(equipId, 0L);
timeRange2Equip2FaultTimeMap.get(timeRange).put(equipId, timeRange2Equip2FaultTimeMap.get(timeRange).get(equipId) + diff);
break;
}
}
}
// 封装结果集
List<Map<String, Object>> resMapList = new ArrayList<>();
for (Map.Entry<String, Map<String, Long>> entry : timeRange2Equip2FaultTimeMap.entrySet()) {
String timeRange = entry.getKey();
String[] timeRangeArray = timeRange.split("~");
long interval = DateUtils.dateStr2Sec(timeRangeArray[1], BusinessConstant.dateFormat) - DateUtils.dateStr2Sec(timeRangeArray[0], BusinessConstant.dateFormat) + 1;
Map<String, Long> equip2FaultTimeMap = entry.getValue();
// 计算完好率
long value0 = equip2FaultTimeMap.values().stream().mapToLong(Long::longValue).sum();
long value1 = equipTotal * interval;
double intactRate = 1 - 1.0 * value0 / value1;
// 结果
Map<String, Object> resMap = new HashMap<>(4);
resMap.put("time", timeRange);
resMap.put("intactRate", intactRate);
resMapList.add(resMap);
}
return resMapList;
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!