|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.wms.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.R; | 
|---|
|  |  |  | 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.LocDetlField; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.MatField; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.param.GeneratePakInParam; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.param.LocAdjustParam; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.wms.common.annotation.OperationLog; | 
|---|
|  |  |  | import com.zy.asrs.wms.system.controller.BaseController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | 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.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/api") | 
|---|
|  |  |  | public class WorkController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WorkService workService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocDetlService locDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocService locService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatFieldService matFieldService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocDetlFieldService locDetlFieldService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @OperationLog("生成入库任务") | 
|---|
|  |  |  | @PostMapping("/rpc/generatePakIn") | 
|---|
|  |  |  | public R generatePakIn(@RequestBody GeneratePakInParam param) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (param.getTaskType() == 10) { | 
|---|
|  |  |  | workService.generateEmptyPakIn(param);//空托盘 | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | workService.generatePakIn(param);//满托盘 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("添加成功"); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | return R.error(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @OperationLog("库存调整") | 
|---|
|  |  |  | @PostMapping("/loc/adjust") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R locAdjust(@RequestBody LocAdjustParam param) { | 
|---|
|  |  |  | if (param == null) { | 
|---|
|  |  |  | return R.error("参数不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(param.getLocNo())) { | 
|---|
|  |  |  | return R.error("库位号不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (param.getDetls() == null) { | 
|---|
|  |  |  | return R.error("库存明细不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, param.getLocNo())); | 
|---|
|  |  |  | if (loc == null) { | 
|---|
|  |  |  | return R.error("库位不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除源库存 | 
|---|
|  |  |  | locDetlService.removeLocDetl(loc.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<MatField> matFields = matFieldService.list(new LambdaQueryWrapper<MatField>().eq(MatField::getUnique, 1)); | 
|---|
|  |  |  | for (Map<String, Object> map : param.getDetls()) { | 
|---|
|  |  |  | LocDetl locDetl = JSON.parseObject(JSON.toJSONString(map), LocDetl.class); | 
|---|
|  |  |  | HashMap<String, Object> uniqueFields = new HashMap<>(); | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()) { | 
|---|
|  |  |  | for (MatField field : matFields) { | 
|---|
|  |  |  | if (entry.getKey().equals(field.getName())) { | 
|---|
|  |  |  | uniqueFields.put(entry.getKey(), entry.getValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locDetl.setAnfme(Double.parseDouble(map.get("qty").toString())); | 
|---|
|  |  |  | locDetl.syncFieldMap(uniqueFields); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (locDetl.getAnfme() <= 0D) { | 
|---|
|  |  |  | throw new CoolException("数量不能小于0"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | locDetl.setId(null); | 
|---|
|  |  |  | locDetl.setLocId(loc.getId()); | 
|---|
|  |  |  | locDetl.setLocNo(loc.getLocNo()); | 
|---|
|  |  |  | boolean save = locDetlService.save(locDetl); | 
|---|
|  |  |  | if (!save) { | 
|---|
|  |  |  | throw new CoolException("库存调整失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //插入库存明细字段 | 
|---|
|  |  |  | for (MatField matField : matFields) { | 
|---|
|  |  |  | LocDetlField locDetlField = new LocDetlField(); | 
|---|
|  |  |  | locDetlField.setDetlId(locDetl.getId()); | 
|---|
|  |  |  | locDetlField.setFieldId(matField.getId()); | 
|---|
|  |  |  | locDetlField.setName(matField.getName()); | 
|---|
|  |  |  | locDetlField.setValue(Optional.ofNullable(uniqueFields.get(matField.getName()).toString()).orElse("")); | 
|---|
|  |  |  | locDetlFieldService.save(locDetlField); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | package com.zy.asrs.wms.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.R; | 
|---|
|  |  |  | 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.enums.OrderSettleType; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.enums.TaskStsType; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.param.GeneratePakInParam; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.param.LocAdjustParam; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.entity.param.LocTransferParam; | 
|---|
|  |  |  | import com.zy.asrs.wms.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.wms.common.annotation.OperationLog; | 
|---|
|  |  |  | import com.zy.asrs.wms.system.controller.BaseController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | 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.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/api") | 
|---|
|  |  |  | public class WorkController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WorkService workService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocDetlService locDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocService locService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatFieldService matFieldService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocDetlFieldService locDetlFieldService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @OperationLog("生成入库任务") | 
|---|
|  |  |  | @PostMapping("/rpc/generatePakIn") | 
|---|
|  |  |  | public R generatePakIn(@RequestBody GeneratePakInParam param) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (param.getTaskType() == 10) { | 
|---|
|  |  |  | workService.generateEmptyPakIn(param);//空托盘 | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | workService.generatePakIn(param);//满托盘 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("添加成功"); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | return R.error(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @OperationLog("库存调整") | 
|---|
|  |  |  | @PostMapping("/loc/adjust") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R locAdjust(@RequestBody LocAdjustParam param) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | workService.locAdjust(param); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | return R.error(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @OperationLog("库存移转") | 
|---|
|  |  |  | @PostMapping("/loc/transfer") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R locTransfer(@RequestBody LocTransferParam param) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | workService.locTransfer(param); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | return R.error(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|