From 83b51a5a0774ea8ecb9a06304af3b956a21307c8 Mon Sep 17 00:00:00 2001 From: pjb <123456> Date: 星期六, 08 三月 2025 09:06:55 +0800 Subject: [PATCH] CUT库条码T开头,截取后10位 --- zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/LocDetlServiceImpl.java | 254 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 242 insertions(+), 12 deletions(-) diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/LocDetlServiceImpl.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/LocDetlServiceImpl.java index 74db866..666a234 100644 --- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/LocDetlServiceImpl.java +++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/LocDetlServiceImpl.java @@ -1,12 +1,242 @@ -package com.zy.asrs.wms.asrs.service.impl; - -import com.zy.asrs.wms.asrs.mapper.LocDetlMapper; -import com.zy.asrs.wms.asrs.entity.LocDetl; -import com.zy.asrs.wms.asrs.service.LocDetlService; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.springframework.stereotype.Service; - -@Service("locDetlService") -public class LocDetlServiceImpl extends ServiceImpl<LocDetlMapper, LocDetl> implements LocDetlService { - -} +package com.zy.asrs.wms.asrs.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.zy.asrs.framework.exception.CoolException; +import com.zy.asrs.wms.asrs.entity.*; +import com.zy.asrs.wms.asrs.entity.enums.LocAreaTypeSts; +import com.zy.asrs.wms.asrs.entity.enums.LocStsType; +import com.zy.asrs.wms.asrs.entity.param.FieldParam; +import com.zy.asrs.wms.asrs.entity.param.FieldSortParam; +import com.zy.asrs.wms.asrs.entity.param.LocDetlFreezeParam; +import com.zy.asrs.wms.asrs.mapper.LocDetlMapper; +import com.zy.asrs.wms.asrs.mapper.ViewLocDetlMapper; +import com.zy.asrs.wms.asrs.service.LanewayRuleService; +import com.zy.asrs.wms.asrs.service.LocDetlFieldService; +import com.zy.asrs.wms.asrs.service.LocDetlService; +import com.zy.asrs.wms.asrs.service.LocService; +import com.zy.asrs.wms.common.domain.BaseParam; +import com.zy.asrs.wms.common.domain.PageParam; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +@Service("locDetlService") +public class LocDetlServiceImpl extends ServiceImpl<LocDetlMapper, LocDetl> implements LocDetlService { + + @Autowired + private ViewLocDetlMapper viewLocDetlMapper; + @Autowired + private LocDetlFieldService locDetlFieldService; + @Autowired + private LocService locService; + @Autowired + private LanewayRuleService lanewayRuleService; + + @Override + public PageParam<ViewLocDetl, BaseParam> getPage(PageParam<ViewLocDetl, BaseParam> pageParam, QueryWrapper<ViewLocDetl> buildWrapper) { + PageParam<ViewLocDetl, BaseParam> result = viewLocDetlMapper.selectPage(pageParam, buildWrapper); + + //瑙f瀽鍔ㄦ�佸瓧娈� + JSONObject data = JSON.parseObject(JSON.toJSONString(result)); + List<ViewLocDetl> records = result.getRecords(); + data.put("records", records); + for (ViewLocDetl locDetl : records) { + Map<String, Object> resultMap = viewLocDetlMapper.getById(locDetl.getId()); + locDetl.syncFieldMap(resultMap); + } + return result; + } + + @Override + public List<LocDetl> getLocDetlList(Map<String, Object> map) { + String matnr = null; + String batch = null; + if (map.containsKey("matnr")) { + matnr = map.get("matnr").toString(); + map.remove("matnr"); + } + if (map.containsKey("batch")) { + batch = map.get("batch").toString(); + map.remove("batch"); + } + ArrayList<FieldParam> param = new ArrayList<>(); + for (Map.Entry<String, Object> entry : map.entrySet()) { + if (entry.getValue() == null) { + continue; + } + FieldParam fieldParam = new FieldParam(); + fieldParam.setName(entry.getKey()); + fieldParam.setValue(entry.getValue()); + param.add(fieldParam); + } + + List<Map<String, Object>> list2 = viewLocDetlMapper.getListLike(matnr, batch, param); + List<LocDetl> locDetls = new ArrayList<>(); + for (Map<String, Object> objectMap : list2) { + LocDetl locDetl = JSON.parseObject(JSON.toJSONString(objectMap), LocDetl.class); + locDetl.syncFieldMap(objectMap); + locDetls.add(locDetl); + } + return locDetls; + } + + @Override + public List<LocDetl> parseLocDetl(List<LocDetl> list) { + for (LocDetl locDetl : list) { + List<LocDetlField> locDetlFieldList = locDetlFieldService.list(new LambdaQueryWrapper<LocDetlField>().eq(LocDetlField::getDetlId, locDetl.getId())); + locDetl.syncField(locDetlFieldList); + } + return list; + } + + @Override + public List<LocDetl> queryStock(String matnr, String batch, List<FieldParam> param) { + return queryStock(matnr, batch, param, null); + } + + @Override + public List<LocDetl> queryStock(String matnr, String batch, List<FieldParam> param, List<FieldSortParam> sortParam) { + List<Map<String, Object>> list = viewLocDetlMapper.queryStock(matnr, batch, param, sortParam, LocAreaTypeSts.LOC_AREA_TYPE_UTC.id); + List<LocDetl> locDetlsSort = resortDetls(list); + return locDetlsSort; + } + + private List<LocDetl> resortDetls(List<Map<String, Object>> list) { + List<LocDetl> locDetls = new ArrayList<>(); + + for (Map<String, Object> map : list) { + LocDetl locDetl = JSON.parseObject(JSON.toJSONString(map), LocDetl.class); + locDetls.add(locDetl); + } + locDetls = parseLocDetl(locDetls); + + List<Long> sortDirctLoc = new ArrayList<>(); + HashMap<Long, List<LocDetl>> sortMap = new HashMap<>(); + for (LocDetl locDetl : locDetls) { + List<LocDetl> detls = sortMap.get(locDetl.getLocId()); + if (detls == null) { + detls = new ArrayList<>(); + detls.add(locDetl); + sortMap.put(locDetl.getLocId(), detls); + }else { + detls.add(locDetl); + sortMap.put(locDetl.getLocId(), detls); + } + + Loc loc = locService.getById(locDetl.getLocId()); + if (loc == null) { + continue; + } + //褰撳墠搴撲綅鐘舵�佹槸鍚﹀湪搴� + if(!loc.getLocStsId().equals(LocStsType.F.val())){ + continue; + } + + //鑾峰彇搴撲綅鎵�鍦ㄥ贩閬� + LanewayRule lanewayRule = lanewayRuleService.getLaneByLoc(loc); + if(lanewayRule == null) { + throw new CoolException("搴撲綅鏈厤缃贩閬�"); + } + + //鑾峰彇搴撲綅鏂瑰悜 + List<Integer> direction = null; + if (lanewayRule.getLaneX$().contains(loc.getRow1())) { + direction = lanewayRule.getLaneX$(); + }else { + direction = lanewayRule.getLaneY$(); + } + Collections.reverse(direction); + + for (Integer row : direction) { + Loc one = locService.getOne(new LambdaQueryWrapper<Loc>() + .eq(Loc::getRow1, row) + .eq(Loc::getBay1, loc.getBay1()) + .eq(Loc::getLev1, loc.getLev1())); + if (one == null) { + continue; + } + + if (!sortDirctLoc.contains(one.getId())) { + sortDirctLoc.add(one.getId()); + } + } + } + + List<LocDetl> sortDirctDetls = new ArrayList<>(); + + for (Long locId : sortDirctLoc) { + List<LocDetl> detls = sortMap.get(locId); + if(detls == null) { + continue; + } + + sortDirctDetls.addAll(detls); + } + + return sortDirctDetls; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void locDetlFreeze(LocDetlFreezeParam param) { + if (param == null) { + throw new CoolException("鍙傛暟涓嶈兘涓虹┖"); + } + + if (param.getDetlIds() == null) { + throw new CoolException("搴撳瓨鏄庣粏鍙傛暟涓嶈兘涓虹┖"); + } + + if (param.getFreeze() == null) { + throw new CoolException("鍐荤粨鍙傛暟涓嶈兘涓虹┖"); + } + + List<LocDetl> locDetls = this.listByIds(param.getDetlIds()); + if(locDetls.isEmpty()){ + throw new CoolException("搴撳瓨涓嶅瓨鍦�"); + } + + for (LocDetl locDetl : locDetls) { + locDetl.setFreeze(param.getFreeze()); + locDetl.setUpdateTime(new Date()); + if (!this.updateById(locDetl)) { + throw new CoolException("鏇存柊澶辫触"); + } + } + } + + @Override + public void removeLocDetl(Long locId) { + List<LocDetl> locDetls = this.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, locId)); + for (LocDetl locDetl : locDetls) { + boolean remove = locDetlFieldService.remove(new LambdaQueryWrapper<LocDetlField>().eq(LocDetlField::getDetlId, locDetl.getId())); + if (!remove) { + throw new CoolException("鎵╁睍瀛楁鍒犻櫎澶辫触"); + } + + boolean result = this.removeById(locDetl.getId()); + if (!result) { + throw new CoolException("鏄庣粏鍒犻櫎澶辫触"); + } + } + } + + @Override + public List<LocDetl> queryFlatStock(String matnr, String batch, List<FieldParam> params) { + //鑾峰彇骞冲簱涓鍚堟潯浠剁殑搴撲綅 + List<Map<String, Object>> list = viewLocDetlMapper.queryFlatStock(matnr, batch, params, LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id); + List<LocDetl> detls = new ArrayList<>(); + list.forEach(action -> { + LocDetl parseObject = JSONObject.parseObject(JSON.toJSONString(action), LocDetl.class); + detls.add(parseObject); + }); + return detls; + } +} -- Gitblit v1.9.1