叶松
2023-11-27 111a401f033749c965f02f58c586a8feafd9afd1
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package com.thhy.materials.modules.biz.concret.controller;
 
 
import com.thhy.materials.modules.biz.concret.entity.dto.DicetName;
import com.thhy.materials.modules.biz.concret.entity.dto.TMinxingPlant;
import com.thhy.materials.modules.biz.concret.entity.dto.WeighDto;
import com.thhy.materials.modules.biz.weigh.entity.TWeighbridge;
import com.thhy.materials.modules.biz.weigh.mapper.WeighMapper;
import com.thhy.materials.modules.biz.weigh.service.WeighService;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
 
@Component
public class MixingPlantNewScheduled {
    @Resource
    private WeighService weighService;
    @Resource
    private WeighMapper weighMapper;
 
    @Resource
    private RedissonClient redissonclient;
 
 
    @Scheduled(fixedRate = 2000000) // 每隔3秒执行一次任务
    public void task() {
        //查询搅拌 所有类型
        List<DicetName> dictList = weighService.dictList();
        System.out.println("-------"+dictList);
        Integer byId = weighService.mixingPlantIdNew();
        for (DicetName values : dictList){
            if(byId!=null){
                List<WeighDto> weighVos =weighService.findAlltaskNew(byId,values.getDictName());
                for (WeighDto weighVo : weighVos){
 
                    HashMap<String, Object> hashMap = new HashMap<>();
                    hashMap.put("byId",weighVo.getById());
                    hashMap.put("carName",weighVo.getCarNumber());
                    //*****************改为净重*********************
                    hashMap.put("changeStock",weighVo.getNetWeight()/1000);
                    hashMap.put("dictId",values.getDictId());
                    hashMap.put("createTime",weighVo.getUpdateTime());
                    String forwardingUnit = weighVo.getForwardingUnit();
                    String id = weighService.forwardingUnitSelectBy(forwardingUnit);
                    hashMap.put("supplierId",id);
                    hashMap.put("companyId","02d2fc8b7ea0eff7ec70c649");
                    //***********数据消耗(毛重 改为净重) ***********
                    double v = (weighVo.getNetWeight() / 1000);
                    //字典表id
                    String dictId = values.getDictId();
                    //查询当前库存
                    Double materialValue =  weighMapper.selectMaterialValueNew(dictId);
 
                    //**********判断净重是否入库( 净重>0 )  增加库存 **********
                    if(weighVo.getNetWeight()>0){
                        hashMap.put("isIn",2);
                        //入库记录添加
                        HashMap<String, Object> hashMap1 = new HashMap<>();
                        hashMap1.put("createDate",new Date());
                        hashMap1.put("materialName",dictId);
                        hashMap1.put("type",1);
                        hashMap1.put("opType",1);
                        hashMap1.put("materialValue",v);
                        BigDecimal b1 = new BigDecimal(v);
                        BigDecimal b2 = new BigDecimal(materialValue);
                        hashMap1.put("beforeStock",materialValue);
                        hashMap1.put("afterStock",b1.add(b2).doubleValue());
                        hashMap1.put("companyId","02d2fc8b7ea0eff7ec70c649");
                        RLock lock = redissonclient.getLock("materlock");
                        System.out.println(hashMap1);
 
                        if(!lock.isLocked()) {
                            lock.lock(10, TimeUnit.SECONDS);
                            //插入记录表
                            weighMapper.materialStockRecordInNew(hashMap1);
                            //更改记录值
                            weighMapper.materialStockRecordUpNew(dictId,b1.add(b2).doubleValue());
                            lock.unlock();
                        }
                    }else {
                        hashMap.put("isIn",1);
                    }
                    weighMapper.minxingInNew(hashMap);
                }
            }else {
                List<WeighDto> weighVos =weighService.findAlltaskAllNew(values.getDictName());
                for (WeighDto weighVo : weighVos){
                    HashMap<String, Object> hashMap = new HashMap<>();
                    hashMap.put("byId",weighVo.getById());
                    hashMap.put("carName",weighVo.getCarNumber());
                    //*****************改为净重*********************
                    hashMap.put("changeStock",weighVo.getNetWeight()/1000);
                    hashMap.put("dictId",values.getDictId());
                    hashMap.put("createTime",weighVo.getUpdateTime());
                    //供应商
                    String forwardingUnit = weighVo.getForwardingUnit();
                    String id = weighService.forwardingUnitSelectBy(forwardingUnit);
                    hashMap.put("supplierId",id);
                    hashMap.put("companyId","02d2fc8b7ea0eff7ec70c649");
                    System.out.println("----------"+hashMap);
 
                    //数据消耗
                    double v = (weighVo.getGrossWeight() / 1000);
                    //字典表id
                    String dictId = values.getDictId();
                    //查询当前库存
                    Double materialValue =  weighMapper.selectMaterialValueNew(dictId);
                    if(weighVo.getNetWeight()>0){
                        hashMap.put("isIn",2);
                        //入库记录添加
                        HashMap<String, Object> hashMap1 = new HashMap<>();
                        hashMap1.put("createDate",new Date());
                        hashMap1.put("materialName",dictId);
                        hashMap1.put("type",1);
                        hashMap1.put("opType",1);
                        hashMap1.put("materialValue",v);
                        BigDecimal b1 = new BigDecimal(v);
                        BigDecimal b2 = new BigDecimal(materialValue);
                        hashMap1.put("beforeStock",materialValue);
 
                        double v1 = b1.add(b2).doubleValue();
                        System.out.println("---------====-=--="+v1);
                        System.out.println("---------====-=--="+v1);
                        hashMap1.put("afterStock",v1);
                        hashMap1.put("companyId","02d2fc8b7ea0eff7ec70c649");
                        RLock lock = redissonclient.getLock("materlock");
                        if(!lock.isLocked()) {
                            lock.lock(10, TimeUnit.SECONDS);
                            //插入记录表
                            weighMapper.materialStockRecordInNew(hashMap1);
                            //更改记录值
                            weighMapper.materialStockRecordUpNew(dictId,b1.add(b2).doubleValue());
                            lock.unlock();
                        }
                    }else {
                        hashMap.put("isIn",1);
                    }
                    weighMapper.minxingInNew(hashMap);
                }
            }
        // 定时执行的任务内容
        }
    }
 
