From a28e0d402702e69e0e75b0c902835239d21bfb6f Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期四, 21 十一月 2024 14:19:01 +0800
Subject: [PATCH] 设备、巡检任务业务

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwPatrolLineServiceImpl.java |  142 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 97 insertions(+), 45 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwPatrolLineServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwPatrolLineServiceImpl.java
index cc81d81..80565ec 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwPatrolLineServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwPatrolLineServiceImpl.java
@@ -1,21 +1,30 @@
 package com.doumee.service.business.impl;
 
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
 import com.doumee.core.model.LoginUserInfo;
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
+import com.doumee.core.utils.Constants;
 import com.doumee.core.utils.Utils;
+import com.doumee.dao.business.YwLinePointMapper;
 import com.doumee.dao.business.YwPatrolLineMapper;
-import com.doumee.dao.business.model.YwPatrolLine;
+import com.doumee.dao.business.model.*;
 import com.doumee.service.business.YwPatrolLineService;
 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.Date;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * 杩愮淮宸℃璺嚎淇℃伅琛⊿ervice瀹炵幇
@@ -28,9 +37,40 @@
     @Autowired
     private YwPatrolLineMapper ywPatrolLineMapper;
 
+    @Autowired
+    private YwLinePointMapper ywLinePointMapper;
+
     @Override
+    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
     public Integer create(YwPatrolLine ywPatrolLine) {
+        if(Objects.isNull(ywPatrolLine)
+        || StringUtils.isBlank(ywPatrolLine.getName())
+        || com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywPatrolLine.getLinePointList())){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+
+        LoginUserInfo loginUserInfo = ywPatrolLine.getLoginUserInfo();
+        ywPatrolLine.setCreateDate(new Date());
+        ywPatrolLine.setCreator(loginUserInfo.getId());
+        ywPatrolLine.setIsdeleted(Constants.ZERO);
+        ywPatrolLine.setStatus(Constants.ZERO);
         ywPatrolLineMapper.insert(ywPatrolLine);
+        //寰幆澶勭悊 瀛愰泦鏁版嵁
+
+        List<YwLinePoint> ywLinePointList = ywPatrolLine.getLinePointList();
+        for (YwLinePoint ywLinePoint:ywLinePointList) {
+            if(Objects.isNull(ywLinePoint)
+            || Objects.isNull(ywLinePoint.getPointId())
+            || Objects.isNull(ywLinePoint.getNeedScancode())
+            ){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"宸℃鐐归厤缃敊璇�");
+            }
+            ywLinePoint.setCreateDate(new Date());
+            ywLinePoint.setCreator(loginUserInfo.getId());
+            ywLinePoint.setIsdeleted(Constants.ZERO);
+            ywLinePoint.setLineId(ywLinePoint.getId());
+        }
+        ywLinePointMapper.insert(ywLinePointList);
         return ywPatrolLine.getId();
     }
 
@@ -55,7 +95,34 @@
 
     @Override
     public void updateById(YwPatrolLine ywPatrolLine) {
+        if(Objects.isNull(ywPatrolLine)
+                || StringUtils.isBlank(ywPatrolLine.getName())
+                || com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywPatrolLine.getLinePointList())){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+
+        LoginUserInfo loginUserInfo = ywPatrolLine.getLoginUserInfo();
+        ywPatrolLine.setEditDate(new Date());
+        ywPatrolLine.setEditor(loginUserInfo.getId());
         ywPatrolLineMapper.updateById(ywPatrolLine);
+        //鍒犻櫎瀛愭暟鎹�
+        ywLinePointMapper.delete(new QueryWrapper<YwLinePoint>().lambda()
+                .eq(YwLinePoint::getLineId,ywPatrolLine.getId()));
+        //寰幆澶勭悊 瀛愰泦鏁版嵁
+        List<YwLinePoint> ywLinePointList = ywPatrolLine.getLinePointList();
+        for (YwLinePoint ywLinePoint:ywLinePointList) {
+            if(Objects.isNull(ywLinePoint)
+                    || Objects.isNull(ywLinePoint.getPointId())
+                    || Objects.isNull(ywLinePoint.getNeedScancode())
+            ){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"宸℃鐐归厤缃敊璇�");
+            }
+            ywLinePoint.setLineId(ywLinePoint.getId());
+            ywLinePoint.setCreateDate(new Date());
+            ywLinePoint.setCreator(loginUserInfo.getId());
+            ywLinePoint.setIsdeleted(Constants.ZERO);
+        }
+        ywLinePointMapper.insert(ywLinePointList);
     }
 
     @Override
@@ -73,6 +140,25 @@
         return ywPatrolLineMapper.selectById(id);
     }
 
