From d7dca690cedd12e271f0ee0b9050679d73796f5c Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期一, 06 一月 2025 09:28:10 +0800
Subject: [PATCH] 1

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwDeviceServiceImpl.java |  237 +++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 173 insertions(+), 64 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwDeviceServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwDeviceServiceImpl.java
index 0684415..e96dd30 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwDeviceServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwDeviceServiceImpl.java
@@ -1,21 +1,42 @@
 package com.doumee.service.business.impl;
 
+import com.doumee.biz.system.SystemDictDataBiz;
+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.DateUtil;
 import com.doumee.core.utils.Utils;
 import com.doumee.dao.business.YwDeviceMapper;
+import com.doumee.dao.business.YwDeviceRecordMapper;
+import com.doumee.dao.business.model.Category;
+import com.doumee.dao.business.model.Company;
 import com.doumee.dao.business.model.YwDevice;
+import com.doumee.dao.business.model.YwDeviceRecord;
+import com.doumee.dao.business.vo.YwDeviceDataVO;
+import com.doumee.dao.system.MultifileMapper;
+import com.doumee.dao.system.model.Multifile;
+import com.doumee.dao.system.model.SystemUser;
+import com.doumee.service.business.YwDeviceRecordService;
 import com.doumee.service.business.YwDeviceService;
 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 lombok.extern.java.Log;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import java.util.Date;
 import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * 杩愮淮璁惧淇℃伅琛⊿ervice瀹炵幇
@@ -28,15 +49,61 @@
     @Autowired
     private YwDeviceMapper ywDeviceMapper;
 
+    @Autowired
+    private SystemDictDataBiz systemDictDataBiz;
+    @Autowired
+    private MultifileMapper multifileMapper;
+    @Autowired
+    private YwDeviceRecordMapper ywDeviceRecordMapper;
+
+    @Autowired
+    private RedisTemplate<String,Object> redisTemplate;
+
+
     @Override
     public Integer create(YwDevice ywDevice) {
+        if(Objects.isNull(ywDevice)
+            || StringUtils.isBlank(ywDevice.getName())
+            || StringUtils.isBlank(ywDevice.getCode())
+            || Objects.isNull(ywDevice.getStatus())
+        ){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        LoginUserInfo loginUserInfo = ywDevice.getLoginUserInfo();
+        if(ywDeviceMapper.selectCount(new QueryWrapper<YwDevice>().lambda().eq(YwDevice::getIsdeleted,Constants.ZERO).eq(YwDevice::getCode,ywDevice.getCode()))>Constants.ZERO){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璁惧缂栧彿閲嶅!");
+        }
+        ywDevice.setCreateDate(new Date());
+        ywDevice.setCreator(loginUserInfo.getId());
+        ywDevice.setIsdeleted(Constants.ZERO);
         ywDeviceMapper.insert(ywDevice);
+
+        if(Objects.nonNull(ywDevice.getFileUrl())){
+            Multifile multifile = new Multifile();
+            multifile.setCreator(loginUserInfo.getId());
+            multifile.setCreateDate(new Date());
+            multifile.setIsdeleted(Constants.ZERO);
+            multifile.setObjType(Constants.MultiFile.FN_DEVICE_FILE.getKey());
+            multifile.setObjId(ywDevice.getId());
+            multifile.setFileurl(ywDevice.getFileUrl());
+            multifileMapper.insert(multifile);
+        }
+
         return ywDevice.getId();
     }
 
     @Override
     public void deleteById(Integer id, LoginUserInfo user) {
-        ywDeviceMapper.deleteById(id);
+        //鏌ヨ璁惧鏄惁瀛樺湪杩愮淮璁板綍
+        if(ywDeviceRecordMapper.selectCount(new QueryWrapper<YwDeviceRecord>().lambda().eq(YwDeviceRecord::getDeviceId,id).eq(YwDeviceRecord::getIsdeleted,Constants.ZERO))>Constants.ZERO){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"褰撳墠璁惧瀛樺湪杩愮淮璁板綍锛屾棤娉曞垹闄�");
+        };
+        ywDeviceMapper.update(new UpdateWrapper<YwDevice>()
+                .lambda().set(YwDevice::getIsdeleted,Constants.ONE)
+                .set(YwDevice::getEditDate, DateUtil.getCurrDateTime())
+                .set(YwDevice::getEditor,user.getId())
+                .eq(YwDevice::getId,id)
+        );
     }
 
     @Override
