Kaynağa Gözat

修改study内容

lzu918 6 ay önce
ebeveyn
işleme
cd80b86cff

+ 33 - 5
ruoyi-zzb/src/main/java/com/ruoyi/zzb/study/controller/StudyController.java

@@ -2,6 +2,9 @@ package com.ruoyi.zzb.study.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.domain.model.LoginUser;
+import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.zzb.common.RspResult;
 import com.ruoyi.zzb.study.domain.StudyDocInfo;
 import com.ruoyi.zzb.study.domain.UserSearchParam;
@@ -36,12 +39,11 @@ public class StudyController {
 
 	}
 
-	@PostMapping("/findByWrapper")
-	public JSONObject findByWrapper(HttpServletResponse response, HttpServletRequest request,@RequestBody JSONObject params) {
+	@PostMapping("/findDocInfoById")
+	public JSONObject findDocInfoById(HttpServletResponse response, HttpServletRequest request,@RequestBody JSONObject params) {
 
 		try {
-			//JSONObject obj = JSONObject.parseObject(jsonString);
-			JSONObject result = studyService.findByWrapper(params.getString("docId"));
+			StudyDocInfo result = studyService.findDocInfoById(params.getString("docId"));
 			return RspResult.success(result);
 		}catch (Exception e){
 			e.printStackTrace();
@@ -53,6 +55,13 @@ public class StudyController {
 	public JSONObject saveDoc(HttpServletResponse response, HttpServletRequest request,@Validated @RequestBody StudyDocInfo studyDocInfo) {
 
 		try {
+			LoginUser loginUser = SecurityUtils.getLoginUser();
+			SysUser sysUser = loginUser.getUser();
+
+			studyDocInfo.setCreateUserId(sysUser.getUserId()+"");
+			studyDocInfo.setCreatePoliceNo(sysUser.getPoliceNo());
+			studyDocInfo.setCreateUserName(sysUser.getNickName());
+
 			boolean result = studyService.saveDocInfo(studyDocInfo);
 			return RspResult.success(result);
 		}catch (Exception e){
@@ -89,7 +98,12 @@ public class StudyController {
 	@PostMapping("/saveViewLog")
 	public JSONObject saveViewLog(HttpServletResponse response, HttpServletRequest request, @Validated @RequestBody SaveViewLogVO saveViewLogVO) {
 		try {
-			boolean result = studyService.saveViewLogInfo(saveViewLogVO);
+
+			LoginUser loginUser = SecurityUtils.getLoginUser();
+			SysUser sysUser = loginUser.getUser();
+
+			saveViewLogVO.setUserId(sysUser.getUserId()+"");
+			boolean result = studyService.saveViewLogInfo(saveViewLogVO,sysUser);
 			return RspResult.success(result);
 		}catch (Exception e){
 			e.printStackTrace();
@@ -113,4 +127,18 @@ public class StudyController {
 
 	}
 
+
+
+	@PostMapping("/updateDocByDocId")
+	public JSONObject updateDocByDocId(HttpServletResponse response, HttpServletRequest request,@Validated @RequestBody StudyDocInfo studyDocInfo) {
+		try {
+			boolean result = studyService.updateById(studyDocInfo);
+			return RspResult.success(result);
+		}catch (Exception e){
+			e.printStackTrace();
+			return RspResult.error(e.getMessage());
+		}
+
+	}
+
 }

+ 2 - 3
ruoyi-zzb/src/main/java/com/ruoyi/zzb/study/domain/StudyDocInfo.java

@@ -19,6 +19,8 @@ import java.util.Date;
 @TableName("STUDY_DOC_INFO")
 public class StudyDocInfo {
 
+
+    @NotBlank
     @TableId(type = IdType.ASSIGN_ID)
     private String  docId;
     private String  datasourceCode;
@@ -41,11 +43,8 @@ public class StudyDocInfo {
     private Integer  deleteStatus;
     private Integer  pageViewNum;
 
-    @NotBlank
     private String  createUserId;
-    @NotBlank
     private String  createUserName;
-    @NotBlank
     private String  createPoliceNo;
 
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")

+ 0 - 1
ruoyi-zzb/src/main/java/com/ruoyi/zzb/study/domain/req/SaveViewLogVO.java

@@ -13,7 +13,6 @@ public class SaveViewLogVO {
     @NotBlank
     private String  docId;
 
-    @NotBlank
     private String userId;
 
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")

+ 48 - 35
ruoyi-zzb/src/main/java/com/ruoyi/zzb/study/service/StudyService.java

@@ -2,14 +2,12 @@ package com.ruoyi.zzb.study.service;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.annotation.DataSource;
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.enums.DataSourceType;
 import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.zzb.base.domain.BasePersonInfo;
-import com.ruoyi.zzb.base.mapper.BasePersonInfoMapper;
 import com.ruoyi.zzb.study.domain.StudyDocInfo;
 import com.ruoyi.zzb.study.domain.StudyViewLogInfo;
 import com.ruoyi.zzb.study.domain.UserSearchParam;
@@ -20,6 +18,7 @@ import com.ruoyi.zzb.study.mapper.StudyViewLogInfoMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 @Service
 @Slf4j
@@ -37,13 +36,14 @@ public class StudyService {
 
 
     public Page<StudyDocInfo>  findAllInfo(UserSearchParam searchParam) {
-  //分页参数
+        //分页参数
         Page<StudyDocInfo> rowPage = new Page(searchParam.getPageIndex(), searchParam.getPageSize());
 
         //查询条件
         LambdaQueryWrapper<StudyDocInfo> queryWrapper = new LambdaQueryWrapper<>();
-        if(StringUtils.isNotEmpty(searchParam.getTitle()))
-
+        if(StringUtils.isNotEmpty(searchParam.getTitle())){
+            queryWrapper.like(StudyDocInfo::getTitle,searchParam.getTitle());
+        }
 
         //排序
         queryWrapper.orderByAsc(StudyDocInfo::getOrderNum);
@@ -54,27 +54,29 @@ public class StudyService {
 
     }
 
-    public JSONObject findByWrapper(String id) {
-        JSONObject resultData = new JSONObject();
-        QueryWrapper<StudyDocInfo>  queryWrapper = new QueryWrapper();
-//        queryWrapper.like(false,"username","aaa");
-        queryWrapper.eq(StringUtils.isNotEmpty(id),"DOC_ID",id);
+    public StudyDocInfo findDocInfoById(String id) {
+        LambdaQueryWrapper<StudyDocInfo>  queryWrapper = new LambdaQueryWrapper();
+        queryWrapper.eq(StudyDocInfo::getDocId,id);
 
         StudyDocInfo studyDocInfo= studyDocInfoMapper.selectOne(queryWrapper);
-        System.out.println(JSONObject.toJSONString(studyDocInfo));
-
-        resultData.put("records",studyDocInfo);
-
-        return resultData;
+        return studyDocInfo;
     }
 
     public boolean saveDocInfo(StudyDocInfo studyDocInfo) {
         int i = studyDocInfoMapper.insert(studyDocInfo);
+        if( i!=1 ){
+            throw new RuntimeException("数据写入失败,成功0条,入参:"+JSONObject.toJSONString(studyDocInfo));
+        }
+
         return i == 1;
     }
 
     public boolean deleteById(String id) {
         int i = studyDocInfoMapper.deleteById(id);
+
+        if( i!=1 ){
+            throw new RuntimeException("数据删除失败,docId不存在:"+id);
+        }
         return i == 1;
     }
 
@@ -83,20 +85,16 @@ public class StudyService {
         UpdateWrapper<StudyDocInfo> updateWrapper = new UpdateWrapper<>();
         updateWrapper.eq("DOC_ID",updatePageViewNumVO.getDocId()).set("PAGE_VIEW_NUM", updatePageViewNumVO.getPageViewNum());
         Integer i = studyDocInfoMapper.update(null, updateWrapper);
+
+        if( i!=1 ){
+            throw new RuntimeException("修改文章浏览量失败,docId不存在:"+updatePageViewNumVO.getDocId());
+        }
         return i == 1;
     }
 
-    public boolean saveViewLogInfo(SaveViewLogVO saveViewLogVO) {
-        //获取人员信息
-
-        QueryWrapper<BasePersonInfo>  queryPersonWrapper = new QueryWrapper();
-        queryPersonWrapper.eq("USER_ID",saveViewLogVO.getUserId());
-        queryPersonWrapper.eq("STATUS",0);      //非禁用用户
-        BasePersonInfo personInfo =basePersonInfoMapper.selectOne(queryPersonWrapper);
+    @Transactional
+    public boolean saveViewLogInfo(SaveViewLogVO saveViewLogVO,SysUser sysUser) {
 
-        if(personInfo == null){
-            return false;
-        }
 
         //记录浏览量+1
         UpdateWrapper<StudyDocInfo> updateDocWrapper = new UpdateWrapper<>();
@@ -105,29 +103,33 @@ public class StudyService {
         Integer j =   studyDocInfoMapper.update(null,updateDocWrapper);
 
         if(j != 1){
-            return false;
+            throw new RuntimeException("记录浏览量更新异常,docId不存在:"+saveViewLogVO.getDocId());
         }
 
         //保存访问记录
         StudyViewLogInfo studyViewLogInfo = new StudyViewLogInfo();
         studyViewLogInfo.setDocId(saveViewLogVO.getDocId());
         studyViewLogInfo.setUserId(saveViewLogVO.getUserId());
-        studyViewLogInfo.setUserName(personInfo.getName());
-        studyViewLogInfo.setUserIdcard(personInfo.getIdcard());
-        studyViewLogInfo.setUserPoliceNo(personInfo.getPoliceNo());
-        studyViewLogInfo.setParentDeptCode(personInfo.getParentDeptCode());
-        studyViewLogInfo.setParentDeptName(personInfo.getParentDeptName());
-        studyViewLogInfo.setDeptCode(personInfo.getDeptCode());
-        studyViewLogInfo.setDeptName(personInfo.getDeptName());
+        studyViewLogInfo.setUserName(sysUser.getNickName());
+        studyViewLogInfo.setUserIdcard(sysUser.getIdCard());
+        studyViewLogInfo.setUserPoliceNo(sysUser.getPoliceNo());
+        studyViewLogInfo.setParentDeptCode(sysUser.getDept().getParentId()+"");
+        studyViewLogInfo.setParentDeptName(sysUser.getDept().getParentName());
+        studyViewLogInfo.setDeptCode(sysUser.getDept().getDeptId()+"");
+        studyViewLogInfo.setDeptName(sysUser.getDept().getDeptName());
         int i = studyViewLogInfoMapper.insert(studyViewLogInfo);
 
+        if(i != 1){
+            throw new RuntimeException("保存访问记录日志保存失败:"+JSONObject.toJSONString(studyViewLogInfo));
+        }
+
 
         return i == 1 && j ==1;
     }
 
 
 
-     /**
+    /**
      * 分页查询用户列表
      */
     public Page<StudyDocInfo> findInfoByTitle(UserSearchParam searchParam)
@@ -150,4 +152,15 @@ public class StudyService {
         return rowPage;
     }
 
+
+
+    public boolean updateById(StudyDocInfo studyDocInfo) {
+
+        int i = studyDocInfoMapper.updateById(studyDocInfo);
+        if(i != 1){
+            throw new RuntimeException("docId不存在:"+studyDocInfo.getDocId());
+        }
+        return i == 1;
+    }
+
 }