diff --git a/nladmin-system/src/main/java/org/nl/hand/rest/HandController.java b/nladmin-system/src/main/java/org/nl/hand/rest/HandController.java new file mode 100644 index 0000000..41c020e --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/hand/rest/HandController.java @@ -0,0 +1,125 @@ + +package org.nl.hand.rest; + + +import com.alibaba.fastjson.JSONObject; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.annotation.Log; +import org.nl.hand.service.HandService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; +import java.util.Map; + +@Slf4j +@RestController +@RequiredArgsConstructor +@Api(tags = "海量子管包装手持接口") +@RequestMapping("/api/hand") +public class HandController { + + private final HandService handService; + + /** + * 手持登陆 + * + * @param param String user 用户名 + * String password 密码 + * @return 登陆成功将携带用户id返回 + */ + @PostMapping("/handlogin") + @Log("手持登陆") + @ApiOperation("手持登陆") + public ResponseEntity handlogin(@RequestBody Map param) { + return new ResponseEntity<>(handService.handlogin(param), HttpStatus.OK); + } + + /** + * 查询工单及明细 + * + * @return 工单及明细 + */ + @PostMapping("/order") + @Log("查询工单及明细") + @ApiOperation("查询工单及明细") + public ResponseEntity order() { + return new ResponseEntity<>(handService.order(), HttpStatus.OK); + } + + /** + * 工单操作 + * + * @param param String type 操作类型 + * String order_uuid 工单uuid + * String orderDetail_uuid 工单明细uuid(only type IN ("3", "4")) + * @return 提示 + */ + @PostMapping("/orderOperation") + @Log("工单操作") + @ApiOperation("工单操作") + public ResponseEntity orderOperation(@RequestBody Map param) { + return new ResponseEntity<>(handService.orderOperation(param), HttpStatus.OK); + } + + /** + * 查询分拣工单及明细 + * + * @return 分拣工单及明细 + */ + @PostMapping("/sortingOrder") + @Log("查询分拣工单及明细") + @ApiOperation("查询分拣工单及明细") + public ResponseEntity sortingOrder() { + return new ResponseEntity<>(handService.sortingOrder(), HttpStatus.OK); + } + + /** + * 下发刻字、贴标 + * + * @param param String type 操作类型 + * String order_uuid 工单uuid + * String orderDetail_uuid 工单明细uuid + * @return 提示 + */ + @PostMapping("/sendMessage") + @Log("下发刻字、贴标") + @ApiOperation("下发刻字、贴标") + public ResponseEntity sendMessage(@RequestBody Map param) { + return new ResponseEntity<>(handService.sendMessage(param), HttpStatus.OK); + } + + /** + * 下发设备信号 + * + * @param param String type 操作类型 + * @return 提示 + */ + @PostMapping("/deviceOperation") + @Log("下发设备信号") + @ApiOperation("下发设备信号") + public ResponseEntity deviceOperation(@RequestBody Map param) { + return new ResponseEntity<>(handService.deviceOperation(param), HttpStatus.OK); + } + + /** + * 下发设备信号(确认按钮) + * + * @param param String outer_diameter 管径(mm) + * String length 管长(mm) + * String color 颜色 + * String jackup_num 合格提升每次提升根数 + * String strap_number 每捆根数 + * @return 提示 + */ + @PostMapping("/putPoint") + @Log("下发设备信号(确认按钮)") + @ApiOperation("下发设备信号(确认按钮)") + public ResponseEntity putPoint(@RequestBody Map param) { + return new ResponseEntity<>(handService.putPoint(param), HttpStatus.OK); + } +} diff --git a/nladmin-system/src/main/java/org/nl/hand/service/HandService.java b/nladmin-system/src/main/java/org/nl/hand/service/HandService.java new file mode 100644 index 0000000..cab2a31 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/hand/service/HandService.java @@ -0,0 +1,73 @@ +package org.nl.hand.service; + + +import com.alibaba.fastjson.JSONObject; + +import java.io.IOException; +import java.util.Map; + +public interface HandService { + + /** + * 手持登陆 + * + * @param param String user 用户名 + * String password 密码 + * @return 如果登陆成功携带用户id返回 + */ + JSONObject handlogin(Map param); + + /** + * 查询工单及明细 + * + * @return 工单及明细 + */ + JSONObject order(); + + /** + * 工单操作 + * + * @param param String type 操作类型 + * String order_uuid 工单uuid + * String orderDetail_uuid 工单明细uuid(只有 type IN ("3", "4") 才有) + * @return 提示 + */ + JSONObject orderOperation(Map param); + + /** + * 查询分拣工单及明细 + * + * @return 分拣工单及明细 + */ + JSONObject sortingOrder(); + + /** + * 下发刻字、贴标 + * + * @param param String type 操作类型 + * String order_uuid 工单uuid + * String orderDetail_uuid 工单明细uuid + * @return 提示 + */ + JSONObject sendMessage(Map param); + + /** + * 下发设备信号 + * + * @param param String type 操作类型 + * @return 提示 + */ + JSONObject deviceOperation(Map param); + + /** + * 下发设备信号(确认按钮) + * + * @param param String outer_diameter 管径(mm) + * String length 管长(mm) + * String color 颜色 + * String jackup_num 合格提升每次提升根数 + * String strap_number 每捆根数 + * @return 提示 + */ + JSONObject putPoint(Map param); +} diff --git a/nladmin-system/src/main/java/org/nl/hand/service/impl/HandServiceImpl.java b/nladmin-system/src/main/java/org/nl/hand/service/impl/HandServiceImpl.java new file mode 100644 index 0000000..34794e5 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/hand/service/impl/HandServiceImpl.java @@ -0,0 +1,457 @@ +package org.nl.hand.service.impl; + + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device_driver.hailiang.hailiang_feeding_trunk.HaiLiangFeedingTrunkDeviceDriver; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.ProduceshiftorderdetailService; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.acs.order.service.dto.ProduceshiftorderdetailDto; +import org.nl.config.RsaProperties; +import org.nl.hand.service.HandService; +import org.nl.modules.system.service.UserService; +import org.nl.modules.system.service.dto.UserDto; +import org.nl.utils.RsaUtils; +import org.nl.wql.WQL; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.Map; + +@Service +@RequiredArgsConstructor +@Slf4j +public class HandServiceImpl implements HandService { + + private final UserService userService; + + private final PasswordEncoder passwordEncoder; + + private final ProduceshiftorderService produceshiftorderService; + + private final ProduceshiftorderdetailService produceshiftorderdetailService; + + private final DeviceAppService deviceAppService; + + @Override + public JSONObject handlogin(Map param) { + // 返回值 + JSONObject resultJSON = new JSONObject(); + + // 参数校验 + String user = param.get("user"); + if (StrUtil.isEmpty(user)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "用户名不能为空"); + return resultJSON; + } + String password = param.get("password"); + if (StrUtil.isEmpty(password)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "密码不能为空"); + return resultJSON; + } + + // 根据用户名查询用户 + UserDto userDto; + try { + userDto = userService.findByName(user); + } catch (Exception e) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "用户名或密码错误"); + return resultJSON; + } + + String pwd; + try { + // 解密前端传入的加密密码 + pwd = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, password); + } catch (Exception e) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "用户名或密码错误"); + return resultJSON; + } + + // 用户输入的密码与数据库中的密码比对 + if (!passwordEncoder.matches(pwd, userDto.getPassword())) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "用户名或密码错误"); + return resultJSON; + } + + // 登陆成功 + resultJSON.put("code", "1"); + resultJSON.put("desc", "登陆成功"); + JSONObject result = new JSONObject(); + result.put("accountId", userDto.getId().toString()); + resultJSON.put("result", result); + return resultJSON; + } + + @Override + public JSONObject order() { + // 查询工单 + JSONArray result = WQL.getWO("HAND").addParam("flag", "1").process().getResultJSONArray(0); + + // 遍历工单集合,补全信息 + for (Object o : result) { + JSONObject order = (JSONObject) o; + order.put("type", "order"); + order.put("is_flag", "1"); + + JSONArray children = WQL + .getWO("HAND") + .addParam("flag", "2") + .addParam("order_id", order.get("order_id")) + .process() + .getResultJSONArray(0); + + // 遍历工单明细数组补全信息 + for (Object d : children) { + JSONObject detail = (JSONObject) d; + detail.put("type", "orderDetail"); + detail.put("is_flag", "0"); + } + + // 添加进order + order.put("children", children); + } + + // 返回 + JSONObject resultJSON = new JSONObject(); + resultJSON.put("code", "1"); + resultJSON.put("desc", "查询成功"); + resultJSON.put("result", result); + return resultJSON; + } + + @Override + public JSONObject orderOperation(Map param) { + // 返回值 + JSONObject resultJSON = new JSONObject(); + + // 参数校验 + String type = param.get("type"); + if (StrUtil.isEmpty(type)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "操作类型不能为空"); + return resultJSON; + } + String orderId = param.get("order_uuid"); + if (StrUtil.isEmpty(orderId)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "工单不能为空"); + return resultJSON; + } + String detailId = param.get("orderDetail_uuid"); + if ((StrUtil.equals(type, "3") || StrUtil.equals(type, "4")) && StrUtil.isEmpty(detailId)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "工单明细不能为空"); + return resultJSON; + } + + // 查询工单 + ProduceshiftorderDto order = produceshiftorderService.findById(orderId); + if (ObjectUtil.isEmpty(order)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "工单不存在"); + return resultJSON; + } + String orderCode = order.getOrder_code(); + + // 如果有,查询工单明细 + String detailCode = null; + if (StrUtil.isNotEmpty(detailId)) { + ProduceshiftorderdetailDto detail = produceshiftorderdetailService.findById(detailId); + if (ObjectUtil.isEmpty(detail)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "工单明细不存在"); + return resultJSON; + } + if (!StrUtil.equals(detail.getOrder_id(), orderId)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "非当前工单的明细"); + return resultJSON; + } + detailCode = detail.getOrder_detail_code(); + } + + // 根据操作类型做不同的操作 + String desc; + try { + JSONObject whereJSON = new JSONObject(); + switch (type) { + case "1": + // 工单开始分拣 + produceshiftorderService.send(orderId); + desc = "工单已开始分拣"; + break; + case "2": + // 强制完成工单 + whereJSON.put("order_code", orderCode); + produceshiftorderService.order_force_complete(whereJSON); + desc = "工单已强制完成"; + break; + case "3": + // 手动完成明细 + whereJSON.put("parent_order_code", orderCode); + whereJSON.put("order_code", detailCode); + produceshiftorderService.manual_finish(whereJSON); + desc = "明细已手动完成"; + break; + case "4": + // 强制完成明细 + whereJSON.put("parent_order_code", orderCode); + whereJSON.put("order_code", detailCode); + produceshiftorderService.detail_force_complete(whereJSON); + desc = "明细已强制完成"; + break; + default: + resultJSON.put("code", "0"); + resultJSON.put("desc", "操作类型错误"); + return resultJSON; + } + } catch (Exception e) { + resultJSON.put("code", "0"); + resultJSON.put("desc", e.getMessage()); + return resultJSON; + } + + // 返回 + resultJSON.put("code", "1"); + resultJSON.put("desc", desc); + return resultJSON; + } + + @Override + public JSONObject sortingOrder() { + // 查询工单 + JSONArray result = WQL.getWO("HAND").addParam("flag", "3").process().getResultJSONArray(0); + + // 遍历工单集合,补全信息 + for (Object o : result) { + JSONObject order = (JSONObject) o; + order.put("type", "order"); + order.put("is_flag", "1"); + + JSONArray children = WQL + .getWO("HAND") + .addParam("flag", "4") + .addParam("order_id", order.get("order_id")) + .process() + .getResultJSONArray(0); + + // 遍历工单明细数组补全信息 + for (Object d : children) { + JSONObject detail = (JSONObject) d; + detail.put("type", "orderDetail"); + detail.put("is_flag", "0"); + } + + // 添加进order + order.put("children", children); + } + + // 返回 + JSONObject resultJSON = new JSONObject(); + resultJSON.put("code", "1"); + resultJSON.put("desc", "查询成功"); + resultJSON.put("result", result); + return resultJSON; + } + + @Override + public JSONObject sendMessage(Map param) { + // 返回值 + JSONObject resultJSON = new JSONObject(); + + // 参数校验 + String type = param.get("type"); + if (StrUtil.isEmpty(type)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "操作类型不能为空"); + return resultJSON; + } + String orderId = param.get("order_uuid"); + if (StrUtil.isEmpty(orderId)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "工单不能为空"); + return resultJSON; + } + String detailId = param.get("orderDetail_uuid"); + if (StrUtil.isEmpty(detailId)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "工单明细不能为空"); + return resultJSON; + } + + // 查询工单 + ProduceshiftorderDto order = produceshiftorderService.findById(orderId); + if (ObjectUtil.isEmpty(order)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "工单不存在"); + return resultJSON; + } + String orderCode = order.getOrder_code(); + + // 查询工单明细 + ProduceshiftorderdetailDto detail = produceshiftorderdetailService.findById(detailId); + if (ObjectUtil.isEmpty(detail)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "工单明细不存在"); + return resultJSON; + } + if (!StrUtil.equals(detail.getOrder_id(), orderId)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "非当前工单的明细"); + return resultJSON; + } + String detailCode = detail.getOrder_detail_code(); + + // 根据操作类型选择 + String desc; + try { + JSONObject whereJSON = new JSONObject(); + switch (type) { + case "1": + // 手动下发刻字信息 + whereJSON.put("parent_order_code", orderCode); + whereJSON.put("order_code", detailCode); + produceshiftorderService.send_letteringMess(whereJSON); + desc = "已下发刻字信息"; + break; + case "2": + // 手动下发贴标信息 + whereJSON.put("parent_order_code", orderCode); + whereJSON.put("order_code", detailCode); + produceshiftorderService.send_labelingMess(whereJSON); + desc = "已下发贴标信息"; + break; + default: + resultJSON.put("code", "0"); + resultJSON.put("desc", "操作类型错误"); + return resultJSON; + } + } catch (IOException e) { + resultJSON.put("code", "0"); + resultJSON.put("desc", e.getMessage()); + return resultJSON; + } + + // 返回 + resultJSON.put("code", "1"); + resultJSON.put("desc", desc); + return resultJSON; + } + + @Override + public JSONObject deviceOperation(Map param) { + // 返回值 + JSONObject resultJSON = new JSONObject(); + + // 参数校验 + String type = param.get("type"); + if (StrUtil.isEmpty(type)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "操作类型不能为空"); + return resultJSON; + } + + // 获取设备驱动 + HaiLiangFeedingTrunkDeviceDriver driver = deviceAppService.findDeviceDriver(HaiLiangFeedingTrunkDeviceDriver.class).get(0); + + // 根据操作类型下发信号 + String desc; + switch (type) { + case "1": + // 设备暂停 + driver.writing("to_pause", "1"); + desc = "设备已暂停"; + break; + case "2": + // 设备恢复 + driver.writing("to_pause", "0"); + desc = "设备已恢复"; + break; + case "3": + // 急停 + driver.writing("to_stop", "1"); + desc = "设备已急停"; + break; + case "4": + // 清料 + driver.writing("to_clear", "1"); + desc = "设备开始清料"; + break; + default: + resultJSON.put("code", "0"); + resultJSON.put("desc", "操作类型错误"); + return resultJSON; + } + + // 返回 + resultJSON.put("code", "1"); + resultJSON.put("desc", desc); + return resultJSON; + } + + @Override + public JSONObject putPoint(Map param) { + // 返回值 + JSONObject resultJSON = new JSONObject(); + + // 参数校验 + String outerDiameter = param.get("outer_diameter"); + if (StrUtil.isEmpty(outerDiameter)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "管径不能为空"); + return resultJSON; + } + String length = param.get("length"); + if (StrUtil.isEmpty(length)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "管长不能为空"); + return resultJSON; + } + String color = param.get("color"); + if (StrUtil.isEmpty(color)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "颜色不能为空"); + return resultJSON; + } + String jackupNum = param.get("jackup_num"); + if (StrUtil.isEmpty(jackupNum)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "合格提升每次提升根数不能为空"); + return resultJSON; + } + String strapNumber = param.get("strap_number"); + if (StrUtil.isEmpty(strapNumber)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "每捆根数不能为空"); + return resultJSON; + } + + // 获取设备驱动 + HaiLiangFeedingTrunkDeviceDriver driver = deviceAppService.findDeviceDriver(HaiLiangFeedingTrunkDeviceDriver.class).get(0); + + // 写信号 + driver.writing("to_outer_diameter", outerDiameter); + driver.writing("to_length", length); + driver.writing("to_color", color); + driver.writing("to_jackup_num", jackupNum); + driver.writing("to_one_strapping_qty", strapNumber); + + // 返回 + resultJSON.put("code", "1"); + resultJSON.put("desc", "下发成功"); + return resultJSON; + } +} diff --git a/nladmin-system/src/main/java/org/nl/hand/wql/HAND.wql b/nladmin-system/src/main/java/org/nl/hand/wql/HAND.wql new file mode 100644 index 0000000..a12b344 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/hand/wql/HAND.wql @@ -0,0 +1,167 @@ +[交易说明] + 交易名: 包装工单查询 + 所属模块: + 功能简述: + 版权所有: + 表引用: + 版本经历: + +[数据库] + --指定数据库,为空采用默认值,默认为db.properties中列出的第一个库 + +[IO定义] + ################################################# + ## 表字段对应输入参数 + ################################################# + 输入.flag TYPEAS s_string + 输入.order_id TYPEAS s_string + +[临时表] + --这边列出来的临时表就会在运行期动态创建 + +[临时变量] + --所有中间过程变量均可在此处定义 + +[业务过程] + + ########################################## + # 1、输入输出检查 # + ########################################## + + + ########################################## + # 2、主过程前处理 # + ########################################## + + + ########################################## + # 3、业务主过程 # + ########################################## + + IF 输入.flag = "1" + QUERY + SELECT + order_id, + order_code, + alloy, + is_labeling, + order_status, + material_uuid, + material_spec, + material_name, + wall_thickness, + is_coating, + jackup_num, + length, + end_time, + outer_diameter, + start_time, + temper, + feeding_mouth, + is_strapping, + qty, + is_risking, + is_lettering, + material_code + FROM + acs_produceshiftorder + WHERE + is_deleted = '0' + AND order_status NOT IN ('07', '08', '09') + ENDSELECT + ENDQUERY + ENDIF + + IF 输入.flag = "2" + QUERY + SELECT + labeling_template, + color_type, + lettering_message, + order_detail_code AS order_code, + order_detail_status AS order_status, + cust_code, + lettering_icon, + strap_number, + order_code AS parent_order_code, + order_qty AS qty, + lettering_message2, + cust_name, + order_id AS parent_order_id, + order_detail_id AS order_id, + cust_id + FROM + acs_produceshiftorderdetail + WHERE + is_deleted = '0' + OPTION 输入.order_id <> "" + order_id = 输入.order_id + ENDOPTION + ENDSELECT + ENDQUERY + ENDIF + + IF 输入.flag = "3" + QUERY + SELECT + order_id, + order_code, + alloy, + order_status, + material_uuid, + material_spec, + material_name, + wall_thickness, + length, + outer_diameter, + qty, + material_code + FROM + acs_produceshiftorder + WHERE + is_deleted = '0' + AND order_status NOT IN ('07', '08', '09') + ENDSELECT + ENDQUERY + ENDIF + + IF 输入.flag = "4" + QUERY + SELECT + labeling_finished, + feeding_finished, + qualified_sleeveing_number, + lettering_finished, + create_by, + order_detail_status AS order_status, + qualified_lettering_number, + strap_finished, + present_strap_number, + cust_name, + present_strap_pack_number, + order_id AS parent_order_id, + present_feeding_number, + present_wraping_number, + qualified_wraping_number, + order_detail_code AS order_code, + present_lettering_number, + cust_code, + present_sleeveing_number, + wraping_finished, + order_code AS parent_order_code, + order_qty AS qty, + order_detail_id AS order_id, + cust_id, + present_labeling_number, + feeding_qualified_number, + sleeveing_finished + FROM + acs_produceshiftorderdetail + WHERE + is_deleted = '0' + OPTION 输入.order_id <> "" + order_id = 输入.order_id + ENDOPTION + ENDSELECT + ENDQUERY + ENDIF