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);
|
}
|
}
|