| | |
| | | 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.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.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); |
| | | |
| | | //解析动态字段 |
| | | 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); |
| | | 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 |
| | | 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("明细删除失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | 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.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.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);
|
| | |
|
| | | //解析动态字段
|
| | | 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);
|
| | | 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
|
| | | 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("明细删除失败");
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|