From a04453432c9898df83961eaea26dd97b65537f02 Mon Sep 17 00:00:00 2001
From: sgj <1442489573@qq.com>
Date: 星期三, 03 十二月 2025 09:56:34 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutRecordService.java |  227 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 227 insertions(+), 0 deletions(-)

diff --git a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutRecordService.java b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutRecordService.java
new file mode 100644
index 0000000..007066b
--- /dev/null
+++ b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutRecordService.java
@@ -0,0 +1,227 @@
+package com.fzzy.igds.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fzzy.igds.constant.Constant;
+import com.fzzy.igds.constant.RedisConst;
+import com.fzzy.igds.data.InoutParam;
+import com.fzzy.igds.domain.InoutRecord;
+import com.fzzy.igds.mapper.InoutRecordMapper;
+import com.fzzy.igds.utils.ContextUtil;
+import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.utils.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.time.DateFormatUtils;
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Description
+ * @Author CZT
+ * @Date 2025/12/2 10:36
+ */
+@Slf4j
+@Service
+public class InoutRecordService {
+
+    @Resource
+    private InoutRecordMapper inoutRecordMapper;
+    @Resource
+    private RedisCache redisCache;
+
+    /**
+     * 鍒嗛〉鏌ヨ鏁版嵁
+     * @param page
+     * @param param
+     */
+    public void listPageInout(Page<InoutRecord> page, InoutParam param) {
+        QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>();
+
+        param.setCompanyId(ContextUtil.getCompanyId());
+        param.setDeptId(ContextUtil.subDeptId(null));
+        queryWrapper.eq("company_id", param.getCompanyId());
+        queryWrapper.eq("dept_id", param.getDeptId());
+
+        if (StringUtils.isNotBlank(param.getDepotId())) {
+            queryWrapper.eq("depot_id", param.getDepotId());
+        }
+        if (StringUtils.isNotBlank(param.getType())) {
+            queryWrapper.eq("type", param.getType());
+        }
+        queryWrapper.orderByDesc("create_time");
+        inoutRecordMapper.selectPage(page, queryWrapper);
+    }
+
+
+    /**
+     * 鏍规嵁id鏌ヨ鏁版嵁
+     * @param id
+     * @return
+     */
+    public InoutRecord selectById(String id) {
+        if(StringUtils.isBlank(id)){
+            return null;
+
+        }
+        return inoutRecordMapper.selectById(id);
+    }
+
+    /**
+     * 楠岃瘉杞︾墝鍙锋槸鍚﹀湪娴佺▼涓�
+     * @param companyId
+     * @param plateNum
+     * @return
+     */
+    public int checkExist(String companyId, String plateNum) {
+        if (StringUtils.isEmpty(companyId)) {
+            companyId = ContextUtil.getCompanyId();
+        }
+        QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>();
+
+        queryWrapper.eq("company_id", companyId);
+        queryWrapper.eq("plate_num", plateNum);
+        queryWrapper.ne("progress", Constant.PROGRESS_RECORD);
+        queryWrapper.eq("record_status", "NORMAL");
+
+        return inoutRecordMapper.selectCount(queryWrapper);
+    }
+
+    /**
+     * 鏂板鍑哄叆搴撹褰�
+     *
+     * @param data
+     * @return
+     */
+    public int addInoutRecord(InoutRecord data) {
+
+        if (StringUtils.isBlank(data.getId())) {
+            String id = this.createId(data.getRegisterTime(), data.getCompanyId());
+            if (Constant.TYPE_IN.equals(data.getType())) {
+                data.setId("R_" + id);
+            } else if (Constant.TYPE_OUT.equals(data.getType())) {
+                data.setId("C_" + id);
+            }else {
+                data.setId("M_" + id);
+            }
+        }
+        data.setCreateBy(ContextUtil.getLoginUserName());
+        data.setCreateTime(new Date());
+        data.setUpdateBy(ContextUtil.getLoginUserName());
+        data.setUpdateTime(new Date());
+
+        int num = inoutRecordMapper.insert(data);
+        //TODO 鏇存柊缂撳瓨
+        //updateInoutCache(data);
+        return num;
+        
+    }
+
+    /**
+     * 鏂板鍑哄叆搴撹褰�
+     *
+     * @param data
+     * @return
+     */
+    public int updateInoutRecord(InoutRecord data) {
+
+        data.setUpdateBy(ContextUtil.getLoginUserName());
+        data.setUpdateTime(new Date());
+
+        int num = inoutRecordMapper.updateById(data);
+        //TODO 鏇存柊缂撳瓨
+        //updateInoutCache(data);
+        return num;
+
+    }
+
+    /**
+     * 鍑哄叆搴撴祦绋婭D鍒涘缓 202001030001 202001030001
+     * @param registerTime
+     * @param companyId
+     * @return
+     */
+    public String createId(Date registerTime, String companyId) {
+
+        // 鏃堕棿鎴虫爣绛�
+        String timeKey = DateFormatUtils.format(registerTime, "yyyyMMdd");
+
+        // 浠庣紦瀛樹腑鑾峰彇宸叉湁鐨勭粍缁囩紪鐮�
+        String cacheKey = RedisConst.buildKey(companyId, Constant.CACHE_RECORD_ID);
+
+        String cacheId = (String) redisCache.getCacheObject(cacheKey);
+
+        if (null != cacheId && cacheId.indexOf(timeKey) >= 0) {
+            String temp = cacheId.substring(cacheId.length() - 4);
+            Integer i = Integer.valueOf(temp);
+            i++;
+            temp = String.valueOf(i);
+            if (temp.length() == 1) {
+                cacheId = timeKey + "000" + temp;
+            }
+            if (temp.length() == 2) {
+                cacheId = timeKey + "00" + temp;
+            }
+            if (temp.length() == 3) {
+                cacheId = timeKey + "0" + temp;
+            }
+            if (temp.length() == 4) {
+                cacheId = timeKey + temp;
+            }
+        } else {
+            String result = this.getMaxId(companyId, timeKey);
+            if (null == result) {
+                cacheId = timeKey + "0001";
+            } else {
+                // 鑾峰彇鏈�鍚庡洓浣�
+                int i = Integer.valueOf(result.substring(result.length() - 4));
+                i++;
+                String temp = String.valueOf(i);
+                if (temp.length() == 1) {
+                    cacheId = timeKey + "000" + temp;
+                }
+                if (temp.length() == 2) {
+                    cacheId = timeKey + "00" + temp;
+                }
+                if (temp.length() == 3) {
+                    cacheId = timeKey + "0" + temp;
+                }
+                if (temp.length() == 4) {
+                    cacheId = timeKey + temp;
+                }
+            }
+        }
+
+        // 鏇存柊缂撳瓨
+        redisCache.setCacheObject(cacheKey, cacheId);
+
+        return cacheId;
+    }
+
+    /**
+     * 鏌ヨ鏈�澶d鍙凤紝涓虹┖鍒欒繑鍥瀗ull
+     * @param companyId
+     * @param timeKey
+     * @return
+     */
+    public String getMaxId(String companyId, String timeKey) {
+
+        if (StringUtils.isEmpty(companyId)) {
+            companyId = ContextUtil.getCompanyId();
+        }
+        QueryWrapper<InoutRecord> queryWrapper = new QueryWrapper<>();
+
+        queryWrapper.eq("company_id", companyId);
+        queryWrapper.like("id", timeKey);
+        queryWrapper.orderByDesc("create_time");
+
+        List<InoutRecord> inoutRecords = inoutRecordMapper.selectList(queryWrapper);
+        if(null == inoutRecords || inoutRecords.isEmpty()){
+            return null;
+        }else {
+            return inoutRecords.get(0).getId();
+        }
+    }
+
+}

--
Gitblit v1.9.3