From 1563fa33e203959c80ee713ffff3cad2f825b098 Mon Sep 17 00:00:00 2001 From: cuilei <ray_tsu1@163.com> Date: 星期三, 16 七月 2025 15:05:23 +0800 Subject: [PATCH] 设备维修新增报修时触发消息推送(客户现场要求) --- lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 167 insertions(+), 11 deletions(-) diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java index faf446f..826dec7 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java @@ -1,5 +1,7 @@ package org.jeecg.modules.eam.service.impl; +import cn.hutool.core.collection.CollectionUtil; +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.fasterxml.jackson.core.JsonProcessingException; @@ -8,20 +10,38 @@ import org.apache.shiro.SecurityUtils; import org.jeecg.common.api.vo.FileUploadResult; import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.constant.DataBaseConstant; import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; import org.jeecg.modules.eam.constant.*; import org.jeecg.modules.eam.entity.*; import org.jeecg.modules.eam.mapper.EamReportRepairMapper; import org.jeecg.modules.eam.request.EamReportRepairQuery; import org.jeecg.modules.eam.service.IEamEquipmentExtendService; +import org.jeecg.modules.eam.service.IEamEquipmentFaultReasonService; +import org.jeecg.modules.eam.service.IEamEquipmentService; import org.jeecg.modules.eam.service.IEamReportRepairService; +import org.jeecg.modules.eam.vo.EquipmentRepairListVO; +import org.jeecg.modules.eam.vo.EquipmentRepairStatistics; +import org.jeecg.modules.eam.vo.EquipmentRepairStatusStatistics; +import org.jeecg.modules.eam.vo.FaultTypeStatisticsVO; +import org.jeecg.modules.qywx.message.vo.TemplateCard; +import org.jeecg.modules.qywx.message.vo.TemplateCardEntity; +import org.jeecg.modules.system.service.IMdcProductionService; +import org.jeecg.modules.system.service.ISysUserService; +import org.jeecg.modules.system.service.impl.ThirdAppWechatEnterpriseServiceImpl; +import org.jeecg.modules.system.vo.UserSelector; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.time.LocalDate; import java.util.*; +import java.util.stream.Collectors; /** * @Description: 鏁呴殰鎶ヤ慨 @@ -33,27 +53,86 @@ @Resource private IEamEquipmentExtendService eamEquipmentExtendService; + @Autowired + private IMdcProductionService mdcProductionService; + @Autowired + private IEamEquipmentFaultReasonService eamEquipmentFaultReasonService; + @Autowired + private ISysUserService sysUserService; + @Autowired + private IEamEquipmentService eamEquipmentService; + @Autowired + private ThirdAppWechatEnterpriseServiceImpl wechatEnterpriseService; + + @Value("${wechatEnterprise.cardActionUrl}") + private String cardActionUrl; /** * 鍒嗛〉鍒楄〃 * * @param page - * @param eamReportRepairQuery + * @param query * @return */ @Override - public IPage<EamReportRepair> pageList(Page<EamReportRepair> page, EamReportRepairQuery eamReportRepairQuery) { + public IPage<EamReportRepair> pageList(Page<EamReportRepair> page, EamReportRepairQuery query) { + QueryWrapper<EamReportRepair> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("wmo.del_flag", CommonConstant.DEL_FLAG_0); //鐢ㄦ埛鏁版嵁鏉冮檺 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); if (sysUser == null) { return page; } - List<String> equipmentIds = new ArrayList<>(); if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { //閫夋嫨浜嗚澶囷紝鏍规嵁璁惧id杩囨护璁惧 - equipmentIds = Arrays.asList(sysUser.getEquipmentIds().split(",")); + List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); + queryWrapper.in("e.equipment_code", equipArr); + } else { + //娌℃湁閫夋嫨璁惧锛屾牴鎹溅闂磋繃婊よ澶� + queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id ", sysUser.getId()); } - return this.baseMapper.pageList(page, eamReportRepairQuery, sysUser.getId(), equipmentIds); + //鏌ヨ鏉′欢杩囨护 + if (query != null) { + if (StringUtils.isNotBlank(query.getEquipmentId())) { + queryWrapper.eq("wmo.equipment_id", query.getEquipmentId()); + } + if (StringUtils.isNotBlank(query.getEquipmentCode())) { + queryWrapper.like("e.equipment_code", query.getEquipmentCode()); + } + if (StringUtils.isNotBlank(query.getEquipmentName())) { + queryWrapper.like("e.equipment_name", query.getEquipmentName()); + } + if (StringUtils.isNotBlank(query.getBreakdownFlag())) { + queryWrapper.eq("wmo.breakdown_flag", query.getBreakdownFlag()); + } + if (StringUtils.isNotBlank(query.getReportStatus())) { + queryWrapper.eq("wmo.report_status", query.getReportStatus()); + } + if (StringUtils.isNotBlank(query.getFaultDescription())) { + queryWrapper.like("wmo.fault_description", query.getFaultDescription()); + } + if(query.getStartTime() != null && query.getEndTime() != null) { + queryWrapper.between("wmo.fault_start_time", query.getStartTime(), query.getEndTime()); + } + //鎺掑簭 + if (StringUtils.isNotBlank(query.getColumn()) && StringUtils.isNotBlank(query.getOrder())) { + String column = query.getColumn(); + if (column.endsWith(CommonConstant.DICT_TEXT_SUFFIX)) { + column = column.substring(0, column.lastIndexOf(CommonConstant.DICT_TEXT_SUFFIX)); + } + if (DataBaseConstant.SQL_ASC.equalsIgnoreCase(query.getOrder())) { + queryWrapper.orderByAsc("wmo." + oConvertUtils.camelToUnderline(column)); + } else { + queryWrapper.orderByDesc("wmo." + oConvertUtils.camelToUnderline(column)); + } + } else { + queryWrapper.orderByDesc("wmo.create_time"); + } + } else { + queryWrapper.orderByDesc("wmo.create_time"); + } + + return baseMapper.queryPageList(page, queryWrapper); } @Override @@ -65,15 +144,20 @@ sb.append(detail.getItemCode()).append("銆�"); sb.append(detail.getExceptionDescription()).append(";"); }); + EamEquipmentFaultReason reason = eamEquipmentFaultReasonService.selectByFaultCode(BusinessCodeConst.EFR20250009); EamReportRepair entity = new EamReportRepair(); entity.setEquipmentId(equipmentId); entity.setCreateBy(reportUser); entity.setFaultStartTime(new Date()); entity.setBreakdownFlag(CommonConstant.DEFAULT_0); entity.setDelFlag(CommonConstant.DEL_FLAG_0); - entity.setFaultName("鍛ㄤ繚鎵ц鎶ヤ慨澶勭悊"); - entity.setFaultDescription(sb.toString()); - entity.setFaultType(CommonConstant.DEFAULT_1); + if(reason == null){ + entity.setFaultName("鍛ㄤ繚鎵ц鎶ヤ慨澶勭悊"); + entity.setFaultDescription(sb.toString()); + }else { + entity.setFaultName(reason.getFaultName()); + entity.setFaultType(reason.getFaultCategory()); + } entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name()); this.baseMapper.insert(entity); //鏇存柊璁惧缁翠慨鐘舵�� @@ -90,15 +174,20 @@ sb.append(detail.getItemCode()).append("銆�"); sb.append(detail.getExceptionDescription()).append(";"); }); + EamEquipmentFaultReason reason = eamEquipmentFaultReasonService.selectByFaultCode(BusinessCodeConst.EFR20250010); EamReportRepair entity = new EamReportRepair(); entity.setEquipmentId(equipmentId); entity.setCreateBy(reportUser); entity.setFaultStartTime(new Date()); entity.setBreakdownFlag(CommonConstant.DEFAULT_0); entity.setDelFlag(CommonConstant.DEL_FLAG_0); - entity.setFaultName("鐐规鎵ц鎶ヤ慨澶勭悊"); - entity.setFaultDescription(sb.toString()); - entity.setFaultType(CommonConstant.DEFAULT_1); + if(reason == null){ + entity.setFaultName("鐐规鎵ц鎶ヤ慨澶勭悊"); + entity.setFaultDescription(sb.toString()); + }else { + entity.setFaultName(reason.getFaultName()); + entity.setFaultType(reason.getFaultCategory()); + } entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name()); this.baseMapper.insert(entity); //鏇存柊璁惧缁翠慨鐘舵�� @@ -126,7 +215,38 @@ this.baseMapper.insert(eamReportRepair); //鏇存柊璁惧缁翠慨鐘舵�� eamEquipmentExtendService.updateEquipmentRepairStatus(eamReportRepair.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name()); + //鎺ㄩ�佷紒涓氬井淇℃秷鎭� + sendQywxTemplateCardMessage(eamReportRepair); return eamReportRepair; + } + + private void sendQywxTemplateCardMessage(EamReportRepair eamReportRepair) { + TemplateCard templateCard = new TemplateCard(); + String equipmentId = eamReportRepair.getEquipmentId(); + EamEquipment equipment = eamEquipmentService.getById(equipmentId); + if (equipment != null) { + //鏌ヨ鏈夎璁惧鏉冮檺鐨勬墍鏈夌淮淇伐 + String productionId = equipment.getOrgId(); + List<UserSelector> userSelectorList = sysUserService.selectOperatorList(equipment.getEquipmentCode(), productionId, BusinessCodeConst.PCR0002); + String toUsers = userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.joining(",")); + String touser = wechatEnterpriseService.getTouser(toUsers, false); + templateCard.setTouser(touser); + + TemplateCardEntity templateCardEntity = new TemplateCardEntity(); + templateCard.setTemplate_card(templateCardEntity); + templateCardEntity.setTask_id(eamReportRepair.getId()); + TemplateCardEntity.MainTitle mainTitle = new TemplateCardEntity.MainTitle(); + mainTitle.setTitle("璁惧缁翠慨"); + templateCardEntity.setMain_title(mainTitle); + templateCardEntity.setSub_title_text("鎮ㄦ湁寰呴鍙栫淮淇伐鍗曪紝璇疯繘鍏ョ郴缁熼鍙�"); + TemplateCardEntity.CardAction cardAction = new TemplateCardEntity.CardAction(); + cardAction.setType(1); + cardAction.setUrl(cardActionUrl); + templateCardEntity.setCard_action(cardAction); + wechatEnterpriseService.sendTemplateCardMsg(templateCard, true); + } else { + log.error("鎶ヤ慨宸ュ崟: " + eamReportRepair.getId() + " 璁惧涓嶅瓨鍦紝鏃犳硶鎺ㄩ�佸伐鍗曞緟棰嗗彇鎻愰啋娑堟伅锛�"); + } } @Override @@ -148,4 +268,40 @@ this.baseMapper.updateById(eamReportRepair); return true; } + + @Override + public List<EquipmentRepairStatistics> equipmentRepairStatistics(String productionId, LocalDate firstOfMonth, LocalDate today) { + if (StringUtils.isNotBlank(productionId)) { + //杞﹂棿缂栫爜涓嶄负绌� + List<String> productIds = mdcProductionService.recursionChildren(productionId); + if (CollectionUtil.isEmpty(productIds)) { + return Collections.emptyList(); + } + List<EquipmentRepairStatistics> list = this.baseMapper.equipmentRepairStatistics(productIds, firstOfMonth.toString(), today.plusDays(1).toString()); + if (CollectionUtil.isEmpty(list)) { + return Collections.emptyList(); + } + return list; + } + List<EquipmentRepairStatistics> list = this.baseMapper.equipmentRepairStatistics(null, firstOfMonth.toString(), today.plusDays(1).toString()); + if (CollectionUtil.isEmpty(list)) { + return Collections.emptyList(); + } + return list; + } + + @Override + public EquipmentRepairStatusStatistics repairStatusStatistics() { + return this.baseMapper.repairStatusStatistics(); + } + + @Override + public List<EquipmentRepairListVO> repairList() { + return this.baseMapper.repairList(); + } + + @Override + public List<FaultTypeStatisticsVO> faultTypeStatistics(String start, String end) { + return this.baseMapper.faultTypeStatistics(start, end); + } } -- Gitblit v1.9.3