package zy.cloud.wms.manager.controller;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.core.common.BaseRes;
|
import com.core.common.Cools;
|
import com.core.common.R;
|
import com.core.common.SnowflakeIdWorker;
|
import com.core.exception.CoolException;
|
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 zy.cloud.wms.common.entity.Parameter;
|
import zy.cloud.wms.common.model.ErpUpload;
|
import zy.cloud.wms.common.model.param.ReplenishDto;
|
import zy.cloud.wms.common.model.param.ReplenishParam;
|
import zy.cloud.wms.common.service.erp.ErpService;
|
import zy.cloud.wms.common.utils.VersionUtils;
|
import zy.cloud.wms.common.web.BaseController;
|
import zy.cloud.wms.manager.entity.*;
|
import zy.cloud.wms.manager.service.*;
|
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* Created by vincent on 2021/5/27
|
*/
|
@RestController
|
@RequestMapping("/open/api")
|
public class OpenController extends BaseController {
|
|
@Autowired
|
private PriorService priorService;
|
@Autowired
|
private NodeService nodeService;
|
@Autowired
|
private MatService matService;
|
@Autowired
|
private LocDetlService locDetlService;
|
@Autowired
|
private ErpService erpService;
|
@Autowired
|
private PakinService pakinService;
|
@Autowired
|
private SnowflakeIdWorker snowflakeIdWorker;
|
|
@PostMapping("/erp/upload")
|
public R erpUpload(@RequestBody ErpUpload erpUpload){
|
Boolean result = erpService.uploadBill(erpUpload.getDtos(), erpUpload.getDocId(), erpUpload.getDocNumber()).getSuccess();
|
return result ? R.ok() : R.error();
|
}
|
|
@PostMapping("/replenish")
|
@Transactional
|
public synchronized R asrsReplenish(@RequestBody ReplenishParam params){
|
if (Cools.isEmpty(params.getList())) {
|
return R.parse(BaseRes.PARAM);
|
}
|
Date now = new Date();
|
for (ReplenishDto param : params.getList()) {
|
Mat mat = matService.selectByMatnr(param.getMatnr());
|
List<Prior> priors = priorService.selectList(new EntityWrapper<Prior>().eq("matnr", param.getMatnr()));
|
Node node;
|
// 有推荐货位
|
if (!Cools.isEmpty(priors)) {
|
Prior prior = priors.get(0);
|
node = nodeService.selectById(prior.getNodeId());
|
|
LocDetl locDetl = locDetlService.getLocDetl(node.getId(), param.getMatnr());
|
if (locDetl == null) {
|
locDetl = new LocDetl();
|
locDetl.setLocNo(node.getName());
|
locDetl.setNodeId(node.getId());
|
locDetl.setAnfme(param.getCount());
|
VersionUtils.setLocDetl(locDetl, mat);
|
locDetl.setStatus(1);
|
locDetl.setCreateBy(9527L);
|
locDetl.setCreateTime(now);
|
locDetl.setUpdateBy(9527L);
|
locDetl.setUpdateTime(now);
|
boolean insert = locDetlService.insert(locDetl);
|
if (!insert) {
|
throw new CoolException("新增库存明细档失败");
|
}
|
} else {
|
if (!locDetlService.incrementStock(node.getId(), param.getMatnr(), param.getCount())) {
|
throw new CoolException("新增库存明细档失败");
|
}
|
}
|
|
// 没有推荐货物
|
} else {
|
node = nodeService.selectByUuid(Parameter.get().getUniNode());
|
|
LocDetl locDetl = locDetlService.getLocDetl(node.getId(), param.getMatnr());
|
if (locDetl == null) {
|
locDetl = new LocDetl();
|
locDetl.setLocNo(node.getName());
|
locDetl.setNodeId(node.getId());
|
locDetl.setAnfme(param.getCount());
|
VersionUtils.setLocDetl(locDetl, mat);
|
locDetl.setStatus(1);
|
locDetl.setCreateBy(9527L);
|
locDetl.setCreateTime(now);
|
locDetl.setUpdateBy(9527L);
|
locDetl.setUpdateTime(now);
|
boolean insert = locDetlService.insert(locDetl);
|
if (!insert) {
|
throw new CoolException("新增库存明细档失败");
|
}
|
} else {
|
if (!locDetlService.incrementStock(node.getId(), param.getMatnr(), param.getCount())) {
|
throw new CoolException("新增库存明细档失败");
|
}
|
}
|
}
|
|
// 保存入库记录
|
Pakin pakin = new Pakin(
|
"BC" + String.valueOf(snowflakeIdWorker.nextId()), // 任务号[非空]
|
null, // 工作状态
|
null, // 托盘号
|
param.getCount(), // 入库数量
|
node.getId(), // 关联货位[非空]
|
node.getUuid(), // 货位[非空]
|
mat.getMatnr(), // 商品编码[非空]
|
null, // 商品名称
|
null, // 名称
|
null, // 尺码
|
null, // 型号
|
null, // 批号
|
null, // 单位
|
null, // SKC
|
null, // 单据类型
|
null, // 单据编号
|
null, // 客户名称
|
null, // 品项数
|
null, // 数量
|
null, // 重量
|
1, // 状态
|
9527L, // 添加人员
|
now, // 添加时间
|
9527L, // 修改人员
|
now, // 修改时间
|
"补仓入库" // 备注
|
);
|
VersionUtils.setPakin(pakin, mat);
|
if (!pakinService.insert(pakin)) {
|
throw new CoolException("保存入库记录失败");
|
}
|
}
|
return R.ok();
|
}
|
|
|
}
|