From 725a6ed97f7501de1795fce78fbd42624b310015 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期五, 16 五月 2025 15:03:33 +0800
Subject: [PATCH] art: 设备管理-设备处置 借用归还 列表,新增,编辑,提交

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentLeanOutServiceImpl.java |  182 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 180 insertions(+), 2 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentLeanOutServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentLeanOutServiceImpl.java
index 43209ae..c122711 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentLeanOutServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentLeanOutServiceImpl.java
@@ -1,19 +1,197 @@
 package org.jeecg.modules.eam.service.impl;
 
+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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.constant.DataBaseConstant;
+import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.eam.constant.AssetStatusEnum;
+import org.jeecg.modules.eam.constant.EquipmentLeanOutStatusEnum;
+import org.jeecg.modules.eam.entity.EamEquipment;
 import org.jeecg.modules.eam.entity.EamEquipmentLeanOut;
 import org.jeecg.modules.eam.mapper.EamEquipmentLeanOutMapper;
+import org.jeecg.modules.eam.request.EamEquipmentLeanOutQuery;
 import org.jeecg.modules.eam.service.IEamEquipmentLeanOutService;
+import org.jeecg.modules.eam.service.IEamEquipmentService;
+import org.jeecg.modules.system.service.IMdcProductionService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import javax.annotation.Resource;
+import java.util.Arrays;
+import java.util.List;
 
 /**
  * @Description: 璁惧鍊熷嚭褰掕繕
  * @Author: jeecg-boot
- * @Date:   2025-05-13
+ * @Date: 2025-05-13
  * @Version: V1.0
  */
 @Service
 public class EamEquipmentLeanOutServiceImpl extends ServiceImpl<EamEquipmentLeanOutMapper, EamEquipmentLeanOut> implements IEamEquipmentLeanOutService {
+    @Resource
+    private EamEquipmentLeanOutMapper equipmentLeanOutMapper;
+    @Autowired
+    private IEamEquipmentService eamEquipmentService;
+    @Autowired
+    private IMdcProductionService mdcProductionService;
 
+    @Override
+    public IPage<EamEquipmentLeanOut> queryPageList(Page<EamEquipmentLeanOut> page, EamEquipmentLeanOutQuery query) {
+        QueryWrapper<EamEquipmentLeanOut> queryWrapper = new QueryWrapper<>();
+        //鐢ㄦ埛鏁版嵁鏉冮檺
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        if (sysUser == null) {
+            return page;
+        }
+        if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) {
+            //閫夋嫨浜嗚澶囷紝鏍规嵁璁惧id杩囨护璁惧
+            List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(","));
+            queryWrapper.in("e.equipment_code", equipArr);
+        } else {
+            //娌℃湁閫夋嫨璁惧锛屾牴鎹溅闂磋繃婊よ澶�
+            queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id ", sysUser.getId());
+        }
+        //鎺у埗寰呮彁浜ょ姸鎬佺殑鏁版嵁鍙兘鏈汉鏌ョ湅
+        queryWrapper.and(i -> i.ne("wmo.lean_status", EquipmentLeanOutStatusEnum.WAIT_SUBMIT).or().eq("wmo.lean_person", sysUser.getUsername()));
+        //鏌ヨ鏉′欢杩囨护
+        if (query != null) {
+            if (StringUtils.isNotBlank(query.getEquipmentId())) {
+                queryWrapper.eq("wmo.equipment_id", query.getEquipmentId());
+            }
+            if (StringUtils.isNotBlank(query.getCode())) {
+                queryWrapper.like("wmo.code", query.getCode());
+            }
+            if (StringUtils.isNotBlank(query.getLeanStatus())) {
+                queryWrapper.eq("wmo.lean_status", query.getLeanStatus());
+            }
+            if (query.getLeanDateBegin() != null && query.getLeanDateEnd() != null) {
+                queryWrapper.between("wmo.lean_start_time", query.getLeanDateBegin(), query.getLeanDateEnd());
+            }
+            //鎺掑簭
+            if (StringUtils.isNotBlank(query.getColumn()) && StringUtils.isNotBlank(query.getOrder())) {
+                String column = query.getColumn();
+                if (column.endsWith(CommonConstant.DICT_TEXT_SUFFIX)) {
+                    column = column.substring(0, column.lastIndexOf(CommonConstant.DICT_TEXT_SUFFIX));
+                }
+                if (DataBaseConstant.SQL_ASC.equalsIgnoreCase(query.getOrder())) {
+                    queryWrapper.orderByAsc("wmo." + oConvertUtils.camelToUnderline(column));
+                } else {
+                    queryWrapper.orderByDesc("wmo." + oConvertUtils.camelToUnderline(column));
+                }
+            } else {
+                queryWrapper.orderByDesc("wmo.create_time");
+            }
+        } else {
+            queryWrapper.orderByDesc("wmo.create_time");
+        }
+
+        return equipmentLeanOutMapper.queryPageList(page, queryWrapper);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean addLeanOut(EamEquipmentLeanOut request) {
+        //妫�鏌ヨ澶�
+        EamEquipment equipment = eamEquipmentService.getById(request.getEquipmentId());
+        if (equipment == null) {
+            throw new JeecgBootException("璁惧涓嶅瓨鍦紒");
+        }
+        if (!AssetStatusEnum.NORMAL.name().equals(equipment.getAssetStatus())) {
+            throw new JeecgBootException("姝よ澶囧綋鍓嶈祫浜х姸鎬佷笉鍏佽鍊熷嚭锛�");
+        }
+        if (StringUtils.isBlank(request.getLeanDepartId())) {
+            throw new JeecgBootException("鍊熷叆杞﹂棿涓嶅厑璁镐负绌猴紒");
+        }
+        if (request.getLeanDepartId().equals(equipment.getOrgId())) {
+            throw new JeecgBootException("褰撳墠璁惧灞炰簬姝よ溅闂达紝涓嶉渶瑕佸�熺敤锛�");
+        }
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        if (sysUser == null) {
+            throw new JeecgBootException("褰撳墠鐢ㄦ埛鏃犳硶娣诲姞鍊熺敤璁板綍锛�");
+        }
+        request.setLeanPerson(sysUser.getUsername());
+        return equipmentLeanOutMapper.insert(request) > 0;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean editLeanOut(EamEquipmentLeanOut request) {
+        EamEquipmentLeanOut entity = equipmentLeanOutMapper.selectById(request.getId());
+        if (entity == null) {
+            throw new JeecgBootException("瑕佺紪杈戠殑鏁版嵁涓嶅瓨鍦紝璇峰埛鏂伴噸璇曪紒");
+        }
+        if(!EquipmentLeanOutStatusEnum.WAIT_SUBMIT.name().equals(entity.getLeanStatus())) {
+            throw new JeecgBootException("褰撳墠鏁版嵁鐘舵�佷笉鍏佽缂栬緫锛�");
+        }
+        //妫�鏌ヨ澶�
+        EamEquipment equipment = eamEquipmentService.getById(request.getEquipmentId());
+        if (equipment == null) {
+            throw new JeecgBootException("璁惧涓嶅瓨鍦紒");
+        }
+        if (!AssetStatusEnum.NORMAL.name().equals(equipment.getAssetStatus())) {
+            throw new JeecgBootException("姝よ澶囧綋鍓嶈祫浜х姸鎬佷笉鍏佽鍊熷嚭锛�");
+        }
+        if (StringUtils.isBlank(request.getLeanDepartId())) {
+            throw new JeecgBootException("鍊熷叆杞﹂棿涓嶅厑璁镐负绌猴紒");
+        }
+        if (request.getLeanDepartId().equals(equipment.getOrgId())) {
+            throw new JeecgBootException("褰撳墠璁惧灞炰簬姝よ溅闂达紝涓嶉渶瑕佸�熺敤锛�");
+        }
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        if (sysUser == null) {
+            throw new JeecgBootException("褰撳墠鐢ㄦ埛鏃犳硶缂栬緫鍊熺敤璁板綍锛�");
+        }
+        UpdateWrapper<EamEquipmentLeanOut> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.set("equipment_id", request.getEquipmentId());
+        updateWrapper.set("lean_depart_id", request.getLeanDepartId());
+        updateWrapper.set("remark", request.getRemark());
+        updateWrapper.set("lean_reason", request.getLeanReason());
+        updateWrapper.eq("id", request.getId());
+        updateWrapper.eq("lean_person", sysUser.getUsername());
+        return super.update(updateWrapper);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean submit(String id) {
+        EamEquipmentLeanOut entity = equipmentLeanOutMapper.selectById(id);
+        if (entity == null) {
+            throw new JeecgBootException("瑕佹彁浜ょ殑鏁版嵁涓嶅瓨鍦紝璇峰埛鏂伴噸璇曪紒");
+        }
+        if(!EquipmentLeanOutStatusEnum.WAIT_SUBMIT.name().equals(entity.getLeanStatus())) {
+            throw new JeecgBootException("褰撳墠鏁版嵁鐘舵�佷笉鍏佽缂栬緫锛�");
+        }
+        //妫�鏌ヨ澶�
+        EamEquipment equipment = eamEquipmentService.getById(entity.getEquipmentId());
+        if (equipment == null) {
+            throw new JeecgBootException("璁惧涓嶅瓨鍦紒");
+        }
+        if (!AssetStatusEnum.NORMAL.name().equals(equipment.getAssetStatus())) {
+            throw new JeecgBootException("姝よ澶囧綋鍓嶈祫浜х姸鎬佷笉鍏佽鍊熷嚭锛�");
+        }
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        if (sysUser == null) {
+            throw new JeecgBootException("褰撳墠鐢ㄦ埛鏃犳硶缂栬緫鍊熺敤璁板綍锛�");
+        }
+        UpdateWrapper<EamEquipmentLeanOut> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.set("lean_status", EquipmentLeanOutStatusEnum.WAIT_APPROVAL.name());
+        updateWrapper.eq("id", id);
+        updateWrapper.eq("lean_person", sysUser.getUsername());
+        boolean success = super.update(updateWrapper);
+        if(success) {
+            equipment.setAssetStatus(AssetStatusEnum.LEAN_OUT.name());
+            eamEquipmentService.updateById(equipment);
+        }
+        //鍚姩瀹℃壒娴佺▼ TODO
+        return true;
+    }
 }

--
Gitblit v1.9.3