Administrator
2023-06-19 49588f5a462ae7425e7eb030438a35fd80c246fa
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
242
243
244
245
246
247
248
249
250
251
package com.gk.firework.Service.ServiceImpl;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.firework.Domain.EntryDetailInfo;
import com.gk.firework.Domain.EntryOrderInfo;
import com.gk.firework.Domain.Exception.BusinessException;
import com.gk.firework.Domain.SoldNoStockInfo;
import com.gk.firework.Domain.UserInfo;
import com.gk.firework.Domain.Vo.EntryOrderInfoVo;
import com.gk.firework.Domain.Vo.EntryUtils;
import com.gk.firework.Domain.Vo.FireworkDeal;
import com.gk.firework.Domain.Vo.ProductVo;
import com.gk.firework.Mapper.EntryDetailInfoMapper;
import com.gk.firework.Domain.Utils.StringUtils;
import com.gk.firework.Mapper.EntryOrderInfoMapper;
import com.gk.firework.Service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
 
import java.util.ArrayList;
import java.util.Date;
 
/**
 * @author : jingjy
 * @date : 2021/3/24 11:10
 */
@Service("EntryService")
public class EntryServiceImpl extends ServiceImpl<EntryOrderInfoMapper,EntryOrderInfo> implements EntryService{
    @Autowired
    private ProductService productService;
    @Autowired
    private EntryService entryService;
    @Autowired
    private EntryDetailService entryDetailService;
    @Autowired
    private SoldNoStockService soldNoStockService;
    @Autowired
    private SaleOrderService orderService;
 
    @Override
    public void entryPatch(List<SoldNoStockInfo> soldNoStockInfos, UserInfo user, String auth) {
        EntryOrderInfo orderInfo = generateEntryOrderInfo(EntryUtils.RK_ENTRY,user,new Date(),"",auth);
        List<EntryDetailInfo>detailInfos = new ArrayList<>();
        int i = 0;
        for (SoldNoStockInfo soldNoStockInfo : soldNoStockInfos){
            String dire = soldNoStockInfo.getDirectioncode();
            ProductVo productVo = productService.selectVoByDirection(dire);
            EntryDetailInfo detailInfo = new EntryDetailInfo(orderInfo.getCode(),dire,productVo.getItemCode(),
                    productVo.getName(),productVo.getManufacturer(),new Date(),user.getCompanynumber());
            //已销未入库信息只会存19位流向码信息
            detailInfo.setNum(1);
            detailInfos.add(detailInfo);
            i++;
 
            //更新soldNoStock信息
            soldNoStockInfo.setHandler(user.getUsername());
            soldNoStockInfo.setHandledat(new Date());
            soldNoStockInfo.setEntryorder(orderInfo.getCode());
            soldNoStockInfo.setFlag(SoldNoStockInfo.PROCESSED);
        }
        //插入入库单及入库明细单,更新已销未入库单,不更新库存
        orderInfo.setNum(i);
        entryService.save(orderInfo);
        entryDetailService.saveBatch(detailInfos);
        soldNoStockService.updateBatchById(soldNoStockInfos);
 
    }
 
    @Autowired
    private EntryOrderInfoMapper entryOrderInfoMapper;
    @Autowired
    private UserService userService;
    @Autowired
    private EntryDetailInfoMapper entryDetailInfoMapper;
 
    /**
    * @Description: 入库查询
    * @date 2021/4/15 10:28
    */
    @Override
    public IPage selectPage(Page<EntryOrderInfoVo> page, Map filter, UserInfo user) {
 
        UserInfo userInfo = userService.getById(user.getId());
 
        Map<String, Object> params = new HashMap<>();
        //筛选条件
        //可视权限
        {
            params.put("enterprisenumber", userInfo.getCompanynumber());
            params.put("province", userInfo.getProvince());
            params.put("city", userInfo.getCity());
            params.put("district", userInfo.getArea());
            params.put("street", userInfo.getTown());
            params.put("committee", userInfo.getCommunity());
        }
        //基本查询条件
        {
            params.put("filterProvince", filter.get("province"));
            params.put("filterCity", filter.get("city"));
            params.put("filterDistrict", filter.get("district"));
            params.put("filterStreet", filter.get("street"));
            params.put("filterCommittee", filter.get("committee"));
 
            params.put("transportcert", filter.get("transportcert"));
            params.put("starttime", filter.get("starttime"));
            params.put("endtime", filter.get("endtime"));
            params.put("enterprisename", filter.get("enterprisename"));
            params.put("safetysupervision", filter.get("safetysupervision"));
            params.put("type", filter.get("type"));
            params.put("code", filter.get("code"));
        }
 
        List<EntryOrderInfoVo> list = entryOrderInfoMapper.selectPages(page,params);
        return page.setRecords(list);
    }
 