@@ -55,7 +122,38 @@
 
     @Override
     public void updateById(YwDevice ywDevice) {
+        if(Objects.isNull(ywDevice)
+                || StringUtils.isBlank(ywDevice.getName())
+                || StringUtils.isBlank(ywDevice.getCode())
+                || Objects.isNull(ywDevice.getStatus())
+        ){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        LoginUserInfo loginUserInfo = ywDevice.getLoginUserInfo();
+        if(ywDeviceMapper.selectCount(new QueryWrapper<YwDevice>().lambda().eq(YwDevice::getIsdeleted,Constants.ZERO)
+                .eq(YwDevice::getCode,ywDevice.getCode())
+                .ne(YwDevice::getId,ywDevice.getId()))>Constants.ZERO){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璁惧缂栧彿閲嶅!");
+        }
+        ywDevice.setEditDate(new Date());
+        ywDevice.setEditor(loginUserInfo.getId());
         ywDeviceMapper.updateById(ywDevice);
+        multifileMapper.delete(new QueryWrapper<Multifile>().lambda()
+                .eq(Multifile::getObjId,ywDevice.getId())
+                .eq(Multifile::getObjType,Constants.MultiFile.FN_DEVICE_FILE.getKey())
+        );
+        if(Objects.nonNull(ywDevice.getFileUrl())){
+            Multifile multifile = new Multifile();
+            multifile.setCreator(loginUserInfo.getId());
+            multifile.setCreateDate(new Date());
+            multifile.setIsdeleted(Constants.ZERO);
+            multifile.setObjType(Constants.MultiFile.FN_DEVICE_FILE.getKey());
+            multifile.setObjId(ywDevice.getId());
+            multifile.setFileurl(ywDevice.getFileUrl());
+            multifileMapper.insert(multifile);
+        }
+
+
     }
 
     @Override
@@ -74,6 +172,44 @@
     }
 
     @Override
