GoodsService.java
5.87 KB
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
package cn.csbr.app.service;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.springboot.dao.mapper.HisGoodsBoundMapper;
import cn.csbr.springboot.dao.mapper.HisGoodsMapper;
import cn.csbr.springboot.dao.model.HisGoods;
import cn.csbr.springboot.dao.model.HisGoodsBound;
import com.alibaba.fastjson.JSON;
import com.csbr.mybatis.CommonMapper;
import com.csbr.util.IdUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class GoodsService {
@Autowired
private CommonMapper commonMapper;
@Autowired
private GUIContext guiContext;
@Autowired
private HisGoodsMapper hisGoodsMapper;
@Autowired
private HisGoodsBoundMapper hisGoodsBoundMapper;
public synchronized String getProducer(String guid){
String sql = "select Producer from his_goods where guid='"+guid+"'";
return commonMapper.queryOne(sql).get("Producer").toString();
}
public synchronized List<HisGoods> getStockedGoodsData() {
String sql = "select *,hgb.StockLowerLimit as lowerlimit,hgb.StockUpperLimit as upperlimit" +
" from his_goods hg LEFT JOIN his_goods_bound hgb on hg.GUID = hgb.HisGoodsGUID and hgb.orgGUID " +
"= '"+guiContext.getLoginUser().getOrgGuid()+"' ORDER BY hgb.UPDATETIME desc;";
List<Map> list = commonMapper.queryList(sql);
List<HisGoods> goodsList = new ArrayList<>();
for(Map map:list) {
HisGoods goods = JSON.parseObject(JSON.toJSONString(map), HisGoods.class);
goods.setStockupperlimit(map.get("upperlimit")==null?BigDecimal.ZERO:new BigDecimal(map.get("upperlimit").toString()));
goods.setStocklowerlimit(map.get("lowerlimit")==null?BigDecimal.ZERO:new BigDecimal(map.get("lowerlimit").toString()));
goodsList.add(goods);
}
return goodsList;
}
private static Logger log = LoggerFactory.getLogger(GoodsService.class);
public synchronized List<HisGoods> getStockedGoodsData(String goodscode) {
String sql = "select *,hgb.StockLowerLimit as lowerlimit,hgb.StockUpperLimit as upperlimit" +
" from his_goods hg LEFT JOIN his_goods_bound hgb on hg.GUID = hgb.HisGoodsGUID and hgb.orgGUID " +
"= '"+guiContext.getLoginUser().getOrgGuid()+"' where ( hg.goodscode like '%"+goodscode+"%' or hg.goodsname like "+"'%"+goodscode+"%'"+" or hg.goodsspec like " +"'%"+goodscode+"%'"+" or hg.model like "+"'%"+goodscode+"%'"+" ) ORDER BY hgb.UPDATETIME desc";
log.info(sql);
List<Map> list = commonMapper.queryList(sql);
List<HisGoods> goodsList = new ArrayList<>();
log.info(list.toString());
for(Map map:list) {
HisGoods goods = JSON.parseObject(JSON.toJSONString(map), HisGoods.class);
goods.setStockupperlimit(map.get("upperlimit")==null?BigDecimal.ZERO:new BigDecimal(map.get("upperlimit").toString()));
goods.setStocklowerlimit(map.get("lowerlimit")==null?BigDecimal.ZERO:new BigDecimal(map.get("lowerlimit").toString()));
goodsList.add(goods);
}
return goodsList;
}
//保存上下限修改
@Transactional
public synchronized void updateGoodsUpLower(List<HisGoods> goodsList) {
List<HisGoodsBound> hisGoodsBounds = new ArrayList<>();
for (HisGoods hisGoods : goodsList) {
HisGoodsBound hisGoodsBound = new HisGoodsBound();
hisGoodsBound.setHisgoodguid(hisGoods.getGuid());
hisGoodsBound.setOrgguid(guiContext.getLoginUser().getOrgGuid());
List<HisGoodsBound> list = hisGoodsBoundMapper.select(hisGoodsBound);
hisGoodsBound.setStocklowerlimit(hisGoods.getStocklowerlimit());
hisGoodsBound.setStockupperlimit(hisGoods.getStockupperlimit());
//能在his_goods_bound表找到,对比数据是否有变化,有则做更新操作,否则做插入操作
if(CollectionUtils.isNotEmpty(list)) {
if(hisGoodsBound.getStockupperlimit().compareTo(BigDecimal.ZERO) == 0 && hisGoodsBound.getStocklowerlimit().compareTo(BigDecimal.ZERO) == 0) {
hisGoodsBound.setGuid(list.get(0).getGuid());
hisGoodsBoundMapper.deleteByPrimaryKey(hisGoodsBound);
continue;
}
if(list.get(0).getStocklowerlimit().compareTo(hisGoodsBound.getStocklowerlimit())!=0 || list.get(0).getStockupperlimit().compareTo(hisGoodsBound.getStockupperlimit())!=0) {
hisGoodsBound.setUpdatetime(new Date());
hisGoodsBound.setGuid(list.get(0).getGuid());
hisGoodsBound.setUpdaterid(guiContext.getLoginUser().getGuid());
hisGoodsBoundMapper.updateByPrimaryKeySelective(hisGoodsBound);
}
continue;
}
//上下限存在不为0则做插入操作
if(hisGoods.getStockupperlimit().compareTo(BigDecimal.ZERO) != 0 || hisGoods.getStocklowerlimit().compareTo(BigDecimal.ZERO)!=0) {
hisGoodsBound.setGuid(IdUtils.getUUID());
hisGoodsBound.setCreaterid(guiContext.getLoginUser().getGuid());
hisGoodsBound.setUpdaterid(guiContext.getLoginUser().getGuid());
hisGoodsBound.setUpdatetime(new Date());
hisGoodsBound.setCreatetime(new Date());
hisGoodsBounds.add(hisGoodsBound);
}
}
if(CollectionUtils.isNotEmpty(hisGoodsBounds)) {
hisGoodsBoundMapper.insertList(hisGoodsBounds);
}
}
}