New file |
| | |
| | | package com.zy.asrs.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotations.TableField; |
| | | import com.baomidou.mybatisplus.annotations.TableId; |
| | | import com.baomidou.mybatisplus.annotations.TableName; |
| | | import com.baomidou.mybatisplus.enums.IdType; |
| | | import com.core.common.Cools; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.io.Serializable; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | @Data |
| | | @TableName("man_api_log") |
| | | public class ApiLog implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * ID |
| | | */ |
| | | @ApiModelProperty(value= "ID") |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | | /** |
| | | * 日志编号 |
| | | */ |
| | | @ApiModelProperty(value= "日志编号") |
| | | private String uuid; |
| | | |
| | | /** |
| | | * 名称空间 |
| | | */ |
| | | @ApiModelProperty(value= "名称空间") |
| | | private String namespace; |
| | | |
| | | /** |
| | | * 接口地址 |
| | | */ |
| | | @ApiModelProperty(value= "接口地址") |
| | | private String url; |
| | | |
| | | /** |
| | | * 平台密钥 |
| | | */ |
| | | @ApiModelProperty(value= "平台密钥") |
| | | private String appkey; |
| | | |
| | | /** |
| | | * 时间戳 |
| | | */ |
| | | @ApiModelProperty(value= "时间戳") |
| | | private String timestamp; |
| | | |
| | | /** |
| | | * 客户端IP |
| | | */ |
| | | @ApiModelProperty(value= "客户端IP") |
| | | @TableField("client_ip") |
| | | private String clientIp; |
| | | |
| | | /** |
| | | * 请求内容 |
| | | */ |
| | | @ApiModelProperty(value= "请求内容") |
| | | private String request; |
| | | |
| | | /** |
| | | * 响应内容 |
| | | */ |
| | | @ApiModelProperty(value= "响应内容") |
| | | private String response; |
| | | |
| | | /** |
| | | * 异常内容 |
| | | */ |
| | | @ApiModelProperty(value= "异常内容") |
| | | private String err; |
| | | |
| | | /** |
| | | * 结果 1: 成功 0: 失败 |
| | | */ |
| | | @ApiModelProperty(value= "结果 1: 成功 0: 失败 ") |
| | | private Integer result; |
| | | |
| | | /** |
| | | * 状态 1: 正常 0: 禁用 |
| | | */ |
| | | @ApiModelProperty(value= "状态 1: 正常 0: 禁用 ") |
| | | private Integer status; |
| | | |
| | | /** |
| | | * 添加时间 |
| | | */ |
| | | @ApiModelProperty(value= "添加时间") |
| | | @TableField("create_time") |
| | | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") |
| | | private Date createTime; |
| | | |
| | | /** |
| | | * 修改时间 |
| | | */ |
| | | @ApiModelProperty(value= "修改时间") |
| | | @TableField("update_time") |
| | | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") |
| | | private Date updateTime; |
| | | |
| | | /** |
| | | * 备注 |
| | | */ |
| | | @ApiModelProperty(value= "备注") |
| | | private String memo; |
| | | |
| | | public ApiLog() {} |
| | | |
| | | public ApiLog(String uuid, String namespace, String url, String appkey, String timestamp, String clientIp, String request, String response, String err, Integer result, Integer status, Date createTime, Date updateTime, String memo) { |
| | | this.uuid = uuid; |
| | | this.namespace = namespace; |
| | | this.url = url; |
| | | this.appkey = appkey; |
| | | this.timestamp = timestamp; |
| | | this.clientIp = clientIp; |
| | | this.request = request; |
| | | this.response = response; |
| | | this.err = err; |
| | | this.result = result; |
| | | this.status = status; |
| | | this.createTime = createTime; |
| | | this.updateTime = updateTime; |
| | | this.memo = memo; |
| | | } |
| | | |
| | | // ApiLog apiLog = new ApiLog( |
| | | // null, // 日志编号 |
| | | // null, // 名称空间 |
| | | // null, // 接口地址 |
| | | // null, // 平台密钥 |
| | | // null, // 时间戳 |
| | | // null, // 客户端IP |
| | | // null, // 请求内容 |
| | | // null, // 响应内容 |
| | | // null, // 异常内容 |
| | | // null, // 结果 |
| | | // null, // 状态 |
| | | // null, // 添加时间 |
| | | // null, // 修改时间 |
| | | // null // 备注 |
| | | // ); |
| | | |
| | | public String getResult$(){ |
| | | if (null == this.result){ return null; } |
| | | switch (this.result){ |
| | | case 1: |
| | | return "成功"; |
| | | case 0: |
| | | return "失败"; |
| | | default: |
| | | return String.valueOf(this.result); |
| | | } |
| | | } |
| | | |
| | | public String getStatus$(){ |
| | | if (null == this.status){ return null; } |
| | | switch (this.status){ |
| | | case 1: |
| | | return "正常"; |
| | | case 0: |
| | | return "禁用"; |
| | | default: |
| | | return String.valueOf(this.status); |
| | | } |
| | | } |
| | | |
| | | public String getCreateTime$(){ |
| | | if (Cools.isEmpty(this.createTime)){ |
| | | return ""; |
| | | } |
| | | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.createTime); |
| | | } |
| | | |
| | | public String getUpdateTime$(){ |
| | | if (Cools.isEmpty(this.updateTime)){ |
| | | return ""; |
| | | } |
| | | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.updateTime); |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.BaseMapper; |
| | | import com.zy.asrs.entity.ApiLog; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | @Mapper |
| | | @Repository |
| | | public interface ApiLogMapper extends BaseMapper<ApiLog> { |
| | | int clearWeekBefore(); |
| | | } |
New file |
| | |
| | | package com.zy.asrs.service; |
| | | |
| | | import com.baomidou.mybatisplus.service.IService; |
| | | import com.zy.asrs.entity.ApiLog; |
| | | |
| | | public interface ApiLogService extends IService<ApiLog> { |
| | | void save(String namespace, String url, String appkey, String ip, String request, String response, boolean success); |
| | | |
| | | boolean clearWeekBefore(); |
| | | } |
New file |
| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.zy.asrs.entity.ApiLog; |
| | | import com.zy.asrs.mapper.ApiLogMapper; |
| | | import com.zy.asrs.service.ApiLogService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | |
| | | @Slf4j |
| | | @Service("apiLogService") |
| | | public class ApiLogServiceImpl extends ServiceImpl<ApiLogMapper, ApiLog> implements ApiLogService { |
| | | |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | |
| | | @Async |
| | | @Override |
| | | public void save(String namespace, String url, String appkey, String ip, String request, String response, boolean success) { |
| | | Date now = new Date(); |
| | | ApiLog apiLog = new ApiLog( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 日志编号 |
| | | namespace, // 名称空间 |
| | | url, // 接口地址 |
| | | appkey, // 平台密钥 |
| | | String.valueOf(now.getTime()), // 时间戳 |
| | | ip, // 客户端IP |
| | | request, // 请求内容 |
| | | response, |
| | | null, // 异常内容 |
| | | success?1:0 , // 结果 |
| | | 1, // 状态 |
| | | now, // 添加时间 |
| | | null, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!this.insert(apiLog)) { |
| | | log.error("接口调用日志保存失败!"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean clearWeekBefore() { |
| | | return this.baseMapper.clearWeekBefore() > 0; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.task; |
| | | |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.MessageFormat; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/7/4 |
| | | */ |
| | | @Slf4j |
| | | public abstract class AbstractHandler<T> { |
| | | |
| | | public final ReturnT<T> SUCCESS = new ReturnT<>(200, null); |
| | | public final ReturnT<T> FAIL = new ReturnT<>(500, null); |
| | | |
| | | // protected abstract ReturnT<T> start(); |
| | | |
| | | protected void exceptionHandle(String errorMsg){ |
| | | log.error(errorMsg); |
| | | exceptionHandle(errorMsg, (Object) null); |
| | | } |
| | | |
| | | protected void exceptionHandle(String errorMsg, Object... args){ |
| | | log.error(errorMsg); |
| | | throw new CoolException(MessageFormat.format(errorMsg, args)); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.task; |
| | | |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.task.handler.ReportToDismantleTheStackHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * Created by Monkey D. Luffy on 2023.07.25 |
| | | * 徐工汉云..............以下.............上饶江铜.............拆垛信息上传 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class ReportToDismantleTheStackScheduler { |
| | | |
| | | @Autowired |
| | | private ReportToDismantleTheStackHandler reportToDismantleTheStackHandler; |
| | | |
| | | @Scheduled(cron = "0/3 * * * * ? ") |
| | | private void execute(){//拆垛信息上传 |
| | | int[] staNos =new int[]{118,119,120,121}; |
| | | for (int staNo : staNos){ |
| | | try{ |
| | | ReturnT<String> result = reportToDismantleTheStackHandler.start(staNo); |
| | | if (result.getCode()==200){ |
| | | break; |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("站点"+staNo+"拆垛信息上传处理失败,异常信息:"+e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.task.core; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/7/7 |
| | | */ |
| | | public class AsrsException extends RuntimeException { |
| | | |
| | | public AsrsException(Throwable e) { |
| | | super(e); |
| | | } |
| | | |
| | | public AsrsException(String message) { |
| | | super(message); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.task.core; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/7/7 |
| | | */ |
| | | public class ReturnT<T> implements Serializable { |
| | | |
| | | public static final long serialVersionUID = 42L; |
| | | public static final int SUCCESS_CODE = 200; |
| | | public static final int FAIL_CODE = 500; |
| | | private int code; |
| | | private String msg; |
| | | private T content; |
| | | |
| | | public ReturnT() { |
| | | } |
| | | |
| | | public ReturnT(int code, String msg) { |
| | | this.code = code; |
| | | this.msg = msg; |
| | | } |
| | | |
| | | public ReturnT(T content) { |
| | | this.code = 200; |
| | | this.content = content; |
| | | } |
| | | |
| | | public boolean isSuccess(){ |
| | | return this.code == 200; |
| | | } |
| | | |
| | | public int getCode() { |
| | | return this.code; |
| | | } |
| | | |
| | | public ReturnT<T> setCode(int code) { |
| | | this.code = code; |
| | | return this; |
| | | } |
| | | |
| | | public String getMsg() { |
| | | return this.msg; |
| | | } |
| | | |
| | | public ReturnT<T> setMsg(String msg) { |
| | | this.msg = msg; |
| | | return this; |
| | | } |
| | | |
| | | public T getContent() { |
| | | return this.content; |
| | | } |
| | | |
| | | public ReturnT<T> setContent(T content) { |
| | | this.content = content; |
| | | return this; |
| | | } |
| | | |
| | | public String toString() { |
| | | return "ReturnT [code=" + this.code + ", msg=" + this.msg + ", content=" + this.content + "]"; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.task.core;//package com.zy.asrs.task.core; |
| | | // |
| | | //import com.zy.asrs.task.handler.WorkLogHandler; |
| | | //import com.zy.asrs.task.handler.WorkMastHandler; |
| | | //import com.zy.system.service.ConfigService; |
| | | //import org.slf4j.Logger; |
| | | //import org.slf4j.LoggerFactory; |
| | | //import org.springframework.beans.factory.annotation.Autowired; |
| | | // |
| | | //import javax.annotation.PostConstruct; |
| | | //import javax.annotation.PreDestroy; |
| | | // |
| | | ///** |
| | | // * 单线程模式 ( 已弃用 ) |
| | | // * 任务中心调度器 |
| | | // * Created by vincent on 2020/7/4 |
| | | // */ |
| | | ////@Component |
| | | //@Deprecated |
| | | //public class WcsDispatcher { |
| | | // |
| | | // private static final Logger log = LoggerFactory.getLogger(WcsDispatcher.class); |
| | | // private Thread thread; |
| | | // |
| | | // @Autowired |
| | | // private WorkMastHandler workMastHandler; |
| | | // @Autowired |
| | | // private WorkLogHandler workLogHandler; |
| | | // @Autowired |
| | | // private ConfigService configService; |
| | | // |
| | | // @PostConstruct |
| | | // private void start(){ |
| | | // thread = new Thread(() -> { |
| | | // while (!Thread.currentThread().isInterrupted()) { |
| | | // try { |
| | | // Thread.sleep(3000); |
| | | // |
| | | //// workMastHandler.start(); |
| | | //// |
| | | //// workLogHandler.start(); |
| | | // |
| | | // } catch (Exception e) { |
| | | // log.error("Exception", e); |
| | | // } |
| | | // } |
| | | // }); |
| | | // thread.start(); |
| | | // log.info("任务中心调度器已启动......"); |
| | | // } |
| | | // |
| | | // @PreDestroy |
| | | // public void shutDown(){ |
| | | // if (thread != null) |
| | | // thread.interrupt(); |
| | | // log.info("任务中心调度器已停止......"); |
| | | // } |
| | | // |
| | | //} |
New file |
| | |
| | | package com.zy.asrs.task.handler; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.WrkDetl; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.task.AbstractHandler; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.protocol.StaProtocol; |
| | | import com.zy.core.thread.SiemensDevpThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Created by Monkey D. Luffy on 2023.07.25 |
| | | * 徐工汉云..............以下.............上饶江铜.............拆垛信息上传 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | @Transactional |
| | | public class ReportToDismantleTheStackHandler extends AbstractHandler<String> { |
| | | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | |
| | | // @Value("${srHangJia.url}") |
| | | private String erpUrl = "192.168.18.229:16126"; |
| | | // @Value("${srHangJia.reportOutPath}") |
| | | private String reportOutPath = "api/DepalletizingInfo/Post"; |
| | | |
| | | public ReturnT<String> start(int staNo) { |
| | | try{ |
| | | }catch (Exception e){ |
| | | log.error("异常!!!"+e); |
| | | return FAIL; |
| | | } |
| | | return FAIL; |
| | | } |
| | | |
| | | private ReturnT<String> postMesData(String erpPath,Object combParam){ |
| | | if(combParam != null){ |
| | | String response = ""; |
| | | boolean success = false; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(erpUrl) |
| | | .setPath(erpPath) |
| | | .setJson(JSON.toJSONString(combParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("Code")==200) { |
| | | success = true; |
| | | } else { |
| | | log.error("拆垛信息上传请求接口失败!!!url:{};request:{};response:{}"+erpUrl+erpPath, JSON.toJSONString(combParam), response); |
| | | throw new CoolException("上报erp系统失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("fail", e); |
| | | // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return FAIL.setMsg(e.getMessage()); |
| | | } finally { |
| | | try { |
| | | // 保存接口日志 |
| | | apiLogService.save( |
| | | "上报桁架系统", |
| | | erpUrl + erpPath, |
| | | null, |
| | | erpUrl, |
| | | JSON.toJSONString(combParam), |
| | | response, |
| | | success |
| | | ); |
| | | } catch (Exception e) { log.error("", e); } |
| | | } |
| | | } |
| | | return SUCCESS; |
| | | } |
| | | |
| | | public Integer getStaOther(Integer staNo){ |
| | | switch (staNo){ |
| | | case 118: |
| | | return 119; |
| | | case 119: |
| | | return 118; |
| | | case 120: |
| | | return 121; |
| | | case 121: |
| | | return 120; |
| | | default: |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | public Integer getStaEnd(Integer staNo){ |
| | | switch (staNo){ |
| | | case 118: |
| | | case 119: |
| | | return 131; |
| | | case 120: |
| | | case 121: |
| | | return 135; |
| | | default: |
| | | return 0; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.zy.asrs.mapper.ApiLogMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.zy.asrs.entity.ApiLog"> |
| | | <id column="id" property="id" /> |
| | | <result column="uuid" property="uuid" /> |
| | | <result column="namespace" property="namespace" /> |
| | | <result column="url" property="url" /> |
| | | <result column="appkey" property="appkey" /> |
| | | <result column="timestamp" property="timestamp" /> |
| | | <result column="client_ip" property="clientIp" /> |
| | | <result column="request" property="request" /> |
| | | <result column="response" property="response" /> |
| | | <result column="err" property="err" /> |
| | | <result column="result" property="result" /> |
| | | <result column="status" property="status" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="update_time" property="updateTime" /> |
| | | <result column="memo" property="memo" /> |
| | | |
| | | </resultMap> |
| | | |
| | | <delete id="clearWeekBefore"> |
| | | delete from man_api_log |
| | | where 1=1 |
| | | and datediff(week,create_time,getdate()) >= 1 |
| | | and result != 1 |
| | | </delete> |
| | | |
| | | </mapper> |