|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.Wrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.plugins.Page; | 
|---|
|  |  |  | import com.core.common.DateUtils; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.TaskStatusType; | 
|---|
|  |  |  | import com.zy.asrs.entity.CommandInfo; | 
|---|
|  |  |  | import com.zy.asrs.entity.LocMast; | 
|---|
|  |  |  | import com.zy.asrs.entity.TaskWrk; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.TaskOverToWms; | 
|---|
|  |  |  | import com.zy.asrs.service.ApiLogService; | 
|---|
|  |  |  | import com.zy.asrs.service.CommandInfoService; | 
|---|
|  |  |  | import com.zy.asrs.service.LocMastService; | 
|---|
|  |  |  | import com.zy.asrs.service.TaskWrkService; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.BaseRes; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.DateUtils; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.zy.common.utils.HttpHandler; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.TaskStatusType; | 
|---|
|  |  |  | import com.zy.asrs.entity.LocMast; | 
|---|
|  |  |  | import com.zy.asrs.entity.TaskWrk; | 
|---|
|  |  |  | import com.zy.asrs.service.LocMastService; | 
|---|
|  |  |  | import com.zy.asrs.service.TaskWrkService; | 
|---|
|  |  |  | import com.zy.asrs.service.ToWmsService; | 
|---|
|  |  |  | import com.zy.common.web.BaseController; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | public class TaskWrkController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${wms.url}") | 
|---|
|  |  |  | private String wmsUrl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskWrkService taskWrkService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CommandInfoService commandInfoService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocMastService locMastService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${wms.TaskExecCallback}") | 
|---|
|  |  |  | private String TaskExecCallback; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApiLogService apiLogService; | 
|---|
|  |  |  | private ToWmsService toWmsService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static String getTaskType(Integer paramIoType) { | 
|---|
|  |  |  | switch (paramIoType) { | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | return "RK"; | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | return "CK"; | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | return "YK"; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | return "未知"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/taskWrk/{wrkNo}/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/taskWrk/list/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R list(@RequestParam(defaultValue = "1")Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10")Integer limit, | 
|---|
|  |  |  | @RequestParam(required = false)String orderByField, | 
|---|
|  |  |  | @RequestParam(required = false)String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param){ | 
|---|
|  |  |  | public R list(@RequestParam(defaultValue = "1") Integer curr, | 
|---|
|  |  |  | @RequestParam(defaultValue = "10") Integer limit, | 
|---|
|  |  |  | @RequestParam(required = false) String orderByField, | 
|---|
|  |  |  | @RequestParam(required = false) String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param) { | 
|---|
|  |  |  | EntityWrapper<TaskWrk> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | excludeTrash(param); | 
|---|
|  |  |  | convert(param, wrapper); | 
|---|
|  |  |  | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} | 
|---|
|  |  |  | if (!Cools.isEmpty(orderByField)) { | 
|---|
|  |  |  | wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(taskWrkService.selectPage(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()){ | 
|---|
|  |  |  | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper) { | 
|---|
|  |  |  | for (Map.Entry<String, Object> entry : map.entrySet()) { | 
|---|
|  |  |  | String val = String.valueOf(entry.getValue()); | 
|---|
|  |  |  | if (val.contains(RANGE_TIME_LINK)){ | 
|---|
|  |  |  | if (val.contains(RANGE_TIME_LINK)) { | 
|---|
|  |  |  | String[] dates = val.split(RANGE_TIME_LINK); | 
|---|
|  |  |  | wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); | 
|---|
|  |  |  | wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/taskWrk/update/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R update(TaskWrk taskWrk){ | 
|---|
|  |  |  | @RequestMapping(value = "/taskWrk/update/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R update(TaskWrk taskWrk) { | 
|---|
|  |  |  | if (Cools.isEmpty(taskWrk) || null == taskWrk.getTaskNo()) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/taskWrk/updatePoint/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R updatePoint(TaskWrk taskWrk){ | 
|---|
|  |  |  | public R updatePoint(TaskWrk taskWrk) { | 
|---|
|  |  |  | if (Cools.isEmpty(taskWrk) || null == taskWrk.getTaskNo()) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/taskWrk/delete/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R delete(@RequestParam(value="ids[]") Long[] ids){ | 
|---|
|  |  |  | for (Long id : ids){ | 
|---|
|  |  |  | public R delete(@RequestParam(value = "ids[]") Long[] ids) { | 
|---|
|  |  |  | for (Long id : ids) { | 
|---|
|  |  |  | taskWrkService.deleteById(id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/taskWrk/export/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R export(@RequestBody JSONObject param){ | 
|---|
|  |  |  | public R export(@RequestBody JSONObject param) { | 
|---|
|  |  |  | EntityWrapper<TaskWrk> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); | 
|---|
|  |  |  | Map<String, Object> map = excludeTrash(param.getJSONObject("taskWrk")); | 
|---|
|  |  |  | 
|---|
|  |  |  | wrapper.like("id", condition); | 
|---|
|  |  |  | Page<TaskWrk> page = taskWrkService.selectPage(new Page<>(0, 10), wrapper); | 
|---|
|  |  |  | List<Map<String, Object>> result = new ArrayList<>(); | 
|---|
|  |  |  | for (TaskWrk taskWrk : page.getRecords()){ | 
|---|
|  |  |  | for (TaskWrk taskWrk : page.getRecords()) { | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("id", taskWrk.getTaskNo()); | 
|---|
|  |  |  | map.put("value", taskWrk.getTaskNo()); | 
|---|
|  |  |  | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R query(@RequestBody JSONObject param) { | 
|---|
|  |  |  | Wrapper<TaskWrk> wrapper = new EntityWrapper<TaskWrk>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); | 
|---|
|  |  |  | if (null != taskWrkService.selectOne(wrapper)){ | 
|---|
|  |  |  | if (null != taskWrkService.selectOne(wrapper)) { | 
|---|
|  |  |  | return R.parse(BaseRes.REPEAT).add(getComment(TaskWrk.class, String.valueOf(param.get("key")))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | 
|---|
|  |  |  | @ManagerAuth(memo = "手动完成任务") | 
|---|
|  |  |  | public R complete(@RequestParam String taskNo) { | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkService.selectByTaskNo(taskNo); | 
|---|
|  |  |  | if (Cools.isEmpty(taskWrk) || taskWrk.getStatus()>=3){ | 
|---|
|  |  |  | return R.error("已完结或已取消") ; | 
|---|
|  |  |  | if (Cools.isEmpty(taskWrk)) { | 
|---|
|  |  |  | return R.error("找不到工作档"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | LocMast locMast=new LocMast(); | 
|---|
|  |  |  | if(taskWrk.getIoType()==1){//入库任务完成库位为F | 
|---|
|  |  |  | locMast=locMastService.selectByLocNo(taskWrk.getTargetPoint()); | 
|---|
|  |  |  | if(Cools.isEmpty(locMast)){ | 
|---|
|  |  |  | R.error("没有找到该库位") ; | 
|---|
|  |  |  | LocMast locMast = new LocMast(); | 
|---|
|  |  |  | if (taskWrk.getIoType() == 1) {//入库任务完成库位为F | 
|---|
|  |  |  | locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint()); | 
|---|
|  |  |  | if (Cools.isEmpty(locMast)) { | 
|---|
|  |  |  | R.error("没有找到该库位"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locMast.setLocSts("F"); | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | locMast.setBarcode(taskWrk.getBarcode()); | 
|---|
|  |  |  | }else if(taskWrk.getIoType()==2){//出库任务完成库位为O | 
|---|
|  |  |  | locMast=locMastService.selectByLocNo(taskWrk.getStartPoint()); | 
|---|
|  |  |  | if(Cools.isEmpty(locMast)){ | 
|---|
|  |  |  | R.error("没有找到该库位") ; | 
|---|
|  |  |  | } else if (taskWrk.getIoType() == 2) {//出库任务完成库位为O | 
|---|
|  |  |  | locMast = locMastService.selectByLocNo(taskWrk.getStartPoint()); | 
|---|
|  |  |  | if (Cools.isEmpty(locMast)) { | 
|---|
|  |  |  | R.error("没有找到该库位"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locMast.setLocSts("O"); | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | }else if(taskWrk.getIoType()==3){ | 
|---|
|  |  |  | locMast=locMastService.selectByLocNo(taskWrk.getStartPoint()); | 
|---|
|  |  |  | if(Cools.isEmpty(locMast)){ | 
|---|
|  |  |  | R.error("没有找到该库位") ; | 
|---|
|  |  |  | } else if (taskWrk.getIoType() == 3) { | 
|---|
|  |  |  | locMast = locMastService.selectByLocNo(taskWrk.getStartPoint()); | 
|---|
|  |  |  | if (Cools.isEmpty(locMast)) { | 
|---|
|  |  |  | R.error("没有找到该库位"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locMast.setLocSts("O"); | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | locMastService.updateById(locMast); | 
|---|
|  |  |  | locMast=locMastService.selectByLocNo(taskWrk.getTargetPoint()); | 
|---|
|  |  |  | if(Cools.isEmpty(locMast)){ | 
|---|
|  |  |  | R.error("没有找到该库位") ; | 
|---|
|  |  |  | locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint()); | 
|---|
|  |  |  | if (Cools.isEmpty(locMast)) { | 
|---|
|  |  |  | R.error("没有找到该库位"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locMast.setLocSts("F"); | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | locMast.setBarcode(taskWrk.getBarcode()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String response=""; | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | HashMap<String, Object> headParam = new HashMap<>(); | 
|---|
|  |  |  | headParam.put("TaskNo",taskWrk.getTaskNo()); | 
|---|
|  |  |  | headParam.put("Result",1); | 
|---|
|  |  |  | //            headParam.put("reportTime",new Date()); | 
|---|
|  |  |  | log.info("wcs手动完成任务上报wms={}", taskWrk); | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | // .setHeaders(headParam) | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath(TaskExecCallback) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(headParam)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | apiLogService.save("wcs手动完成任务上报wms" | 
|---|
|  |  |  | ,wmsUrl+TaskExecCallback | 
|---|
|  |  |  | ,null | 
|---|
|  |  |  | ,"127.0.0.1" | 
|---|
|  |  |  | ,JSON.toJSONString(headParam) | 
|---|
|  |  |  | ,response | 
|---|
|  |  |  | ,true | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error("wcs手动完成任务上报wms失{},返回值={}", taskWrk,response); | 
|---|
|  |  |  | //            throw new CoolException(e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        toWmsService.addReportLog(taskWrk); | 
|---|
|  |  |  | locMastService.updateById(locMast); | 
|---|
|  |  |  | taskWrk.setCompleteTime(new Date()); | 
|---|
|  |  |  | taskWrk.setStatus(7);//手动完成任务 | 
|---|
|  |  |  | taskWrk.setModiTime(new Date()); | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping(value = "/taskWrk/returnWorkingCondition/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "重新给堆垛机下发任务") | 
|---|
|  |  |  | public R returnWorkingCondition(@RequestParam String taskNo) { | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkService.selectByTaskNo(taskNo); | 
|---|
|  |  |  | if (!Cools.isEmpty(taskWrk) && taskWrk.getWrkSts() == 12) { | 
|---|
|  |  |  | taskWrk.setWrkSts(11); | 
|---|
|  |  |  | if (!taskWrkService.updateById(taskWrk)) { | 
|---|
|  |  |  | return R.error("更新任务状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } else if (!Cools.isEmpty(taskWrk) && taskWrk.getWrkSts() == 3) { | 
|---|
|  |  |  | taskWrk.setWrkSts(2); | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  | if (!taskWrkService.updateById(taskWrk)) { | 
|---|
|  |  |  | return R.error("更新任务状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return R.error("任务状态不对无法重新给堆垛机下发任务"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping(value = "/taskWrk/cancel/auth") | 
|---|
|  |  |  | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | taskWrk.setStatus(TaskStatusType.CANCEL.id); | 
|---|
|  |  |  | taskWrk.setModiTime(now);//操作时间 | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | taskWrk.setModiUser(getUserId());//操作员 | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | taskWrk.setModiUser(9999L);//操作员 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String response=""; | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | HashMap<String, Object> headParam = new HashMap<>(); | 
|---|
|  |  |  | headParam.put("TaskNo",taskWrk.getTaskNo()); | 
|---|
|  |  |  | headParam.put("Result",0); | 
|---|
|  |  |  | //            headParam.put("reportTime",new Date()); | 
|---|
|  |  |  | //        toWmsService.addReportLog(taskWrk); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | log.info("wcs手动取消任务上报wm={}", taskWrk); | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | // .setHeaders(headParam) | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath(TaskExecCallback) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(headParam)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | apiLogService.save("wcs手动取消任务上报wms" | 
|---|
|  |  |  | ,wmsUrl+TaskExecCallback | 
|---|
|  |  |  | ,null | 
|---|
|  |  |  | ,"127.0.0.1" | 
|---|
|  |  |  | ,JSON.toJSONString(headParam) | 
|---|
|  |  |  | ,response | 
|---|
|  |  |  | ,true | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error("wcs手动取消任务上报wms失败={},返回值={}", taskWrk,response); | 
|---|
|  |  |  | //            throw new CoolException(e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | taskWrk.setCompleteTime(now);//完结时间 | 
|---|
|  |  |  | taskWrk.setCancelTime(now);//完结时间 | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | taskWrk.setModiUser(getUserId());//操作员 | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static String getTaskType(Integer paramIoType){ | 
|---|
|  |  |  | switch (paramIoType){ | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | return "RK"; | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | return "CK"; | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | return "YK"; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | return "未知"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|