|
|
@@ -0,0 +1,318 @@
|
|
|
+package com.sckw.transport.five.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.sckw.core.exception.ApiException;
|
|
|
+import com.sckw.transport.five.entity.ApiLog;
|
|
|
+import com.sckw.transport.five.entity.ApiUser;
|
|
|
+import com.sckw.transport.five.pojo.LoadInfo;
|
|
|
+import com.sckw.transport.five.pojo.LoadPara;
|
|
|
+import com.sckw.transport.five.pojo.LoadUser;
|
|
|
+import com.sckw.transport.five.pojo.UnloadCar;
|
|
|
+import com.sckw.transport.five.service.ApiLogService;
|
|
|
+import com.sckw.transport.five.service.common.BusinessCheck;
|
|
|
+import com.sckw.transport.five.service.common.KllService;
|
|
|
+import com.sckw.transport.five.util.ApiUtil;
|
|
|
+import com.sckw.transport.five.util.R;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author xucaiqin
|
|
|
+ * @date 2023-06-13 09:12:32
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/kll")
|
|
|
+@Slf4j
|
|
|
+public class KllController {
|
|
|
+ @Resource
|
|
|
+ private BusinessCheck businessCheck;
|
|
|
+ @Resource
|
|
|
+ private KllService kllService;
|
|
|
+ @Resource
|
|
|
+ private ApiLogService apiLogService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定时查询待装载车辆集合
|
|
|
+ *
|
|
|
+ * @param productId 产品id
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/category/unload/data")
|
|
|
+ public R<List<UnloadCar>> unloadData(HttpServletRequest request, HttpServletResponse response, @RequestParam("productId") List<Long> productId) {
|
|
|
+ //header校验
|
|
|
+ ApiUser apiUser = businessCheck.headerCheck(request);
|
|
|
+ ApiLog reqId = businessCheck.paraCheck(() -> new HashMap<>() {{
|
|
|
+ put(productId, (d) -> {
|
|
|
+ if (Objects.isNull(d)) {
|
|
|
+ throw new ApiException("产品id不能为空");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }}).signCheck(() -> new HashMap<>() {{
|
|
|
+ put("key", apiUser.getPriKey());
|
|
|
+ put("productId", JSONObject.toJSONString(productId));
|
|
|
+ }}, request);
|
|
|
+ final Map<String, String> CHINESE_TO_ARABIC = new HashMap<>();
|
|
|
+ CHINESE_TO_ARABIC.put("一", "1");
|
|
|
+ CHINESE_TO_ARABIC.put("二", "2");
|
|
|
+ CHINESE_TO_ARABIC.put("三", "3");
|
|
|
+ CHINESE_TO_ARABIC.put("四", "4");
|
|
|
+ CHINESE_TO_ARABIC.put("五", "5");
|
|
|
+ CHINESE_TO_ARABIC.put("六", "6");
|
|
|
+ CHINESE_TO_ARABIC.put("七", "7");
|
|
|
+ CHINESE_TO_ARABIC.put("八", "8");
|
|
|
+ CHINESE_TO_ARABIC.put("九", "9");
|
|
|
+ /*业务*/
|
|
|
+ List<UnloadCar> unloadCars = kllService.unloadCar(productId);
|
|
|
+ unloadCars.forEach(d -> {
|
|
|
+ if (StringUtils.contains(d.getModelStr(), "轴车")) {
|
|
|
+ int i = StringUtils.indexOf(d.getModelStr(), "轴车");
|
|
|
+ if (i != -1 && i != 0) {
|
|
|
+ d.setModelStr(CHINESE_TO_ARABIC.get(StringUtils.substring(d.getModelStr(), i - 1, i)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //返回值增加签名
|
|
|
+ R<List<UnloadCar>> ok = R.ok(unloadCars, "查询成功!");
|
|
|
+ String signType = request.getHeader(ApiUtil.ApiConstant.SignType.getCode());
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String account = request.getHeader(ApiUtil.ApiConstant.account.getCode());
|
|
|
+ String sign = businessCheck.resSign(() -> new HashMap<>() {{
|
|
|
+ put("signType", signType);
|
|
|
+ put("account", account);
|
|
|
+ put("time", String.valueOf(time));
|
|
|
+ put("array", JSONObject.toJSONString(unloadCars));
|
|
|
+ put("key", apiUser.getPriKey());
|
|
|
+ }});
|
|
|
+ ok.setSign(sign);
|
|
|
+ response.setHeader("timestamp", String.valueOf(time));
|
|
|
+ reqId.setResData(JSONObject.toJSONString(unloadCars));
|
|
|
+ reqId.setResTime(LocalDateTime.now());
|
|
|
+ /*记录日志*/
|
|
|
+ apiLogService.enqueue(reqId);
|
|
|
+ return ok;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 给订单分配装车位置
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param loadInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/category/allocation/location")
|
|
|
+ public R<Object> location(HttpServletRequest request, HttpServletResponse response, @RequestBody LoadInfo loadInfo) {
|
|
|
+ //header校验
|
|
|
+ ApiUser apiUser = businessCheck.headerCheck(request);
|
|
|
+ ApiLog reqId = businessCheck.paraCheck(() -> new HashMap<>() {{
|
|
|
+ put(loadInfo.getForkliftNo(), (d) -> {
|
|
|
+ if (StringUtils.isBlank((String) d)) {
|
|
|
+ throw new ApiException("装载单号不能为空");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }}).signCheck(() -> new HashMap<>() {{
|
|
|
+ put("key", apiUser.getPriKey());
|
|
|
+ put("forkliftNo", loadInfo.getForkliftNo());
|
|
|
+ put("remark", loadInfo.getRemark());
|
|
|
+ }}, request);
|
|
|
+ /*业务*/
|
|
|
+ kllService.loadInfo(loadInfo);
|
|
|
+ //返回值增加签名
|
|
|
+ R<Object> ok = R.ok().setMsg("操作成功!");
|
|
|
+ String signType = request.getHeader(ApiUtil.ApiConstant.SignType.getCode());
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String account = request.getHeader(ApiUtil.ApiConstant.account.getCode());
|
|
|
+ String sign = businessCheck.resSign(() -> new HashMap<>() {{
|
|
|
+ put("signType", signType);
|
|
|
+ put("account", account);
|
|
|
+ put("time", String.valueOf(time));
|
|
|
+ put("key", apiUser.getPriKey());
|
|
|
+ }});
|
|
|
+ ok.setSign(sign);
|
|
|
+ response.setHeader("timestamp", String.valueOf(time));
|
|
|
+ reqId.setResData("");
|
|
|
+ reqId.setResTime(LocalDateTime.now());
|
|
|
+ /*记录日志*/
|
|
|
+ apiLogService.enqueue(reqId);
|
|
|
+ return ok;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开始装车
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param loadPara
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/category/start/load")
|
|
|
+ public R<Object> startLoad(HttpServletRequest request, HttpServletResponse response, @RequestBody LoadPara loadPara) {
|
|
|
+ //header校验
|
|
|
+ ApiUser apiUser = businessCheck.headerCheck(request);
|
|
|
+ ApiLog reqId = businessCheck.paraCheck(() -> new HashMap<>() {{
|
|
|
+ put(loadPara.getForkliftNo(), (d) -> {
|
|
|
+ if (StringUtils.isBlank((String) d)) {
|
|
|
+ throw new ApiException("装载单号不能为空");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ put(loadPara.getLoadUser(), (d) -> {
|
|
|
+ if (Objects.isNull(d)) {
|
|
|
+ throw new ApiException("用户信息不能为空");
|
|
|
+ }
|
|
|
+ if (d instanceof LoadUser user) {
|
|
|
+ if (Objects.isNull(user.getId())) {
|
|
|
+ throw new ApiException("用户id不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }}).signCheck(() -> new HashMap<>() {{
|
|
|
+ put("key", apiUser.getPriKey());
|
|
|
+ put("forkliftNo", loadPara.getForkliftNo());
|
|
|
+ put("loadUser", JSONObject.toJSONString(loadPara.getLoadUser()));
|
|
|
+ }}, request);
|
|
|
+ /*业务*/
|
|
|
+ kllService.startLoad(loadPara);
|
|
|
+ //返回值增加签名
|
|
|
+ R<Object> ok = R.ok().setMsg("操作成功!");
|
|
|
+ String signType = request.getHeader(ApiUtil.ApiConstant.SignType.getCode());
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String account = request.getHeader(ApiUtil.ApiConstant.account.getCode());
|
|
|
+ String sign = businessCheck.resSign(() -> new HashMap<>() {{
|
|
|
+ put("signType", signType);
|
|
|
+ put("account", account);
|
|
|
+ put("time", String.valueOf(time));
|
|
|
+ put("key", apiUser.getPriKey());
|
|
|
+ }});
|
|
|
+ ok.setSign(sign);
|
|
|
+ response.setHeader("timestamp", String.valueOf(time));
|
|
|
+ reqId.setResData("");
|
|
|
+ reqId.setResTime(LocalDateTime.now());
|
|
|
+ /*记录日志*/
|
|
|
+ apiLogService.enqueue(reqId);
|
|
|
+ return ok;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 装车完毕
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param loadPara
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/category/finish/load")
|
|
|
+ public R<Object> finishLoad(HttpServletRequest request, HttpServletResponse response, @RequestBody LoadPara loadPara) {
|
|
|
+ //header校验
|
|
|
+ ApiUser apiUser = businessCheck.headerCheck(request);
|
|
|
+ ApiLog reqId = businessCheck.paraCheck(() -> new HashMap<>() {{
|
|
|
+ put(loadPara.getForkliftNo(), (d) -> {
|
|
|
+ if (StringUtils.isBlank((String) d)) {
|
|
|
+ throw new ApiException("装载单号不能为空");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ put(loadPara.getLoadUser(), (d) -> {
|
|
|
+ if (Objects.isNull(d)) {
|
|
|
+ throw new ApiException("用户信息不能为空");
|
|
|
+ }
|
|
|
+ if (d instanceof LoadUser user) {
|
|
|
+ if (Objects.isNull(user.getId())) {
|
|
|
+ throw new ApiException("用户id不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }}).signCheck(() -> new HashMap<>() {{
|
|
|
+ put("key", apiUser.getPriKey());
|
|
|
+ put("forkliftNo", loadPara.getForkliftNo());
|
|
|
+ put("loadUser", JSONObject.toJSONString(loadPara.getLoadUser()));
|
|
|
+ }}, request);
|
|
|
+ /*业务*/
|
|
|
+ kllService.finishLoad(loadPara);
|
|
|
+ //返回值增加签名
|
|
|
+ R<Object> ok = R.ok().setMsg("操作成功!");
|
|
|
+ String signType = request.getHeader(ApiUtil.ApiConstant.SignType.getCode());
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String account = request.getHeader(ApiUtil.ApiConstant.account.getCode());
|
|
|
+ String sign = businessCheck.resSign(() -> new HashMap<>() {{
|
|
|
+ put("signType", signType);
|
|
|
+ put("account", account);
|
|
|
+ put("time", String.valueOf(time));
|
|
|
+ put("key", apiUser.getPriKey());
|
|
|
+ }});
|
|
|
+ ok.setSign(sign);
|
|
|
+ response.setHeader("timestamp", String.valueOf(time));
|
|
|
+ reqId.setResData("");
|
|
|
+ reqId.setResTime(LocalDateTime.now());
|
|
|
+ /*记录日志*/
|
|
|
+ apiLogService.enqueue(reqId);
|
|
|
+ return ok;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 取消装载
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param loadPara
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/category/cancel/load")
|
|
|
+ public R<Object> cancelLoad(HttpServletRequest request, HttpServletResponse response, @RequestBody LoadPara loadPara) {
|
|
|
+ //header校验
|
|
|
+ ApiUser apiUser = businessCheck.headerCheck(request);
|
|
|
+ ApiLog reqId = businessCheck.paraCheck(() -> new HashMap<>() {{
|
|
|
+ put(loadPara.getForkliftNo(), (d) -> {
|
|
|
+ if (StringUtils.isBlank((String) d)) {
|
|
|
+ throw new ApiException("装载单号不能为空");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ put(loadPara.getLoadUser(), (d) -> {
|
|
|
+ if (Objects.isNull(d)) {
|
|
|
+ throw new ApiException("用户信息不能为空");
|
|
|
+ }
|
|
|
+ if (d instanceof LoadUser user) {
|
|
|
+ if (Objects.isNull(user.getId())) {
|
|
|
+ throw new ApiException("用户id不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }}).signCheck(() -> new HashMap<>() {{
|
|
|
+ put("key", apiUser.getPriKey());
|
|
|
+ put("forkliftNo", loadPara.getForkliftNo());
|
|
|
+ put("loadUser", JSONObject.toJSONString(loadPara.getLoadUser()));
|
|
|
+ }}, request);
|
|
|
+ /*业务*/
|
|
|
+ kllService.cancelLoad(loadPara);
|
|
|
+ //返回值增加签名
|
|
|
+ R<Object> ok = R.ok().setMsg("操作成功!");
|
|
|
+ String signType = request.getHeader(ApiUtil.ApiConstant.SignType.getCode());
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String account = request.getHeader(ApiUtil.ApiConstant.account.getCode());
|
|
|
+ String sign = businessCheck.resSign(() -> new HashMap<>() {{
|
|
|
+ put("signType", signType);
|
|
|
+ put("account", account);
|
|
|
+ put("time", String.valueOf(time));
|
|
|
+ put("key", apiUser.getPriKey());
|
|
|
+ }});
|
|
|
+ ok.setSign(sign);
|
|
|
+ response.setHeader("timestamp", String.valueOf(time));
|
|
|
+ reqId.setResData("");
|
|
|
+ reqId.setResTime(LocalDateTime.now());
|
|
|
+ /*记录日志*/
|
|
|
+ apiLogService.enqueue(reqId);
|
|
|
+ return ok;
|
|
|
+ }
|
|
|
+}
|