    /**
    * @Description:  根据{入库单code}查询入库明细
    * @date 2021/4/15 11:12
    */
    @Override
    public Page selectDetailPage(Page<Map> page, Map filter) {
        String code = (String) filter.get("code");
        if (StringUtils.isBlank(code)) {
            throw new BusinessException("入库单号不能为空");
        }
 
        Map<String, Object> params = new HashMap<>();
        params.put("code", code);
        params.put("starttime", filter.get("starttime"));
        params.put("endtime", filter.get("endtime"));
        List<Map> list = entryDetailInfoMapper.selectDetailPage(page, params);
        return page.setRecords(list);
    }
 
    @Override
    public BigDecimal getEntryNumByCondition(Map<String, Object> condition) {
        return entryDetailInfoMapper.getEntryNumByCondition(condition);
    }
 
    @Override
    public BigDecimal getReturnNumByCondition(Map<String, Object> condition) {
        return entryDetailInfoMapper.getReturnNumByCondition(condition);
    }
 
    @Override
    public boolean isEntryExist(String datetime, UserInfo userInfo) {
        EntryOrderInfo entryOrderInfo = entryOrderInfoMapper.selectEntryOrderByTimeAndUser(datetime,userInfo.getUsername());
        return entryOrderInfo != null;
    }
 
    /**
    * @Description: 入库导出
    * @date 2021/4/19 17:13
    */
    @Override
    public List<EntryOrderInfo> selectExportInBound(Map filter, UserInfo user) {
 
        UserInfo userInfo = userService.getById(user.getId());
 
        Map<String, Object> params = new HashMap<>();
        //筛选条件
        //可视权限
        {
            params.put("enterprisenumber", userInfo.getCompanynumber());
            params.put("province", userInfo.getProvince());
            params.put("city", userInfo.getCity());
            params.put("district", userInfo.getArea());
            params.put("street", userInfo.getTown());
            params.put("committee", userInfo.getCommunity());
        }
        //基本查询条件
        {
            params.put("filterProvince", filter.get("province"));
            params.put("filterCity", filter.get("city"));
            params.put("filterDistrict", filter.get("district"));
            params.put("filterStreet", filter.get("street"));
            params.put("filterCommittee", filter.get("committee"));
 
            params.put("transportcert", filter.get("transportcert"));
            params.put("starttime", filter.get("starttime"));
            params.put("endtime", filter.get("endtime"));
            params.put("enterprisename", filter.get("enterprisename"));
            params.put("type", filter.get("type"));
        }
 
        return entryOrderInfoMapper.selectPages(params);
    }
 
    @Override
    public BigDecimal selectEnterpriseEntryNumber(String enterprisenumber, Object starttime, Object endtime) {
        return entryOrderInfoMapper.selectEnterpriseEntryNumber(enterprisenumber,starttime,endtime);
    }
 
    @Override
    public BigDecimal selectCityEntryNumber(String name, Object starttime, Object endtime) {
        return entryOrderInfoMapper.selectCityEntryNumber(name,starttime,endtime);
    }
 
    @Override
    public Boolean isTransportCertEntry(String code) {
        if (StringUtils.isBlank(code)){
            return false;
        }
        List<EntryOrderInfo> entryOrderInfo = entryOrderInfoMapper.selectByCert(code);
        return entryOrderInfo != null && entryOrderInfo.size() > 0;
    }
 
    @Override
    public IPage selectStockPage(Page<EntryOrderInfoVo> page, Map<String, Object> filter, UserInfo user) {
        Map<String, Object> params = new HashMap<>();
        {
            params.put("filterProvince", filter.get("province"));
            params.put("filterCity", filter.get("city"));
            params.put("filterDistrict", filter.get("district"));
            params.put("filterStreet", filter.get("street"));
            params.put("filterCommittee", filter.get("committee"));
 
            params.put("transportcert", filter.get("transportcert"));
            params.put("starttime", filter.get("starttime"));
            params.put("endtime", filter.get("endtime"));
            params.put("enterprisename", filter.get("enterprisename"));
            params.put("type", filter.get("type"));
        }
        List<EntryOrderInfoVo> list = entryOrderInfoMapper.selectPages(page,params);
        return page.setRecords(list);
    }
 
    @Override
    public EntryOrderInfo generateEntryOrderInfo(String type, UserInfo userInfo, Date date, String transport, String auth){
        EntryOrderInfo orderInfo = new EntryOrderInfo();
        orderInfo.setCode(orderService.generateOrderCode(FireworkDeal.MODULE_ENTRY,type,new Date(),userInfo.getId()));
        orderInfo.setType(Byte.parseByte(type));
        orderInfo.setCreateddate(new Date());
        orderInfo.setCreatedby(userInfo.getUsername());
        orderInfo.setEntrydate(date);
        orderInfo.setTransportcert(transport);
        orderInfo.setUnit(userInfo.getCompany());
        orderInfo.setCompanynumber(userInfo.getCompanynumber());
        return orderInfo;
    }
 
}