New file |
| | |
| | | package com.zy.asrs.common.openapi.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.zy.asrs.common.openapi.entity.ApiLog; |
| | | import com.zy.asrs.common.openapi.service.ApiLogService; |
| | | import com.zy.asrs.framework.annotations.ManagerAuth; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import com.zy.asrs.framework.domain.KeyValueVo; |
| | | import com.zy.asrs.framework.common.DateUtils; |
| | | import com.zy.asrs.common.web.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | public class ApiLogController extends BaseController { |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | |
| | | @RequestMapping(value = "/apiLog/{id}/auth") |
| | | @ManagerAuth |
| | | public R get(@PathVariable("id") String id) { |
| | | return R.ok(apiLogService.getById(String.valueOf(id))); |
| | | } |
| | | |
| | | @RequestMapping(value = "/apiLog/page/auth") |
| | | @ManagerAuth |
| | | public R page(@RequestParam(defaultValue = "1") Integer curr, |
| | | @RequestParam(defaultValue = "10") Integer limit, |
| | | @RequestParam(required = false) String condition, |
| | | @RequestParam(required = false) String timeRange, |
| | | @RequestParam Map<String, Object> param) { |
| | | LambdaQueryWrapper<ApiLog> wrapper = new LambdaQueryWrapper<>(); |
| | | if (!Cools.isEmpty(condition)) { |
| | | wrapper.like(ApiLog::getUuid, condition); |
| | | } |
| | | if (!Cools.isEmpty(timeRange)) { |
| | | String[] range = timeRange.split(RANGE_TIME_LINK); |
| | | wrapper.ge(ApiLog::getCreateTime, DateUtils.convert(range[0])); |
| | | wrapper.le(ApiLog::getCreateTime, DateUtils.convert(range[1])); |
| | | } |
| | | return R.ok(apiLogService.page(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/apiLog/add/auth") |
| | | @ManagerAuth |
| | | public R add(ApiLog apiLog) { |
| | | apiLogService.save(apiLog); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/apiLog/update/auth") |
| | | @ManagerAuth |
| | | public R update(ApiLog apiLog){ |
| | | if (Cools.isEmpty(apiLog) || null==apiLog.getId()){ |
| | | return R.error(); |
| | | } |
| | | apiLogService.updateById(apiLog); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/apiLog/delete/auth") |
| | | @ManagerAuth |
| | | public R delete(@RequestParam(value="ids[]") Long[] ids){ |
| | | for (Long id : ids){ |
| | | apiLogService.removeById(id); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/apiLogQuery/auth") |
| | | @ManagerAuth |
| | | public R query(String condition) { |
| | | LambdaQueryWrapper<ApiLog> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.like(ApiLog::getUuid, condition); |
| | | Page<ApiLog> page = apiLogService.page(new Page<>(0, 10), wrapper); |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (ApiLog apiLog : page.getRecords()){ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("id", apiLog.getId()); |
| | | map.put("value", apiLog.getUuid()); |
| | | result.add(map); |
| | | } |
| | | return R.ok(result); |
| | | } |
| | | |
| | | @RequestMapping("/apiLog/all/get/kv") |
| | | @ManagerAuth |
| | | public R getDataKV(@RequestParam(required = false) String condition) { |
| | | List<KeyValueVo> vos = new ArrayList<>(); |
| | | LambdaQueryWrapper<ApiLog> wrapper = new LambdaQueryWrapper<>(); |
| | | if (!Cools.isEmpty(condition)) { |
| | | wrapper.like(ApiLog::getUuid, condition); |
| | | } |
| | | apiLogService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getUuid()), item.getId()))); |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.common.openapi.entity; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableLogic; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.SpringUtils; |
| | | import com.zy.asrs.common.sys.entity.User; |
| | | import com.zy.asrs.common.sys.entity.Host; |
| | | import com.zy.asrs.common.sys.service.UserService; |
| | | import com.zy.asrs.common.sys.service.HostService; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | @Data |
| | | @TableName("openapi_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") |
| | | 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= "添加时间") |
| | | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") |
| | | private Date createTime; |
| | | |
| | | /** |
| | | * 修改时间 |
| | | */ |
| | | @ApiModelProperty(value= "修改时间") |
| | | @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.common.openapi.entity.param; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/6/28 |
| | | */ |
| | | @Data |
| | | public class CombParam { |
| | | |
| | | // 单据编号 |
| | | private String orderNo; |
| | | |
| | | // 托盘条码 |
| | | private String barcode; |
| | | |
| | | // 库位编号 |
| | | private String locno; |
| | | |
| | | //组托物料 |
| | | private List<CombMat> combMats; |
| | | |
| | | //仓库ID |
| | | private Long hostId; |
| | | |
| | | @Data |
| | | public static class CombMat { |
| | | |
| | | //料想码 |
| | | private String containerCode; |
| | | |
| | | //销售订单号 |
| | | private String csocode; |
| | | |
| | | //销售订单行号 |
| | | private String isoseq; |
| | | |
| | | // 物料编号 |
| | | private String matnr; |
| | | |
| | | // 序列码 |
| | | private String batch; |
| | | |
| | | // 物料数量 |
| | | private Double anfme; |
| | | |
| | | // 商品名称 |
| | | private String maktx; |
| | | |
| | | // 规格 |
| | | private String specs; |
| | | |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.common.openapi.mapper; |
| | | |
| | | import com.zy.asrs.common.openapi.entity.ApiLog; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | @Mapper |
| | | @Repository |
| | | public interface ApiLogMapper extends BaseMapper<ApiLog> { |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.common.openapi.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.zy.asrs.common.openapi.entity.ApiLog; |
| | | |
| | | public interface ApiLogService extends IService<ApiLog> { |
| | | |
| | | void saveLog(String namespace, String url, String appkey, String ip, String request, String response, boolean success); |
| | | |
| | | } |
| | |
| | | package com.zy.asrs.common.openapi.service; |
| | | |
| | | import com.zy.asrs.common.openapi.entity.param.CombParam; |
| | | import com.zy.asrs.common.openapi.entity.param.GenerateOrderPakInParam; |
| | | import com.zy.asrs.common.wms.entity.DocType; |
| | | |
| | | import java.util.List; |
| | | |
| | | public interface ApiService { |
| | | |
| | |
| | | */ |
| | | void generateOrderPakIn(GenerateOrderPakInParam param); |
| | | |
| | | List<DocType> getOrderType(); |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.common.openapi.service.impl; |
| | | |
| | | import com.zy.asrs.common.openapi.mapper.ApiLogMapper; |
| | | import com.zy.asrs.common.openapi.entity.ApiLog; |
| | | import com.zy.asrs.common.openapi.service.ApiLogService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.zy.asrs.framework.common.SnowflakeIdWorker; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | |
| | | @Service("apiLogService") |
| | | public class ApiLogServiceImpl extends ServiceImpl<ApiLogMapper, ApiLog> implements ApiLogService { |
| | | |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | |
| | | @Override |
| | | public void saveLog(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.save(apiLog)) { |
| | | log.error("接口调用日志保存失败!"); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.common.domain.dto.DetlDto; |
| | | import com.zy.asrs.common.openapi.entity.param.CombParam; |
| | | import com.zy.asrs.common.openapi.entity.param.GenerateOrderPakInParam; |
| | | import com.zy.asrs.common.openapi.service.ApiService; |
| | | import com.zy.asrs.common.wms.entity.DocType; |
| | | import com.zy.asrs.common.wms.entity.Mat; |
| | | import com.zy.asrs.common.wms.entity.Order; |
| | | import com.zy.asrs.common.wms.entity.OrderDetl; |
| | | import com.zy.asrs.common.wms.service.DocTypeService; |
| | | import com.zy.asrs.common.wms.service.MatService; |
| | | import com.zy.asrs.common.wms.service.OrderDetlService; |
| | | import com.zy.asrs.common.wms.service.OrderService; |
| | | import com.zy.asrs.common.wms.entity.*; |
| | | import com.zy.asrs.common.wms.service.*; |
| | | import com.zy.asrs.framework.common.BaseRes; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.DateUtils; |
| | | import com.zy.asrs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | | 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; |
| | |
| | | private MatService matService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | |
| | | @Override |
| | | public void generateOrderPakIn(GenerateOrderPakInParam param) { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<DocType> getOrderType() { |
| | | List<DocType> list = docTypeService.list(); |
| | | return list; |
| | | } |
| | | } |
New file |
| | |
| | | package com.zy.asrs.common.utils; |
| | | |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.net.Inet4Address; |
| | | import java.net.InetAddress; |
| | | import java.net.NetworkInterface; |
| | | import java.util.Enumeration; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/8/6 |
| | | */ |
| | | @Slf4j |
| | | public class IpTools { |
| | | |
| | | public static String gainRealIp(HttpServletRequest request) { |
| | | String ipAddress = ""; |
| | | try { |
| | | if (request == null) { |
| | | return ipAddress; |
| | | } |
| | | |
| | | //排除本地测试 |
| | | if ("127.0.0.1".equals(request.getServerName()) || "localhost".equals(request.getServerName())) { |
| | | ipAddress = "127.0.0.1"; |
| | | return ipAddress; |
| | | } |
| | | |
| | | ipAddress = request.getRemoteAddr(); |
| | | if (Cools.isEmpty(ipAddress)) { |
| | | ipAddress = request.getRemoteHost(); |
| | | } else { |
| | | return ipAddress; |
| | | } |
| | | |
| | | if (!Cools.isEmpty(ipAddress)) { |
| | | return ipAddress; |
| | | } |
| | | |
| | | // 获取真实ip,排除代理ip |
| | | ipAddress = request.getHeader("Referer"); |
| | | |
| | | // ipAddress = this.getRequest().getRemoteAddr(); |
| | | ipAddress = request.getHeader("X-Forwarded-For"); |
| | | if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { |
| | | ipAddress = request.getHeader("Proxy-Client-IP"); |
| | | } |
| | | if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { |
| | | ipAddress = request.getHeader("WL-Proxy-Client-IP"); |
| | | } |
| | | if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { |
| | | // 更换niginx代理 |
| | | // ipAddress = request.getRemoteAddr(); |
| | | ipAddress = request.getHeader("X-Real-IP"); |
| | | if (ipAddress != null && (ipAddress.equals("" + "") || ipAddress.endsWith("0:0:0:0:0:0:0:1"))) { |
| | | // 根据网卡取本机配置的IP |
| | | |
| | | // linux下也可以获取本地的ip地址 |
| | | Enumeration<?> allNetInterfaces = NetworkInterface.getNetworkInterfaces(); |
| | | InetAddress ip; |
| | | while (allNetInterfaces.hasMoreElements()) { |
| | | NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement(); |
| | | Enumeration<InetAddress> addresses = netInterface.getInetAddresses(); |
| | | while (addresses.hasMoreElements()) { |
| | | ip = addresses.nextElement(); |
| | | if (ip instanceof Inet4Address) { |
| | | // 获取真实的Ip地址 |
| | | ipAddress = ip.getHostAddress(); |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割"***.***.***.***".length()=15 |
| | | if (ipAddress != null && ipAddress.length() > 15) { |
| | | |
| | | if (ipAddress.indexOf(",") > 0) { |
| | | ipAddress = ipAddress.substring(0, ipAddress.indexOf(",")); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.warn("ip{},解析异常", ipAddress, e); |
| | | } |
| | | return ipAddress; |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | import com.zy.asrs.common.utils.Synchro; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | |
| | | return null; |
| | | } |
| | | |
| | | public void sync(Object source) { |
| | | Synchro.Copy(source, this); |
| | | } |
| | | |
| | | } |
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.common.openapi.mapper.ApiLogMapper"> |
| | | |
| | | </mapper> |
New file |
| | |
| | | package com.zy.asrs.openapi.config; |
| | | |
| | | import com.zy.asrs.common.sys.entity.OperateLog; |
| | | import com.zy.asrs.common.sys.service.OperateLogService; |
| | | import com.zy.asrs.framework.annotations.AppAuth; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.lang.Nullable; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.lang.reflect.Method; |
| | | |
| | | @Component |
| | | public class AdminInterceptor extends HandlerInterceptorAdapter { |
| | | |
| | | @Autowired |
| | | private OperateLogService operateLogService; |
| | | |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
| | | cors(response); |
| | | if (handler instanceof org.springframework.web.servlet.resource.ResourceHttpRequestHandler) { |
| | | return true; |
| | | } |
| | | // 跨域设置 |
| | | // response.setHeader("Access-Control-Allow-Origin", "*"); |
| | | HandlerMethod handlerMethod = (HandlerMethod) handler; |
| | | Method method = handlerMethod.getMethod(); |
| | | if (method.isAnnotationPresent(AppAuth.class)){ |
| | | AppAuth annotation = method.getAnnotation(AppAuth.class); |
| | | if (annotation.value().equals(AppAuth.Auth.CHECK)){ |
| | | request.setAttribute("appAuth", annotation.memo()); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) { |
| | | Object obj = request.getAttribute("operateLog"); |
| | | if (obj instanceof OperateLog) { |
| | | OperateLog operate = (OperateLog) obj; |
| | | operate.setResponse(String.valueOf(response.getStatus())); |
| | | operateLogService.save(operate); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception { |
| | | // Object r = request.getAttribute("cool-response"); |
| | | } |
| | | |
| | | /** |
| | | * 跨域 |
| | | */ |
| | | public static void cors(HttpServletResponse response){ |
| | | // 跨域设置 |
| | | response.setHeader("Access-Control-Allow-Origin", "*"); |
| | | response.setHeader("Access-Control-Allow-Credentials", "true"); |
| | | response.setHeader("Access-Control-Allow-Methods", "*"); |
| | | response.setHeader("Access-Control-Allow-Headers", "Content-Type,Access-Token"); |
| | | response.setHeader("Access-Control-Expose-Headers", "*"); |
| | | |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.openapi.config; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.zy.asrs.common.openapi.service.ApiLogService; |
| | | import com.zy.asrs.common.utils.IpTools; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.core.MethodParameter; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.converter.HttpMessageConverter; |
| | | import org.springframework.http.server.ServerHttpRequest; |
| | | import org.springframework.http.server.ServerHttpResponse; |
| | | import org.springframework.http.server.ServletServerHttpRequest; |
| | | import org.springframework.web.bind.annotation.ControllerAdvice; |
| | | import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | /** |
| | | * 返回值处理 |
| | | */ |
| | | @Slf4j |
| | | @ControllerAdvice |
| | | public class ControllerResAdvice implements ResponseBodyAdvice<Object> { |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | |
| | | @Override |
| | | public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) { |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public Object beforeBodyWrite(Object o, MethodParameter methodParameter, MediaType mediaType, Class<? extends HttpMessageConverter<?>> aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) { |
| | | if (serverHttpRequest instanceof ServletServerHttpRequest) { |
| | | HttpServletRequest request = ((ServletServerHttpRequest) serverHttpRequest).getServletRequest(); |
| | | Object appAuth = request.getAttribute("appAuth"); |
| | | if (appAuth != null) { |
| | | if (o instanceof R) { |
| | | String appkey = request.getHeader("appkey"); |
| | | Object reqCache = request.getAttribute("cache"); |
| | | if (!Cools.isEmpty(appkey)) { |
| | | // 保存接口日志 |
| | | apiLogService.saveLog( |
| | | String.valueOf(appAuth), |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache==null?"": JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | String.valueOf(((R) o).get("code")).equalsIgnoreCase("200") |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return o; |
| | | } |
| | | |
| | | public static String json(HttpServletRequest request) { |
| | | try { |
| | | BufferedReader streamReader = new BufferedReader( new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8)); |
| | | StringBuilder sb = new StringBuilder(); |
| | | String inputStr; |
| | | while ((inputStr = streamReader.readLine()) != null) { |
| | | sb.append(inputStr); |
| | | } |
| | | return sb.toString(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.openapi.config; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| | | |
| | | /** |
| | | * Created by vincent on 2019-06-13 |
| | | */ |
| | | @Configuration |
| | | public class WebConfig implements WebMvcConfigurer { |
| | | |
| | | @Autowired |
| | | private AdminInterceptor adminInterceptor; |
| | | |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) { |
| | | registry.addInterceptor(adminInterceptor) |
| | | .addPathPatterns("/**") |
| | | ; |
| | | } |
| | | |
| | | } |
| | |
| | | import com.zy.asrs.common.openapi.service.HostKeyService; |
| | | import com.zy.asrs.common.web.BaseController; |
| | | import com.zy.asrs.common.wms.entity.DocType; |
| | | import com.zy.asrs.common.wms.service.DocTypeService; |
| | | import com.zy.asrs.framework.annotations.AppAuth; |
| | | import com.zy.asrs.framework.common.BaseRes; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | |
| | | @Autowired |
| | | private HostKeyService hostKeyService; |
| | | @Autowired |
| | | private DocTypeService docTypeService; |
| | | @Autowired |
| | | private ApiService apiService; |
| | | |
| | | /** |
| | | * 生成入库订单 |
| | | */ |
| | | @PostMapping("/generateOrderPakIn") |
| | | @AppAuth(memo = "生成入库订单") |
| | | public synchronized R generateOrderPakIn(@RequestHeader(required = false) String appkey, |
| | | @RequestBody GenerateOrderPakInParam param) { |
| | | HostKey hostKey = auth(appkey, param, true); |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 获取订单类型 |
| | | */ |
| | | @PostMapping("/getOrderType") |
| | | public synchronized R getOrderType(@RequestHeader(required = false) String appkey) { |
| | | auth(appkey, null, false); |
| | | List<DocType> list = docTypeService.list(); |
| | | List<DocType> list = apiService.getOrderType(); |
| | | return R.ok().add(list); |
| | | } |
| | | |
| | | private HostKey auth(String appkey, Object obj, boolean signCheck) { |
| | | request.setAttribute("cache", obj); |
| | | if (Cools.isEmpty(appkey)) { |
| | | throw new CoolException("认证失败,请确认appKey无误!"); |
| | | } |