czt
2025-05-29 753abfcaf090f79a4226693c2829a2d47b422058
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.fzzy.igds.sys;
 
import com.fzzy.igds.dzhwk.constant.RedisConst;
import com.fzzy.igds.dzhwk.domain.DepotStatusConfirm;
import com.fzzy.igds.sys.repository.DepotStatusConfirmRepository;
import com.fzzy.igds.util.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.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
/**
 * @Description
 * @Author CZT
 * @Date 2024/11/23 10:48
 */
@Slf4j
@Service("sys.depotStatusConfirmService")
public class DepotStatusConfirmService {
 
    public static final String CACHE_DEPOT_STATUS_CONFIRM_ID = "DEPOT_STATUS_CONFIRM_ID";
 
    @Resource
    private DepotStatusConfirmRepository DepotStatusConfirmRepository;
    @Resource
    private RedisCache redisCache;
 
    /**
     * JPA分页查询数据
     *
     * @param specification
     * @param pageable
     * @return
     */
    public Page<DepotStatusConfirm> findAll(Specification<DepotStatusConfirm> specification, Pageable pageable) {
        return DepotStatusConfirmRepository.findAll(specification, pageable);
    }
 
    /**
     * JPA更新保存
     * @param data
     */
    public void saveOrUpdate(DepotStatusConfirm data) {
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(data.getDeptId())) {
            data.setDeptId(ContextUtil.subDeptId(null));
        }
        data.setUpdateTime(new Date());
        if (StringUtils.isEmpty(data.getFcqrdh())) {
            data.setFcqrdh(buildId(data.getFcrq()));
        }
        DepotStatusConfirmRepository.save(data);
    }
 
 
    /**
     * JPA删除
     * @param data
     */
    public void delData(DepotStatusConfirm data) {
        DepotStatusConfirmRepository.delete(data);
    }
 
    /**
     * 获取封仓单号
     * @param time
     * @return
     */
    public String buildId(Date time) {
 
        String timeKey = "21" + DateFormatUtils.format(time, "yyyyMMdd");
        // 从缓存中获取已有的组织编码
        String cacheKey = RedisConst.buildKey(ContextUtil.getCompanyId(), CACHE_DEPOT_STATUS_CONFIRM_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);
            cacheId = timeKey + String.format("%04d", ++i);
        } else {
            List<DepotStatusConfirm> list = DepotStatusConfirmRepository.getDataByFcqrdh(timeKey + "%");
            if (null == list || list.isEmpty()) {
                cacheId = timeKey + "0001";
            } else {
                String temp = list.get(0).getFcqrdh();
                String tempNum = temp.substring(temp.length() - 4);
                Integer i = Integer.valueOf(tempNum);
                cacheId = timeKey + String.format("%04d", ++i);
            }
        }
        // 更新缓存
        redisCache.setCacheObject(cacheKey, cacheId);
        return cacheId;
    }
 
}