jiazx0107@163.com
2023-11-06 69cd9f59a0fabf12f8c9147fcba7f69817a870b3
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.ld.igds.timer;
 
import com.bstek.bdf2.core.model.DefaultCompany;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.constant.Constant;
import com.ld.igds.constant.DepotStatus;
import com.ld.igds.inout.InoutConstant;
import com.ld.igds.inout.dto.InoutData;
import com.ld.igds.inout.dto.InoutParam;
import com.ld.igds.inout.service.InoutService;
import com.ld.igds.models.DepotStore;
import com.ld.igds.models.InoutLossOver;
import com.ld.igds.models.InoutRecord;
import com.ld.igds.util.ContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.*;
 
/**
 * @Desc: 账面库存 - 每月底自动统计每个仓库的账面库存
 * @author: czt
 * @update-time: 2023/10/30
 */
@Slf4j
@Component(DepotBookStoreScheduled.BEAN_ID)
public class DepotBookStoreScheduled {
 
    public static final String BEAN_ID = "inout.depotBookStoreScheduled";
 
    @Resource
    private CoreCommonService commonService;
 
    /**
     * 每月最后一天22点25分执行
     */
    @Scheduled(cron = "0 25 22 28-31 * ?")
    public void scheduled() {
 
        final Calendar c = Calendar.getInstance();
        //如果是最后一天 则执行定时任务
        if (c.get(Calendar.DATE) == c.getActualMaximum(Calendar.DATE)) {
 
            List<DefaultCompany> listCompany = commonService.getCompanyList();
            if (null == listCompany){
                return;
            }
 
            for (DefaultCompany company : listCompany) {
                //TODO 统计每个仓库账面库存
 
            }
        }
    }
 
    /**
     * 统计账面库存
     * @param companyId
     * @param listLossOver
     * @param param
     */
    private void sumDepotBookStore(String companyId, List<InoutLossOver> listLossOver, InoutParam param) {
 
//        if (null == listLossOver || listLossOver.isEmpty()) {
//            log.info("-----------系统自动同步库存,近期无损益记录,取消同步仓库库存……{}", companyId);
//            return;
//        }
//
//        // 获取有出入库记录的仓库
//        Map<String, InoutLossOver> map = new HashMap<>();
//        String key;
//        DepotStore lastStore;
//        double sumRecordWeight = 0.0;
//        for (InoutLossOver data : listLossOver) {
//            key = data.getDepotId() + "_" + data.getType();
//            if (null != map.get(key)) {
//                continue;
//            }
//
//            map.put(key, data);
//
//            // 根据最后一车进行汇总统计,开始时间是仓库库存最后一个时间截止到当前
//            lastStore = commonService.getLastDepotStore(data.getDepotId());
//            if (null == lastStore) {
//                log.error("--------库存定时任务-----没有获取到仓库最后库存信息,取消自动统计,请核对业务逻辑--仓库-{}",
//                        data.getDepotId());
//                continue;
//            }
//
//            param.setDeptId(data.getDeptId());
//            param.setDepotId(data.getDepotId());
//            param.setCompanyId(data.getCompanyId());
//            param.setType(data.getType());
//
//            //获取出入库的重量信息
//            sumRecordWeight = inoutService.sumLossOverWeight(param);
//
//            //新增一条库存记录
//            lastStore.setRemark("系统定时生成记录");
//            lastStore.setId(ContextUtil.getUUID());
//            lastStore.setUpdateUser("系统管理员");
//            lastStore.setUpdateDate(new Date());
//            lastStore.setCreateDate(new Date());
//            if(Constant.LOSS_OVER_LOSS.equals(data.getType())){
//                lastStore.setStorageReal(lastStore.getStorageReal() + sumRecordWeight);
//
//            }
//            if(Constant.LOSS_OVER_OVER.equals(data.getType())){
//                lastStore.setStorageReal(lastStore.getStorageReal() - sumRecordWeight);
//            }
//
//            lastStore.setStorageSettle(lastStore.getStorageReal());
//            commonService.addDepotStore(lastStore, true);
//        }
    }
 
}