+
+    @Override
+    public YwPatrolLine getDetail(Integer id) {
+        YwPatrolLine ywPatrolLine =  ywPatrolLineMapper.selectById(id);
+
+        List<YwLinePoint> ywLinePointList = ywLinePointMapper.selectJoinList(YwLinePoint.class,new MPJLambdaWrapper<YwLinePoint>()
+                .selectAll(YwLinePoint.class)
+                .selectAs(YwPatrolPoint::getName,YwLinePoint::getPointName)
+                .leftJoin(YwPatrolLine.class,YwPatrolLine::getId,YwLinePoint::getPointId)
+                .eq(YwLinePoint::getLineId,id)
+                .orderByAsc(YwLinePoint::getSortnum)
+        );
+
+        ywPatrolLine.setLinePointList(ywLinePointList);
+
+        return ywPatrolLine;
+    }
+
+
     @Override
     public YwPatrolLine findOne(YwPatrolLine ywPatrolLine) {
         QueryWrapper<YwPatrolLine> wrapper = new QueryWrapper<>(ywPatrolLine);
@@ -88,51 +174,17 @@
     @Override
     public PageData<YwPatrolLine> findPage(PageWrap<YwPatrolLine> pageWrap) {
         IPage<YwPatrolLine> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
-        QueryWrapper<YwPatrolLine> queryWrapper = new QueryWrapper<>();
+        MPJLambdaWrapper<YwPatrolLine> queryWrapper = new MPJLambdaWrapper<YwPatrolLine>();
         Utils.MP.blankToNull(pageWrap.getModel());
-        if (pageWrap.getModel().getId() != null) {
-            queryWrapper.lambda().eq(YwPatrolLine::getId, pageWrap.getModel().getId());
-        }
-        if (pageWrap.getModel().getCreator() != null) {
-            queryWrapper.lambda().eq(YwPatrolLine::getCreator, pageWrap.getModel().getCreator());
-        }
-        if (pageWrap.getModel().getCreateDate() != null) {
-            queryWrapper.lambda().ge(YwPatrolLine::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
-            queryWrapper.lambda().le(YwPatrolLine::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
-        }
-        if (pageWrap.getModel().getEditor() != null) {
-            queryWrapper.lambda().eq(YwPatrolLine::getEditor, pageWrap.getModel().getEditor());
-        }
-        if (pageWrap.getModel().getEditDate() != null) {
-            queryWrapper.lambda().ge(YwPatrolLine::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
-            queryWrapper.lambda().le(YwPatrolLine::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
-        }
-        if (pageWrap.getModel().getIsdeleted() != null) {
-            queryWrapper.lambda().eq(YwPatrolLine::getIsdeleted, pageWrap.getModel().getIsdeleted());
-        }
-        if (pageWrap.getModel().getName() != null) {
-            queryWrapper.lambda().eq(YwPatrolLine::getName, pageWrap.getModel().getName());
-        }
-        if (pageWrap.getModel().getRemark() != null) {
-            queryWrapper.lambda().eq(YwPatrolLine::getRemark, pageWrap.getModel().getRemark());
-        }
-        if (pageWrap.getModel().getStatus() != null) {
-            queryWrapper.lambda().eq(YwPatrolLine::getStatus, pageWrap.getModel().getStatus());
-        }
-        if (pageWrap.getModel().getSortnum() != null) {
-            queryWrapper.lambda().eq(YwPatrolLine::getSortnum, pageWrap.getModel().getSortnum());
-        }
-        if (pageWrap.getModel().getImgurl() != null) {
-            queryWrapper.lambda().eq(YwPatrolLine::getImgurl, pageWrap.getModel().getImgurl());
-        }
-        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
-            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
-                queryWrapper.orderByDesc(sortData.getProperty());
-            } else {
-                queryWrapper.orderByAsc(sortData.getProperty());
-            }
-        }
-        return PageData.from(ywPatrolLineMapper.selectPage(page, queryWrapper));
+        YwPatrolLine model = pageWrap.getModel();
+        queryWrapper.selectAll(YwPatrolLine.class)
+                .select(" ( select count(1) from  yw_line_point y where y.LINE_ID = yw_patrol_line.id ) as lineAmount ")
+                .like(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getName()),YwPatrolLine::getName,model.getName())
+                .eq(YwPatrolLine::getIsdeleted,Constants.ZERO)
+                .orderByDesc(YwPatrolLine::getCreateDate)
+        ;
+        IPage iPage = ywPatrolLineMapper.selectJoinPage(page,YwPatrolLine.class,queryWrapper);
+        return PageData.from(iPage);
     }
 
     @Override

--
Gitblit v1.9.3