| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.common.openapi.entity.HostKey; |
| | | import com.zy.asrs.common.openapi.entity.param.GenerateOrderPakInParam; |
| | | import com.zy.asrs.common.openapi.entity.dto.OrderListDto; |
| | | import com.zy.asrs.common.openapi.entity.param.*; |
| | | import com.zy.asrs.common.openapi.service.ApiService; |
| | | import com.zy.asrs.common.openapi.service.HostKeyService; |
| | | import com.zy.asrs.common.web.BaseController; |
| | | import com.zy.asrs.common.wms.entity.DocType; |
| | | import com.zy.asrs.common.wms.service.DocTypeService; |
| | | import com.zy.asrs.common.wms.entity.OrderSettle; |
| | | import com.zy.asrs.framework.annotations.AppAuth; |
| | | import com.zy.asrs.framework.common.BaseRes; |
| | | 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.openapi.param.MatParam; |
| | | import com.zy.asrs.openapi.param.OrderParam; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | @Autowired |
| | | private HostKeyService hostKeyService; |
| | | @Autowired |
| | | private DocTypeService docTypeService; |
| | | @Autowired |
| | | private ApiService apiService; |
| | | |
| | | @PostMapping("/test") |
| | | public R test() { |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 生成入库订单 |
| | | */ |
| | | @PostMapping("/generateOrderPakIn") |
| | | public synchronized R generateOrderPakIn(@RequestHeader(required = false) String appkey, |
| | | @AppAuth(memo = "生成入库订单") |
| | | public synchronized R generateOrderPakIn(@RequestHeader(required = true) String appkey, |
| | | @RequestBody GenerateOrderPakInParam param) { |
| | | HostKey hostKey = auth(appkey, param, true); |
| | | if (Cools.isEmpty(param)) { |
| | |
| | | if (Cools.isEmpty(param.getOrderType())) { |
| | | return R.error("单据类型[orderType]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getOrderDetails())) { |
| | | return R.error("单据明细[orderDetails]不能为空"); |
| | | if (Cools.isEmpty(param.getMats())) { |
| | | return R.error("物料[mats]不能为空"); |
| | | } |
| | | param.setHostId(hostKey.getHostId()); |
| | | apiService.generateOrderPakIn(param); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 生成出库订单 |
| | | */ |
| | | @PostMapping("generateOrderPakOut") |
| | | @AppAuth(memo = "生成出库订单") |
| | | public synchronized R generateOrderPakOut(@RequestHeader(required = false) String appkey, |
| | | @RequestBody GenerateOrderPakOutParam param) { |
| | | HostKey hostKey = auth(appkey, param, true); |
| | | if (Cools.isEmpty(param)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | } |
| | | if (Cools.isEmpty(param.getOrderNo())) { |
| | | return R.error("单据编号[orderNo]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getOrderType())) { |
| | | return R.error("单据类型[orderType]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getMats())) { |
| | | return R.error("物料[mats]不能为空"); |
| | | } |
| | | param.setHostId(hostKey.getHostId()); |
| | | apiService.generateOrderPakOut(param); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 获取订单类型 |
| | | */ |
| | | @PostMapping("/getOrderType") |
| | | public synchronized R getOrderType(@RequestHeader(required = false) String appkey) { |
| | | public synchronized R getOrderType(@RequestHeader(required = true) String appkey) { |
| | | auth(appkey, null, false); |
| | | List<DocType> list = docTypeService.list(); |
| | | List<DocType> list = apiService.getOrderType(); |
| | | return R.ok().add(list); |
| | | } |
| | | |
| | | /** |
| | | * 获取订单状态列表 |
| | | */ |
| | | @PostMapping("/getOrderStatus") |
| | | public synchronized R getOrderStatus(@RequestHeader(required = true) String appkey) { |
| | | auth(appkey, null, false); |
| | | List<OrderSettle> list = apiService.getOrderStatus(); |
| | | return R.ok().add(list); |
| | | } |
| | | |
| | | /** |
| | | * 获取订单列表 |
| | | */ |
| | | @PostMapping("/getOrderList") |
| | | public synchronized R getOrderList(@RequestHeader(required = true) String appkey, |
| | | @RequestBody(required = false) OrderListParam param) { |
| | | HostKey hostKey = auth(appkey, null, false); |
| | | List<OrderListDto> orderList = apiService.getOrderList(param, hostKey.getHostId()); |
| | | return R.ok().add(orderList); |
| | | } |
| | | |
| | | /** |
| | | * 创建物料信息 |
| | | */ |
| | | @PostMapping("/createMat") |
| | | public synchronized R createMat(@RequestHeader(required = true) String appkey, |
| | | @RequestBody(required = false) CreateMatParam param) { |
| | | HostKey hostKey = auth(appkey, param, true); |
| | | param.setHostId(hostKey.getHostId()); |
| | | int result = apiService.createMat(param); |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | private HostKey auth(String appkey, Object obj, boolean signCheck) { |
| | | request.setAttribute("cache", obj); |
| | | if (Cools.isEmpty(appkey)) { |
| | | throw new CoolException("认证失败,请确认appKey无误!"); |
| | | } |
| | |
| | | return hostKey; |
| | | } |
| | | |
| | | @PostMapping("order/execute/auth/v1") |
| | | public R wms1(@RequestBody Map<String, Object> map) { |
| | | try { |
| | | System.out.println(map.toString()); |
| | | log.info("order/execute/auth/v1:" + JSON.toJSONString(map)); |
| | | OrderParam orderParam = JSON.parseObject(JSON.toJSONString(map), OrderParam.class); |
| | | List<DocType> list = apiService.getOrderType(); |
| | | DocType type = null; |
| | | for (DocType docType : list) { |
| | | if (docType.getDocName().equals(orderParam.getOrderType())) { |
| | | type = docType; |
| | | break; |
| | | } |
| | | } |
| | | if (type == null) { |
| | | return R.error("单据类型不存在"); |
| | | } |
| | | |
| | | ArrayList<GenerateOrderMatParam> mats = new ArrayList<>(); |
| | | for (MatParam matParam : orderParam.getList()) { |
| | | GenerateOrderMatParam mat = new GenerateOrderMatParam(); |
| | | mat.setMatnr(matParam.getMatnr()); |
| | | mat.setBatch(matParam.getBatch()); |
| | | mat.setAnfme(matParam.getCount()); |
| | | mat.setUnit(matParam.getUnit()); |
| | | mat.setWarehouse(matParam.getWarehouse()); |
| | | mat.setOrigin(matParam.getOrigin()); |
| | | mat.setOriginNo(matParam.getOriginNo()); |
| | | mats.add(mat); |
| | | } |
| | | |
| | | if (orderParam.getInOut() == 1) { |
| | | //入库 |
| | | GenerateOrderPakInParam param = new GenerateOrderPakInParam(); |
| | | param.setHostId(1L); |
| | | param.setOrderType(type.getDocId().intValue()); |
| | | param.setOrderNo(orderParam.getOrderNo()); |
| | | param.setMats(mats); |
| | | apiService.generateOrderPakIn(param); |
| | | } else if (orderParam.getInOut() == 2) { |
| | | //出库 |
| | | GenerateOrderPakOutParam param = new GenerateOrderPakOutParam(); |
| | | param.setHostId(1L); |
| | | param.setOrderType(type.getDocId().intValue()); |
| | | param.setOrderNo(orderParam.getOrderNo()); |
| | | param.setMats(mats); |
| | | apiService.generateOrderPakOut(param); |
| | | } else { |
| | | //其他 |
| | | return R.error("出入库类型错误"); |
| | | } |
| | | |
| | | return R.ok(); |
| | | } catch (Exception e) { |
| | | return R.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |