Browse Source

操作日志

master
xyiege 4 years ago
parent
commit
10611db7af
  1. 43
      src/main/java/cn/chjyj/szwh/bean/OperationLog.java
  2. 32
      src/main/java/cn/chjyj/szwh/controller/admin/AdminLogController.java
  3. 29
      src/main/java/cn/chjyj/szwh/mapper/OperationLogMapper.java
  4. 15
      src/main/java/cn/chjyj/szwh/service/OperationLogService.java
  5. 21
      src/main/java/cn/chjyj/szwh/service/impl/OperationLogServiceImpl.java
  6. 71
      src/main/resources/mapper/szwh/OperationLogMapper.xml
  7. 31
      src/test/java/cn/chjyj/szwh/mapper/OperationLogMapperTest.java

43
src/main/java/cn/chjyj/szwh/bean/OperationLog.java

@ -0,0 +1,43 @@
package cn.chjyj.szwh.bean;
/**
* 操作日志
*/
public class OperationLog {
private Integer id;
private String type; // 种类
private Integer logid; //操作id
private String message; //操作记录
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Integer getLogid() {
return logid;
}
public void setLogid(Integer logid) {
this.logid = logid;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

32
src/main/java/cn/chjyj/szwh/controller/admin/AdminLogController.java

@ -0,0 +1,32 @@
package cn.chjyj.szwh.controller.admin;
import cn.chjyj.szwh.bean.OperationLog;
import cn.chjyj.szwh.controller.BaseController;
import cn.chjyj.szwh.service.OperationLogService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* 日志控制器
*/
@RestController
@RequestMapping("admin/Log")
public class AdminLogController extends BaseController {
@Autowired
private OperationLogService operationLogService;
@PostMapping("/getLog")
public JSONObject getLog(HttpServletRequest request){
String logid=request.getParameter("log_id");
String type=request.getParameter("type");
List<OperationLog> oplist = operationLogService.getLog(type,logid);
return jsonObject;
}
}

29
src/main/java/cn/chjyj/szwh/mapper/OperationLogMapper.java

@ -0,0 +1,29 @@
package cn.chjyj.szwh.mapper;
import cn.chjyj.szwh.bean.OperationLog;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 操作日志 mapper
*/
@Component
public interface OperationLogMapper {
/**
* 检索相应的操作日志
* @param logId
* @param type
* @return
*/
List<OperationLog> getOperationLog(@Param("logId") String logId,
@Param("type") String type);
/**
* 添加日志
* @param operationLog
* @return
*/
int addLog(OperationLog operationLog);
}

15
src/main/java/cn/chjyj/szwh/service/OperationLogService.java

@ -0,0 +1,15 @@
package cn.chjyj.szwh.service;
import cn.chjyj.szwh.bean.OperationLog;
import java.util.List;
public interface OperationLogService {
/**
* 查找日志
* @param type
* @param logId
* @return
*/
List<OperationLog> getLog(String type, String logId);
}

21
src/main/java/cn/chjyj/szwh/service/impl/OperationLogServiceImpl.java

@ -0,0 +1,21 @@
package cn.chjyj.szwh.service.impl;
import cn.chjyj.szwh.bean.OperationLog;
import cn.chjyj.szwh.mapper.OperationLogMapper;
import cn.chjyj.szwh.service.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class OperationLogServiceImpl implements OperationLogService {
@Autowired
private OperationLogMapper operationLogMapper;
@Override
public List<OperationLog> getLog(String type, int logId) {
String slogId = String.valueOf(logId);
return operationLogMapper.getOperationLog(slogId,type);
}
}

71
src/main/resources/mapper/szwh/OperationLogMapper.xml

@ -0,0 +1,71 @@
<?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="cn.chjyj.szwh.mapper.OperationLogMapper">
<sql id="column">
id,`type`,log_id as logId,message
</sql>
<sql id="tbName">operation_log</sql>
<!--查询记录列表-->
<select id="getOperationLog" parameterType="java.lang.String" resultType="cn.chjyj.szwh.bean.OperationLog">
select <include refid="column"/>
from <include refid="tbName"/>
where `type`=#{type} and log_id=#{logId}
</select>
<!--查询用户名,加上密码-->
<select id="getUserByIsli" parameterType="java.lang.String" resultType="cn.chjyj.szwh.bean.User">
select<include refid="column"/>,password
from
<include refid="tbName"/>
where user_isli=#{userIsli} limit 1;
</select>
<!--查询用户-->
<select id="getSingleUserByOpenid" parameterType="java.lang.String" resultType="cn.chjyj.szwh.bean.Goods">
select
<include refid="column"/>
from
<include refid="tbName"/>
where openid=#{openid};
</select>
<!--新增用户-->
<insert id="addLog" parameterType="cn.chjyj.szwh.bean.OperationLog" useGeneratedKeys="true" keyColumn="id">
insert into
<include refid="tbName"/>
(`type`,log_id,mesage)
values (
#{type},
#{logId},
#{message}
)
</insert>
<update id="updateUser" parameterType="cn.chjyj.szwh.bean.Goods">
update
<include refid="tbName"/>
<set>
<if test="userIsli!=null">
user_isli=#{userIsli},
</if>
<if test="username!=null">
username=#{username},
</if>
<if test="institutionCode!=null">
institution_code =#{institutionCode},
</if>
<if test="agencyType!=null">
agency_type=#{agencyType}
</if>
</set>
where id=#{id};
</update>
</mapper>

31
src/test/java/cn/chjyj/szwh/mapper/OperationLogMapperTest.java

@ -0,0 +1,31 @@
package cn.chjyj.szwh.mapper;
import cn.chjyj.szwh.bean.OperationLog;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import static org.junit.Assert.*;
@SpringBootTest
@RunWith(SpringRunner.class)
public class OperationLogMapperTest {
@Autowired
private OperationLogMapper operationLogMapper;
@Test
public void getOperationLog() {
String type="goods";
int logid=17;
List<OperationLog> aoplist =operationLogMapper.getOperationLog(String.valueOf(logid),type);
System.out.println(aoplist.size());
}
@Test
public void addLog() {
}
}
Loading…
Cancel
Save