| | |
| | | <version>5.2.5.RELEASE</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-test</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>junit</groupId> |
| | | <artifactId>junit</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import com.zy.asrs.wms.asrs.entity.*; |
| | | import com.zy.asrs.wms.asrs.mapper.LocDetlMapper; |
| | | import com.zy.asrs.wms.asrs.service.LocDetlFieldService; |
| | | import com.zy.asrs.wms.asrs.service.MatFieldService; |
| | | import com.zy.asrs.wms.common.annotation.OperationLog; |
| | |
| | | @Autowired |
| | | private LocDetlFieldService locDetlFieldService; |
| | | |
| | | |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:locDetl:list')") |
| | | @PostMapping("/locDetl/page") |
| | | public R page(@RequestBody Map<String, Object> map) { |
New file |
| | |
| | | package com.zy.asrs.wms.asrs.controller; |
| | | |
| | | import com.zy.asrs.framework.common.R; |
| | | import com.zy.asrs.wms.asrs.controller.req.OutReq; |
| | | import com.zy.asrs.wms.asrs.entity.LocDetl; |
| | | import com.zy.asrs.wms.asrs.manage.OutManage; |
| | | import com.zy.asrs.wms.system.controller.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 这里处理所有的出库流程的接口 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/api") |
| | | public class OutController extends BaseController { |
| | | |
| | | @Autowired |
| | | private OutManage outManage; |
| | | |
| | | |
| | | /** |
| | | * 获取库存 |
| | | * |
| | | * @param map |
| | | * @return |
| | | */ |
| | | @PostMapping("/out/getStock") |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | List<LocDetl> suitableMat = outManage.getSuitableMat(map); |
| | | return R.ok(suitableMat); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 出库 |
| | | * |
| | | * @param outReq 出库列表 |
| | | * @return |
| | | */ |
| | | @PostMapping("/out/start") |
| | | public R page(@RequestBody OutReq outReq) { |
| | | outManage.out(outReq); |
| | | return R.ok(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wms.asrs.controller.req; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | public class OutReq implements Serializable { |
| | | /** |
| | | * 库位明细 |
| | | */ |
| | | private List<Detl> detls; |
| | | /** |
| | | * 目标站点 |
| | | */ |
| | | private String targetSite; |
| | | |
| | | @Data |
| | | public class Detl { |
| | | /** |
| | | * 库存明细ID |
| | | */ |
| | | private Long locDetlId; |
| | | /** |
| | | * 数量 |
| | | */ |
| | | private Double anfme; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | @Data |
| | | public class FieldParam { |
| | | |
| | | /** |
| | | * 字段名 |
| | | */ |
| | | private String name; |
| | | |
| | | /** |
| | | * 比较类型,常见的 =,>,<,>=,<=,like,in,between,is null,is not null |
| | | * 注:有些需要转义 |
| | | */ |
| | | private String type; |
| | | /** |
| | | * 字段值 |
| | | */ |
| | | private Object value; |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wms.asrs.entity.param; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class FieldSortParam { |
| | | /** |
| | | * 字段名 |
| | | */ |
| | | private String name; |
| | | /** |
| | | * desc和asc |
| | | */ |
| | | private String value; |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wms.asrs.entity.po; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | @Data |
| | | public class OutStrategyPO implements Serializable { |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wms.asrs.manage; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | | import com.zy.asrs.wms.asrs.entity.Loc; |
| | | import com.zy.asrs.wms.asrs.entity.LocDetl; |
| | | import com.zy.asrs.wms.asrs.entity.Task; |
| | | import com.zy.asrs.wms.asrs.entity.TaskDetl; |
| | | import com.zy.asrs.wms.asrs.entity.enums.LocStsType; |
| | | import com.zy.asrs.wms.asrs.service.*; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class LocManage { |
| | | |
| | | private static Logger logger = LoggerFactory.getLogger(LocManage.class); |
| | | |
| | | @Autowired |
| | | private LocService locService; |
| | | |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | |
| | | @Autowired |
| | | private WorkService workService; |
| | | |
| | | |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | |
| | | @Autowired |
| | | private TaskDetlService taskDetlService; |
| | | |
| | | |
| | | /** |
| | | * 移库方法 |
| | | * |
| | | * @param sourceLocId 源库位 |
| | | * @param locId 目标库位 |
| | | */ |
| | | @Transactional |
| | | public void locMove(Long sourceLocId, Long locId) { |
| | | logger.info("移库操作,源库位:{},目标库位:{}", sourceLocId, locId); |
| | | if (Cools.isEmpty(sourceLocId) || Cools.isEmpty(locId)) { |
| | | throw new CoolException("源库位或目标为空"); |
| | | } |
| | | Loc sourceLoc = locService.getById(sourceLocId); |
| | | Loc loc = locService.getById(locId); |
| | | if (Cools.isEmpty(sourceLoc) || Cools.isEmpty(loc)) { |
| | | throw new CoolException("源库位或目标为空"); |
| | | } |
| | | List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, sourceLoc.getId())); |
| | | //TODO 根据不同的设备,可能有不同的移库规则 |
| | | |
| | | // 保存工作档 |
| | | Task task = new Task(); |
| | | task.setTaskNo(workService.generateTaskNo(1L)); |
| | | // 任务状态 |
| | | task.setTaskSts(11L); |
| | | // 任务类型 |
| | | task.setTaskType(11L); |
| | | // 优先级 |
| | | task.setIoPri(1); |
| | | // 源库位 |
| | | task.setOriginLoc(sourceLoc.getLocNo()); |
| | | // 目标库位 |
| | | task.setTargetLoc(loc.getLocNo()); |
| | | // 托盘码 |
| | | task.setBarcode(loc.getBarcode()); |
| | | boolean res = taskService.save(task); |
| | | if (!res) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 工作档明细保存 |
| | | for (LocDetl locDetl : locDetls) { |
| | | TaskDetl taskDetl = new TaskDetl(); |
| | | taskDetl.sync(locDetl); |
| | | taskDetl.setTaskId(task.getId()); |
| | | if (!taskDetlService.save(taskDetl)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | } |
| | | // 修改源库位状态 |
| | | if (sourceLoc.getLocStsId$().equals("D") || sourceLoc.getLocStsId$().equals("F")) { |
| | | sourceLoc.setLocStsId(LocStsType.R.val()); // R.出库预约 |
| | | if (!locService.updateById(sourceLoc)) { |
| | | throw new CoolException("更新源库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("源库位出库失败,状态:" + sourceLoc.getLocStsId$()); |
| | | } |
| | | // 修改目标库位状态 |
| | | if (loc.getLocStsId$().equals("O")) { |
| | | loc.setLocStsId(LocStsType.S.val()); // S.入库预约 |
| | | if (!locService.updateById(loc)) { |
| | | throw new CoolException("更新目标库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("移转失败,目标库位状态:" + loc.getLocStsId$()); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wms.asrs.manage; |
| | | |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | | import com.zy.asrs.wms.asrs.controller.req.OutReq; |
| | | import com.zy.asrs.wms.asrs.entity.Loc; |
| | | import com.zy.asrs.wms.asrs.entity.LocDetl; |
| | | import com.zy.asrs.wms.asrs.entity.Task; |
| | | import com.zy.asrs.wms.asrs.entity.TaskDetl; |
| | | import com.zy.asrs.wms.asrs.entity.param.FieldParam; |
| | | import com.zy.asrs.wms.asrs.service.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 出库管理 |
| | | */ |
| | | @Service |
| | | public class OutManage { |
| | | |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | |
| | | @Autowired |
| | | private TaskDetlService taskDetlService; |
| | | |
| | | @Autowired |
| | | private LocService locService; |
| | | |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | |
| | | |
| | | @Autowired |
| | | private WorkService workService; |
| | | |
| | | |
| | | /** |
| | | * 获取库存 |
| | | * |
| | | * @param map |
| | | */ |
| | | public List<LocDetl> getSuitableMat(Map<String, Object> map) { |
| | | List<FieldParam> param = new ArrayList<>(); |
| | | map.entrySet().stream().filter(entry -> entry.getValue() != null).forEach(entry -> { |
| | | FieldParam fieldParam = new FieldParam(); |
| | | fieldParam.setName(entry.getKey()); |
| | | fieldParam.setValue(entry.getValue()); |
| | | param.add(fieldParam); |
| | | }); |
| | | //TODO 这里加上出库规则 |
| | | List<LocDetl> stock = locDetlService.getSuitableMat(param, null); |
| | | return stock; |
| | | } |
| | | |
| | | /** |
| | | * 出库 |
| | | * |
| | | * @param outReq |
| | | */ |
| | | public void out(OutReq outReq) { |
| | | Map<Long, List<OutReq.Detl>> map = outReq.getDetls().stream().collect(Collectors.groupingBy(OutReq.Detl::getLocDetlId)); |
| | | map.forEach((k, v) -> { |
| | | Loc loc = locService.getById(k); |
| | | processTask(loc, v, outReq.getTargetSite()); |
| | | }); |
| | | } |
| | | |
| | | |
| | | private void processTask(Loc loc, List<OutReq.Detl> detls, String targetSite) { |
| | | // 保存工作档 |
| | | Task task = new Task(); |
| | | task.setTaskNo(workService.generateTaskNo(1L)); |
| | | // 任务状态 |
| | | task.setTaskSts(101L); |
| | | // 任务类型 |
| | | task.setTaskType(101L); |
| | | // 优先级 |
| | | task.setIoPri(1); |
| | | // 源库位 |
| | | task.setOriginLoc(loc.getLocNo()); |
| | | // 目标站点 |
| | | task.setTargetSite(targetSite); |
| | | // 托盘码 |
| | | task.setBarcode(loc.getBarcode()); |
| | | boolean res = taskService.save(task); |
| | | if (!res) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 工作档明细保存 |
| | | for (OutReq.Detl detl : detls) { |
| | | LocDetl locDetl = locDetlService.getById(detl.getLocDetlId()); |
| | | TaskDetl taskDetl = new TaskDetl(); |
| | | taskDetl.sync(locDetl); |
| | | taskDetl.setTaskId(task.getId()); |
| | | if (!taskDetlService.save(taskDetl)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wms.asrs.manage; |
| | | |
| | | import com.zy.asrs.wms.asrs.mapper.ViewLocDetlMapper; |
| | | import com.zy.asrs.wms.asrs.service.TaskDetlService; |
| | | import com.zy.asrs.wms.asrs.service.TaskService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | @Service |
| | | public class TaskManage { |
| | | |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | |
| | | @Autowired |
| | | private TaskDetlService taskDetlService; |
| | | |
| | | @Autowired |
| | | private ViewLocDetlMapper viewLocDetlMapper; |
| | | |
| | | |
| | | } |
| | |
| | | import com.zy.asrs.wms.asrs.entity.LocDetl; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.executor.Executor; |
| | | import org.apache.ibatis.mapping.MappedStatement; |
| | | import org.apache.ibatis.plugin.Intercepts; |
| | | import org.apache.ibatis.plugin.Signature; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.util.List; |
| | |
| | | |
| | | List<LocDetl> getList(String matnr, String batch, List<Long> ids); |
| | | |
| | | |
| | | List<LocDetl> getStock(String matnr, String batch, List<Long> ids); |
| | | } |
| | |
| | | package com.zy.asrs.wms.asrs.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.zy.asrs.wms.asrs.entity.LocDetl; |
| | | import com.zy.asrs.wms.asrs.entity.ViewLocDetl; |
| | | import com.zy.asrs.wms.asrs.entity.param.FieldParam; |
| | | import com.zy.asrs.wms.asrs.entity.param.FieldSortParam; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.util.List; |
| | |
| | | |
| | | Map<String,Object> getById(Long id); |
| | | |
| | | |
| | | List<Map<String,Object>> getSuitableMat( @Param("param") List<FieldParam> param, @Param("sortParam") List<FieldSortParam> sortParam); |
| | | |
| | | } |
| | |
| | | import com.zy.asrs.wms.asrs.entity.LocDetl; |
| | | import com.zy.asrs.wms.asrs.entity.ViewLocDetl; |
| | | import com.zy.asrs.wms.asrs.entity.param.FieldParam; |
| | | import com.zy.asrs.wms.asrs.entity.param.FieldSortParam; |
| | | import com.zy.asrs.wms.common.domain.BaseParam; |
| | | import com.zy.asrs.wms.common.domain.PageParam; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | |
| | | |
| | | List<LocDetl> parseLocDetl(List<LocDetl> list); |
| | | |
| | | List<LocDetl> getSuitableMat( List<FieldParam> param, List<FieldSortParam> sortParam); |
| | | |
| | | } |
| | |
| | | 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.wms.asrs.entity.LocDetl; |
| | | import com.zy.asrs.wms.asrs.entity.LocDetlField; |
| | | import com.zy.asrs.wms.asrs.entity.ViewLocDetl; |
| | | import com.zy.asrs.wms.asrs.entity.param.FieldParam; |
| | | import com.zy.asrs.wms.asrs.entity.param.FieldSortParam; |
| | | import com.zy.asrs.wms.asrs.mapper.LocDetlMapper; |
| | | import com.zy.asrs.wms.asrs.entity.LocDetl; |
| | | import com.zy.asrs.wms.asrs.mapper.ViewLocDetlMapper; |
| | | import com.zy.asrs.wms.asrs.service.LocDetlFieldService; |
| | | import com.zy.asrs.wms.asrs.service.LocDetlService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | 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 java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service("locDetlService") |
| | | public class LocDetlServiceImpl extends ServiceImpl<LocDetlMapper, LocDetl> implements LocDetlService { |
| | |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 根据出库条件查询符合的库存 |
| | | * @param param 查询条件 |
| | | * @param sortParam 排序字段 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<LocDetl> getSuitableMat( List<FieldParam> param, List<FieldSortParam> sortParam) { |
| | | List<Map<String, Object>> stock = viewLocDetlMapper.getSuitableMat(param, sortParam); |
| | | List<LocDetl> locDetls = new ArrayList<>(); |
| | | for (Map<String, Object> objectMap : stock) { |
| | | LocDetl detl = JSON.parseObject(JSON.toJSONString(objectMap), LocDetl.class); |
| | | detl.syncFieldMap(objectMap); |
| | | locDetls.add(detl); |
| | | } |
| | | return locDetls; |
| | | } |
| | | |
| | | } |
| | |
| | | package com.zy.asrs.wms.asrs.service.impl; |
| | | |
| | | import com.zy.asrs.wms.asrs.entity.enums.LocStsType; |
| | | import com.zy.asrs.wms.asrs.mapper.LocMapper; |
| | | import com.zy.asrs.wms.asrs.entity.Loc; |
| | | import com.zy.asrs.wms.asrs.service.LocService; |
| | |
| | | @Service("locService") |
| | | public class LocServiceImpl extends ServiceImpl<LocMapper, Loc> implements LocService { |
| | | |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wms.asrs.strategy; |
| | | |
| | | import com.zy.asrs.wms.asrs.entity.LocDetl; |
| | | import com.zy.asrs.wms.asrs.entity.Mat; |
| | | |
| | | /** |
| | | * 先进先出 |
| | | */ |
| | | public class FIFOWithdrawalStrategy implements WithdrawalStrategy { |
| | | @Override |
| | | public Mat selectMatStrategy(LocDetl storageLocation) { |
| | | |
| | | return null; |
| | | } |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wms.asrs.strategy; |
| | | |
| | | import com.zy.asrs.wms.asrs.entity.LocDetl; |
| | | import com.zy.asrs.wms.asrs.entity.Mat; |
| | | |
| | | public class WithdrawalService { |
| | | private WithdrawalStrategy strategy; |
| | | |
| | | public WithdrawalService(WithdrawalStrategy strategy) { |
| | | this.strategy = strategy; |
| | | } |
| | | |
| | | public Mat withdrawProduct(LocDetl storageLocation) { |
| | | return strategy.selectMatStrategy(storageLocation); |
| | | } |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wms.asrs.strategy; |
| | | |
| | | import com.zy.asrs.wms.asrs.entity.LocDetl; |
| | | import com.zy.asrs.wms.asrs.entity.Mat; |
| | | |
| | | public interface WithdrawalStrategy { |
| | | Mat selectMatStrategy(LocDetl locDetl); |
| | | } |
| | |
| | | |
| | | //保存任务明细历史档 |
| | | List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId()); |
| | | if(taskDetls.isEmpty()) { |
| | | if (taskDetls.isEmpty()) { |
| | | throw new CoolException("任务明细不存在"); |
| | | } |
| | | for (TaskDetl taskDetl : taskDetls) { |
| | |
| | | |
| | | //删除明细扩展 |
| | | boolean removeField = taskDetlFieldService.removeById(detlField.getId()); |
| | | if(!removeField){ |
| | | if (!removeField) { |
| | | throw new CoolException("删除明细扩展失败"); |
| | | } |
| | | } |
| | | |
| | | //删除明细 |
| | | boolean removeDetl = taskDetlService.removeById(taskDetl.getId()); |
| | | if(!removeDetl){ |
| | | if (!removeDetl) { |
| | | throw new CoolException("明细删除失败"); |
| | | } |
| | | } |
| | |
| | | if (checkOrderComplete) { |
| | | //订单已经完成 |
| | | Order order = orderService.getById(orderDetl.getOrderId()); |
| | | if(order == null) { |
| | | if (order == null) { |
| | | throw new CoolException("订单不存在"); |
| | | } |
| | | |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | }finally { |
| | | } finally { |
| | | InterceptorIgnoreHelper.clearIgnoreStrategy(); |
| | | } |
| | | } |
| | |
| | | public void outExecute() { |
| | | InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build()); |
| | | try { |
| | | //获取入库完成任务 |
| | | List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskSts, 200)); |
| | | if (list.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | for (Task task : list) { |
| | | Long hostId = task.getHostId(); |
| | | |
| | | //保存任务历史档 |
| | | TaskLog taskLog = new TaskLog(); |
| | | taskLog.sync(task); |
| | | if (!taskLogService.save(taskLog)) { |
| | | throw new CoolException("保存任务历史档失败"); |
| | | } |
| | | |
| | | //删除任务历史档案 |
| | | if (!taskService.removeById(task.getId())) { |
| | | throw new CoolException("删除任务档失败"); |
| | | } |
| | | |
| | | //保存任务明细历史档 |
| | | List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId()); |
| | | if (taskDetls.isEmpty()) { |
| | | throw new CoolException("任务明细不存在"); |
| | | } |
| | | for (TaskDetl taskDetl : taskDetls) { |
| | | TaskDetlLog taskDetlLog = new TaskDetlLog(); |
| | | taskDetlLog.sync(taskDetl); |
| | | if (!taskDetlLogService.save(taskDetlLog)) { |
| | | throw new CoolException("保存任务明细历史档失败"); |
| | | } |
| | | |
| | | //保存明细扩展字段历史档 |
| | | List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()).eq(TaskDetlField::getHostId, hostId)); |
| | | for (TaskDetlField detlField : detlFields) { |
| | | //明细扩展字段数据保存至历史档 |
| | | TaskDetlFieldLog taskDetlFieldLog = new TaskDetlFieldLog(); |
| | | taskDetlFieldLog.sync(detlField); |
| | | if (!taskDetlFieldLogService.save(taskDetlFieldLog)) { |
| | | throw new CoolException("明细扩展字段转历史档案失败"); |
| | | } |
| | | |
| | | //删除明细扩展 |
| | | boolean removeField = taskDetlFieldService.removeById(detlField.getId()); |
| | | if (!removeField) { |
| | | throw new CoolException("删除明细扩展失败"); |
| | | } |
| | | } |
| | | |
| | | //删除明细 |
| | | boolean removeDetl = taskDetlService.removeById(taskDetl.getId()); |
| | | if (!removeDetl) { |
| | | throw new CoolException("明细删除失败"); |
| | | } |
| | | } |
| | | |
| | | //更新订单信息 |
| | | for (TaskDetl taskDetl : taskDetls) { |
| | | OrderDetl orderDetl = orderDetlService.getById(taskDetl.getDetlId()); |
| | | if (orderDetl == null) { |
| | | throw new CoolException("订单明细不存在"); |
| | | } |
| | | |
| | | orderDetl.setWorkQty(orderDetl.getWorkQty() - taskDetl.getAnfme());//工作中数量减少 |
| | | orderDetl.setQty(orderDetl.getQty() + taskDetl.getAnfme());//已完成数量增加 |
| | | orderDetl.setUpdateTime(new Date()); |
| | | if (!orderDetlService.updateById(orderDetl)) { |
| | | throw new CoolException("更新订单明细失败"); |
| | | } |
| | | |
| | | //检测订单是否完成 |
| | | boolean checkOrderComplete = orderService.checkOrderComplete(orderDetl.getOrderId()); |
| | | if (checkOrderComplete) { |
| | | //订单已经完成 |
| | | Order order = orderService.getById(orderDetl.getOrderId()); |
| | | if (order == null) { |
| | | throw new CoolException("订单不存在"); |
| | | } |
| | | |
| | | order.setOrderSettle(OrderSettleType.COMPLETE.val()); |
| | | order.setUpdateTime(new Date()); |
| | | if (!orderService.updateById(order)) { |
| | | throw new CoolException("订单更新失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | }finally { |
| | | } finally { |
| | | InterceptorIgnoreHelper.clearIgnoreStrategy(); |
| | | } |
| | | } |
| | |
| | | |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | @Autowired |
| | | private TaskDetlService taskDetlService; |
| | | |
| | | @Autowired |
| | | private TaskDetlFieldService taskDetlFieldService; |
| | | |
| | | @Autowired |
| | | private LocService locService; |
| | | |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | |
| | | @Autowired |
| | | private LocDetlFieldService locDetlFieldService; |
| | | |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | |
| | | @Autowired |
| | | private WaitPakinLogService waitPakinLogService; |
| | | |
| | | @Autowired |
| | | private TaskDetlLogService taskDetlLogService; |
| | | |
| | | @Autowired |
| | | private TaskDetlFieldLogService taskDetlFieldLogService; |
| | | |
| | | @Autowired |
| | | private OrderService orderService; |
| | | |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | |
| | | |
| | | @Scheduled(cron = "0/3 * * * * ? ") |
| | | @Transactional |
| | |
| | | switch (task.getTaskType().intValue()) { |
| | | case 1://入库 |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()).eq(Loc::getHostId, hostId)); |
| | | if(loc == null) { |
| | | if (loc == null) { |
| | | throw new CoolException("库位不存在"); |
| | | } |
| | | |
| | | if(loc.getLocStsId() != LocStsType.S.val()){ |
| | | if (loc.getLocStsId() != LocStsType.S.val()) { |
| | | throw new CoolException("库位状态不处于S.入库预约"); |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId()); |
| | | if(taskDetls.isEmpty()) { |
| | | if (taskDetls.isEmpty()) { |
| | | throw new CoolException("任务明细不存在"); |
| | | } |
| | | |
| | |
| | | |
| | | //组托通知档转历史档 |
| | | List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, task.getBarcode()).eq(WaitPakin::getHostId, hostId)); |
| | | if(waitPakins.isEmpty()) { |
| | | if (waitPakins.isEmpty()) { |
| | | throw new CoolException("组托通知档不存在"); |
| | | } |
| | | for (WaitPakin waitPakin : waitPakins) { |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | }finally { |
| | | } finally { |
| | | InterceptorIgnoreHelper.clearIgnoreStrategy(); |
| | | } |
| | | } |
| | |
| | | public void outExecute() { |
| | | InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build()); |
| | | try { |
| | | //获取出库完成任务 |
| | | List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskSts, 199)); |
| | | if (list.isEmpty()) { |
| | | return; |
| | | } |
| | | for (Task task : list) { |
| | | //同步数据 |
| | | Long hostId = task.getHostId(); |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()).eq(Loc::getHostId, hostId)); |
| | | if (loc == null) { |
| | | throw new CoolException("库位不存在"); |
| | | } |
| | | if (loc.getLocStsId() != LocStsType.R.val()) { |
| | | throw new CoolException("库位状态不处于R.出库预约"); |
| | | } |
| | | List<TaskDetl> taskDetls = taskDetlService.getTaskDetlByTaskId(task.getId()); |
| | | if (taskDetls.isEmpty()) { |
| | | throw new CoolException("任务明细不存在"); |
| | | } |
| | | switch (task.getTaskType().intValue()) { |
| | | //出库 |
| | | case 101: |
| | | loc.setLocStsId(LocStsType.O.val()); |
| | | loc.setBarcode(""); |
| | | if (!locService.updateById(loc)) { |
| | | throw new CoolException("库位状态更新失败"); |
| | | } |
| | | List<LocDetl> detlList = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocNo, loc.getId()).eq(LocDetl::getHostId, hostId)); |
| | | //删除库存明细 |
| | | for (LocDetl locDetl : detlList) { |
| | | if (!locDetlService.removeById(locDetl)) { |
| | | throw new CoolException("删除库存明细失败"); |
| | | } |
| | | List<LocDetlField> detlFields = locDetlFieldService.list(new LambdaQueryWrapper<LocDetlField>().eq(LocDetlField::getDetlId, locDetl.getId()).eq(LocDetlField::getHostId, hostId)); |
| | | for (LocDetlField detlField : detlFields) { |
| | | if (!locDetlFieldService.removeById(detlField)) { |
| | | throw new CoolException("删除明细扩展字段失败"); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | |
| | | } |
| | | |
| | | task.setTaskSts(200L);//200.库存更新完成 |
| | | if (!taskService.updateById(task)) { |
| | | throw new CoolException("库存更新失败"); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | }finally { |
| | | } finally { |
| | | InterceptorIgnoreHelper.clearIgnoreStrategy(); |
| | | } |
| | | } |
| | |
| | | PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); |
| | | interceptor.addInnerInterceptor(paginationInnerInterceptor); |
| | | |
| | | |
| | | return interceptor; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Bean |
| | | public ConfigurationCustomizer mybatisConfigurationCustomizer(){ |
| | | public ConfigurationCustomizer mybatisConfigurationCustomizer() { |
| | | return configuration -> configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory()); |
| | | } |
| | | |
New file |
| | |
| | | package com.zy.asrs.wms.common.event; |
| | | |
| | | import org.springframework.context.ApplicationEvent; |
| | | |
| | | |
| | | public class OrderBatchEvent extends ApplicationEvent { |
| | | private String orderId; |
| | | |
| | | public OrderBatchEvent(Object source, String orderId) { |
| | | super(source); |
| | | this.orderId = orderId; |
| | | } |
| | | |
| | | public String getOrderId() { |
| | | return orderId; |
| | | } |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wms.common.event; |
| | | |
| | | import org.springframework.context.ApplicationListener; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | //实现ApplicationListener接口,并指定监听的事件类型 |
| | | @Component |
| | | public class OrderBatchListener implements ApplicationListener<OrderBatchEvent> { |
| | | |
| | | @Override |
| | | public void onApplicationEvent(OrderBatchEvent event) { |
| | | //使用onApplicationEvent方法对消息进行接受处理 |
| | | String orderId = event.getOrderId(); |
| | | System.out.println("DemoListener获取到了监听消息:" + orderId); |
| | | |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.zy.asrs.wms.common.interceptor; |
| | | |
| | | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
| | | import org.apache.ibatis.reflection.MetaObject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 实现mybatisplus的接口,对一些字段的自动填从 |
| | | */ |
| | | @Component |
| | | public class MyMetaObjectHandler implements MetaObjectHandler { |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(MyMetaObjectHandler.class); |
| | | |
| | | @Override |
| | | public void insertFill(MetaObject metaObject) { |
| | | log.info("323434323211221"); |
| | | // String username = SecurityUtils.getUsername(); |
| | | // if (StrUtil.isNotBlank(username)) { |
| | | // this.setFieldValByName("createName", username, metaObject); |
| | | // } |
| | | // this.setFieldValByName("createId", SecurityUtils.getUserId(), metaObject); |
| | | this.setFieldValByName("createTime", new Date(), metaObject); |
| | | this.setFieldValByName("status", 1, metaObject); |
| | | this.setFieldValByName("isDeleted", 0, metaObject); |
| | | } |
| | | |
| | | @Override |
| | | public void updateFill(MetaObject metaObject) { |
| | | log.info("ceshishsihsshiisis"); |
| | | // String username = SecurityUtils.getUsername(); |
| | | // if (StrUtil.isNotBlank(username)) { |
| | | // this.setFieldValByName("updateName", username, metaObject); |
| | | // } |
| | | // this.setFieldValByName("updateId", SecurityUtils.getUserId(), metaObject); |
| | | this.setFieldValByName("updateTime", new Date(), metaObject); |
| | | } |
| | | } |
New file |
| | |
| | | //package com.zy.asrs.wms.common.interceptor; |
| | | // |
| | | //import com.baomidou.mybatisplus.core.toolkit.PluginUtils; |
| | | //import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor; |
| | | //import org.apache.ibatis.executor.Executor; |
| | | //import org.apache.ibatis.mapping.BoundSql; |
| | | //import org.apache.ibatis.mapping.MappedStatement; |
| | | //import org.apache.ibatis.session.ResultHandler; |
| | | //import org.apache.ibatis.session.RowBounds; |
| | | // |
| | | //import java.sql.SQLException; |
| | | // |
| | | // |
| | | //public class StockSortInterceptor implements InnerInterceptor { |
| | | // |
| | | // @Override |
| | | // public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { |
| | | // // 获取原始SQL语句 |
| | | // String originalSql = boundSql.getSql(); |
| | | // // 判断方法是否为特定的查询方法 |
| | | // if (isSpecificQueryMethod(ms)) { |
| | | // // 添加排序逻辑 |
| | | // String sql = addSort(originalSql); |
| | | // // 修改完成的sql 再设置回去 |
| | | // PluginUtils.MPBoundSql mpBoundSql = PluginUtils.mpBoundSql(boundSql); |
| | | // mpBoundSql.sql(sql); |
| | | // } |
| | | // } |
| | | // |
| | | // private boolean isSpecificQueryMethod(MappedStatement ms) { |
| | | // // 检查MappedStatement的ID以判断是否为特定的查询方法 |
| | | // String statementId = ms.getId(); |
| | | // return statementId.equals("com.zy.asrs.wms.asrs.mapper.LocDetlMapper.getStock"); |
| | | // } |
| | | // |
| | | // private String addSort(String originalSql) { |
| | | // // 根据需要添加排序逻辑 |
| | | // return originalSql + " ORDER BY" + isQueue(); |
| | | // } |
| | | // |
| | | // private String isQueue() { |
| | | // //先进先出:在查询库存记录时,排序字段按照man_loc_detl表的createTime升序排序 |
| | | // return " create_time ASC"; |
| | | // } |
| | | // |
| | | // private String isFree() { |
| | | // //设备空闲情况:优先查询空闲的设备,在有空闲的设备时,从空闲的设备对应的货架上查询 |
| | | // //TODO |
| | | // return " create_time ASC"; |
| | | // } |
| | | // |
| | | // private String isBarcodeDesc() { |
| | | // //托盘最大值降序:就是按照托盘号降序 |
| | | // return " barcode DESC"; |
| | | // } |
| | | // |
| | | // private String isBarcodeAsc() { |
| | | // //托盘最大值升序:就是按照托盘号升序 |
| | | // return " barcode ASC"; |
| | | // } |
| | | // |
| | | // private String isEven() { |
| | | // // 楼层均匀分布: |
| | | // //TODO |
| | | // return " barcode ASC"; |
| | | // } |
| | | // |
| | | //} |
| | |
| | | </foreach> |
| | | </if> |
| | | </select> |
| | | |
| | | <select id="getStock" resultType="com.zy.asrs.wms.asrs.entity.LocDetl"> |
| | | select * from man_loc_detl |
| | | where matnr = #{matnr} |
| | | <if test="batch!=null"> |
| | | and batch = #{batch} |
| | | </if> |
| | | <if test="ids!=null and ids.size()>0"> |
| | | and id in |
| | | <foreach item="item" collection="ids" index="index" separator="," open="(" close=")"> |
| | | #{item} |
| | | </foreach> |
| | | </if> |
| | | </select> |
| | | |
| | | </mapper> |
| | |
| | | </select> |
| | | |
| | | <select id="getById" resultType="map"> |
| | | select * from view_man_loc_detl |
| | | select * |
| | | from view_man_loc_detl |
| | | where id = #{id} |
| | | </select> |
| | | |
| | | |
| | | |
| | | <select id="getSuitableMat" resultType="map"> |
| | | select * from view_man_loc_detl ld |
| | | where 1=1 |
| | | <if test="param!=null and param.size()>0"> |
| | | <foreach item="item" collection="param" index="index"> |
| | | and ${item.name} ${type} #{item.value} |
| | | </foreach> |
| | | </if> |
| | | <if test="sortParam!=null and sortParam.size()>0"> |
| | | <foreach collection="sortParam" item="order" open="order by " separator="," close=" "> |
| | | ${item.name} #{item.value} |
| | | </foreach> |
| | | </if> |
| | | </select> |
| | | </mapper> |