| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.domain.param.*; |
| | | import com.zy.asrs.entity.ApiLog; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.ApiLogService; |
| | | import com.zy.asrs.service.DeviceConfigService; |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.utils.NotifyUtils; |
| | | import com.zy.common.annotations.OpenApiLog; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.core.cache.SlaveConnection; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | |
| | | private String mainProcessPlugin; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private NotifyUtils notifyUtils; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | |
| | | return R.error("åæ°ä¸è½ä¸ºç©º"); |
| | | } |
| | | boolean result = commonService.createLocMoveTask(param); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "ç§»åºä»»å¡" |
| | | , "/createLocMoveTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , null |
| | | , null |
| | | , result ? 1 : 0 |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | if (result) { |
| | | return R.ok(); |
| | | } |
| | |
| | | return R.error("åæ°ä¸è½ä¸ºç©º"); |
| | | } |
| | | boolean result = commonService.createInTask(param); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "å
¥åºä»»å¡" |
| | | , "/createInTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , null |
| | | , null |
| | | , result ? 1 : 0 |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | if (result) { |
| | | return R.ok(); |
| | | } |
| | |
| | | return R.error("åæ°ä¸è½ä¸ºç©º"); |
| | | } |
| | | boolean result = commonService.createOutTask(param); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "åºåºä»»å¡" |
| | | , "/createOutTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , null |
| | | , null |
| | | , result ? 1 : 0 |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | if (result) { |
| | | return R.ok(); |
| | | } |
| | |
| | | return R.error("åæ°ä¸è½ä¸ºç©º"); |
| | | } |
| | | boolean completeTask = commonService.completeTask(param); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "ä»»å¡å®æ" |
| | | , "/completeTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , null |
| | | , null |
| | | , completeTask ? 1 : 0 |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | if (completeTask) { |
| | | return R.ok(); |
| | | } |
| | |
| | | return R.error("åæ°ä¸è½ä¸ºç©º"); |
| | | } |
| | | boolean completeTask = commonService.cancelTask(param); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "ä»»å¡åæ¶" |
| | | , "/cancelTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , null |
| | | , null |
| | | , completeTask ? 1 : 0 |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | if (completeTask) { |
| | | return R.ok(); |
| | | } |
| | |
| | | wrapper.eq("io_type", ioType.id); |
| | | } |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(wrapper); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "æ¥è¯¢ä»»å¡" |
| | | , "/queryTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , JSON.toJSONString(wrkMasts) |
| | | , null |
| | | , null |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | |
| | | return R.ok().add(wrkMasts); |
| | | } |
| | | |
| New file |
| | |
| | | package com.zy.common.config; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.ApiLog; |
| | | import com.zy.asrs.service.ApiLogService; |
| | | import com.zy.common.annotations.OpenApiLog; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.aspectj.lang.ProceedingJoinPoint; |
| | | import org.aspectj.lang.annotation.Around; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.annotation.Pointcut; |
| | | import org.aspectj.lang.reflect.MethodSignature; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.lang.reflect.Method; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | @Aspect |
| | | @Slf4j |
| | | public class AspectConfig { |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | |
| | | @Pointcut("execution(* com.zy.asrs.controller.*(..))") |
| | | private void webLog() { |
| | | } |
| | | |
| | | @Around("@within(org.springframework.web.bind.annotation.RestController)" + |
| | | "||@within(org.springframework.stereotype.Controller)") |
| | | public Object after(ProceedingJoinPoint joinPoint) throws Throwable { |
| | | ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
| | | HttpServletRequest request = requestAttributes != null ? requestAttributes.getRequest() : null; |
| | | long start = System.currentTimeMillis(); |
| | | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
| | | Method method = signature.getMethod(); |
| | | OpenApiLog annotation = method.isAnnotationPresent(OpenApiLog.class) ? method.getAnnotation(OpenApiLog.class) : null; |
| | | Object result = null; |
| | | Object errorResponse = null; |
| | | try { |
| | | result = joinPoint.proceed(joinPoint.getArgs()); |
| | | if (annotation != null && !Cools.isEmpty(annotation.memo())) { |
| | | saveLog(joinPoint, request, result, annotation.memo()); |
| | | } |
| | | return result; |
| | | } catch (Throwable ex) { |
| | | errorResponse = buildErrorResponse(ex); |
| | | if (annotation != null && !Cools.isEmpty(annotation.memo())) { |
| | | saveErrLog(joinPoint, request, errorResponse, ex, annotation.memo()); |
| | | } |
| | | throw ex; |
| | | } finally { |
| | | long end = System.currentTimeMillis(); |
| | | // log.info("è¯·æ±æ¥å¿çæå°"); |
| | | // log.info("请æ±å°å:{}", request != null ? Optional.ofNullable(request.getRequestURI()).orElse(null) : null); |
| | | // log.info("è¯·æ±æ¹å¼:{}", request != null ? request.getMethod() : null); |
| | | // log.info("请æ±ç±»æ¹æ³:{}", joinPoint.getSignature()); |
| | | // log.info("请æ±ç±»æ¹æ³åæ°:{}", JSONObject.toJSONString(filterArgs(joinPoint.getArgs()))); |
| | | // log.info("请æ±ååºåæ°{}", JSONObject.toJSONString(result != null ? result : errorResponse)); |
| | | // log.info("æ§è¡èæ¶:{}", end - start); |
| | | } |
| | | } |
| | | |
| | | private List<Object> filterArgs(Object[] objects) { |
| | | return Arrays.stream(objects).filter(obj -> !(obj instanceof MultipartFile) |
| | | && !(obj instanceof HttpServletResponse) |
| | | && !(obj instanceof HttpServletRequest)).collect(Collectors.toList()); |
| | | } |
| | | |
| | | private void saveLog(ProceedingJoinPoint joinPoint, HttpServletRequest request, Object result, String memo) { |
| | | apiLogService.insert(new ApiLog( |
| | | null, |
| | | memo, |
| | | request != null ? Optional.ofNullable(String.valueOf(request.getRequestURI())).orElse(null) : null, |
| | | null, |
| | | null, |
| | | null, |
| | | JSONObject.toJSONString(filterArgs(joinPoint.getArgs())), |
| | | JSON.toJSONString(result), |
| | | null, |
| | | 1, |
| | | 1, |
| | | new Date(), |
| | | null, |
| | | null |
| | | )); |
| | | } |
| | | |
| | | private void saveErrLog(ProceedingJoinPoint joinPoint, HttpServletRequest request, Object response, Throwable ex, String memo) { |
| | | apiLogService.insert(new ApiLog( |
| | | null, |
| | | memo, |
| | | request != null ? Optional.ofNullable(String.valueOf(request.getRequestURI())).orElse(null) : null, |
| | | null, |
| | | null, |
| | | null, |
| | | JSONObject.toJSONString(filterArgs(joinPoint.getArgs())), |
| | | JSON.toJSONString(response), |
| | | String.valueOf(ex), |
| | | 0, |
| | | 1, |
| | | new Date(), |
| | | null, |
| | | null |
| | | )); |
| | | } |
| | | |
| | | private Object buildErrorResponse(Throwable ex) { |
| | | if (ex instanceof CoolException) { |
| | | return R.parse(ex.getMessage()); |
| | | } |
| | | return R.error(); |
| | | } |
| | | |
| | | } |
| | |
| | | Date now = new Date(); |
| | | LocMast sourceLocMast = locMastService.queryByLoc(param.getSourceLocNo()); |
| | | if (null == sourceLocMast) { |
| | | throw new CoolException("æºåºä½ä¸åå¨"); |
| | | throw new CoolException(param.getSourceLocNo() + "æºåºä½ä¸åå¨"); |
| | | } |
| | | |
| | | if (!sourceLocMast.getLocSts().equals("F")) { |
| | | throw new CoolException("æºåºä½ä¸å¤äºå¨åºç¶æ"); |
| | | throw new CoolException(sourceLocMast.getLocNo() + "æºåºä½ä¸å¤äºå¨åºç¶æ"); |
| | | } |
| | | |
| | | LocMast locMast = locMastService.queryByLoc(param.getLocNo()); |
| | | if (null == locMast) { |
| | | throw new CoolException("ç®æ åºä½ä¸åå¨"); |
| | | throw new CoolException(param.getLocNo() + "ç®æ åºä½ä¸åå¨"); |
| | | } |
| | | |
| | | if (!locMast.getLocSts().equals("O")) { |
| | | throw new CoolException("ç®æ åºä½ä¸å¤äºç©ºåºç¶æ"); |
| | | throw new CoolException(locMast.getLocNo() + "ç®æ åºä½ä¸å¤äºç©ºåºç¶æ"); |
| | | } |
| | | |
| | | double ioPri = 800D; |
| | |
| | | Date now = new Date(); |
| | | LocMast locMast = locMastService.queryByLoc(param.getLocNo()); |
| | | if (null == locMast) { |
| | | throw new CoolException("ç®æ åºä½ä¸åå¨"); |
| | | throw new CoolException(param.getLocNo() + "ç®æ åºä½ä¸åå¨"); |
| | | } |
| | | |
| | | if (!locMast.getLocSts().equals("O")) { |
| | | throw new CoolException("ç®æ åºä½ä¸å¤äºç©ºåºç¶æ"); |
| | | throw new CoolException(locMast.getLocNo() + "ç®æ åºä½ä¸å¤äºç©ºåºç¶æ"); |
| | | } |
| | | |
| | | double ioPri = 100D; |
| | |
| | | GENERATE_FAKE_IN_STATION_DATA_LIMIT("generate_fake_in_station_data_limit_"), |
| | | CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT("check_out_station_stay_time_out_limit_"), |
| | | CHECK_IN_STATION_STAY_TIME_OUT_LIMIT("check_in_station_stay_time_out_limit_"), |
| | | CRN_IO_EXECUTE_FINISH_LIMIT("crn_io_execute_finish_limit_"), |
| | | |
| | | CURRENT_CIRCLE_TASK_CRN_NO("current_circle_task_crn_no_") |
| | | CURRENT_CIRCLE_TASK_CRN_NO("current_circle_task_crn_no_"), |
| | | ; |
| | | |
| | | public String key; |
| | |
| | | && crnProtocol.getTaskNo() > 0 |
| | | && crnProtocol.getStatus() == CrnStatusType.WAITING.id |
| | | ) { |
| | | Object lock = redisUtil.get(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo()); |
| | | if(lock != null){ |
| | | continue; |
| | | } |
| | | |
| | | // è·åå¾
ç¡®è®¤å·¥ä½æ¡£ |
| | | WrkMast wrkMast = wrkMastService.selectByWorkNo(crnProtocol.getTaskNo()); |
| | |
| | | MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, resetCommand)); |
| | | News.info("å åæºä»»å¡ç¶ææ´æ°æåï¼å åæºå·={}ï¼å·¥ä½å·={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo()); |
| | | } |
| | | |
| | | redisUtil.set(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo(), "lock",10); |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.CrnModeType; |
| | | import com.zy.core.enums.CrnStatusType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.enums.WrkStsType; |
| | | import com.zy.core.enums.*; |
| | | import com.zy.core.model.StationObjModel; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.CrnCommand; |
| | |
| | | private BasCrnpService basCrnpService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | //å
¥åºåº ===>> å åæºå
¥åºåºä½ä¸ä¸å |
| | | public synchronized void crnIoExecute() { |
| | |
| | | && crnProtocol.getTaskNo() > 0 |
| | | && crnProtocol.getStatus() == CrnStatusType.WAITING.id |
| | | ) { |
| | | Object lock = redisUtil.get(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo()); |
| | | if(lock != null){ |
| | | continue; |
| | | } |
| | | |
| | | // è·åå¾
ç¡®è®¤å·¥ä½æ¡£ |
| | | WrkMast wrkMast = wrkMastService.selectByWorkNo(crnProtocol.getTaskNo()); |
| | |
| | | MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, resetCommand)); |
| | | News.info("å åæºä»»å¡ç¶ææ´æ°æåï¼å åæºå·={}ï¼å·¥ä½å·={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo()); |
| | | } |
| | | |
| | | redisUtil.set(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo(), "lock",10); |
| | | } |
| | | } |
| | | } |