|  |  |  | 
|---|
|  |  |  | 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.zy.asrs.domain.enums.TaskStatusType; | 
|---|
|  |  |  | import com.zy.asrs.entity.LocMast; | 
|---|
|  |  |  | import com.zy.asrs.entity.TaskWrk; | 
|---|
|  |  |  | 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.zy.common.utils.HttpHandler; | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | 
|---|
|  |  |  | @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.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); | 
|---|
|  |  |  | 
|---|
|  |  |  | } 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(); | 
|---|
|  |  |  | } | 
|---|