| @@ -1,5 +1,6 @@ | |||
| package com.simple.controller; | |||
| import com.simple.domain.po.MallUserInfo; | |||
| import org.apache.log4j.Logger; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.util.Assert; | |||
| @@ -9,45 +10,47 @@ import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxWebLog; | |||
| import com.simple.service.WxWebLogService; | |||
| import com.simple.domain.po.WxAdminLog; | |||
| import com.simple.service.WxAdminLogService; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| @RestController | |||
| @RequestMapping("wxWebLog") | |||
| public class WxWebLogController extends BaseController | |||
| @RequestMapping("wxAdminLog") | |||
| public class WxAdminLogController extends BaseController | |||
| { | |||
| @Autowired | |||
| private WxWebLogService wxWebLogService; | |||
| private WxAdminLogService wxAdminLogService; | |||
| private Logger logger = Logger.getLogger(WxWebLogController.class); | |||
| private Logger logger = Logger.getLogger(WxAdminLogController.class); | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | |||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | |||
| public ResultData list(@ModelAttribute WxWebLog wxWebLog,Integer pageNum, Integer pageSize) { | |||
| if (null == wxWebLog) wxWebLog = new WxWebLog(); | |||
| final PageInfo<WxWebLog> page = wxWebLogService.listAsPage(wxWebLog, pageNum, pageSize); | |||
| public ResultData list(@ModelAttribute WxAdminLog wxAdminLog,Integer pageNum, Integer pageSize) { | |||
| if (null == wxAdminLog) wxAdminLog = new WxAdminLog(); | |||
| final PageInfo<WxAdminLog> page = wxAdminLogService.listAsPage(wxAdminLog, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation("新增接口") | |||
| @PostMapping("add") | |||
| public ResultData add(@RequestBody WxWebLog wxWebLog) { | |||
| //Assert.notNull(wxWebLog.getName(), "角色名不能为空"); | |||
| public ResultData add(@RequestBody WxAdminLog wxAdminLog) { | |||
| //Assert.notNull(wxAdminLog.getName(), "角色名不能为空"); | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| wxWebLogService.saveOrUpdate(wxWebLog); | |||
| wxAdminLogService.saveOrUpdate(wxAdminLog); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("根据id更新接口") | |||
| @PostMapping("update") | |||
| public ResultData update(@RequestBody WxWebLog wxWebLog) { | |||
| wxWebLogService.saveOrUpdate(wxWebLog); | |||
| public ResultData update(@RequestBody WxAdminLog wxAdminLog) { | |||
| String tenantId = getTenantId(); | |||
| wxAdminLog.setTenantId(tenantId); | |||
| wxAdminLogService.saveOrUpdate(wxAdminLog); | |||
| return new ResultData(); | |||
| } | |||
| @@ -55,7 +58,7 @@ public class WxWebLogController extends BaseController | |||
| @GetMapping("/del") | |||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||
| public ResultData delete(Long id) { | |||
| wxWebLogService.deleteById(id); | |||
| wxAdminLogService.deleteById(id); | |||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||
| } | |||
| @@ -63,9 +66,16 @@ public class WxWebLogController extends BaseController | |||
| @GetMapping("/findById") | |||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||
| public ResultData findById(Long id) { | |||
| return new ResultData(Result.SUCCESS,"查询成功",wxWebLogService.getById(id)); | |||
| return new ResultData(Result.SUCCESS,"查询成功",wxAdminLogService.getById(id)); | |||
| } | |||
| @ApiOperation("PV计数") | |||
| @PostMapping("pvlog") | |||
| public ResultData pvLog(@RequestBody WxAdminLog wxAdminLog) { | |||
| String tenantId = getTenantId(); | |||
| wxAdminLog.setTenantId(tenantId); | |||
| wxAdminLogService.saveLogCount(wxAdminLog); | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -8,15 +8,15 @@ import java.util.List; | |||
| import javax.persistence.Id; | |||
| import java.io.Serializable; | |||
| @Table(name = "wx_web_log") | |||
| public class WxWebLog implements Serializable { | |||
| @Table(name = "wx_admin_log") | |||
| public class WxAdminLog implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @Id | |||
| protected Long id; | |||
| @Transient | |||
| protected List<String> ids; | |||
| protected List<Long> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| @@ -32,10 +32,11 @@ public class WxWebLog implements Serializable { | |||
| return sortColumns; | |||
| } | |||
| public List<String> getIds() { | |||
| public List<Long> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<String> ids) { | |||
| public void setIds(List<Long> ids) { | |||
| this.ids = ids; | |||
| } | |||
| @@ -44,29 +45,47 @@ public class WxWebLog implements Serializable { | |||
| /*租户ID**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||
| private String tenantId; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="data") | |||
| private String data; | |||
| /*创建时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
| private Date createDate; | |||
| /*网址**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="网址",name="url") | |||
| private String url; | |||
| /*时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="时间",name="actionDate") | |||
| private String actionDate; | |||
| /*1. pv 2. uv**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="1. pv 2. uv",name="type") | |||
| private Integer type; | |||
| /*计数**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="计数",name="count") | |||
| private Integer count; | |||
| public String getTenantId() { | |||
| return tenantId; | |||
| } | |||
| public void setTenantId(String _tenantId) { | |||
| tenantId = _tenantId; | |||
| } | |||
| public String getData() { | |||
| return data; | |||
| public String getUrl() { | |||
| return url; | |||
| } | |||
| public void setUrl(String _url) { | |||
| url = _url; | |||
| } | |||
| public String getActionDate() { | |||
| return actionDate; | |||
| } | |||
| public void setActionDate(String _actionDate) { | |||
| actionDate = _actionDate; | |||
| } | |||
| public Integer getType() { | |||
| return type; | |||
| } | |||
| public void setData(String _data) { | |||
| data = _data; | |||
| public void setType(Integer _type) { | |||
| type = _type; | |||
| } | |||
| public Date getCreateDate() { | |||
| return createDate; | |||
| public Integer getCount() { | |||
| return count; | |||
| } | |||
| public void setCreateDate(Date _createDate) { | |||
| createDate = _createDate; | |||
| public void setCount(Integer _count) { | |||
| count = _count; | |||
| } | |||
| @@ -75,8 +94,10 @@ public class WxWebLog implements Serializable { | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | |||
| ,Data_ASC("`data` ASC"),Data_DESC("`data` DESC") | |||
| ,CreateDate_ASC("`createDate` ASC"),CreateDate_DESC("`createDate` DESC") | |||
| ,Url_ASC("`url` ASC"),Url_DESC("`url` DESC") | |||
| ,ActionDate_ASC("`actionDate` ASC"),ActionDate_DESC("`actionDate` DESC") | |||
| ,Type_ASC("`type` ASC"),Type_DESC("`type` DESC") | |||
| ,Count_ASC("`count` ASC"),Count_DESC("`count` DESC") | |||
| ; | |||
| private String value; | |||
| Field(String value){ | |||
| @@ -94,7 +115,7 @@ public class WxWebLog implements Serializable { | |||
| } | |||
| } | |||
| public void setSortColumns(WxWebLog.Field... fields) | |||
| public void setSortColumns(WxAdminLog.Field... fields) | |||
| { | |||
| if (fields == null || fields.length == 0) { | |||
| return; | |||
| @@ -0,0 +1,17 @@ | |||
| package com.simple.mapper; | |||
| import java.util.*; | |||
| import com.simple.common.CommonMapper; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import com.simple.domain.po.WxAdminLog; | |||
| public interface WxAdminLogMapper extends CommonMapper<WxAdminLog, Long> { | |||
| List<WxAdminLog> findList(WxAdminLog wxAdminLog); | |||
| } | |||
| @@ -2,19 +2,19 @@ package com.simple.service; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.domain.po.WxWebLog; | |||
| import com.simple.domain.po.WxAdminLog; | |||
| public interface WxWebLogService { | |||
| public interface WxAdminLogService { | |||
| /** | |||
| * 根据实体查询分页列表 | |||
| * | |||
| * @param record | |||
| * @param offset | |||
| * @param limit | |||
| * @param pageIndex | |||
| * @param pageSize | |||
| * @return | |||
| */ | |||
| PageInfo<WxWebLog> listAsPage(WxWebLog record, Integer pageIndex, Integer pageSize); | |||
| PageInfo<WxAdminLog> listAsPage(WxAdminLog record, Integer pageIndex, Integer pageSize); | |||
| /** | |||
| * 根据Id获得实体 | |||
| @@ -22,14 +22,14 @@ public interface WxWebLogService { | |||
| * @param id | |||
| * @return | |||
| */ | |||
| WxWebLog getById(Long id); | |||
| WxAdminLog getById(Long id); | |||
| /** | |||
| * 保存或更新实体 | |||
| * | |||
| * @param record | |||
| */ | |||
| void saveOrUpdate(WxWebLog record); | |||
| void saveOrUpdate(WxAdminLog record); | |||
| /** | |||
| * 根据Id删除实体 | |||
| @@ -37,6 +37,10 @@ public interface WxWebLogService { | |||
| * @param id | |||
| */ | |||
| void deleteById(Long id); | |||
| void saveLogCount(WxAdminLog record); | |||
| @@ -0,0 +1,72 @@ | |||
| package com.simple.service.impl; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.domain.po.WxAdminLog; | |||
| import com.simple.mapper.WxAdminLogMapper; | |||
| import com.simple.service.WxAdminLogService; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.simple.common.IdWorker; | |||
| @Service | |||
| public class WxAdminLogServiceImpl implements WxAdminLogService { | |||
| @Autowired | |||
| WxAdminLogMapper wxAdminLogMapper; | |||
| @Override | |||
| public PageInfo<WxAdminLog> listAsPage(WxAdminLog record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxAdminLogMapper.findList(record)); | |||
| } | |||
| @Override | |||
| public WxAdminLog getById(Long id) { | |||
| return wxAdminLogMapper.selectByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public void saveOrUpdate(WxAdminLog record) { | |||
| if (record.getId() == null) { | |||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| wxAdminLogMapper.insertSelective(record); | |||
| } else { | |||
| wxAdminLogMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| } | |||
| @Override | |||
| public void deleteById(Long id) { | |||
| wxAdminLogMapper.deleteByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public void saveLogCount(WxAdminLog record) { | |||
| // TODO use redis to optimize | |||
| WxAdminLog reqQ = new WxAdminLog(); | |||
| reqQ.setTenantId(record.getTenantId()); | |||
| reqQ.setUrl(record.getUrl()); | |||
| reqQ.setType(record.getType()); | |||
| reqQ.setActionDate(record.getActionDate()); | |||
| List<WxAdminLog> logList = wxAdminLogMapper.select(reqQ); | |||
| if (logList.size() > 0) { | |||
| WxAdminLog log = logList.get(0); | |||
| log.setCount(log.getCount() + 1); | |||
| wxAdminLogMapper.updateByPrimaryKeySelective(record); | |||
| } else { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| reqQ.setId(idWorker.nextId()); | |||
| reqQ.setCount(1); | |||
| wxAdminLogMapper.insertSelective(reqQ); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,54 +0,0 @@ | |||
| package com.simple.service.impl; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.domain.po.WxWebLog; | |||
| import com.simple.mapper.WxWebLogMapper; | |||
| import com.simple.service.WxWebLogService; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.simple.common.IdWorker; | |||
| @Service | |||
| public class WxWebLogServiceImpl implements WxWebLogService { | |||
| @Autowired | |||
| WxWebLogMapper wxWebLogMapper; | |||
| @Override | |||
| public PageInfo<WxWebLog> listAsPage(WxWebLog record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxWebLogMapper.findList(record)); | |||
| } | |||
| @Override | |||
| public WxWebLog getById(Long id) { | |||
| return wxWebLogMapper.selectByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public void saveOrUpdate(WxWebLog record) { | |||
| if (record.getId() == null) { | |||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| wxWebLogMapper.insertSelective(record); | |||
| } else { | |||
| wxWebLogMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| } | |||
| @Override | |||
| public void deleteById(Long id) { | |||
| wxWebLogMapper.deleteByPrimaryKey(id); | |||
| } | |||
| } | |||
| @@ -2,6 +2,6 @@ package com.simple.utils; | |||
| public class BaseConstant { | |||
| //12小时后过期 | |||
| public final static int EXPIRE = 3600 * 12; | |||
| //24小时后过期 | |||
| public final static int EXPIRE = 3600 * 24; | |||
| } | |||
| @@ -1,15 +1,17 @@ | |||
| <?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.simple.mapper.WxWebLogMapper"> | |||
| <resultMap id="BaseResultMap" type="com.simple.domain.po.WxWebLog"> | |||
| <mapper namespace="com.simple.mapper.WxAdminLogMapper"> | |||
| <resultMap id="BaseResultMap" type="com.simple.domain.po.WxAdminLog"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="data" jdbcType="VARCHAR" property="data" /> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | |||
| <result column="url" jdbcType="VARCHAR" property="url" /> | |||
| <result column="action_date" jdbcType="VARCHAR" property="actionDate" /> | |||
| <result column="type" jdbcType="INTEGER" property="type" /> | |||
| <result column="count" jdbcType="INTEGER" property="count" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`data`,`create_date` | |||
| `id`,`tenant_id`,`url`,`action_date`,`type`,`count` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -25,13 +27,23 @@ | |||
| </if> | |||
| <if test=" null != data "> | |||
| and `data` like concat('%', #{data},'%') | |||
| <if test=" null != url "> | |||
| and `url` like concat('%', #{url},'%') | |||
| </if> | |||
| <if test=" null != createDate "> | |||
| and `create_date` = #{createDate} | |||
| <if test=" null != actionDate "> | |||
| and `action_date` like concat('%', #{actionDate},'%') | |||
| </if> | |||
| <if test=" null != type "> | |||
| and `type` = #{type} | |||
| </if> | |||
| <if test=" null != count "> | |||
| and `count` = #{count} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| @@ -43,8 +55,8 @@ | |||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||
| </sql> | |||
| <select id="findList" parameterType="com.simple.domain.po.WxWebLog" resultMap="BaseResultMap"> | |||
| select <include refid="allColumns" /> from wx_web_log | |||
| <select id="findList" parameterType="com.simple.domain.po.WxAdminLog" resultMap="BaseResultMap"> | |||
| select <include refid="allColumns" /> from wx_admin_log | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||