jiangping
2023-10-26 5a4e4f0ac1e40f45ce4e78b1ae57637c84a64fc7
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
package doumeemes.service.business.impl;
 
import doumeemes.core.model.ApiResponse;
import doumeemes.core.model.LoginUserInfo;
import doumeemes.core.model.PageData;
import doumeemes.core.model.PageWrap;
import doumeemes.core.utils.Constants;
import doumeemes.core.utils.DateUtil;
import doumeemes.core.utils.Utils;
import doumeemes.core.utils.redis.RedisUtil;
import doumeemes.dao.business.WarehouseLocationMapper;
import doumeemes.dao.business.model.BarcodeParam;
import doumeemes.dao.business.model.Warehouse;
import doumeemes.dao.business.model.WarehouseLocation;
import doumeemes.dao.system.model.SystemDictData;
import doumeemes.service.business.BarcodeParamService;
import doumeemes.service.business.WarehouseLocationService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import doumeemes.service.system.SystemDictDataService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
 
/**
 * 仓库管理-库位信息表Service实现
 * @author 江蹄蹄
 * @date 2022/05/05 11:37
 */
@Service
public class WarehouseLocationServiceImpl implements WarehouseLocationService {
 
    @Autowired
    private WarehouseLocationMapper warehouseLocationMapper;
 
    @Autowired
    private BarcodeParamService barcodeParamService;
    @Autowired
    private WarehouseServiceImpl warehouseServiceimpl;
 
    @Autowired
    private SystemDictDataService systemDictDataService;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
 
    @Override
    public ApiResponse create(WarehouseLocation warehouseLocation) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        Warehouse warehouse= warehouseServiceimpl.findById(warehouseLocation.getWarehouseId());
        SystemDictData systemDictData= systemDictDataService.findById(Integer.valueOf(warehouse.getSystemDicDataId()));
        if(!StringUtils.equals(systemDictData.getLabel(),"APPLIANCE_MIX")){
            if(!StringUtils.equals(warehouse.getSystemDicDataId(),warehouseLocation.getSystemDicDataId())){
                return ApiResponse.failed("仓库的属性不是混合,则货位属性需要跟仓库相同");
            }
        }
 
 
        //获取二维码规则
        BarcodeParam queryparam=new BarcodeParam();
        queryparam.setDepartId(user.getCurComDepartment().getId());
        queryparam.setRootDepartId(user.getRootDepartment().getId());
        queryparam.setType(Constants.BARCODEPARAM_TYPE.localtion);
        BarcodeParam barcodeParam =barcodeParamService.findOne(queryparam);
        if(barcodeParam==null){
            return ApiResponse.failed("请先完善二维码货位配置");
        }
        if(StringUtils.isNotEmpty(warehouseLocation.getShelf())){
            if(StringUtils.isNotEmpty(warehouseLocation.getCell())){
                warehouseLocation.setUnionName(warehouseLocation.getArea()+"-"+warehouseLocation.getShelf()+"-"+warehouseLocation.getCell());
            }else{
                warehouseLocation.setUnionName(warehouseLocation.getArea()+"-"+warehouseLocation.getShelf());
            }
        }else{
            warehouseLocation.setUnionName(warehouseLocation.getArea());
        }
        WarehouseLocation codedate=new WarehouseLocation();
        codedate.setDeleted(Constants.ZERO);
        codedate.setRootDepartId(user.getRootDepartment().getId());
        codedate.setCode(warehouseLocation.getCode());
        List<WarehouseLocation> listcode=this.findList(codedate);
        if(listcode.size()>0){
            return ApiResponse.failed("主组织下货位编码不能重复");
        }
 
