| @@ -0,0 +1,14 @@ | |||||
| CREATE TABLE `pos_action_log` ( | |||||
| `id` bigint(20) NOT NULL COMMENT '主键ID', | |||||
| `url` varchar (100) NOT NULL COMMENT '访问url', | |||||
| `ip` varchar (20) NOT NULL COMMENT 'ip地址', | |||||
| `method` varchar (10) NOT NULL COMMENT 'http访问', | |||||
| `start_time` bigint(20) NOT NULL COMMENT 'api发起时间', | |||||
| `end_time` bigint(20) NOT NULL COMMENT 'api发起时间', | |||||
| `cost_time` INTEGER NOT NULL COMMENT '访问花费时间', | |||||
| `req_json` json DEFAULT NULL COMMENT '命令请求JSON', | |||||
| `res_json` json DEFAULT NULL COMMENT '返回结果', | |||||
| PRIMARY KEY (`id`) | |||||
| ) ENGINE=`InnoDB` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='POS访问LOG' CHECKSUM=0 DELAY_KEY_WRITE=0; | |||||
| ALTER TABLE `pos_action_log` ADD INDEX `idx_Index` (`url`, `ip`, `method`, `start_time`); | |||||
| @@ -0,0 +1,10 @@ | |||||
| package com.iformall.annotation; | |||||
| import java.lang.annotation.*; | |||||
| @Target({ElementType.PARAMETER, ElementType.METHOD}) | |||||
| @Retention(RetentionPolicy.RUNTIME) | |||||
| @Documented | |||||
| public @interface SystemControllerLog { | |||||
| String description() default ""; | |||||
| } | |||||
| @@ -0,0 +1,10 @@ | |||||
| package com.iformall.annotation; | |||||
| import java.lang.annotation.*; | |||||
| @Target({ElementType.PARAMETER, ElementType.METHOD}) | |||||
| @Retention(RetentionPolicy.RUNTIME) | |||||
| @Documented | |||||
| public @interface SystemServiceLog { | |||||
| String description() default ""; | |||||
| } | |||||
| @@ -1,6 +1,7 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.iformall.annotation.SystemControllerLog; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| @@ -36,6 +37,7 @@ public class PosController extends BaseController { | |||||
| "\"tenant_id\":\"string(必填)\"," + | "\"tenant_id\":\"string(必填)\"," + | ||||
| "\"nonce_str\":\"string(必填)\"}") | "\"nonce_str\":\"string(必填)\"}") | ||||
| @PostMapping("/getPosMemConfigStatus") | @PostMapping("/getPosMemConfigStatus") | ||||
| @SystemControllerLog(description = "获取会员折扣/优惠券/消费卡是否启用") | |||||
| public Map<String, String> getMemStatus(@RequestBody Map<String, String> params) { | public Map<String, String> getMemStatus(@RequestBody Map<String, String> params) { | ||||
| JSONObject payContent = new JSONObject(); | JSONObject payContent = new JSONObject(); | ||||
| @@ -0,0 +1,68 @@ | |||||
| package com.iformall.log; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.iformall.domain.po.PosActionLog; | |||||
| import com.iformall.pay.WxPayConstant; | |||||
| import com.iformall.service.PosActionLogService; | |||||
| import com.iformall.utils.IPUtil; | |||||
| import org.aspectj.lang.ProceedingJoinPoint; | |||||
| import org.aspectj.lang.annotation.*; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| 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 javax.servlet.http.HttpServletRequest; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| @Aspect | |||||
| @Component | |||||
| public class SystemLogAspect { | |||||
| private static final Logger logger = LoggerFactory.getLogger(SystemLogAspect.class); | |||||
| @Autowired | |||||
| private PosActionLogService posActionLogService; | |||||
| @Pointcut("@annotation(com.iformall.annotation.SystemControllerLog)") | |||||
| public void controllerAspect(){ | |||||
| } | |||||
| @Pointcut("@annotation(com.iformall.annotation.SystemServiceLog)") | |||||
| public void serviceAspect(){ | |||||
| } | |||||
| @Around("controllerAspect()") | |||||
| public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { | |||||
| PosActionLog posActionLog = new PosActionLog(); | |||||
| long startTime = System.currentTimeMillis(); | |||||
| HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||||
| String ipaddress = IPUtil.getIpAddr(request); | |||||
| posActionLog.setUrl(request.getRequestURL().toString()); | |||||
| posActionLog.setIp(ipaddress); | |||||
| posActionLog.setMethod(request.getMethod()); | |||||
| posActionLog.setReqJson(JSON.toJSONString(joinPoint.getArgs()[0])); | |||||
| posActionLog.setStartTime(startTime); | |||||
| try { | |||||
| Object o = joinPoint.proceed(); | |||||
| posActionLog.setResJson(JSON.toJSONString(o)); | |||||
| long endTime = System.currentTimeMillis(); | |||||
| posActionLog.setEndTime(endTime); | |||||
| posActionLog.setCostTime(Long.valueOf(endTime-startTime).intValue()); | |||||
| posActionLogService.saveOrUpdate(posActionLog); | |||||
| return o; | |||||
| } catch (Throwable e) { | |||||
| String errMessage = e.getMessage(); | |||||
| logger.error(errMessage); | |||||
| Map map = new HashMap<>(); | |||||
| map.put(WxPayConstant.RETURN_CODE, WxPayConstant.RET_FAIL); | |||||
| map.put(WxPayConstant.RETURN_MSG, errMessage); | |||||
| map.put(WxPayConstant.RESULT_CODE, WxPayConstant.RET_FAIL); | |||||
| return map; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,41 @@ | |||||
| package com.iformall.domain.po; | |||||
| import lombok.Data; | |||||
| import javax.persistence.*; | |||||
| import java.util.*; | |||||
| import java.math.*; | |||||
| import javax.persistence.Transient; | |||||
| import java.util.List; | |||||
| import javax.persistence.Id; | |||||
| import java.io.Serializable; | |||||
| @Table(name = "pos_action_log") | |||||
| @Data | |||||
| public class PosActionLog implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| @Id | |||||
| protected Long id; | |||||
| @Transient | |||||
| protected List<Long> ids; | |||||
| @io.swagger.annotations.ApiModelProperty(value="访问url",name="url") | |||||
| private String url; | |||||
| @io.swagger.annotations.ApiModelProperty(value="ip地址",name="ip") | |||||
| private String ip; | |||||
| @io.swagger.annotations.ApiModelProperty(value="http访问",name="method") | |||||
| private String method; | |||||
| @io.swagger.annotations.ApiModelProperty(value="api发起时间",name="startTime") | |||||
| private Long startTime; | |||||
| @io.swagger.annotations.ApiModelProperty(value="api发起时间",name="endTime") | |||||
| private Long endTime; | |||||
| @io.swagger.annotations.ApiModelProperty(value="访问花费时间",name="costTime") | |||||
| private Integer costTime; | |||||
| @io.swagger.annotations.ApiModelProperty(value="命令请求JSON",name="reqJson") | |||||
| private String reqJson; | |||||
| @io.swagger.annotations.ApiModelProperty(value="返回结果",name="resJson") | |||||
| private String resJson; | |||||
| } | |||||
| @@ -0,0 +1,17 @@ | |||||
| package com.iformall.mapper; | |||||
| import java.util.*; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import org.apache.ibatis.annotations.Param; | |||||
| import com.iformall.domain.po.PosActionLog; | |||||
| public interface PosActionLogMapper extends CommonMapper<PosActionLog, Long> { | |||||
| List<PosActionLog> findList(PosActionLog posActionLog); | |||||
| } | |||||
| @@ -0,0 +1,48 @@ | |||||
| package com.iformall.service; | |||||
| import java.util.*; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.domain.po.PosActionLog; | |||||
| public interface PosActionLogService { | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | |||||
| */ | |||||
| PageInfo<PosActionLog> listAsPage(PosActionLog record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| * 根据Id获得实体 | |||||
| * | |||||
| * @param id | |||||
| * @return | |||||
| */ | |||||
| PosActionLog getById(Long id); | |||||
| /** | |||||
| * 保存或更新实体 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| void saveOrUpdate(PosActionLog record); | |||||
| /** | |||||
| * 根据Id删除实体 | |||||
| * | |||||
| * @param id | |||||
| */ | |||||
| void deleteById(Long id); | |||||
| } | |||||
| @@ -0,0 +1,54 @@ | |||||
| package com.iformall.service.impl; | |||||
| import java.util.*; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.domain.po.PosActionLog; | |||||
| import com.iformall.mapper.PosActionLogMapper; | |||||
| import com.iformall.service.PosActionLogService; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import com.iformall.common.IdWorker; | |||||
| @Service | |||||
| public class PosActionLogServiceImpl implements PosActionLogService { | |||||
| @Autowired | |||||
| PosActionLogMapper posActionLogMapper; | |||||
| @Override | |||||
| public PageInfo<PosActionLog> listAsPage(PosActionLog record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> posActionLogMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public PosActionLog getById(Long id) { | |||||
| return posActionLogMapper.selectByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public void saveOrUpdate(PosActionLog record) { | |||||
| if (record.getId() == null) { | |||||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| posActionLogMapper.insertSelective(record); | |||||
| } else { | |||||
| posActionLogMapper.updateByPrimaryKeySelective(record); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void deleteById(Long id) { | |||||
| posActionLogMapper.deleteByPrimaryKey(id); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,68 @@ | |||||
| <?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.iformall.mapper.PosActionLogMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.PosActionLog"> | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||||
| <result column="url" jdbcType="VARCHAR" property="url" /> | |||||
| <result column="ip" jdbcType="VARCHAR" property="ip" /> | |||||
| <result column="method" jdbcType="VARCHAR" property="method" /> | |||||
| <result column="start_time" jdbcType="BIGINT" property="startTime" /> | |||||
| <result column="end_time" jdbcType="BIGINT" property="endTime" /> | |||||
| <result column="cost_time" jdbcType="INTEGER" property="costTime" /> | |||||
| <result column="req_json" jdbcType="VARCHAR" property="reqJson" /> | |||||
| <result column="res_json" jdbcType="VARCHAR" property="resJson" /> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`url`,`ip`,`method`,`start_time`,`end_time`,`cost_time`,`req_json`,`res_json` | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != url "> | |||||
| and `url` like concat('%', #{url},'%') | |||||
| </if> | |||||
| <if test=" null != ip "> | |||||
| and `ip` like concat('%', #{ip},'%') | |||||
| </if> | |||||
| <if test=" null != method "> | |||||
| and `method` like concat('%', #{method},'%') | |||||
| </if> | |||||
| <if test=" null != startTime "> | |||||
| and `start_time` = #{startTime} | |||||
| </if> | |||||
| <if test=" null != endTime "> | |||||
| and `end_time` = #{endTime} | |||||
| </if> | |||||
| <if test=" null != costTime "> | |||||
| and `cost_time` = #{costTime} | |||||
| </if> | |||||
| <if test=" null != reqJson "> | |||||
| and `req_json` like concat('%', #{reqJson},'%') | |||||
| </if> | |||||
| <if test=" null != resJson "> | |||||
| and `res_json` like concat('%', #{resJson},'%') | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.PosActionLog" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from pos_action_log | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| </mapper> | |||||