From 3a154bdb0a5aaa2c0ac3eac95a6ba747068bd454 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期二, 13 一月 2026 10:00:37 +0800
Subject: [PATCH] 优化
---
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/WarningRuleServiceImpl.java | 392 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 392 insertions(+), 0 deletions(-)
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/WarningRuleServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/WarningRuleServiceImpl.java
new file mode 100644
index 0000000..e5afe33
--- /dev/null
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/WarningRuleServiceImpl.java
@@ -0,0 +1,392 @@
+package com.doumee.service.business.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
+import com.doumee.core.haikang.model.param.request.EventSubRequest;
+import com.doumee.core.haikang.service.HKService;
+import com.doumee.core.utils.Constants;
+import com.doumee.dao.business.DeviceMapper;
+import com.doumee.dao.business.WarningMapper;
+import com.doumee.dao.business.WarningRuleDetailMapper;
+import com.doumee.dao.business.dao.MemberMapper;
+import com.doumee.dao.business.model.*;
+import com.doumee.service.business.third.model.LoginUserInfo;
+import com.doumee.service.business.third.model.PageData;
+import com.doumee.service.business.third.model.PageWrap;
+import com.doumee.core.utils.Utils;
+import com.doumee.dao.business.WarningRuleMapper;
+import com.doumee.service.business.WarningRuleService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * 鎶ヨ瑙勫垯閰嶇疆琛⊿ervice瀹炵幇
+ * @author 姹熻箘韫�
+ * @date 2025/09/28 09:01
+ */
+@Service
+public class WarningRuleServiceImpl implements WarningRuleService {
+
+ @Autowired
+ private WarningRuleMapper warningRuleMapper;
+ @Autowired
+ private WarningMapper warningMapper;
+ @Autowired
+ private MemberMapper memberMapper;
+ @Autowired
+ private DeviceMapper deviceMapper;
+ @Autowired
+ private WarningRuleDetailMapper warningRuleDetailMapper;
+
+ @Override
+ @Transactional
+ public Integer create(WarningRule warning) {
+ if(warning.getDetailList() == null
+ ||warning.getMemberIds() == null
+ ||warning.getDetailList().size() ==0){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST);
+ }
+ warning.setStatus(Constants.formatIntegerNum(warning.getStatus()));
+ warning.setIsdeleted(Constants.ZERO);
+ warning.setCreator(warning.getLoginUserInfo().getId());
+ warning.setCreateDate(new Date());
+ warning.setEditDate(warning.getCreateDate());
+ warning.setEditor(warning.getCreator());
+ String title = "";
+ for(WarningRuleDetail detail : warning.getDetailList()){
+ if(detail.getWarningId() == null){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST);
+ }
+ Warning wModel = warningMapper.selectById(detail.getWarningId());
+ if(wModel == null || Constants.equalsInteger(wModel.getIsdeleted(),Constants.ONE)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇烽�夋嫨姝g‘鐨勬姤璀︾被鍨�");
+ }
+ if(StringUtils.isNotBlank(detail.getRegionName())){
+ title+= detail.getRegionName()+"鍙戠敓";
+ }
+ title += wModel.getName()+"锛� ";
+ detail.setRuleId(warning.getId());
+ detail.setIsdeleted(Constants.ZERO);
+ detail.setCreator(warning.getLoginUserInfo().getId());
+ detail.setCreateDate(new Date());
+ detail.setEditDate(warning.getCreateDate());
+ detail.setEditor(warning.getCreator());
+ }
+
+ initMemberInfo(warning);
+ initDeviceInfo(warning);
+ warning.setTitle(title);
+ warningRuleMapper.insert(warning);
+ for(WarningRuleDetail detail : warning.getDetailList()){
+ detail.setRuleId(warning.getId());
+ }
+ warningRuleDetailMapper.insert(warning.getDetailList());
+ return warning.getId();
+ }
+
+ private String initMemberInfo(WarningRule warning) {
+ if(Constants.equalsInteger(warning.getMemberNotice(),Constants.ZERO)){
+ return null;
+ }
+ String[] members = warning.getMemberIds().split(",");
+ List<Integer> mIds = new ArrayList<>();
+ for(String str :members){
+ try {
+ mIds.add(Integer.parseInt(str));
+ }catch (Exception e){
+ }
+ }
+ if(mIds.size() ==0){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇烽�夋嫨姝g‘鐨勪汉鍛樹俊鎭�");
+ }
+ List<Member> memberList = memberMapper.selectJoinList(Member.class,new MPJLambdaWrapper<Member>()
+ .selectAll(Member.class )
+ .selectAs(Company::getName,Member::getCompanyName )
+ .leftJoin(Company.class,Company::getId,Member::getCompanyId)
+ .eq(Member::getIsdeleted,Constants.ZERO )
+ .in(Member::getId,mIds ));
+ if(memberList == null || memberList.size() ==0){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇烽�夋嫨姝g‘鐨勪汉鍛樹俊鎭�!");
+ }
+ String memberIds = "";
+ String memberNames = "";
+ for(Member m : memberList){
+ memberIds += (StringUtils.isNotBlank(memberIds)?",":"")+m.getId();
+ memberNames += StringUtils.defaultString(m.getName(),"")+"-"+StringUtils.defaultString(m.getCompanyName(),"" )+"; ";
+ }
+ warning.setMemberIds(memberIds);
+ warning.setMemberNames(memberNames);
+ return memberNames;
+ }
+ private String initDeviceInfo(WarningRule warning) {
+ if(Constants.equalsInteger(warning.getDeviceNotice(),Constants.ZERO)){
+ return null;
+ }
+ String[] ids = warning.getDeviceIds().split(",");
+ List<Integer> mIds = new ArrayList<>();
+ for(String str :ids){
+ try {
+ mIds.add(Integer.parseInt(str));
+ }catch (Exception e){
+ }
+ }
+ if(mIds.size() ==0){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇烽�夋嫨姝g‘鐨勮澶囦俊鎭�");
+ }
+ List<Device> list = deviceMapper.selectJoinList(Device.class,new MPJLambdaWrapper<Device>()
+ .selectAll(Device.class )
+ .eq(Device::getIsdeleted,Constants.ZERO )
+ .eq(Device::getType,Constants.FOUR )
+ .in(Device::getId,mIds ));
+ if(list == null || list.size() ==0){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇烽�夋嫨姝g‘鐨勮澶囦俊鎭�!");
+ }
+ String dids = "";
+ String names = "";
+ for(Device m : list){
+ dids += (StringUtils.isNotBlank(dids)?",":"")+m.getId();
+ names += StringUtils.defaultString(m.getName(),"") +"; ";
+ }
+ warning.setDeviceIds(dids);
+ warning.setDeviceNames(names);
+ return names;
+ }
+
+ @Override
+ public void deleteById(Integer id, LoginUserInfo user) {
+ warningRuleMapper.deleteById(id);
+ warningRuleMapper.update(null,new UpdateWrapper<WarningRule>().lambda()
+ .set(WarningRule::getEditor,user.getId())
+ .set(WarningRule::getEditDate,new Date())
+ .set(WarningRule::getIsdeleted,Constants.ONE)
+ .eq(WarningRule::getId,id)
+ );
+ warningRuleDetailMapper.update(null,new UpdateWrapper<WarningRuleDetail>().lambda()
+ .set(WarningRuleDetail::getEditor,user.getId())
+ .set(WarningRuleDetail::getEditDate,new Date())
+ .set(WarningRuleDetail::getIsdeleted,Constants.ONE)
+ .eq(WarningRuleDetail::getRuleId,id)
+ );
+ }
+
+ @Override
+ public void delete(WarningRule warningRule) {
+ UpdateWrapper<WarningRule> deleteWrapper = new UpdateWrapper<>(warningRule);
+ warningRuleMapper.delete(deleteWrapper);
+ }
+
+ @Override
+ @Transactional
+ public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
+ if (CollectionUtils.isEmpty(ids)) {
+ return;
+ }
+ warningRuleMapper.update(null,new UpdateWrapper<WarningRule>().lambda()
+ .set(WarningRule::getEditor,user.getId())
+ .set(WarningRule::getEditDate,new Date())
+ .set(WarningRule::getIsdeleted,Constants.ONE)
+ .in(WarningRule::getId,ids)
+ );
+ warningRuleDetailMapper.update(null,new UpdateWrapper<WarningRuleDetail>().lambda()
+ .set(WarningRuleDetail::getEditor,user.getId())
+ .set(WarningRuleDetail::getEditDate,new Date())
+ .set(WarningRuleDetail::getIsdeleted,Constants.ONE)
+ .in(WarningRuleDetail::getRuleId,ids)
+ );
+ }
+
+ @Override
+ public void updateById(WarningRule warning) {
+ if(warning.getDetailList() == null
+ ||warning.getId() == null
+ ||warning.getMemberIds() == null
+ || warning.getDetailList().size() ==0){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST);
+ }
+ warning.setEditDate(warning.getCreateDate());
+ warning.setEditor(warning.getCreator());
+ String title = "";
+ for(WarningRuleDetail detail : warning.getDetailList()){
+ if(detail.getWarningId() == null){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST);
+ }
+ Warning wModel = warningMapper.selectById(detail.getWarningId());
+ if(wModel == null || Constants.equalsInteger(wModel.getIsdeleted(),Constants.ONE)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇烽�夋嫨姝g‘鐨勬姤璀︾被鍨�");
+ }
+ if(StringUtils.isNotBlank(detail.getRegionName())){
+ title+= detail.getRegionName()+"鍙戠敓";
+ }
+ title += wModel.getName()+"锛� ";
+ detail.setRuleId(warning.getId());
+ detail.setIsdeleted(Constants.ZERO);
+ detail.setCreator(warning.getLoginUserInfo().getId());
+ detail.setCreateDate(new Date());
+ detail.setEditDate(warning.getCreateDate());
+ detail.setEditor(warning.getCreator());
+ }
+ initMemberInfo(warning);
+ initDeviceInfo(warning);
+ warning.setTitle(title);
+ warningRuleMapper.updateById(warning);
+ for(WarningRuleDetail detail : warning.getDetailList()){
+ detail.setRuleId(warning.getId());
+ }
+ warningRuleDetailMapper.delete(new UpdateWrapper<WarningRuleDetail>()
+ .lambda().eq(WarningRuleDetail::getRuleId,warning.getId()));
+ warningRuleDetailMapper.insert(warning.getDetailList());
+ }
+
+ @Override
+ public void updateByIdInBatch(List<WarningRule> warningRules) {
+ if (CollectionUtils.isEmpty(warningRules)) {
+ return;
+ }
+ for (WarningRule warningRule: warningRules) {
+ this.updateById(warningRule);
+ }
+ }
+
+ @Override
+ public WarningRule findById(Integer id) {
+ WarningRule model =warningRuleMapper.selectById(id);
+ if(model == null || Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY);
+ }
+ model.setDetailList(warningRuleDetailMapper.selectList(new LambdaQueryWrapper<WarningRuleDetail>()
+ .eq(WarningRuleDetail::getIsdeleted,Constants.ZERO)
+ .eq(WarningRuleDetail::getRuleId,model.getId())));
+ return model;
+ }
+
+ @Override
+ public WarningRule findOne(WarningRule warningRule) {
+ QueryWrapper<WarningRule> wrapper = new QueryWrapper<>(warningRule);
+ return warningRuleMapper.selectOne(wrapper);
+ }
+
+ @Override
+ public List<WarningRule> findList(WarningRule warningRule) {
+ QueryWrapper<WarningRule> wrapper = new QueryWrapper<>(warningRule);
+ return warningRuleMapper.selectList(wrapper);
+ }
+
+ @Override
+ public PageData<WarningRule> findPage(PageWrap<WarningRule> pageWrap) {
+ IPage<WarningRule> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
+
+ MPJLambdaWrapper<WarningRule> queryWrapper = new MPJLambdaWrapper<>();
+ Utils.MP.blankToNull(pageWrap.getModel());
+ pageWrap.getModel().setIsdeleted(Constants.ZERO);
+ queryWrapper.selectAll(WarningRule.class );
+ queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getMemberNames()),WarningRule::getMemberNames, pageWrap.getModel().getMemberNames());
+ queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getTitle()),WarningRule::getTitle, pageWrap.getModel().getTitle());
+ queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getDeviceNames()),WarningRule::getDeviceNames, pageWrap.getModel().getDeviceNames());
+
+ if (pageWrap.getModel().getId() != null) {
+ queryWrapper.eq(WarningRule::getId, pageWrap.getModel().getId());
+ }
+ if (pageWrap.getModel().getCreator() != null) {
+ queryWrapper.eq(WarningRule::getCreator, pageWrap.getModel().getCreator());
+ }
+ if (pageWrap.getModel().getCreateDate() != null) {
+ queryWrapper.ge(WarningRule::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
+ queryWrapper.le(WarningRule::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
+ }
+ if (pageWrap.getModel().getEditor() != null) {
+ queryWrapper.eq(WarningRule::getEditor, pageWrap.getModel().getEditor());
+ }
+ if (pageWrap.getModel().getEditDate() != null) {
+ queryWrapper.ge(WarningRule::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
+ queryWrapper.le(WarningRule::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
+ }
+ if (pageWrap.getModel().getIsdeleted() != null) {
+ queryWrapper.eq(WarningRule::getIsdeleted, pageWrap.getModel().getIsdeleted());
+ }
+ if (pageWrap.getModel().getMemberNotice() != null) {
+ queryWrapper.eq(WarningRule::getMemberNotice, pageWrap.getModel().getMemberNotice());
+ }
+ if (pageWrap.getModel().getDeviceNotice() != null) {
+ queryWrapper.eq(WarningRule::getDeviceNotice, pageWrap.getModel().getDeviceNotice());
+ }
+ if (pageWrap.getModel().getInfo() != null) {
+ queryWrapper.eq(WarningRule::getInfo, pageWrap.getModel().getInfo());
+ }
+ if (pageWrap.getModel().getMemberIds() != null) {
+ queryWrapper.eq(WarningRule::getMemberIds, pageWrap.getModel().getMemberIds());
+ }
+ if (pageWrap.getModel().getIntervalSec() != null) {
+ queryWrapper.eq(WarningRule::getIntervalSec, pageWrap.getModel().getIntervalSec());
+ }
+ if (pageWrap.getModel().getSortnum() != null) {
+ queryWrapper.eq(WarningRule::getSortnum, pageWrap.getModel().getSortnum());
+ }
+ if (pageWrap.getModel().getStatus() != null) {
+ queryWrapper.eq(WarningRule::getStatus, pageWrap.getModel().getStatus());
+ }
+ if (pageWrap.getModel().getWarningId() != null) {
+ queryWrapper.eq(WarningRule::getWarningId, pageWrap.getModel().getWarningId());
+ }
+ queryWrapper.orderByDesc(WarningRule::getCreateDate);
+ IPage<WarningRule> result = warningRuleMapper.selectJoinPage(page, WarningRule.class,queryWrapper);
+ if(result.getRecords()!=null && result.getRecords().size()>0){
+ List<WarningRuleDetail> allList = warningRuleDetailMapper.selectJoinList(WarningRuleDetail.class,
+ new MPJLambdaWrapper<WarningRuleDetail>()
+ .selectAll(WarningRuleDetail.class)
+ .selectAs(Warning::getName,WarningRuleDetail::getWarningName)
+ .leftJoin(Warning.class,Warning::getId,WarningRuleDetail::getWarningId)
+ .eq(WarningRuleDetail::getIsdeleted,Constants.ZERO));
+ for(WarningRule model :result.getRecords()){
+ model.setDetailList(getDetailListFromAll(allList,model.getId()));
+ }
+ }
+ return PageData.from(result);
+ }
+
+ private List<WarningRuleDetail> getDetailListFromAll(List<WarningRuleDetail> allList, Integer id) {
+ List<WarningRuleDetail> list = new ArrayList<>();
+ if(allList!=null && allList.size()>0){
+ for(WarningRuleDetail d :allList){
+ if(Constants.equalsInteger(d.getRuleId(),id)){
+ list.add(d);
+ }
+ }
+ }
+ return list;
+ }
+
+ @Override
+ public long count(WarningRule warningRule) {
+ QueryWrapper<WarningRule> wrapper = new QueryWrapper<>(warningRule);
+ return warningRuleMapper.selectCount(wrapper);
+ }
+
+ @Override
+ public void updateStatus(WarningRule param) {
+ WarningRule model = warningRuleMapper.selectById(param.getId());
+ if (model==null || Constants.equalsInteger(model.getIsdeleted(), Constants.ONE)) {
+ throw new BusinessException(ResponseStatus.DATA_EMPTY);
+ }
+ if(Constants.equalsInteger(model.getStatus(),param.getStatus())){
+ return;
+ }
+ model.setStatus(param.getStatus());
+ model.setEditDate(new Date());
+ model.setEditor(param.getLoginUserInfo().getId());
+ warningRuleMapper.updateById(model);
+ }
+}
--
Gitblit v1.9.3