    @Scheduled(fixedRate = 2400000) // 每隔3秒执行一次任务
    public void taskUpdate() {
          List<TMinxingPlant> minxingPlants = weighMapper.mixingPlantIsIn();
          for (TMinxingPlant minxingPlant : minxingPlants){
              Integer byId = minxingPlant.getById();
              //原料值
              Integer netWeight = weighMapper.netWeighNew(byId);
              if(netWeight!=null && netWeight>0){
                  //数据消耗
                  double v = (netWeight/ 1000);
                   HashMap<String, Object> hashMap1 = new HashMap<>();
                  hashMap1.put("createDate",new Date());
                  hashMap1.put("materialName",minxingPlant.getDictId());
                  hashMap1.put("type",1);
                  hashMap1.put("opType",1);
                  hashMap1.put("materialValue",v);
                  //查询当前库存
                  Double materialValue =  weighMapper.selectMaterialValueNew(minxingPlant.getDictId());
                  BigDecimal b1 = new BigDecimal(v);
                  BigDecimal b2 = new BigDecimal(materialValue);
                  hashMap1.put("beforeStock",materialValue);
                  double v1 = b1.add(b2).doubleValue();
                  System.out.println("---------====-=--="+v1);
                  System.out.println("---------====-=--="+v1);
                  hashMap1.put("afterStock",v1);
                  hashMap1.put("companyId","02d2fc8b7ea0eff7ec70c649");
                  RLock lock = redissonclient.getLock("materlock");
                  if(!lock.isLocked()) {
                      lock.lock(10, TimeUnit.SECONDS);
                      //插入记录表
                      weighMapper.materialStockRecordInNew(hashMap1);
                      //更改记录值
                      weighMapper.materialStockRecordUpNew(minxingPlant.getDictId(),b1.add(b2).doubleValue());
                      lock.unlock();
                  }
                  weighMapper.netWeighUpdateNew(byId,v);
              }else {
                  System.out.println("********未二次称重********");
              }
          }
 
    }
 
    //苏州项目------- 地磅入库  记录,及库存修改
    @Scheduled(fixedRate = 2000000) // 每隔3秒执行一次任务
    public void weighbridge() {
        //查询搅拌 所有类型
        List<DicetName> dictList = weighService.dictList();
        List<TWeighbridge> tWeighbridges = weighMapper.weighbridgeListType();
        for (DicetName dicetName : dictList){
            for (TWeighbridge weighbridge :tWeighbridges){
                if(dicetName.getDictName().equals(weighbridge.getMatname())){
                    //开始的库存
                    Double materialValue = weighMapper.materialStockValue(dicetName.getDictId());
                    //净重
                    String jweight = weighbridge.getJweight();
                    HashMap<String, Object> hashMap = new HashMap<>();
                    hashMap.put("id","");
                    hashMap.put("type",1);
                    hashMap.put("opType",1);
                    hashMap.put("materialName",dicetName.getDictId());
                    hashMap.put("materialValue",Double.valueOf(jweight));
                    hashMap.put("beforeStock",materialValue);
                    BigDecimal b1 = new BigDecimal(jweight);
                    BigDecimal b2 = new BigDecimal(materialValue);
                    double v1 = b1.add(b2).doubleValue();
                    hashMap.put("afterStock",v1);
                    hashMap.put("companyId","031e3dd577e8ed28e96aa69b");
                    RLock lock = redissonclient.getLock("materlock");
                    if(!lock.isLocked()) {
                        lock.lock(10, TimeUnit.SECONDS);
                        //插入记录表//苏州项目(入库计入增加)
                        weighMapper.materialStockRecordIns(hashMap);
                        //更改记录值
                        weighMapper.materialStockRecordUp(dicetName.getDictId(),b1.add(b2).doubleValue());
                        lock.unlock();
                    }
 
                    weighMapper.weighbridgeUpdateType(weighbridge.getWeighbridgeId());
                }
            }
 
 
        }
 
 
    }
 
}