From 0155980c6d95ef8f80ca62be0c3df06abff9aabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Mon, 17 Apr 2023 09:23:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=97=A5=E5=B8=B8=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=EF=BC=8C=E5=AE=89=E5=85=A8=E5=B7=A5=E5=85=B7=E5=99=A8=E7=9F=AD?= =?UTF-8?q?=E4=BF=A1=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/message/fegin/IMessageClient.java | 2 + .../hzims/safeproduct/entity/SafetyToolEntity.java | 5 + .../scheduled/MaintenanceTaskCreateTask.java | 46 +- .../impl/OperMaintenancePlanServiceImpl.java | 10 + .../impl/OperMaintenanceTaskServiceImpl.java | 1 + .../abstracts/TemplateAbstractService.java | 54 + .../template/service/TemplateService.java | 24 + .../serviceimpl/MaintenanceTempleServiceImpl.java | 42 + .../station/service/impl/StationServiceImpl.java | 1224 ++++++++++---------- .../service/impl/SafetyToolServiceImpl.java | 474 ++++---- .../abstracts/TemplateAbstractService.java | 54 + .../template/service/TemplateService.java | 24 + .../serviceimpl/MaintenanceTempleServiceImpl.java | 55 + .../impl/StandardTicketInfoServiceImpl.java | 2 +- 14 files changed, 1166 insertions(+), 851 deletions(-) create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/abstracts/TemplateAbstractService.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/service/TemplateService.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/serviceimpl/MaintenanceTempleServiceImpl.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/abstracts/TemplateAbstractService.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/service/TemplateService.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/serviceimpl/MaintenanceTempleServiceImpl.java diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java index 6f22f16..0d5bcb2 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java @@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; +import javax.annotation.Resource; + /** * @author hx */ diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/SafetyToolEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/SafetyToolEntity.java index e909888..13d9e12 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/SafetyToolEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/SafetyToolEntity.java @@ -68,4 +68,9 @@ public class SafetyToolEntity extends TenantEntity { @ApiModelProperty(value = "通知用户") private String noticeUsers; + + + @ApiModelProperty(value = "模板Id") + private Long messageTemplateId; + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java index 9e1e1cb..f243cc1 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java @@ -7,6 +7,7 @@ import com.google.common.collect.Lists; import com.hnac.hzims.equipment.feign.IEmInfoClient; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.dto.MessagePushRecordDto; +import com.hnac.hzims.message.dto.PlanMsgRecordDto; import com.hnac.hzims.message.entity.config.MessageTemplateEntity; import com.hnac.hzims.message.fegin.IMessageClient; import com.hnac.hzims.message.req.PushExtrasReq; @@ -18,6 +19,7 @@ import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; import com.hnac.hzims.operational.maintenance.mapper.OperMaintenancePlanMapper; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; +import com.hnac.hzims.operational.maintenance.template.service.TemplateService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; @@ -64,6 +66,9 @@ public class MaintenanceTaskCreateTask { private final IMessageClient messageClient; private final BladeLogger logger; + + private final List templateService; + @Value("${hzims.operation.task.templateCode.maintenance.taskDispose}") private String maintenanceTaskKey; @@ -195,24 +200,41 @@ public class MaintenanceTaskCreateTask { * @return void **/ private void pushTaskMessage(OperMaintenanceTaskEntity taskEntity) { + + + + XxlJobLogger.log("开始保存{}的日常维护消息推送记录",taskEntity.getDisposer()); R templateR = messageClient.getMsgTemplateById(taskEntity.getMessageTemplateId()); if(templateR.isSuccess() && ObjectUtil.isNotEmpty(templateR.getData())) { Func.toLongList("",taskEntity.getDisposer()).forEach(userId -> { - MessagePushRecordDto recordDto = BeanUtil.copy(templateR.getData(),MessagePushRecordDto.class); - recordDto.setTypes(Arrays.asList(Func.split(recordDto.getType(),","))); - recordDto.setDeptId(taskEntity.getCreateDept()); - recordDto.setCreateUser(taskEntity.getCreateUser()); - recordDto.setCreateDept(taskEntity.getCreateDept()); + // MessagePushRecordDto recordDto = BeanUtil.copy(templateR.getData(),MessagePushRecordDto.class); + // recordDto.setTypes(Arrays.asList(Func.split(recordDto.getType(),","))); + // recordDto.setDeptId(taskEntity.getCreateDept()); + // recordDto.setCreateUser(taskEntity.getCreateUser()); + // recordDto.setCreateDept(taskEntity.getCreateDept()); + // ZoneId zoneId = ZoneId.systemDefault(); + // recordDto.setPlanTime(LocalDateTime.ofInstant(taskEntity.getDisposeTime().toInstant(),zoneId)); + // recordDto.setPushType(MessageConstants.PLAN); + // recordDto.setPusher(userId.toString()); + // recordDto.setPusherName(UserCache.getUser(userId).getName()); + // recordDto.setAccount(recordDto.getPusher()); + // recordDto.setContent("距离任务执行时间已不满一小时,请及时处理"); + //推送消息 ZoneId zoneId = ZoneId.systemDefault(); - recordDto.setPlanTime(LocalDateTime.ofInstant(taskEntity.getDisposeTime().toInstant(),zoneId)); - recordDto.setPushType(MessageConstants.PLAN); - recordDto.setPusher(userId.toString()); - recordDto.setPusherName(UserCache.getUser(userId).getName()); - recordDto.setAccount(recordDto.getPusher()); - recordDto.setContent("距离任务执行时间已不满一小时,请及时处理"); + PlanMsgRecordDto planMsgRecordDto = new PlanMsgRecordDto(); + planMsgRecordDto.setTemplateId(taskEntity.getMessageTemplateId()); + planMsgRecordDto.setCreateUser(taskEntity.getCreateUser()); + planMsgRecordDto.setPlanTime(LocalDateTime.ofInstant(taskEntity.getDisposeTime().toInstant(),zoneId)); + planMsgRecordDto.setTaskId(taskEntity.getId()); + planMsgRecordDto.setDeptId(taskEntity.getCreateDept()); + planMsgRecordDto.setReceiver(userId); + TemplateService templateService1 = templateService.stream().filter(item -> item.isTemplateStatus(1)).findFirst().orElse(null); + templateService1.execute(planMsgRecordDto); + + XxlJobLogger.log("推送内容体为:{}", JSON.toJSONString(taskEntity.getDisposer())); - messageClient.sendMessage(recordDto); + //messageClient.sendMessage(recordDto); }); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenancePlanServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenancePlanServiceImpl.java index b552ccd..59297a6 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenancePlanServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenancePlanServiceImpl.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.common.utils.DateUtil; +import com.hnac.hzims.message.dto.PlanMsgRecordDto; import com.hnac.hzims.operational.duty.entity.ImsDutyClassEntity; import com.hnac.hzims.operational.duty.service.IImsDutyClassService; import com.hnac.hzims.operational.maintenance.dto.OperMaintenancePlanDTO; @@ -14,6 +15,7 @@ import com.hnac.hzims.operational.maintenance.mapper.OperMaintenancePlanMapper; import com.hnac.hzims.operational.maintenance.scheduled.MaintenancePlanCreateTask; import com.hnac.hzims.operational.maintenance.scheduled.MaintenanceTaskCreateTask; import com.hnac.hzims.operational.maintenance.service.IOperMaintenancePlanService; +import com.hnac.hzims.operational.maintenance.template.service.TemplateService; import com.hnac.hzims.operational.maintenance.vo.OperMaintenancePlanVO; import com.hnac.hzims.operational.maintenance.wrapper.OperMaintenancePlanWrapper; import com.hnac.hzims.safeproduct.feign.IDangerSourceClient; @@ -52,6 +54,9 @@ public class OperMaintenancePlanServiceImpl extends BaseServiceImpl templateService; + @Override public R detail(Long id) { OperMaintenancePlanVO detail = OperMaintenancePlanWrapper.build().entityVO(super.getById(id)); @@ -107,12 +112,17 @@ public class OperMaintenancePlanServiceImpl extends BaseServiceImpl().set(OperMaintenancePlanEntity::getCreateTaskTime,new Date()) .eq(OperMaintenancePlanEntity::getId,planEntity.getId())); + } catch(Exception e) { BladeLogger logger = SpringUtil.getBean(BladeLogger.class); logger.error("maintenance:generateTask",e.getMessage()); } }); + + + + return R.success("操作成功"); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenanceTaskServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenanceTaskServiceImpl.java index 996732e..19c19d7 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenanceTaskServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/OperMaintenanceTaskServiceImpl.java @@ -360,6 +360,7 @@ public class OperMaintenanceTaskServiceImpl extends BaseServiceImpl operMaintenanceTaskEntityPage = baseMapper.selectPage(pageParam, queryWrapper); //数据转换 if (CollectionUtil.isNotEmpty(operMaintenanceTaskEntityPage.getRecords())) { diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/abstracts/TemplateAbstractService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/abstracts/TemplateAbstractService.java new file mode 100644 index 0000000..4082e4f --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/abstracts/TemplateAbstractService.java @@ -0,0 +1,54 @@ +package com.hnac.hzims.operational.maintenance.template.abstracts; + +import com.hnac.hzims.message.dto.PlanMsgRecordDto; +import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzims.operational.maintenance.template.service.TemplateService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.annotation.Resource; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/14 14:27 + */ +@Slf4j +public abstract class TemplateAbstractService implements TemplateService { + + @Resource + private IMessageClient messageClient; + + /** + * 具体业务 + * + * @param planMsgRecord + */ + @Override + public void execute(PlanMsgRecordDto planMsgRecord) { + //1.具体的业务逻辑 + PlanMsgRecordDto list = executeTemplateMessage(planMsgRecord); + //2.保存数据 + saveData(list); + } + + /** + * 推送的数据 + * + * @param list + */ + private void saveData(PlanMsgRecordDto list) { + log.info("正在保存推送的数据"); + messageClient.planSendMessage(list); + } + + + /** + * 执行具体的业务场景,推送消息 + * + * @return + */ + public abstract PlanMsgRecordDto executeTemplateMessage(PlanMsgRecordDto planMsgRecord); +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/service/TemplateService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/service/TemplateService.java new file mode 100644 index 0000000..07d6770 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/service/TemplateService.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.operational.maintenance.template.service; + +import com.hnac.hzims.message.dto.PlanMsgRecordDto; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/14 14:25 + */ +public interface TemplateService { + + /** + * 模板状态 + */ + Boolean isTemplateStatus(int status); + + + /** + * 具体业务 + */ + void execute(PlanMsgRecordDto planMsgRecord); + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/serviceimpl/MaintenanceTempleServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/serviceimpl/MaintenanceTempleServiceImpl.java new file mode 100644 index 0000000..b49b931 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/template/serviceimpl/MaintenanceTempleServiceImpl.java @@ -0,0 +1,42 @@ +package com.hnac.hzims.operational.maintenance.template.serviceimpl; + +import com.hnac.hzims.message.dto.PlanMsgRecordDto; +import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzims.operational.maintenance.template.abstracts.TemplateAbstractService; +import com.hnac.hzims.operational.maintenance.template.service.TemplateService; +import org.springframework.stereotype.Service; + +import java.util.Objects; + +/** + * 日常维护计划 + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/14 14:48 + */ +@Service +public class MaintenanceTempleServiceImpl extends TemplateAbstractService { + + + + /** + * 执行具体的业务场景,推送消息 + * + * @return + */ + @Override + public PlanMsgRecordDto executeTemplateMessage(PlanMsgRecordDto planMsgRecord) { + planMsgRecord.setContent("距离任务执行时间已不满一小时,请及时处理"); + return planMsgRecord; + } + + /** + * 模板状态 + * @param status + */ + @Override + public Boolean isTemplateStatus(int status) { + return Objects.equals(status,1); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java index 62bc750..68b2b28 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java @@ -62,619 +62,619 @@ import java.util.stream.Collectors; @RequiredArgsConstructor @Slf4j public class StationServiceImpl extends BaseServiceImpl implements IStationService { - private final ISysClient sysClient; - private final IDeptClient deptClient; - private final UserAuthDataService userAuthDataService; - private final IUserClient userClient; - private final ProjectClient projectClient; - private final BladeLogger logger; - private final IQuestionClient questionClient; - - @Override - public void buildStation(StationEntity req) { - // 新建站点的所属机构 - Assert.isTrue(this.buildDept(req),() -> { - throw new ServiceException("创建/修改机构失败!"); - }); - LambdaQueryWrapper lwq; - if(Func.isEmpty(req.getId())) { - lwq = Wrappers.lambdaQuery() - .eq(StationEntity::getCode,req.getCode()).or().eq(StationEntity::getName,req.getName()); - } - else { - lwq = Wrappers.lambdaQuery().ne(StationEntity::getId,req.getId()) - .and(wrapper -> wrapper.eq(StationEntity::getCode,req.getCode()).or().eq(StationEntity::getName,req.getName())); - } - - List list = super.list(lwq); - Assert.isTrue(CollectionUtil.isEmpty(list),() -> { - throw new ServiceException("该站点名/编码已有对应记录,请找到相应记录做修改处理"); - }); - Optional sort = Optional.ofNullable(this.getStationMaxOrder()); - req.setSort(sort.isPresent() ? sort.get()+1 : 1); - Assert.isTrue(this.saveOrUpdate(req),() -> { - throw new ServiceException("创建/修改站点信息失败!"); - }); - // 如果设备数据来源未选定其他 则进行站点初始化操作 - if(!StationConstants.HZ3000_OTHER.equals(req.getDataSource())) { - // 智能诊断站点推送 - ExecutorService executor = Executors.newSingleThreadExecutor(); - executor.submit(() -> questionClient.submitStationInfo(req.getCode(), "")); - // 新建项目 - executor.submit(() -> this.instanceProject(req)); - } - } - - @Override - public boolean instanceProject(StationEntity req) { - if(Func.isEmpty(req.getSecretKey()) || Func.isEmpty(req.getDataSource())) { - return true; - } - if(super.updateById(req)) { - ProjectDTO projectDTO = new ProjectDTO(); - projectDTO.setName(req.getName()); - projectDTO.setSource(1); - projectDTO.setSecretKey(req.getSecretKey()); - projectDTO.setListenKind(req.getDataSource()); - projectDTO.setId(req.getCode()); - Result result = projectClient.saveOrUpdate(projectDTO); - logger.info("operational:station:buildStation:"+req.getCode(), JSON.toJSONString(result)); - return result.getCode() == ResultCode.SUCCESS.getCode() && result.isSuccess(); - } - return false; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public boolean removeStation(String id) { - StationEntity stationEntity = this.getById(id); - boolean saveFlag = this.removeById(Long.valueOf(id)); - if(saveFlag) { - // 删除数据平台项目 - Result dataDelete = projectClient.delete(stationEntity.getCode()); - Assert.isTrue(dataDelete.isSuccess(),() -> { - logger.error("hzims-operational:station:removeStation",stationEntity.getCode()+"删除失败,报错信息为:"+dataDelete.getMsg()); - throw new ServiceException("数据平台删除项目失败!"); - }); - // 删除所属机构 - R deptResult = sysClient.getDept(stationEntity.getRefDept()); - if(deptResult.isSuccess() && ObjectUtil.isNotEmpty(deptResult.getData())) { - deptClient.deleteDeptById(stationEntity.getRefDept()); - } - // 删除智能诊断站点 - questionClient.deleteStationInfo(stationEntity.getCode()); - //删除所属机构信息 - deptClient.deleteDeptById(stationEntity.getRefDept()); - } - return saveFlag; - } - - @Override - public IPage list(StationEntity req, Query query) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() {{ - if (StringUtils.isNotBlank(req.getCode())) { - like(StationEntity::getCode, "%".concat(req.getCode()).concat("%")); - } - if (StringUtils.isNotBlank(req.getName())) { - like(StationEntity::getName, "%".concat(req.getName()).concat("%")); - } - if (ObjectUtil.isNotEmpty(req.getType())) { - eq(StationEntity::getType, req.getType()); - } - if (ObjectUtil.isNotEmpty(req.getEnableControl())) { - eq(StationEntity::getEnableControl, req.getEnableControl()); - } - if (ObjectUtil.isNotEmpty(req.getRefDomain())) { - eq(StationEntity::getRefDomain, req.getRefDomain()); - } - if (ObjectUtil.isNotEmpty(req.getRefBasin())) { - eq(StationEntity::getRefBasin, req.getRefBasin()); - } - if (ObjectUtil.isNotEmpty(req.getRefArea())) { - eq(StationEntity::getRefArea, req.getRefArea()); - } - if (ObjectUtil.isNotEmpty(req.getAreaCode())) { - eq(StationEntity::getAreaCode, req.getAreaCode()); - } - if (ObjectUtil.isNotEmpty(req.getRefDept())) { - eq(StationEntity::getRefDept, req.getRefDept()); - } - if (ObjectUtil.isNotEmpty(req.getRemark())) { - like(StationEntity::getRemark, "%".concat(req.getRemark()).concat("%")); - } - if (ObjectUtil.isNotEmpty(req.getStartDate())) { - ge(StationEntity::getCreateTime, req.getStartDate()); - } - if (ObjectUtil.isNotEmpty(req.getEndDate())) { - le(StationEntity::getCreateTime, req.getEndDate()); - } - //orderByAsc(StationEntity::getCreateTime); - }}; - queryWrapper.orderByDesc(StationEntity::getSort); - queryWrapper.orderByDesc(StationEntity::getUpdateTime); - IPage pages = super.page(Condition.getPage(query), queryWrapper); - IPage vos = StationWrapper.builder().pageVO(pages); - return vos; - } - - @Override - public List getUsersByStationId(String stationId) { - List userList = new ArrayList<>(); - StationEntity stationEntity = this.getStationByCode(stationId); - if (ObjectUtil.isNotEmpty(stationEntity) && Func.isNotEmpty(stationEntity.getRefDept())) { - //获取拥有站点机构下权限的人员列表 - R> listR = userClient.userListByDeptAndChildrenWithAuth(stationEntity.getRefDept()); - if (listR.isSuccess() && CollectionUtil.isNotEmpty(listR.getData())) { - userList = listR.getData(); - } - } - return userList; - } - - @Override - public boolean updateById(StationEntity req) { - return super.update(Wrappers.lambdaUpdate() - .set(StationEntity::getCode, req.getCode()) - .set(StationEntity::getName, req.getName()) - .set(StationEntity::getType, req.getType()) - .set(StationEntity::getCommissionTime, req.getCommissionTime()) - .set(StationEntity::getEnableControl, req.getEnableControl()) - .set(StationEntity::getLgtd, req.getLgtd()) - .set(StationEntity::getLttd, req.getLttd()) - .set(StationEntity::getRefDept, req.getRefDept()) - .set(StationEntity::getAreaCode, req.getAreaCode()) - .set(StationEntity::getRefDomain, req.getRefDomain()) - .set(StationEntity::getRefBasin, req.getRefBasin()) - .set(StationEntity::getRefArea, req.getRefArea()) - .set(StationEntity::getRemark, req.getRemark()) - .set(StationEntity::getPic, req.getPic()) - .set(StationEntity::getContact, req.getContact()) - .set(StationEntity::getContactor, req.getContactor()) - .set(StationEntity::getAddress, req.getAddress()) - .set(StationEntity::getCompany, req.getCompany()) - .set(StationEntity::getCreateDept, req.getCreateDept()) - .set(StationEntity::getServeType, req.getServeType()) - .set(StationEntity::getLimitWaterLevel, req.getLimitWaterLevel()) - .eq(StationEntity::getId, req.getId())); - } - - - @Override - public List getInRefDept(List depeIds, String stationType, List types) { - return this.baseMapper.selectInRefDept(depeIds, stationType, types); - } - - @Override - public List getLikeRefDept(Long deptId, String stationType, List types) { - return this.baseMapper.selectLikeRefDept(deptId, stationType, types); - } - - @Override - public List getEqualToRefDept(Long deptId, String stationType, List types) { - return this.baseMapper.selectEqualToRefDept(deptId, stationType, types); - } - - @Override - public List getForEachRefDept(List deptIds, String stationType, List types) { - return this.baseMapper.selectForEachRefDept(deptIds, stationType, types); - } - - - @Override - public StationEntity getStationByCodeAndUser(String stationId, Long userId) { - ControlUsersMapper usersMapper = SpringUtil.getBean("controlUsersMapper"); - List controlUsersEntities = usersMapper.selectList( - Wrappers.lambdaQuery().eq(ControlUsersEntity::getStationId, stationId) - ); - List deptIds = new ArrayList<>(); - StationEntity stationEntity = this.baseMapper.getStationByCode(stationId, deptIds, null); - Assert.isTrue(ObjectUtil.isNotEmpty(stationEntity), () -> { - throw new ServiceException("未查询到相关站点"); - }); - if (CollectionUtil.isNotEmpty(controlUsersEntities)) { - List codeList = controlUsersEntities.stream().filter(c -> stationId.equals(c.getStationId())).filter(c -> { - return Func.toLongList(c.getUserIds()).contains(userId); - }).collect(Collectors.toList()); - ControlUsersEntity object = codeList.size() > 0 ? codeList.get(0) : null; - if (ObjectUtil.isNotEmpty(object)) { - return StationEntity.builder().code(stationId).enableControl(2).build(); - } else { - stationEntity.setEnableControl(0); - return stationEntity; - } - } else { - return stationEntity; - } - } - - @Override - public StationEntity getStationByCodeOrRefDept(String stationId, Long deptId) { - return this.baseMapper.getStationByCodeOrRefDept(stationId, deptId); - } - - @Override - public StationEntity getStationByStationCode(String stationId) { - if (Func.isEmpty(AuthUtil.getUserId())) { - return this.baseMapper.getStationByCode(stationId, null, null); - } - StationEntity stationEntity = this.getStationByCodeAndUser(stationId, AuthUtil.getUserId()); - return stationEntity; - } - - @Override - public StationVO getStationByCode(String code) { - StationEntity stationEntity = this.baseMapper.getStationByCode(code, null, null); - return ObjectUtil.isNotEmpty(stationEntity) ? StationWrapper.builder().entityVO(stationEntity) : null; - } - - - @Override - public int getInRefDeptStationCount(List perSeDeptIds, String refDomain, String type, List deptIds) { - return this.baseMapper.selectInRefDeptStationCount(perSeDeptIds, refDomain, type, deptIds); - } - - @Override - public int getLikeRefDeptStationCount(Long deptId, String refDomain, String type, List deptIds) { - return this.baseMapper.selectLikeRefDeptStationCount(deptId, refDomain, type, deptIds); - } - - @Override - public int getEqualToRefDeptStationCount(Long deptId, String refDomain, String type, List deptIds) { - return this.baseMapper.selectEqualToRefDeptStationCount(deptId, refDomain, type, deptIds); - } - - @Override - public int getForEachRefDeptStationCount(List perSeDeptIds, String refDomain, String type, List deptIds) { - return this.baseMapper.selectForEachRefDeptStationCount(perSeDeptIds, refDomain, type, deptIds); - } - - @Override - public List getAll() { - return this.baseMapper.selectAll(); - } - - /** - * 根据用户全选获取站点数据 - * - * @param user - * @return - */ - @Override - public List getStationByUserAuth(BladeUser user) { - List list = new ArrayList<>(); - if (user.getDataScopeType().equals(OperationalConstants.UserDataScopeTypeEnum.EMPLOYER_VISIBLE.getVal()) && StringUtil.isNotBlank(user.getDeptId())) {//所属机构 - list = this.baseMapper.selectEqualToRefDeptStationData(Long.valueOf(user.getDeptId())); - } else if ((user.getDataScopeType().equals(OperationalConstants.UserDataScopeTypeEnum.EMPLOYER_SUBORDINATE_BODY.getVal()) || user.getDataScopeType().equals(OperationalConstants.UserDataScopeTypeEnum.SELT_SUBORDINATE_BODY.getVal())) && ObjectUtil.isNotEmpty(user.getDeptId()) && StringUtil.isNotBlank(user.getDeptId())) {//所属机构及下属机构 || 个人及下属机构 - list = this.baseMapper.selectLikeRefDeptStationData(Long.valueOf(user.getDeptId())); - } else if (user.getDataScopeType().equals(OperationalConstants.UserDataScopeTypeEnum.AFFILIATE.getVal()) && StringUtil.isNotBlank(user.getDeptIds())) {//附属机构 - list = this.baseMapper.selectInRefDeptStationData(Func.toLongList(user.getDeptIds())); - } else if (user.getDataScopeType().equals(OperationalConstants.UserDataScopeTypeEnum.AFFILIATE_SUBORDINATE_BODY.getVal()) && StringUtil.isNotBlank(user.getDeptIds())) {//附属机构及下属 - list = this.baseMapper.selectForEachRefDeptStationData(Func.toLongList(user.getDeptIds())); - } - return list; - } - - /** - * 获取根据站点ID或机构ID查询站点名称 - * - * @param station true 站点ID为key false 机构ID为key - * @return - */ - @Override - public Map getKyeStationNameValueStationId(boolean station) { - Map map = new HashMap<>(); - List stationEntityList = this.baseMapper.selectKyeStationNameValueStationId(); - if (CollectionUtil.isNotEmpty(stationEntityList)) { - for (StationEntity stationEntity : stationEntityList) { - if (station) { - map.put(stationEntity.getCode(), stationEntity.getName()); - } else { - map.put(stationEntity.getRefDept().toString(), stationEntity.getName()); - } - } - } - return map; - } - - /** - * 获取根据站点ID或机构ID查询站点名称 - * - * @param station true 站点ID为key false 机构ID为key - * @return - */ - @Override - public Map getKeyStringValueStation(boolean station) { - Map map = new HashMap<>(); - List stationEntityList = this.baseMapper.selectKyeStationNameValueStationId(); - if (CollectionUtil.isNotEmpty(stationEntityList)) { - for (StationEntity stationEntity : stationEntityList) { - if (station) { - map.put(stationEntity.getCode(), stationEntity); - } else { - map.put(stationEntity.getRefDept().toString(), stationEntity); - } - } - } - return map; - } - - /** - * 站点统计 - * - * @return - */ - @Override - public List getStationTypeGroupCount(Integer serveType) { - return this.baseMapper.selectStationTypeGroupCount(serveType); - } - - @Override - public List getRefDeptByStationId(Integer stationType, Integer serveType) { - return this.baseMapper.selectRefDeptByStationId(stationType, serveType); - } - - /** - * 根据云服务类型查询站点Id - * - * @param serveType - * @return - */ - @Override - public List getStationIdByServeType(Integer stationType, Integer serveType) { - return this.baseMapper.selectStationIdByServeType(stationType, serveType); - } - - @Override - public List getStationIdAndDeptByType(Integer stationType, Integer serveType) { - return this.baseMapper.selectStationIdAndDeptByType(stationType, serveType); - } - - @Override - public List getStationByType(Integer stationType, Integer serveType) { - return this.baseMapper.selectStationByType(stationType, serveType); - } - - @Override - public List doListByServeType(Integer serveType) { - return this.baseMapper.selectListByServeType(serveType); - } - - @Override - public List getStationByInCode(List codes) { - return this.baseMapper.selectStationByInCode(codes); - } - - @Override - public List getStationType(Integer serveType, List typeList, List departIdList) { - return this.list(new LambdaQueryWrapper() {{ - eq(StationEntity::getIsDeleted, 0); - if (ObjectUtil.isNotEmpty(serveType)) { - eq(StationEntity::getServeType, serveType); - } - if (CollectionUtil.isNotEmpty(typeList)) { - in(StationEntity::getType, typeList); - } - if (CollectionUtil.isNotEmpty(departIdList)) { - in(StationEntity::getRefDept, departIdList); - } - }}); - } - - /** - * 根据条件 服务类型及站点类型查询站点数据 - * - * @param serverType - * @param isType true is not null \ false is null - * @return - */ - @Override - public List getStationByServerTypeAndIsType(Integer serverType, Boolean isType) { - return this.baseMapper.getStationByTypeAndIsType(serverType, isType); - } - - /** - * 获取机构下站点集合 - * - * @param deptId - * @param types - * @param servrType - * @return - */ - @Override - public List getStationList(List authList, Long deptId, List types, Integer servrType) { - Dept dept; - if (null == deptId) { - // 最小类型机构 - Optional min = authList.stream().min(Comparator.comparing(Dept::getDeptCategory)); - dept = min.isPresent() ? min.get() : null; - if (ObjectUtil.isEmpty(dept)) { - return null; - } - } else { - // 检查是否存在传入机构 - List list = authList.stream().filter(o -> deptId.equals(o.getId())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(list)) { - return null; - } - // 传入机构为站点 - dept = list.get(0); - } - List refDepList; - if (dept.getDeptCategory().equals(4)) { - refDepList = Collections.singletonList(dept.getId()); - // 传入机构为区域、省子公司、集团 - } else { - // 递归权限机构获取站点级机构 - refDepList = this.getStationDeptList(authList, dept.getId(), new ArrayList<>()); - } - // 获取水利站点(过滤其他站点类型) - return this.getWaterList(refDepList, types, servrType); - } - - /** - * 递归权限机构获取站点级机构 - * - * @param departList - * @param deptId - * @param list - * @return - */ - private List getStationDeptList(List departList, Long deptId, List list) { - if (null == deptId || CollectionUtil.isEmpty(departList)) { - return null; - } - departList.forEach(dept -> { - if (dept.getParentId().equals(deptId)) { - if (dept.getDeptCategory().equals(4)) { - list.add(dept.getId()); - } - getStationDeptList(departList, dept.getId(), list); - } - }); - return list; - } - - /** - * 获取参数类型站点(过滤其他站点类型) - * - * @param refDepList - * @return - */ - private List getWaterList(List refDepList, List types, Integer servrType) { - if (CollectionUtil.isEmpty(refDepList)) { - return null; - } - // 查询水利站点,过滤其他类型站点 - return this.getStationType(servrType, types, refDepList); - - } - - /** - * 获取首页站点列表 - * - * @param deptId - * @param types - * @param serveType - * @return - */ - @Override - public List getHomeStationList(Long deptId, List types, Integer serveType) { - R> result = sysClient.getDeptByCurrentUser(); - if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { - return null; - } - return this.getStationList(result.getData(), deptId, types, serveType); - } - - @Override - public List getRefDeptByCodes(List list, String type) { - return this.baseMapper.getRefDeptByCodes(list, type); - } - - /** - * 根据机构获取站点 - * - * @param refDeptList - * @return - */ - @Override - public List getStationByRefDept(List refDeptList) { - return this.baseMapper.getStationByRefDept(refDeptList); - } - - @Override - public Integer getStationMaxOrder() { - return this.baseMapper.getStationMaxOrder(); - } - - /** - * @return - */ - @Override - public List getStationCount() { - return this.baseMapper.getStationCount(); - } - - /** - * 通过站点编辑所属机构 - * @param stationEntity 站点信息 - * @return - */ - private boolean buildDept(StationEntity stationEntity) { - //若所属机构不为空 则说明机构已建 获取所属机构 - Dept request = new Dept(); - if(Func.isNotEmpty(stationEntity.getRefDept())) { - R deptResult = sysClient.getDept(stationEntity.getRefDept()); - if(deptResult.isSuccess() && Func.isNotEmpty(deptResult.getData())) { - request = deptResult.getData(); - } - } - request.setStationId(stationEntity.getCode()); - request.setTenantId(AuthUtil.getTenantId()); - request.setFullName(stationEntity.getName()); - request.setDeptName(stationEntity.getName()); - request.setParentId(stationEntity.getHigherDept()); - request.setDeptCategory(StationConstants.DeptCategoryEnum.STATION.getValue()); - request.setSort(1); - R buildResult = deptClient.createOrUpdateDept(request); - if(buildResult.isSuccess()) { - // 所属机构回传 - R deptByStation = sysClient.getDeptByStation(request.getStationId(), AuthUtil.getTenantId()); - stationEntity.setRefDept(Optional.ofNullable(deptByStation).map(R::getData).map(Dept::getId).orElse(null)); - } - return buildResult.isSuccess(); - } - - /** - * 查询下拉列表站点 - * @param type - * @param serveType - * @return - */ - @Override - public List select(Integer type, Integer serveType) { - List types; - if(ObjectUtil.isEmpty(type)){ - types = HomePageConstant.types; - }else if(HomePageConstant.WATER_CONSERVANCY.equals(type)){ - types = HomePageConstant.waterList; - }else{ - types = Collections.singletonList(type); - } - List serveTypes; - if(ObjectUtil.isEmpty(serveType)){ - serveTypes = Arrays.asList(HomePageConstant.HYDROPOWER_SERVETYPE,HomePageConstant.CLOUD_SERVETYPE); - }else{ - serveTypes = Collections.singletonList(serveType); - } - return this.list(Wrappers.lambdaQuery() - .in(StationEntity::getType, types) - .in(StationEntity::getServeType,serveTypes) - ); - } - - @Override - public StationEntity getOne(StationEntity request) { - LambdaQueryWrapper queryWrapper = Condition.getQueryWrapper(new StationEntity(), request); - if(Func.isNotEmpty(request.getStatus())) { - queryWrapper.eq(StationEntity::getStatus,request.getStatus()); - } - List list = this.list(queryWrapper); - if(CollectionUtil.isNotEmpty(list) && list.size() > 1) { - throw new ServiceException("获取站点数量超过一条"); - } - return list.size() > 0 ? list.get(0) : null; - } - - /** - * 删除新建站点时绑定的数据(项目、智能诊断站点) - * @param idList id集合 - */ - private void deleteStation(List idList) { - LambdaQueryWrapper lqw = Wrappers.lambdaQuery().in(StationEntity::getId, idList); - List stationEntityList = this.list(lqw); + private final ISysClient sysClient; + private final IDeptClient deptClient; + private final UserAuthDataService userAuthDataService; + private final IUserClient userClient; + private final ProjectClient projectClient; + private final BladeLogger logger; + private final IQuestionClient questionClient; + + @Override + public void buildStation(StationEntity req) { + // 新建站点的所属机构 + Assert.isTrue(this.buildDept(req), () -> { + throw new ServiceException("创建/修改机构失败!"); + }); + LambdaQueryWrapper lwq; + if (Func.isEmpty(req.getId())) { + lwq = Wrappers.lambdaQuery() + .eq(StationEntity::getCode, req.getCode()).or().eq(StationEntity::getName, req.getName()); + } else { + lwq = Wrappers.lambdaQuery().ne(StationEntity::getId, req.getId()) + .and(wrapper -> wrapper.eq(StationEntity::getCode, req.getCode()).or().eq(StationEntity::getName, req.getName())); + } + + List list = super.list(lwq); + Assert.isTrue(CollectionUtil.isEmpty(list), () -> { + throw new ServiceException("该站点名/编码已有对应记录,请找到相应记录做修改处理"); + }); + Optional sort = Optional.ofNullable(this.getStationMaxOrder()); + req.setSort(sort.isPresent() ? sort.get() + 1 : 1); + Assert.isTrue(this.saveOrUpdate(req), () -> { + throw new ServiceException("创建/修改站点信息失败!"); + }); + // 如果设备数据来源未选定其他 则进行站点初始化操作 + if (!StationConstants.HZ3000_OTHER.equals(req.getDataSource())) { + // 智能诊断站点推送 + ExecutorService executor = Executors.newSingleThreadExecutor(); + executor.submit(() -> questionClient.submitStationInfo(req.getCode(), "")); + // 新建项目 + executor.submit(() -> this.instanceProject(req)); + } + } + + @Override + public boolean instanceProject(StationEntity req) { + if (Func.isEmpty(req.getSecretKey()) || Func.isEmpty(req.getDataSource())) { + return true; + } + if (super.updateById(req)) { + ProjectDTO projectDTO = new ProjectDTO(); + projectDTO.setName(req.getName()); + projectDTO.setSource(1); + projectDTO.setSecretKey(req.getSecretKey()); + projectDTO.setListenKind(req.getDataSource()); + projectDTO.setId(req.getCode()); + Result result = projectClient.saveOrUpdate(projectDTO); + logger.info("operational:station:buildStation:" + req.getCode(), JSON.toJSONString(result)); + return result.getCode() == ResultCode.SUCCESS.getCode() && result.isSuccess(); + } + return false; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean removeStation(String id) { + StationEntity stationEntity = this.getById(id); + boolean saveFlag = this.removeById(Long.valueOf(id)); + if (saveFlag) { + // 删除数据平台项目 + Result dataDelete = projectClient.delete(stationEntity.getCode()); + Assert.isTrue(dataDelete.isSuccess(), () -> { + logger.error("hzims-operational:station:removeStation", stationEntity.getCode() + "删除失败,报错信息为:" + dataDelete.getMsg()); + throw new ServiceException("数据平台删除项目失败!"); + }); + // 删除所属机构 + R deptResult = sysClient.getDept(stationEntity.getRefDept()); + if (deptResult.isSuccess() && ObjectUtil.isNotEmpty(deptResult.getData())) { + deptClient.deleteDeptById(stationEntity.getRefDept()); + } + // 删除智能诊断站点 + questionClient.deleteStationInfo(stationEntity.getCode()); + } + return saveFlag; + } + + @Override + public IPage list(StationEntity req, Query query) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() {{ + if (StringUtils.isNotBlank(req.getCode())) { + like(StationEntity::getCode, "%".concat(req.getCode()).concat("%")); + } + if (StringUtils.isNotBlank(req.getName())) { + like(StationEntity::getName, "%".concat(req.getName()).concat("%")); + } + if (ObjectUtil.isNotEmpty(req.getType())) { + eq(StationEntity::getType, req.getType()); + } + if (ObjectUtil.isNotEmpty(req.getEnableControl())) { + eq(StationEntity::getEnableControl, req.getEnableControl()); + } + if (ObjectUtil.isNotEmpty(req.getRefDomain())) { + eq(StationEntity::getRefDomain, req.getRefDomain()); + } + if (ObjectUtil.isNotEmpty(req.getRefBasin())) { + eq(StationEntity::getRefBasin, req.getRefBasin()); + } + if (ObjectUtil.isNotEmpty(req.getRefArea())) { + eq(StationEntity::getRefArea, req.getRefArea()); + } + if (ObjectUtil.isNotEmpty(req.getAreaCode())) { + eq(StationEntity::getAreaCode, req.getAreaCode()); + } + if (ObjectUtil.isNotEmpty(req.getRefDept())) { + eq(StationEntity::getRefDept, req.getRefDept()); + } + if (ObjectUtil.isNotEmpty(req.getRemark())) { + like(StationEntity::getRemark, "%".concat(req.getRemark()).concat("%")); + } + if (ObjectUtil.isNotEmpty(req.getStartDate())) { + ge(StationEntity::getCreateTime, req.getStartDate()); + } + if (ObjectUtil.isNotEmpty(req.getEndDate())) { + le(StationEntity::getCreateTime, req.getEndDate()); + } + //orderByAsc(StationEntity::getCreateTime); + }}; + queryWrapper.orderByDesc(StationEntity::getSort); + queryWrapper.orderByDesc(StationEntity::getUpdateTime); + IPage pages = super.page(Condition.getPage(query), queryWrapper); + IPage vos = StationWrapper.builder().pageVO(pages); + return vos; + } + + @Override + public List getUsersByStationId(String stationId) { + List userList = new ArrayList<>(); + StationEntity stationEntity = this.getStationByCode(stationId); + if (ObjectUtil.isNotEmpty(stationEntity) && Func.isNotEmpty(stationEntity.getRefDept())) { + //获取拥有站点机构下权限的人员列表 + R> listR = userClient.userListByDeptAndChildrenWithAuth(stationEntity.getRefDept()); + if (listR.isSuccess() && CollectionUtil.isNotEmpty(listR.getData())) { + userList = listR.getData(); + } + } + return userList; + } + + @Override + public boolean updateById(StationEntity req) { + return super.update(Wrappers.lambdaUpdate() + .set(StationEntity::getCode, req.getCode()) + .set(StationEntity::getName, req.getName()) + .set(StationEntity::getType, req.getType()) + .set(StationEntity::getCommissionTime, req.getCommissionTime()) + .set(StationEntity::getEnableControl, req.getEnableControl()) + .set(StationEntity::getLgtd, req.getLgtd()) + .set(StationEntity::getLttd, req.getLttd()) + .set(StationEntity::getRefDept, req.getRefDept()) + .set(StationEntity::getAreaCode, req.getAreaCode()) + .set(StationEntity::getRefDomain, req.getRefDomain()) + .set(StationEntity::getRefBasin, req.getRefBasin()) + .set(StationEntity::getRefArea, req.getRefArea()) + .set(StationEntity::getRemark, req.getRemark()) + .set(StationEntity::getPic, req.getPic()) + .set(StationEntity::getContact, req.getContact()) + .set(StationEntity::getContactor, req.getContactor()) + .set(StationEntity::getAddress, req.getAddress()) + .set(StationEntity::getCompany, req.getCompany()) + .set(StationEntity::getCreateDept, req.getCreateDept()) + .set(StationEntity::getServeType, req.getServeType()) + .set(StationEntity::getLimitWaterLevel, req.getLimitWaterLevel()) + .eq(StationEntity::getId, req.getId())); + } + + + @Override + public List getInRefDept(List depeIds, String stationType, List types) { + return this.baseMapper.selectInRefDept(depeIds, stationType, types); + } + + @Override + public List getLikeRefDept(Long deptId, String stationType, List types) { + return this.baseMapper.selectLikeRefDept(deptId, stationType, types); + } + + @Override + public List getEqualToRefDept(Long deptId, String stationType, List types) { + return this.baseMapper.selectEqualToRefDept(deptId, stationType, types); + } + + @Override + public List getForEachRefDept(List deptIds, String stationType, List types) { + return this.baseMapper.selectForEachRefDept(deptIds, stationType, types); + } + + + @Override + public StationEntity getStationByCodeAndUser(String stationId, Long userId) { + ControlUsersMapper usersMapper = SpringUtil.getBean("controlUsersMapper"); + List controlUsersEntities = usersMapper.selectList( + Wrappers.lambdaQuery().eq(ControlUsersEntity::getStationId, stationId) + ); + List deptIds = new ArrayList<>(); + StationEntity stationEntity = this.baseMapper.getStationByCode(stationId, deptIds, null); + Assert.isTrue(ObjectUtil.isNotEmpty(stationEntity), () -> { + throw new ServiceException("未查询到相关站点"); + }); + if (CollectionUtil.isNotEmpty(controlUsersEntities)) { + List codeList = controlUsersEntities.stream().filter(c -> stationId.equals(c.getStationId())).filter(c -> { + return Func.toLongList(c.getUserIds()).contains(userId); + }).collect(Collectors.toList()); + ControlUsersEntity object = codeList.size() > 0 ? codeList.get(0) : null; + if (ObjectUtil.isNotEmpty(object)) { + return StationEntity.builder().code(stationId).enableControl(2).build(); + } else { + stationEntity.setEnableControl(0); + return stationEntity; + } + } else { + return stationEntity; + } + } + + @Override + public StationEntity getStationByCodeOrRefDept(String stationId, Long deptId) { + return this.baseMapper.getStationByCodeOrRefDept(stationId, deptId); + } + + @Override + public StationEntity getStationByStationCode(String stationId) { + if (Func.isEmpty(AuthUtil.getUserId())) { + return this.baseMapper.getStationByCode(stationId, null, null); + } + StationEntity stationEntity = this.getStationByCodeAndUser(stationId, AuthUtil.getUserId()); + return stationEntity; + } + + @Override + public StationVO getStationByCode(String code) { + StationEntity stationEntity = this.baseMapper.getStationByCode(code, null, null); + return ObjectUtil.isNotEmpty(stationEntity) ? StationWrapper.builder().entityVO(stationEntity) : null; + } + + + @Override + public int getInRefDeptStationCount(List perSeDeptIds, String refDomain, String type, List deptIds) { + return this.baseMapper.selectInRefDeptStationCount(perSeDeptIds, refDomain, type, deptIds); + } + + @Override + public int getLikeRefDeptStationCount(Long deptId, String refDomain, String type, List deptIds) { + return this.baseMapper.selectLikeRefDeptStationCount(deptId, refDomain, type, deptIds); + } + + @Override + public int getEqualToRefDeptStationCount(Long deptId, String refDomain, String type, List deptIds) { + return this.baseMapper.selectEqualToRefDeptStationCount(deptId, refDomain, type, deptIds); + } + + @Override + public int getForEachRefDeptStationCount(List perSeDeptIds, String refDomain, String type, List deptIds) { + return this.baseMapper.selectForEachRefDeptStationCount(perSeDeptIds, refDomain, type, deptIds); + } + + @Override + public List getAll() { + return this.baseMapper.selectAll(); + } + + /** + * 根据用户全选获取站点数据 + * + * @param user + * @return + */ + @Override + public List getStationByUserAuth(BladeUser user) { + List list = new ArrayList<>(); + if (user.getDataScopeType().equals(OperationalConstants.UserDataScopeTypeEnum.EMPLOYER_VISIBLE.getVal()) && StringUtil.isNotBlank(user.getDeptId())) {//所属机构 + list = this.baseMapper.selectEqualToRefDeptStationData(Long.valueOf(user.getDeptId())); + } else if ((user.getDataScopeType().equals(OperationalConstants.UserDataScopeTypeEnum.EMPLOYER_SUBORDINATE_BODY.getVal()) || user.getDataScopeType().equals(OperationalConstants.UserDataScopeTypeEnum.SELT_SUBORDINATE_BODY.getVal())) && ObjectUtil.isNotEmpty(user.getDeptId()) && StringUtil.isNotBlank(user.getDeptId())) {//所属机构及下属机构 || 个人及下属机构 + list = this.baseMapper.selectLikeRefDeptStationData(Long.valueOf(user.getDeptId())); + } else if (user.getDataScopeType().equals(OperationalConstants.UserDataScopeTypeEnum.AFFILIATE.getVal()) && StringUtil.isNotBlank(user.getDeptIds())) {//附属机构 + list = this.baseMapper.selectInRefDeptStationData(Func.toLongList(user.getDeptIds())); + } else if (user.getDataScopeType().equals(OperationalConstants.UserDataScopeTypeEnum.AFFILIATE_SUBORDINATE_BODY.getVal()) && StringUtil.isNotBlank(user.getDeptIds())) {//附属机构及下属 + list = this.baseMapper.selectForEachRefDeptStationData(Func.toLongList(user.getDeptIds())); + } + return list; + } + + /** + * 获取根据站点ID或机构ID查询站点名称 + * + * @param station true 站点ID为key false 机构ID为key + * @return + */ + @Override + public Map getKyeStationNameValueStationId(boolean station) { + Map map = new HashMap<>(); + List stationEntityList = this.baseMapper.selectKyeStationNameValueStationId(); + if (CollectionUtil.isNotEmpty(stationEntityList)) { + for (StationEntity stationEntity : stationEntityList) { + if (station) { + map.put(stationEntity.getCode(), stationEntity.getName()); + } else { + map.put(stationEntity.getRefDept().toString(), stationEntity.getName()); + } + } + } + return map; + } + + /** + * 获取根据站点ID或机构ID查询站点名称 + * + * @param station true 站点ID为key false 机构ID为key + * @return + */ + @Override + public Map getKeyStringValueStation(boolean station) { + Map map = new HashMap<>(); + List stationEntityList = this.baseMapper.selectKyeStationNameValueStationId(); + if (CollectionUtil.isNotEmpty(stationEntityList)) { + for (StationEntity stationEntity : stationEntityList) { + if (station) { + map.put(stationEntity.getCode(), stationEntity); + } else { + map.put(stationEntity.getRefDept().toString(), stationEntity); + } + } + } + return map; + } + + /** + * 站点统计 + * + * @return + */ + @Override + public List getStationTypeGroupCount(Integer serveType) { + return this.baseMapper.selectStationTypeGroupCount(serveType); + } + + @Override + public List getRefDeptByStationId(Integer stationType, Integer serveType) { + return this.baseMapper.selectRefDeptByStationId(stationType, serveType); + } + + /** + * 根据云服务类型查询站点Id + * + * @param serveType + * @return + */ + @Override + public List getStationIdByServeType(Integer stationType, Integer serveType) { + return this.baseMapper.selectStationIdByServeType(stationType, serveType); + } + + @Override + public List getStationIdAndDeptByType(Integer stationType, Integer serveType) { + return this.baseMapper.selectStationIdAndDeptByType(stationType, serveType); + } + + @Override + public List getStationByType(Integer stationType, Integer serveType) { + return this.baseMapper.selectStationByType(stationType, serveType); + } + + @Override + public List doListByServeType(Integer serveType) { + return this.baseMapper.selectListByServeType(serveType); + } + + @Override + public List getStationByInCode(List codes) { + return this.baseMapper.selectStationByInCode(codes); + } + + @Override + public List getStationType(Integer serveType, List typeList, List departIdList) { + return this.list(new LambdaQueryWrapper() {{ + eq(StationEntity::getIsDeleted, 0); + if (ObjectUtil.isNotEmpty(serveType)) { + eq(StationEntity::getServeType, serveType); + } + if (CollectionUtil.isNotEmpty(typeList)) { + in(StationEntity::getType, typeList); + } + if (CollectionUtil.isNotEmpty(departIdList)) { + in(StationEntity::getRefDept, departIdList); + } + }}); + } + + /** + * 根据条件 服务类型及站点类型查询站点数据 + * + * @param serverType + * @param isType true is not null \ false is null + * @return + */ + @Override + public List getStationByServerTypeAndIsType(Integer serverType, Boolean isType) { + return this.baseMapper.getStationByTypeAndIsType(serverType, isType); + } + + /** + * 获取机构下站点集合 + * + * @param deptId + * @param types + * @param servrType + * @return + */ + @Override + public List getStationList(List authList, Long deptId, List types, Integer servrType) { + Dept dept; + if (null == deptId) { + // 最小类型机构 + Optional min = authList.stream().min(Comparator.comparing(Dept::getDeptCategory)); + dept = min.isPresent() ? min.get() : null; + if (ObjectUtil.isEmpty(dept)) { + return null; + } + } else { + // 检查是否存在传入机构 + List list = authList.stream().filter(o -> deptId.equals(o.getId())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(list)) { + return null; + } + // 传入机构为站点 + dept = list.get(0); + } + List refDepList; + if (dept.getDeptCategory().equals(4)) { + refDepList = Collections.singletonList(dept.getId()); + // 传入机构为区域、省子公司、集团 + } else { + // 递归权限机构获取站点级机构 + refDepList = this.getStationDeptList(authList, dept.getId(), new ArrayList<>()); + } + // 获取水利站点(过滤其他站点类型) + return this.getWaterList(refDepList, types, servrType); + } + + /** + * 递归权限机构获取站点级机构 + * + * @param departList + * @param deptId + * @param list + * @return + */ + private List getStationDeptList(List departList, Long deptId, List list) { + if (null == deptId || CollectionUtil.isEmpty(departList)) { + return null; + } + departList.forEach(dept -> { + if (dept.getParentId().equals(deptId)) { + if (dept.getDeptCategory().equals(4)) { + list.add(dept.getId()); + } + getStationDeptList(departList, dept.getId(), list); + } + }); + return list; + } + + /** + * 获取参数类型站点(过滤其他站点类型) + * + * @param refDepList + * @return + */ + private List getWaterList(List refDepList, List types, Integer servrType) { + if (CollectionUtil.isEmpty(refDepList)) { + return null; + } + // 查询水利站点,过滤其他类型站点 + return this.getStationType(servrType, types, refDepList); + + } + + /** + * 获取首页站点列表 + * + * @param deptId + * @param types + * @param serveType + * @return + */ + @Override + public List getHomeStationList(Long deptId, List types, Integer serveType) { + R> result = sysClient.getDeptByCurrentUser(); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + return null; + } + return this.getStationList(result.getData(), deptId, types, serveType); + } + + @Override + public List getRefDeptByCodes(List list, String type) { + return this.baseMapper.getRefDeptByCodes(list, type); + } + + /** + * 根据机构获取站点 + * + * @param refDeptList + * @return + */ + @Override + public List getStationByRefDept(List refDeptList) { + return this.baseMapper.getStationByRefDept(refDeptList); + } + + @Override + public Integer getStationMaxOrder() { + return this.baseMapper.getStationMaxOrder(); + } + + /** + * @return + */ + @Override + public List getStationCount() { + return this.baseMapper.getStationCount(); + } + + /** + * 通过站点编辑所属机构 + * + * @param stationEntity 站点信息 + * @return + */ + private boolean buildDept(StationEntity stationEntity) { + //若所属机构不为空 则说明机构已建 获取所属机构 + Dept request = new Dept(); + if (Func.isNotEmpty(stationEntity.getRefDept())) { + R deptResult = sysClient.getDept(stationEntity.getRefDept()); + if (deptResult.isSuccess() && Func.isNotEmpty(deptResult.getData())) { + request = deptResult.getData(); + } + } + request.setStationId(stationEntity.getCode()); + request.setTenantId(AuthUtil.getTenantId()); + request.setFullName(stationEntity.getName()); + request.setDeptName(stationEntity.getName()); + request.setParentId(stationEntity.getHigherDept()); + request.setDeptCategory(StationConstants.DeptCategoryEnum.STATION.getValue()); + request.setSort(1); + R buildResult = deptClient.createOrUpdateDept(request); + if (buildResult.isSuccess()) { + // 所属机构回传 + R deptByStation = sysClient.getDeptByStation(request.getStationId(), AuthUtil.getTenantId()); + stationEntity.setRefDept(Optional.ofNullable(deptByStation).map(R::getData).map(Dept::getId).orElse(null)); + } + return buildResult.isSuccess(); + } + + /** + * 查询下拉列表站点 + * + * @param type + * @param serveType + * @return + */ + @Override + public List select(Integer type, Integer serveType) { + List types; + if (ObjectUtil.isEmpty(type)) { + types = HomePageConstant.types; + } else if (HomePageConstant.WATER_CONSERVANCY.equals(type)) { + types = HomePageConstant.waterList; + } else { + types = Collections.singletonList(type); + } + List serveTypes; + if (ObjectUtil.isEmpty(serveType)) { + serveTypes = Arrays.asList(HomePageConstant.HYDROPOWER_SERVETYPE, HomePageConstant.CLOUD_SERVETYPE); + } else { + serveTypes = Collections.singletonList(serveType); + } + return this.list(Wrappers.lambdaQuery() + .in(StationEntity::getType, types) + .in(StationEntity::getServeType, serveTypes) + ); + } + + @Override + public StationEntity getOne(StationEntity request) { + LambdaQueryWrapper queryWrapper = Condition.getQueryWrapper(new StationEntity(), request); + if (Func.isNotEmpty(request.getStatus())) { + queryWrapper.eq(StationEntity::getStatus, request.getStatus()); + } + List list = this.list(queryWrapper); + if (CollectionUtil.isNotEmpty(list) && list.size() > 1) { + throw new ServiceException("获取站点数量超过一条"); + } + return list.size() > 0 ? list.get(0) : null; + } + + /** + * 删除新建站点时绑定的数据(项目、智能诊断站点) + * + * @param idList id集合 + */ + private void deleteStation(List idList) { + LambdaQueryWrapper lqw = Wrappers.lambdaQuery().in(StationEntity::getId, idList); + List stationEntityList = this.list(lqw); // if(CollectionUtil.isNotEmpty(stationEntityList)) { // stationEntityList.stream().map(StationEntity::getCode).forEach(code -> projectClient.delete()); // } - } + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SafetyToolServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SafetyToolServiceImpl.java index c23e010..bc335a6 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SafetyToolServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SafetyToolServiceImpl.java @@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.zxing.BarcodeFormat; +import com.hnac.hzims.message.dto.PlanMsgRecordDto; import com.hnac.hzims.safeproduct.dto.SafetyToolBatchRecheckDTO; import com.hnac.hzims.safeproduct.dto.SafetyToolDTO; import com.hnac.hzims.safeproduct.entity.SafeProductPdf; @@ -20,6 +21,7 @@ import com.hnac.hzims.safeproduct.mapper.SafetyToolMapper; import com.hnac.hzims.safeproduct.mapper.SafetyToolRecheckMapper; import com.hnac.hzims.safeproduct.mapper.SafetyToolTypeMapper; import com.hnac.hzims.safeproduct.service.ISafetyToolService; +import com.hnac.hzims.safeproduct.template.service.TemplateService; import com.hnac.hzims.safeproduct.utils.ExcelToolListener; import com.hnac.hzims.safeproduct.utils.HtmlModule; import com.hnac.hzims.safeproduct.utils.HtmltoPdf; @@ -53,10 +55,7 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.ZoneOffset; +import java.time.*; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -70,243 +69,266 @@ import java.util.stream.IntStream; @Slf4j @RequiredArgsConstructor public class SafetyToolServiceImpl extends BaseServiceImpl implements ISafetyToolService { - private final HttpServletResponse httpServletResponse; - private final ISysClient sysClient; - private final SafetyToolTypeServiceImpl safetyToolTypeService; - private final SafetyToolMapper safetyToolMapper; - private final SafetyToolTypeMapper safetyToolTypeMapper; - private final SafetyToolRecheckMapper safetyToolRecheckMapper; - private final RedisTemplate redisTemplate; - private final IUserClient userClient; + private final HttpServletResponse httpServletResponse; + private final ISysClient sysClient; + private final SafetyToolTypeServiceImpl safetyToolTypeService; + private final SafetyToolMapper safetyToolMapper; + private final SafetyToolTypeMapper safetyToolTypeMapper; + private final SafetyToolRecheckMapper safetyToolRecheckMapper; + private final RedisTemplate redisTemplate; + private final IUserClient userClient; - @Value("${hzims.safeProduct.safeTool.sadeToolKey}") - private String sadeToolKey; - @Value("${hzims.tenantId}") - private String tenantId; - @Value("${hzims.safeProduct.safeTool.filePath}") - private String uploadPath; - @Value("${hzims.safeProduct.safeTool.modulePath}") - private String modulePath; + private final List templateService; - private static final String UPLOAD_IMG_SUFFIX = ".jpg"; + @Value("${hzims.safeProduct.safeTool.sadeToolKey}") + private String sadeToolKey; + @Value("${hzims.tenantId}") + private String tenantId; + @Value("${hzims.safeProduct.safeTool.filePath}") + private String uploadPath; + @Value("${hzims.safeProduct.safeTool.modulePath}") + private String modulePath; - @Override - public R doSave(SafetyToolEntity req) { - String toolCode = req.getToolCode(); - List list = this.list(new LambdaQueryWrapper().eq(SafetyToolEntity::getToolCode, toolCode)); - if (CollectionUtil.isNotEmpty(list)) { - return R.fail(400,String.format("编号[%s]已经被使用!", toolCode)); - } - return R.status(super.save(req)); - } + private static final String UPLOAD_IMG_SUFFIX = ".jpg"; - @Override - public R doUpdate(SafetyToolEntity req) { - String toolCode = req.getToolCode(); - SafetyToolEntity entity = safetyToolMapper.selectOne(new LambdaQueryWrapper().eq(SafetyToolEntity::getToolCode, toolCode)); - if (entity != null && !entity.getId().equals(req.getId())) { - return R.fail(400,String.format("编号[%s]已经被使用!", toolCode)); - } - return R.status(super.updateById(req)); - } + @Override + public R doSave(SafetyToolEntity req) { + String toolCode = req.getToolCode(); + List list = this.list(new LambdaQueryWrapper().eq(SafetyToolEntity::getToolCode, toolCode)); + if (CollectionUtil.isNotEmpty(list)) { + return R.fail(400, String.format("编号[%s]已经被使用!", toolCode)); + } + return R.status(super.save(req)); + } - @Override - public R> pageCondition(SafetyToolDTO req, Query query) { - IPage page = super.page(Condition.getPage(query), this.getListCondition(req)); - page.setRecords(SafetyToolWrapper.build().listVO(page.getRecords())); - return R.data(page); - } + @Override + public R doUpdate(SafetyToolEntity req) { + String toolCode = req.getToolCode(); + SafetyToolEntity entity = safetyToolMapper.selectOne(new LambdaQueryWrapper().eq(SafetyToolEntity::getToolCode, toolCode)); + if (entity != null && !entity.getId().equals(req.getId())) { + return R.fail(400, String.format("编号[%s]已经被使用!", toolCode)); + } + return R.status(super.updateById(req)); + } - @Override - public R> queryByCondition(SafetyToolDTO req) { - List list = safetyToolMapper.selectList(this.getListCondition(req)); - return R.data(SafetyToolWrapper.build().listVO(list)); - } + @Override + public R> pageCondition(SafetyToolDTO req, Query query) { + IPage page = super.page(Condition.getPage(query), this.getListCondition(req)); + page.setRecords(SafetyToolWrapper.build().listVO(page.getRecords())); + return R.data(page); + } - @Override - public void doBatchRecheck(SafetyToolBatchRecheckDTO req) { - //更新工器具记录数据 - Date currentTime = new Date(); - Long userId = AuthUtil.getUserId(); - String userName = AuthUtil.getUserName(); - List safetyTools = safetyToolMapper.selectBatchIds(req.getToolIds()); - for (SafetyToolEntity item : safetyTools) { - item.setLastCheckTime(currentTime); - item.setNextCheckTime(DateUtil.plusDays(currentTime, Long.valueOf(item.getSafeTime().toString()))); - } - if (!super.updateBatchById(safetyTools)) { - throw new RuntimeException("数据库update操作失败!"); - } + @Override + public R> queryByCondition(SafetyToolDTO req) { + List list = safetyToolMapper.selectList(this.getListCondition(req)); + return R.data(SafetyToolWrapper.build().listVO(list)); + } - //插入复核记录 - List safetyToolRechecks = new ArrayList<>(safetyTools.size()); - for (SafetyToolEntity item : safetyTools) { - SafetyToolRecheckEntity entity = new SafetyToolRecheckEntity(); - entity.setCheckUserName(userName); - entity.setCheckUserId(userId); - entity.setToolId(item.getId()); - entity.setCheckTime(currentTime); - entity.setRemark(req.getRemark()); - safetyToolRechecks.add(entity); - } - if (safetyToolRecheckMapper.insertBatch(safetyToolRechecks) == 0) { - throw new RuntimeException("数据库insert操作失败!"); - } - } + @Override + public void doBatchRecheck(SafetyToolBatchRecheckDTO req) { + //更新工器具记录数据 + Date currentTime = new Date(); + Long userId = AuthUtil.getUserId(); + String userName = AuthUtil.getUserName(); + List safetyTools = safetyToolMapper.selectBatchIds(req.getToolIds()); + for (SafetyToolEntity item : safetyTools) { + item.setLastCheckTime(currentTime); + item.setNextCheckTime(DateUtil.plusDays(currentTime, Long.valueOf(item.getSafeTime().toString()))); - @Override - public void exportExcel(SafetyToolDTO req) { - List list = safetyToolMapper.selectList(this.getListCondition(req)); - List data = SafetyToolWrapper.build().entityExcelList(list, sysClient, safetyToolTypeMapper); - ExcelUtil.export(httpServletResponse, "安全工器具" + System.currentTimeMillis(), "安全工器具", data, SafetyToolExcel.class); - } + String noticeUsers = item.getNoticeUsers(); + if (!StringUtils.isEmpty(noticeUsers)) { + String[] split = noticeUsers.split(","); + for (String s : split) { + PlanMsgRecordDto planMsgRecordDtoDto = new PlanMsgRecordDto(); + planMsgRecordDtoDto.setTemplateId(item.getMessageTemplateId()); + planMsgRecordDtoDto.setTaskId(item.getId()); + planMsgRecordDtoDto.setDeptId(item.getCurSts()); + planMsgRecordDtoDto.setCreateUser(item.getCreateUser()); + planMsgRecordDtoDto.setReceiver(Long.valueOf(s)); + ZoneId zoneId = ZoneId.systemDefault(); + Date nextCheckTime = item.getNextCheckTime(); + planMsgRecordDtoDto.setPlanTime(nextCheckTime.toInstant().atZone(zoneId).toLocalDateTime()); + TemplateService templateService1 = + templateService.stream().filter(item1 -> item1.isTemplateStatus(1)).findFirst().orElse(null); + templateService1.execute(planMsgRecordDtoDto); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void importExcel(MultipartFile file,Long createDept) { - String filename = file.getOriginalFilename(); - ExcelToolListener excelToolListener = new ExcelToolListener(); - if (StringUtils.isEmpty(filename)) { - throw new ExcelException("请上传文件!"); - } else if (!StringUtils.endsWithIgnoreCase(filename, ".xls") && !StringUtils.endsWithIgnoreCase(filename, ".xlsx")) { - throw new ExcelException("请上传正确的excel文件!"); - } else { - try { - InputStream inputStream = new BufferedInputStream(file.getInputStream()); - com.hnac.hzims.safeproduct.utils.ExcelUtil.asyncReadModel(inputStream, excelToolListener,SafetyToolSaveExcel.class,0,1); - } catch (IOException e) { - e.printStackTrace(); - } - } - List dataList = excelToolListener.getDataList(); - if(CollectionUtil.isNotEmpty(dataList)){ - List entityList = new ArrayList<>(); - Map> map = JSONArray.parseArray(JSON.toJSONString(dataList),SafetyToolEntity.class).stream() - .filter(entity -> Func.isNotEmpty(entity.getToolCode())).collect(Collectors.groupingBy(SafetyToolEntity::getToolCode)); - Assert.isTrue(CollectionUtil.isNotEmpty(map),()->{ - throw new ServiceException("填入工器具编码不能为空"); - }); - IntStream.iterate(0,index->index+1).limit(dataList.size()).forEachOrdered(index->{ - SafetyToolEntity entity = BeanUtil.copy(dataList.get(index),SafetyToolEntity.class); - SafetyToolSaveExcel safetyToolSaveExcel = JSONObject.parseObject(JSON.toJSONString(dataList.get(index)),SafetyToolSaveExcel.class); - Assert.isTrue(Func.isNotEmpty(entity.getToolCode()) && Func.isNotEmpty(entity.getToolName()) - && Func.isNotEmpty(entity.getSafeTime()) && Func.isNotEmpty(safetyToolSaveExcel.getTypeName()),()->{ - throw new ServiceException("第"+ index+"填入数据部分缺失,请修改后重新导入"); - }); - List list = this.list(new LambdaQueryWrapper().eq(SafetyToolEntity::getToolCode, entity.getToolCode())); - if (CollectionUtil.isNotEmpty(list) || (CollectionUtil.isNotEmpty(map.get(entity.getToolCode())) && map.get(entity.getToolCode()).size() > 1)) { - throw new ServiceException(String.format("编号[%s]已经被使用!", entity.getToolCode())); - } - List safetyToolTypeEntityList = safetyToolTypeService.list(Wrappers.lambdaQuery() - .eq(SafetyToolTypeEntity::getTypeName, safetyToolSaveExcel.getTypeName())); - Assert.isTrue(safetyToolTypeEntityList.size() > 0,()->{ - throw new ServiceException("第"+ index+"行填入类型未找到相关记录,请修改后重新导入"); - }); - //验证账户 - String userIds = Arrays.stream(safetyToolSaveExcel.getAccounts().split(",")).map(account -> { - R userR = userClient.userByAccount(AuthUtil.getTenantId(), account); - Assert.isTrue(userR.isSuccess() && ObjectUtil.isNotEmpty(userR.getData()), () -> { - throw new ServiceException("第" + index + "行填入用户账号未找到相关记录,请修改后重新导入"); - }); - return userR.getData(); - }).map(User::getId).map(id -> Func.isNotEmpty(id) ? id.toString() : "").collect(Collectors.joining(",")); - entity.setNoticeUsers(userIds); - entity.setTypeId(safetyToolTypeEntityList.get(0).getId()); - entity.setSendType(safetyToolTypeEntityList.get(0).getSendType()); - entity.setCurSts(createDept); - entityList.add(entity); - }); - this.saveBatch(entityList); - } - } + } - /** - * 安全工器具二维码导出 - * @param idList - * @return 文件路径 - */ - @Override - public String safetyToolRQExport(List idList){ - List entityList = null; - if(CollectionUtil.isNotEmpty(idList)){ - entityList = list(new LambdaQueryWrapper(){{ - in(SafetyToolEntity::getId,idList); - orderByDesc(SafetyToolEntity::getCreateTime); - }}); - } - else{ - entityList = page(Condition.getPage(new Query()),new LambdaQueryWrapper()).getRecords(); - } - if(CollectionUtil.isNotEmpty(entityList)){ - List pdfList = new ArrayList<>(entityList.size()); - entityList.forEach(entity->{ - String imgPath = uploadPath + "/" + entity.getTenantId() + entity.getToolCode() + UPLOAD_IMG_SUFFIX; - File file = new File(imgPath); - if (!file.exists()) { - /**生成二维码**/ - ZXingGenCode.encode("AQQJ=" + entity.getId(), 200, 200, imgPath, BarcodeFormat.QR_CODE); - } + } + if (!super.updateBatchById(safetyTools)) { + throw new RuntimeException("数据库update操作失败!"); + } - SafeProductPdf safeProductPdf = new SafeProductPdf(); - safeProductPdf.setData_1(entity.getToolName()); - safeProductPdf.setData_2(DateUtil.format(entity.getCreateTime(),"yyyy年MM月dd日")); - safeProductPdf.setData_3(imgPath); - pdfList.add(safeProductPdf); - }); + //插入复核记录 + List safetyToolRechecks = new ArrayList<>(safetyTools.size()); + for (SafetyToolEntity item : safetyTools) { + SafetyToolRecheckEntity entity = new SafetyToolRecheckEntity(); + entity.setCheckUserName(userName); + entity.setCheckUserId(userId); + entity.setToolId(item.getId()); + entity.setCheckTime(currentTime); + entity.setRemark(req.getRemark()); + safetyToolRechecks.add(entity); + } + if (safetyToolRecheckMapper.insertBatch(safetyToolRechecks) == 0) { + throw new RuntimeException("数据库insert操作失败!"); + } - /**二维码写入html文件中成功后生成pdf文件地址**/ - String pdfPath = uploadPath + "/" + UUID.randomUUID().toString() + ".pdf"; - try{ - /**将生成二维码写入html文件内**/ - String html = HtmlModule.buildHtml(pdfList, modulePath); - HtmltoPdf.htmlToPdf(html, pdfPath); - return pdfPath; - } - catch (Exception e){ - throw new ServiceException("导出pdf发生异常:"+e.getMessage()); - } - } - else{ - return null; - } - } - @Override - public R remove(List idList) { - List toolEntityList = list(new LambdaQueryWrapper(){{ - in(SafetyToolEntity::getId,idList); - isNotNull(SafetyToolEntity::getNextCheckTime); - orderByDesc(SafetyToolEntity::getNextCheckTime); - }}); - return R.status(deleteLogic(idList)); - } + } + @Override + public void exportExcel(SafetyToolDTO req) { + List list = safetyToolMapper.selectList(this.getListCondition(req)); + List data = SafetyToolWrapper.build().entityExcelList(list, sysClient, safetyToolTypeMapper); + ExcelUtil.export(httpServletResponse, "安全工器具" + System.currentTimeMillis(), "安全工器具", data, SafetyToolExcel.class); + } - /** - * 工器具Code唯一性校验 - */ - private void toolCodeUniquenessCheck(Long id, String toolCode) { - SafetyToolEntity entity = safetyToolMapper.selectOne(new LambdaQueryWrapper().eq(SafetyToolEntity::getToolCode, toolCode)); - if (entity != null && !entity.getId().equals(id)) { - throw new RuntimeException(String.format("编号[%s]已经被使用!", toolCode)); - } - } + @Override + @Transactional(rollbackFor = Exception.class) + public void importExcel(MultipartFile file, Long createDept) { + String filename = file.getOriginalFilename(); + ExcelToolListener excelToolListener = new ExcelToolListener(); + if (StringUtils.isEmpty(filename)) { + throw new ExcelException("请上传文件!"); + } else if (!StringUtils.endsWithIgnoreCase(filename, ".xls") && !StringUtils.endsWithIgnoreCase(filename, ".xlsx")) { + throw new ExcelException("请上传正确的excel文件!"); + } else { + try { + InputStream inputStream = new BufferedInputStream(file.getInputStream()); + com.hnac.hzims.safeproduct.utils.ExcelUtil.asyncReadModel(inputStream, excelToolListener, SafetyToolSaveExcel.class, 0, 1); + } catch (IOException e) { + e.printStackTrace(); + } + } + List dataList = excelToolListener.getDataList(); + if (CollectionUtil.isNotEmpty(dataList)) { + List entityList = new ArrayList<>(); + Map> map = JSONArray.parseArray(JSON.toJSONString(dataList), SafetyToolEntity.class).stream() + .filter(entity -> Func.isNotEmpty(entity.getToolCode())).collect(Collectors.groupingBy(SafetyToolEntity::getToolCode)); + Assert.isTrue(CollectionUtil.isNotEmpty(map), () -> { + throw new ServiceException("填入工器具编码不能为空"); + }); + IntStream.iterate(0, index -> index + 1).limit(dataList.size()).forEachOrdered(index -> { + SafetyToolEntity entity = BeanUtil.copy(dataList.get(index), SafetyToolEntity.class); + SafetyToolSaveExcel safetyToolSaveExcel = JSONObject.parseObject(JSON.toJSONString(dataList.get(index)), SafetyToolSaveExcel.class); + Assert.isTrue(Func.isNotEmpty(entity.getToolCode()) && Func.isNotEmpty(entity.getToolName()) + && Func.isNotEmpty(entity.getSafeTime()) && Func.isNotEmpty(safetyToolSaveExcel.getTypeName()), () -> { + throw new ServiceException("第" + index + "填入数据部分缺失,请修改后重新导入"); + }); + List list = this.list(new LambdaQueryWrapper().eq(SafetyToolEntity::getToolCode, entity.getToolCode())); + if (CollectionUtil.isNotEmpty(list) || (CollectionUtil.isNotEmpty(map.get(entity.getToolCode())) && map.get(entity.getToolCode()).size() > 1)) { + throw new ServiceException(String.format("编号[%s]已经被使用!", entity.getToolCode())); + } + List safetyToolTypeEntityList = safetyToolTypeService.list(Wrappers.lambdaQuery() + .eq(SafetyToolTypeEntity::getTypeName, safetyToolSaveExcel.getTypeName())); + Assert.isTrue(safetyToolTypeEntityList.size() > 0, () -> { + throw new ServiceException("第" + index + "行填入类型未找到相关记录,请修改后重新导入"); + }); + //验证账户 + String userIds = Arrays.stream(safetyToolSaveExcel.getAccounts().split(",")).map(account -> { + R userR = userClient.userByAccount(AuthUtil.getTenantId(), account); + Assert.isTrue(userR.isSuccess() && ObjectUtil.isNotEmpty(userR.getData()), () -> { + throw new ServiceException("第" + index + "行填入用户账号未找到相关记录,请修改后重新导入"); + }); + return userR.getData(); + }).map(User::getId).map(id -> Func.isNotEmpty(id) ? id.toString() : "").collect(Collectors.joining(",")); + entity.setNoticeUsers(userIds); + entity.setTypeId(safetyToolTypeEntityList.get(0).getId()); + entity.setSendType(safetyToolTypeEntityList.get(0).getSendType()); + entity.setCurSts(createDept); + entityList.add(entity); + }); + this.saveBatch(entityList); + } + } - /** - * 获取列表查询条件 - */ - private Wrapper getListCondition(SafetyToolDTO req) { - return new LambdaQueryWrapper() {{ - orderByDesc(SafetyToolEntity::getCreateTime); - if (null != req.getTypeId()) { - eq(SafetyToolEntity::getTypeId, req.getTypeId()); - } - if (StringUtil.isNotBlank(req.getToolCode())) { - like(SafetyToolEntity::getToolCode, "%".concat(req.getToolCode()).concat("%")); - } - if (StringUtil.isNotBlank(req.getToolName())) { - like(SafetyToolEntity::getToolName, req.getToolName()); - } - }}; - } + /** + * 安全工器具二维码导出 + * + * @param idList + * @return 文件路径 + */ + @Override + public String safetyToolRQExport(List idList) { + List entityList = null; + if (CollectionUtil.isNotEmpty(idList)) { + entityList = list(new LambdaQueryWrapper() {{ + in(SafetyToolEntity::getId, idList); + orderByDesc(SafetyToolEntity::getCreateTime); + }}); + } else { + entityList = page(Condition.getPage(new Query()), new LambdaQueryWrapper()).getRecords(); + } + if (CollectionUtil.isNotEmpty(entityList)) { + List pdfList = new ArrayList<>(entityList.size()); + entityList.forEach(entity -> { + String imgPath = uploadPath + "/" + entity.getTenantId() + entity.getToolCode() + UPLOAD_IMG_SUFFIX; + File file = new File(imgPath); + if (!file.exists()) { + /**生成二维码**/ + ZXingGenCode.encode("AQQJ=" + entity.getId(), 200, 200, imgPath, BarcodeFormat.QR_CODE); + } + + SafeProductPdf safeProductPdf = new SafeProductPdf(); + safeProductPdf.setData_1(entity.getToolName()); + safeProductPdf.setData_2(DateUtil.format(entity.getCreateTime(), "yyyy年MM月dd日")); + safeProductPdf.setData_3(imgPath); + pdfList.add(safeProductPdf); + }); + + /**二维码写入html文件中成功后生成pdf文件地址**/ + String pdfPath = uploadPath + "/" + UUID.randomUUID().toString() + ".pdf"; + try { + /**将生成二维码写入html文件内**/ + String html = HtmlModule.buildHtml(pdfList, modulePath); + HtmltoPdf.htmlToPdf(html, pdfPath); + return pdfPath; + } catch (Exception e) { + throw new ServiceException("导出pdf发生异常:" + e.getMessage()); + } + } else { + return null; + } + } + + @Override + public R remove(List idList) { + List toolEntityList = list(new LambdaQueryWrapper() {{ + in(SafetyToolEntity::getId, idList); + isNotNull(SafetyToolEntity::getNextCheckTime); + orderByDesc(SafetyToolEntity::getNextCheckTime); + }}); + return R.status(deleteLogic(idList)); + } + + + /** + * 工器具Code唯一性校验 + */ + private void toolCodeUniquenessCheck(Long id, String toolCode) { + SafetyToolEntity entity = safetyToolMapper.selectOne(new LambdaQueryWrapper().eq(SafetyToolEntity::getToolCode, toolCode)); + if (entity != null && !entity.getId().equals(id)) { + throw new RuntimeException(String.format("编号[%s]已经被使用!", toolCode)); + } + } + + /** + * 获取列表查询条件 + */ + private Wrapper getListCondition(SafetyToolDTO req) { + return new LambdaQueryWrapper() {{ + orderByDesc(SafetyToolEntity::getCreateTime); + if (null != req.getTypeId()) { + eq(SafetyToolEntity::getTypeId, req.getTypeId()); + } + if (StringUtil.isNotBlank(req.getToolCode())) { + like(SafetyToolEntity::getToolCode, "%".concat(req.getToolCode()).concat("%")); + } + if (StringUtil.isNotBlank(req.getToolName())) { + like(SafetyToolEntity::getToolName, req.getToolName()); + } + }}; + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/abstracts/TemplateAbstractService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/abstracts/TemplateAbstractService.java new file mode 100644 index 0000000..c275b5e --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/abstracts/TemplateAbstractService.java @@ -0,0 +1,54 @@ +package com.hnac.hzims.safeproduct.template.abstracts; + +import com.hnac.hzims.message.dto.PlanMsgRecordDto; +import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzims.safeproduct.template.service.TemplateService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.annotation.Resource; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/14 14:27 + */ +@Slf4j +public abstract class TemplateAbstractService implements TemplateService { + + @Resource + private IMessageClient messageClient; + + /** + * 具体业务 + * + * @param planMsgRecord + */ + @Override + public void execute(PlanMsgRecordDto planMsgRecord) { + //1.具体的业务逻辑 + PlanMsgRecordDto list = executeTemplateMessage(planMsgRecord); + //2.保存数据 + saveData(list); + } + + /** + * 推送的数据 + * + * @param list + */ + private void saveData(PlanMsgRecordDto list) { + log.info("正在保存推送的数据"); + messageClient.planSendMessage(list); + } + + + /** + * 执行具体的业务场景,推送消息 + * + * @return + */ + public abstract PlanMsgRecordDto executeTemplateMessage(PlanMsgRecordDto planMsgRecord); +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/service/TemplateService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/service/TemplateService.java new file mode 100644 index 0000000..3af0449 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/service/TemplateService.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.safeproduct.template.service; + +import com.hnac.hzims.message.dto.PlanMsgRecordDto; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/14 14:25 + */ +public interface TemplateService { + + /** + * 模板状态 + */ + Boolean isTemplateStatus(int status); + + + /** + * 具体业务 + */ + void execute(PlanMsgRecordDto planMsgRecord); + +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/serviceimpl/MaintenanceTempleServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/serviceimpl/MaintenanceTempleServiceImpl.java new file mode 100644 index 0000000..9c1cce3 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/template/serviceimpl/MaintenanceTempleServiceImpl.java @@ -0,0 +1,55 @@ +package com.hnac.hzims.safeproduct.template.serviceimpl; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.message.dto.PlanMsgRecordDto; +import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzims.safeproduct.template.abstracts.TemplateAbstractService; +import com.qiniu.util.Json; +import org.springblade.system.user.cache.UserCache; +import org.springblade.system.user.entity.User; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +/** + * 日常维护计划 + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/14 14:48 + */ +@Service +public class MaintenanceTempleServiceImpl extends TemplateAbstractService { + + + + /** + * 执行具体的业务场景,推送消息 + * + * @return + */ + @Override + public PlanMsgRecordDto executeTemplateMessage(PlanMsgRecordDto planMsgRecord) { + Map map = new HashMap<>(); + map.put("one", + Optional.ofNullable(UserCache.getUser(planMsgRecord.getReceiver())).map(User::getName).orElse("")); + map.put("two", planMsgRecord.getPlanTime()); + planMsgRecord.setContent(JSON.toJSONString(map)); + return planMsgRecord; + } + + /** + * 模板状态 + * @param status + */ + @Override + public Boolean isTemplateStatus(int status) { + return Objects.equals(status,1); + } + + + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java index 92b7aec..0ae6d17 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java @@ -348,7 +348,7 @@ public class StandardTicketInfoServiceImpl extends BaseServiceImpl standardTicketInfoEntityPage = baseMapper.selectPages(searchPage, queryWrapper); //数据转换StandardTicketInfoEntity ==> StandardTicketVo From 2d5d304c8e367427521604bef96f72b9da13f7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Mon, 17 Apr 2023 09:25:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E7=A5=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java index f569ab3..9952803 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java @@ -902,7 +902,7 @@ public class WorkTicketInfoServiceImpl extends BaseServiceImpl workTicketInfoEntityPage = baseMapper.selectPages(pageEntity, queryWrapper); //数据转换 List standardWorkList = new ArrayList<>();