From 71f83a057f01cc56db8fbeed18d64214e386d813 Mon Sep 17 00:00:00 2001 From: liuxm <liuxm@fescotech.com> Date: 星期二, 23 四月 2024 18:48:42 +0800 Subject: [PATCH] 日志管理相关 --- pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/log/LogCtrl.java | 62 ++++++++++++++++++++ pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/LogSv.java | 37 +++++++++++ pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/QueryVo.java | 14 ++++ pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaLogMapper.java | 2 pms-parent/pms-global/src/main/resources/mapper/BaLogMapper.xml | 24 +++++++- 5 files changed, 134 insertions(+), 5 deletions(-) diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/LogSv.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/LogSv.java index c244feb..838e72b 100644 --- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/LogSv.java +++ b/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 ; } } diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/QueryVo.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/QueryVo.java new file mode 100644 index 0000000..ee07597 --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/QueryVo.java @@ -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; +} diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaLogMapper.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaLogMapper.java index 671a92d..a9a0a60 100644 --- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaLogMapper.java +++ b/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); } \ No newline at end of file diff --git a/pms-parent/pms-global/src/main/resources/mapper/BaLogMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/BaLogMapper.xml index 48010d6..c7cd531 100644 --- a/pms-parent/pms-global/src/main/resources/mapper/BaLogMapper.xml +++ b/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> \ No newline at end of file diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/log/LogCtrl.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/log/LogCtrl.java new file mode 100644 index 0000000..a64949a --- /dev/null +++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/log/LogCtrl.java @@ -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()); + } + } + +} -- Gitblit v1.8.0