        WarehouseLocation codeUnionName=new WarehouseLocation();
        codeUnionName.setDeleted(Constants.ZERO);
        codeUnionName.setRootDepartId(user.getRootDepartment().getId());
        codeUnionName.setUnionName(warehouseLocation.getUnionName());
        List<WarehouseLocation> listUnionName=this.findList(codeUnionName);
        if(listUnionName.size()>0){
            return ApiResponse.failed("仓库下货位组合不能重复");
        }
        warehouseLocation.setRootDepartId(user.getRootDepartment().getId());
        warehouseLocation.setStatus(Constants.ONE);
        warehouseLocation.setDeleted(Constants.ZERO);
        warehouseLocation.setUpdateTime(new Date());
        warehouseLocation.setUpdateUser(user.getId());
        warehouseLocation.setQrcode(barcodeParam.getId());
        if(StringUtils.isBlank(warehouseLocation.getCode())){
            warehouseLocation.setCode(this.getNextCode(user.getCompany().getId()));
        }
        warehouseLocationMapper.insert(warehouseLocation);
        return ApiResponse.success(warehouseLocation.getId());
    }
 
    public synchronized String  getNextCode(Integer comId ){
        String prefix =  "HW-" + DateUtil.getDate(new Date(),"yyyyMMdd") +"-";
        Integer countNum  = RedisUtil.getObject(redisTemplate,Constants.RedisKeys.COM_LOCATION_CHECK_KEY+comId,Integer.class);
        countNum = Constants.formatIntegerNum(countNum)+1;
        //更新缓存
        RedisUtil.addObject(redisTemplate,Constants.RedisKeys.COM_LOCATION_CHECK_KEY+comId,countNum);
        String nextIndex =Integer.toString( countNum );
        return prefix + StringUtils.leftPad(nextIndex,4,"0");
    }
 
 
    @Override
    public void deleteById(Integer id) {
        warehouseLocationMapper.deleteById(id);
    }
 
    @Override
    public void delete(WarehouseLocation warehouseLocation) {
        UpdateWrapper<WarehouseLocation> deleteWrapper = new UpdateWrapper<>(warehouseLocation);
        warehouseLocationMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        warehouseLocationMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(WarehouseLocation warehouseLocation) {
        warehouseLocationMapper.updateById(warehouseLocation);
    }
 
    @Override
    public void updateByIdInBatch(List<WarehouseLocation> warehouseLocations) {
        if (CollectionUtils.isEmpty(warehouseLocations)) {
            return;
        }
        for (WarehouseLocation warehouseLocation: warehouseLocations) {
            this.updateById(warehouseLocation);
        }
    }
 
    @Override
    public WarehouseLocation findById(Integer id) {
        return warehouseLocationMapper.selectById(id);
    }
 
 
    @Override
    public WarehouseLocation findOne(WarehouseLocation warehouseLocation) {
        QueryWrapper<WarehouseLocation> wrapper = new QueryWrapper<>(warehouseLocation);
        return warehouseLocationMapper.selectOne(wrapper);
    }
 
    @Override
    public List<WarehouseLocation> findList(WarehouseLocation warehouseLocation) {
        QueryWrapper<WarehouseLocation> wrapper = new QueryWrapper<>(warehouseLocation);
        wrapper.select(" * , ( select `tmodel`.LABEL from  `system_dict_data` `tmodel` where  SYSTEM_DIC_DATA_ID= tmodel.ID limit 1 ) as label ");
        return warehouseLocationMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<WarehouseLocation> findPage(PageWrap<WarehouseLocation> pageWrap) {
        IPage<WarehouseLocation> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<WarehouseLocation> queryWrapper = new QueryWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getDeleted() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getDeleted, pageWrap.getModel().getDeleted());
        }
        if (pageWrap.getModel().getCreateUser() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getCreateUser, pageWrap.getModel().getCreateUser());
        }
        if (pageWrap.getModel().getCreateTime() != null) {
            queryWrapper.lambda().ge(WarehouseLocation::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateTime()));
            queryWrapper.lambda().le(WarehouseLocation::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateTime()));
        }
        if (pageWrap.getModel().getUpdateUser() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getUpdateUser, pageWrap.getModel().getUpdateUser());
        }
        if (pageWrap.getModel().getUpdateTime() != null) {
            queryWrapper.lambda().ge(WarehouseLocation::getUpdateTime, Utils.Date.getStart(pageWrap.getModel().getUpdateTime()));
            queryWrapper.lambda().le(WarehouseLocation::getUpdateTime, Utils.Date.getEnd(pageWrap.getModel().getUpdateTime()));
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getRemark, pageWrap.getModel().getRemark());
        }
        if (pageWrap.getModel().getRootDepartId() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getRootDepartId, pageWrap.getModel().getRootDepartId());
        }
        if (pageWrap.getModel().getWarehouseId() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getWarehouseId, pageWrap.getModel().getWarehouseId());
        }
        if (pageWrap.getModel().getUnionName() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getUnionName, pageWrap.getModel().getUnionName());
        }
        if (pageWrap.getModel().getArea() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getArea, pageWrap.getModel().getArea());
        }
        if (pageWrap.getModel().getShelf() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getShelf, pageWrap.getModel().getShelf());
        }
        if (pageWrap.getModel().getCell() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getCell, pageWrap.getModel().getCell());
        }
        if (pageWrap.getModel().getQrcode() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getQrcode, pageWrap.getModel().getQrcode());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getCode() != null) {
            queryWrapper.lambda().eq(WarehouseLocation::getCode, pageWrap.getModel().getCode());
        }
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(warehouseLocationMapper.selectPage(page, queryWrapper));
    }
 
    @Override
    public long count(WarehouseLocation warehouseLocation) {
        QueryWrapper<WarehouseLocation> wrapper = new QueryWrapper<>(warehouseLocation);
        return warehouseLocationMapper.selectCount(wrapper);
    }
}