czt
2025-11-27 fdcb3d4255a5897972aae4c31cf0cbaa81aef431
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
package com.fzzy.igds.service;
 
import com.fzzy.igds.domain.DepotStore;
import com.fzzy.igds.repository.DepotRepository;
import com.fzzy.igds.repository.DepotStoreRepository;
import com.fzzy.igds.utils.ContextUtil;
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 2025/11/27 13:44
 */
@Slf4j
@Service
public class DepotStoreService {
 
    @Resource
    private DepotStoreRepository depotStoreRepository;
    @Resource
    private DepotRepository depotRepository;
 
    /**
     * JPA分页查询数据
     *
     * @param specification
     * @param pageable
     * @return
     */
    public Page<DepotStore> findAll(Specification<DepotStore> specification, Pageable pageable) {
        return depotStoreRepository.findAll(specification, pageable);
    }
 
    /**
     * JPA更新保存数据
     *
     * @param data
     */
    public void saveDepotStore(DepotStore data) {
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(data.getDeptId())) {
            data.setDeptId(ContextUtil.subDeptId(null));
        }
        data.setUpdateBy(ContextUtil.getLoginUserName());
        data.setUpdateTime(new Date());
 
        data.setId(data.getDepotId() + "_" + DateFormatUtils.format(data.getStoreDate(), "yyyyMMddHHmmss") + "_" + DateFormatUtils.format(data.getUpdateTime(), "yyyyMMddHHmmss"));
        data.setCreateTime(new Date());
        data.setRemark("系统生成");
 
        depotStoreRepository.save(data);
    }
 
    /**
     * JPA删除数据
     *
     * @param data
     * @return
     */
    public String delDepotStore(DepotStore data) {
        depotStoreRepository.delete(data);
        return null;
    }
 
    /**
     * JPA获取仓库最后一条库存数据
     *
     * @param depotId
     * @param time
     * @return
     */
    public DepotStore getLastData(String depotId, Date time) {
        List<DepotStore> list = depotStoreRepository.getDataByDepotId(depotId, time);
        if (null == list || list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }
 
    public void addDepotStore(DepotStore store, boolean updateDepot) {
        if (null == store.getUpdateTime()) store.setUpdateTime(new Date());
        if (null == store.getId()) store.setId(ContextUtil.generateId());
 
        depotStoreRepository.save(store);
 
        if (updateDepot) {
            depotRepository.updateDepotStorage(store.getStorageReal(), store.getDepotId());
        }
    }
 
 
}