+    public YwDevice getDetail(Integer id) {
+        YwDevice ywDevice = ywDeviceMapper.selectById(id);
+        Multifile multifile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda()
+                .eq(Multifile::getObjId,id).eq(Multifile::getObjType,Constants.MultiFile.FN_DEVICE_FILE.getKey()).last(" limit 1"));
+        if(Objects.nonNull(multifile)){
+            String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode()
+                    +systemDictDataBiz.queryByCode(Constants.FTP,Constants.YW_DEVICE).getCode();
+            ywDevice.setFileFullUrl(path + multifile.getFileurl());
+        }
+        return ywDevice;
+    }
+
+
+    /**
+     * 鏍规嵁缂栫爜鏌ヨ
+     * @param deviceCode
+     * @return
+     */
+    @Override
+    public YwDevice findByCode(String deviceCode) {
+        YwDevice ywDevice =  ywDeviceMapper.selectOne(
+                new QueryWrapper<YwDevice>()
+                        .lambda()
+                        .eq(YwDevice::getIsdeleted,Constants.ZERO)
+                        .eq(YwDevice::getCode,deviceCode)
+                        .last(" limit  1 ")
+        );
+        if(Objects.isNull(ywDevice)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+
+        return ywDevice;
+    }
+
+
+
+
+    @Override
     public YwDevice findOne(YwDevice ywDevice) {
         QueryWrapper<YwDevice> wrapper = new QueryWrapper<>(ywDevice);
         return ywDeviceMapper.selectOne(wrapper);
@@ -88,70 +224,21 @@
     @Override
     public PageData<YwDevice> findPage(PageWrap<YwDevice> pageWrap) {
         IPage<YwDevice> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
-        QueryWrapper<YwDevice> queryWrapper = new QueryWrapper<>();
+        MPJLambdaWrapper<YwDevice> queryWrapper = new MPJLambdaWrapper<YwDevice>();
         Utils.MP.blankToNull(pageWrap.getModel());
-        if (pageWrap.getModel().getId() != null) {
-            queryWrapper.lambda().eq(YwDevice::getId, pageWrap.getModel().getId());
-        }
-        if (pageWrap.getModel().getCreator() != null) {
-            queryWrapper.lambda().eq(YwDevice::getCreator, pageWrap.getModel().getCreator());
-        }
-        if (pageWrap.getModel().getCreateDate() != null) {
-            queryWrapper.lambda().ge(YwDevice::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
-            queryWrapper.lambda().le(YwDevice::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
-        }
-        if (pageWrap.getModel().getEditor() != null) {
-            queryWrapper.lambda().eq(YwDevice::getEditor, pageWrap.getModel().getEditor());
-        }
-        if (pageWrap.getModel().getEditDate() != null) {
-            queryWrapper.lambda().ge(YwDevice::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
-            queryWrapper.lambda().le(YwDevice::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
-        }
-        if (pageWrap.getModel().getIsdeleted() != null) {
-            queryWrapper.lambda().eq(YwDevice::getIsdeleted, pageWrap.getModel().getIsdeleted());
-        }
-        if (pageWrap.getModel().getName() != null) {
-            queryWrapper.lambda().eq(YwDevice::getName, pageWrap.getModel().getName());
-        }
-        if (pageWrap.getModel().getRemark() != null) {
-            queryWrapper.lambda().eq(YwDevice::getRemark, pageWrap.getModel().getRemark());
-        }
-        if (pageWrap.getModel().getStatus() != null) {
-            queryWrapper.lambda().eq(YwDevice::getStatus, pageWrap.getModel().getStatus());
-        }
-        if (pageWrap.getModel().getSortnum() != null) {
-            queryWrapper.lambda().eq(YwDevice::getSortnum, pageWrap.getModel().getSortnum());
-        }
-        if (pageWrap.getModel().getModelNo() != null) {
-            queryWrapper.lambda().eq(YwDevice::getModelNo, pageWrap.getModel().getModelNo());
-        }
-        if (pageWrap.getModel().getCateId() != null) {
-            queryWrapper.lambda().eq(YwDevice::getCateId, pageWrap.getModel().getCateId());
-        }
-        if (pageWrap.getModel().getUserId() != null) {
-            queryWrapper.lambda().eq(YwDevice::getUserId, pageWrap.getModel().getUserId());
-        }
-        if (pageWrap.getModel().getCompany() != null) {
-            queryWrapper.lambda().ge(YwDevice::getCompany, Utils.Date.getStart(pageWrap.getModel().getCompany()));
-            queryWrapper.lambda().le(YwDevice::getCompany, Utils.Date.getEnd(pageWrap.getModel().getCompany()));
-        }
-        if (pageWrap.getModel().getContent() != null) {
-            queryWrapper.lambda().eq(YwDevice::getContent, pageWrap.getModel().getContent());
-        }
-        if (pageWrap.getModel().getCode() != null) {
-            queryWrapper.lambda().eq(YwDevice::getCode, pageWrap.getModel().getCode());
-        }
-        if (pageWrap.getModel().getAddr() != null) {
-            queryWrapper.lambda().eq(YwDevice::getAddr, pageWrap.getModel().getAddr());
-        }
-        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
-            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
-                queryWrapper.orderByDesc(sortData.getProperty());
-            } else {
-                queryWrapper.orderByAsc(sortData.getProperty());
-            }
-        }
-        return PageData.from(ywDeviceMapper.selectPage(page, queryWrapper));
+        YwDevice model = pageWrap.getModel();
+        queryWrapper.selectAll(YwDevice.class)
+                .selectAs(Category::getName,YwDevice::getCategoryName)
+                .selectAs(SystemUser::getRealname,YwDevice::getRealName)
+                .leftJoin(Category.class,Category::getId,YwDevice::getCateId)
+                .leftJoin(SystemUser.class,SystemUser::getId,YwDevice::getUserId)
+                .and(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getName()),i->i.like(YwDevice::getName,model.getName()).or().like(YwDevice::getCode,model.getName()))
+                .eq(Objects.nonNull(model.getStatus()),YwDevice::getStatus,model.getStatus())
+                .eq(YwDevice::getIsdeleted,Constants.ZERO)
+                .orderByDesc(YwDevice::getCreateDate)
+        ;
+        IPage iPage = ywDeviceMapper.selectJoinPage(page,YwDevice.class,queryWrapper);
+        return PageData.from(iPage);
     }
 
     @Override
@@ -159,4 +246,26 @@
         QueryWrapper<YwDevice> wrapper = new QueryWrapper<>(ywDevice);
         return ywDeviceMapper.selectCount(wrapper);
     }
+
+
+
+    @Override
+    public YwDeviceDataVO getYwDeviceData(){
+        YwDeviceDataVO ywDeviceDataVO = new YwDeviceDataVO();
+        List<YwDevice> ywDeviceList = ywDeviceMapper.selectList(new QueryWrapper<YwDevice>().lambda().eq(YwDevice::getIsdeleted,Constants.ZERO));
+        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywDeviceList)){
+            ywDeviceDataVO.setQualityNum(ywDeviceList.size());
+            ywDeviceDataVO.setTotalNum(ywDeviceList.size());
+            ywDeviceDataVO.setNormalNum(ywDeviceList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ZERO)).collect(Collectors.toList()).size());
+            ywDeviceDataVO.setAbnormalNum(ywDeviceList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ONE)).collect(Collectors.toList()).size());
+            ywDeviceDataVO.setScrapNum(ywDeviceList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.TWO)).collect(Collectors.toList()).size());
+        }
+        return ywDeviceDataVO;
+    }
+
+
+
 }
+
+
+

--
Gitblit v1.9.3