liuxm
2024-04-23 71f83a057f01cc56db8fbeed18d64214e386d813
日志管理相关
3个文件已修改
2个文件已添加
139 ■■■■■ 已修改文件
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/LogSv.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/QueryVo.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaLogMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/resources/mapper/BaLogMapper.xml 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/log/LogCtrl.java 62 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/LogSv.java
@@ -1,17 +1,21 @@
package com.dy.pmsGlobal.aop;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pmsGlobal.daoBa.BaLogMapper;
import com.dy.pmsGlobal.pojoBa.BaLog;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class LogSv {
    @Autowired
    private BaLogMapper logMapper;
    private BaLogMapper dao;
    public void save(long operator, String operation,String resIp) {
        BaLog log = new BaLog();
@@ -19,6 +23,35 @@
        log.setContent(operation);
        log.setCreateDt(new Date());
        log.setResIp(resIp);
        logMapper.insert(log);
        dao.insert(log);
    }
    /**
     * 得到日志
     *
     * @param id 日志ID
     * @return 实体
     */
    public BaLog selectById(Long id) {
        return dao.selectByPrimaryKey(id);
    }
    /**
     * 获取日志列表
     */
    public QueryResultVo<List<BaLog>> selectSome(QueryVo queryVo) {
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
        //查询符合条件的记录总数
        Long itemTotal = dao.selectSomeCount(params);
        QueryResultVo<List<BaLog>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ;
        //计算分页等信息
        rsVo.calculateAndSet(itemTotal, params);
        //查询符合条件的记录
        rsVo.obj = this.dao.selectSome(params) ;
        return rsVo ;
    }
}
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/QueryVo.java
New file
@@ -0,0 +1,14 @@
package com.dy.pmsGlobal.aop;
import com.dy.common.webUtil.QueryConditionVo;
import lombok.*;
@Data
@EqualsAndHashCode(callSuper = false)
@ToString(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class QueryVo extends QueryConditionVo {
    public String name;
}
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaLogMapper.java
@@ -15,4 +15,6 @@
    BaLog selectByPrimaryKey(Long id);
    List<BaLog> selectSome(Map<String, Object> params);
    Long selectSomeCount(Map<String, Object> params);
}
pms-parent/pms-global/src/main/resources/mapper/BaLogMapper.xml
@@ -68,8 +68,7 @@
      <property name="alias" value="r"/>
    </include>
    from ba_log r
    where
    <trim prefix="and" suffixOverrides="and">
    <trim prefix="where " suffixOverrides="and">
      <if test="userId != null and userId != ''">
        user_id = #{userId,jdbcType=BIGINT} and
      </if>
@@ -83,11 +82,30 @@
        res_ip =#{resIp,jdbcType=VARCHAR} and
      </if>
    </trim>
    order by id DESC
    order by id desc
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start}, #{count}
      </if>
    </trim>
  </select>
  <select id="selectSomeCount" resultType="java.lang.Long">
    select count(1)
    from ba_log r
    <trim prefix="where " suffixOverrides="and">
      <if test="userId != null and userId != ''">
        user_id = #{userId,jdbcType=BIGINT} and
      </if>
      <if test="content != null  and content != '' ">
        content like concat('%', #{content}, '%') and
      </if>
      <if test="createDt != null and createDt != '' ">
        create_dt = #{createDt,jdbcType=TIMESTAMP} and
      </if>
      <if test="resIp != null and resIp != '' ">
        res_ip =#{resIp,jdbcType=VARCHAR} and
      </if>
    </trim>
  </select>
</mapper>
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/log/LogCtrl.java
New file
@@ -0,0 +1,62 @@
package com.dy.pmsBase.log;
import com.dy.common.aop.SsoPowerAop;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pmsGlobal.aop.LogSv;
import com.dy.pmsGlobal.aop.OperationDescription;
import com.dy.pmsGlobal.aop.QueryVo;
import com.dy.pmsGlobal.pojoBa.BaLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RestController
@RequestMapping(path = "log")
@SuppressWarnings("unchecked")
public class LogCtrl {
    private LogSv sv;
    @Autowired
    public void setSv(LogSv sv) {
        this.sv = sv;
    }
    /**
     * 根据id查询日志
     * @return
     */
    @GetMapping(path = "one")
    @SsoPowerAop(power = "10100010") //登录与权限同时验证
    @OperationDescription("查询单条日志")
    public BaseResponse<BaLog> one(String id){
        try {
            return BaseResponseUtils.buildSuccess(sv.selectById(Long.parseLong(id)));
        } catch (Exception e) {
            log.error("查询单条日志数据异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
    }
    /**
     * 分页查询日志
     * @return
     */
    @PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoPowerAop(power = "10100010") //登录与权限同时验证
    @OperationDescription("分页查询日志")
    public BaseResponse<QueryResultVo<List<BaLog>>> some(@RequestBody QueryVo vo){
        try {
            QueryResultVo<List<BaLog>> res = sv.selectSome(vo);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("分页查询日志异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
    }
}