TRX 1 год назад
Родитель
Сommit
3a690a115f

+ 15 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/service/school/BookInfoService.java

@@ -1,8 +1,23 @@
 package com.zhongshu.card.client.service.school;
 
+import com.zhongshu.card.client.model.school.BookInfoAddParam;
+import com.zhongshu.card.client.model.school.BookInfoModel;
+import com.zhongshu.card.client.model.school.BookInfoSearch;
+import com.zhongshu.card.client.ret.ResultContent;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
 /**
  * @author TRX
  * @date 2024/6/7
  */
 public interface BookInfoService {
+
+    ResultContent addBookInfo(BookInfoAddParam param);
+
+    ResultContent<Page<BookInfoModel>> page(BookInfoSearch param, Pageable pageable);
+
+    ResultContent<BookInfoModel> getByDetailById(String id);
+
+    ResultContent deleteById(String id);
 }

+ 4 - 4
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/org/DepartmentController.java

@@ -17,28 +17,28 @@ import org.springframework.web.bind.annotation.RestController;
 
 @RestController
 @RequestMapping("department")
-@Tag(name = "部门管理")
+@Tag(name = "部门管理--通用")
 public class DepartmentController {
 
     @Autowired
     private DepartmentService departmentService;
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "添加-编辑部门", description = "添加-编辑部门")
+    @Operation(summary = "添加-编辑部门-通用", description = "添加-编辑部门")
     @RequestMapping(value = "addDepartment", method = {RequestMethod.POST})
     public ResultContent addDepartment(@RequestBody DepartmentParam param) {
         return this.departmentService.addDepartment(param);
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "得到机构部门树", description = "得到机构部门树")
+    @Operation(summary = "得到机构部门树-通用", description = "得到机构部门树")
     @RequestMapping(value = "getDepartmentTree", method = {RequestMethod.POST})
     public ResultContent getDepartmentTree(@RequestBody OidModel param) {
         return this.departmentService.getDepartmentTree(param.getOid());
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "删除部门", description = "删除部门")
+    @Operation(summary = "删除部门-通用", description = "删除部门")
     @RequestMapping(value = "deleteDepartment", method = {RequestMethod.POST})
     public ResultContent deleteDepartment(@RequestBody IDParam param) {
         return this.departmentService.deleteDepartment(param.getId());

+ 43 - 30
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/school/BookInfoController.java

@@ -7,6 +7,7 @@ import com.zhongshu.card.client.model.school.*;
 import com.zhongshu.card.client.ret.ResultContent;
 import com.zhongshu.card.client.service.school.BookInfoService;
 import com.zhongshu.card.client.service.school.NoticeInfoService;
+import com.zhongshu.card.client.utils.type.OrganizationUserType;
 import com.zhongshu.card.server.core.service.org.RoleServiceImpl;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -41,55 +42,67 @@ public class BookInfoController {
     BookInfoService bookInfoService;
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "添加-编辑公告", description = "添加-编辑公告")
-    @RequestMapping(value = "addNoticeInfo", method = {RequestMethod.POST})
-    public ResultContent addNoticeInfo(@RequestBody NoticeInfoAddParam param) {
-        return this.noticeInfoService.addNoticeInfo(param);
+    @Operation(summary = "添加-编辑教师", description = "添加-编辑教师")
+    @RequestMapping(value = "addTeacher", method = {RequestMethod.POST})
+    public ResultContent addTeacher(@RequestBody BookInfoAddParam param) {
+        param.setUserType(OrganizationUserType.Teacher);
+        return this.bookInfoService.addBookInfo(param);
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "删除公告", description = "删除公告")
-    @RequestMapping(value = "deleteNoticeInfo", method = {RequestMethod.POST})
-    public ResultContent deleteNoticeInfo(@RequestBody IDParam param) {
-        return this.noticeInfoService.deleteNoticeInfo(param.getId());
+    @Operation(summary = "添加-编辑学生", description = "添加-编辑学生")
+    @RequestMapping(value = "addStudent", method = {RequestMethod.POST})
+    public ResultContent addStudent(@RequestBody BookInfoAddParam param) {
+        param.setUserType(OrganizationUserType.Student);
+        return this.bookInfoService.addBookInfo(param);
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "置顶公告", description = "置顶公告")
-    @RequestMapping(value = "topping", method = {RequestMethod.POST})
-    public ResultContent topping(@RequestBody IDParam param) {
-        return this.noticeInfoService.topping(param.getId());
+    @Operation(summary = "删除教师", description = "删除学生")
+    @RequestMapping(value = "deleteTeacher", method = {RequestMethod.POST})
+    public ResultContent deleteTeacher(@RequestBody IDParam param) {
+        return this.bookInfoService.deleteById(param.getId());
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "公告详情", description = "公告详情")
-    @RequestMapping(value = "getDetail", method = {RequestMethod.POST})
-    public ResultContent<NoticeInfoModel> getDetail(@RequestBody IDParam param) {
-        return this.noticeInfoService.getDetail(param.getId());
+    @Operation(summary = "删除学生", description = "删除学生")
+    @RequestMapping(value = "deleteStudent", method = {RequestMethod.POST})
+    public ResultContent deleteStudent(@RequestBody IDParam param) {
+        return this.bookInfoService.deleteById(param.getId());
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "公告增加阅读量", description = "公告增加阅读量")
-    @RequestMapping(value = "addView", method = {RequestMethod.POST})
-    public ResultContent addView(@RequestBody IDParam param) {
-        return this.noticeInfoService.addView(param.getId());
+    @Operation(summary = "教师详情", description = "教师详情")
+    @RequestMapping(value = "getTeacherDetail", method = {RequestMethod.POST})
+    public ResultContent<BookInfoModel> getTeacherDetail(@RequestBody IDParam param) {
+        return this.bookInfoService.getByDetailById(param.getId());
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "公告列表-分页查询", description = "公告列表-分页查询")
-    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
-    public ResultContent<Page<NoticeInfoModel>> page(
+    @Operation(summary = "学生详情", description = "学生详情")
+    @RequestMapping(value = "getStudentDetail", method = {RequestMethod.POST})
+    public ResultContent<BookInfoModel> getStudentDetail(@RequestBody IDParam param) {
+        return this.bookInfoService.getByDetailById(param.getId());
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "教师列表-分页查询", description = "教师列表-分页查询")
+    @RequestMapping(value = {"pageTeacher"}, method = {RequestMethod.POST})
+    public ResultContent<Page<BookInfoModel>> pageTeacher(
             @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
-            @Parameter(required = false) NoticeInfoSearchParam param) {
-        return noticeInfoService.page(param, pageable);
+            @Parameter(required = false) BookInfoSearch param) {
+        param.setUserType(OrganizationUserType.Teacher);
+        return bookInfoService.page(param, pageable);
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "公告阅读量列表-分页查询", description = "公告阅读量-分页查询")
-    @RequestMapping(value = {"pageView"}, method = {RequestMethod.POST})
-    public ResultContent<Page<NoticeInfoViewModel>> pageView(
+    @Operation(summary = "学生列表-分页查询", description = "学生列表-分页查询")
+    @RequestMapping(value = {"pageStudent"}, method = {RequestMethod.POST})
+    public ResultContent<Page<BookInfoModel>> pageStudent(
             @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
-            @Parameter(required = false) NoticeInfoViewSearch param) {
-        return noticeInfoService.pageView(param, pageable);
+            @Parameter(required = false) BookInfoSearch param) {
+        param.setUserType(OrganizationUserType.Student);
+        return bookInfoService.page(param, pageable);
     }
+
 }

+ 6 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/school/BookInfoDao.java

@@ -1,6 +1,7 @@
 package com.zhongshu.card.server.core.dao.school;
 
 import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.card.client.utils.type.OrganizationUserType;
 import com.zhongshu.card.server.core.dao.school.extend.BookInfoDaoExtend;
 import com.zhongshu.card.server.core.dao.school.extend.NoticeInfoDaoExtend;
 import com.zhongshu.card.server.core.domain.school.BookInfo;
@@ -14,4 +15,9 @@ public interface BookInfoDao extends MongoDao<BookInfo>, BookInfoDaoExtend {
 
     BookInfo findTopById(String id);
 
+    BookInfo findTopByPhoneAndOidAndUserType(String phone, String oid, OrganizationUserType userType);
+
+    BookInfo findTopByCodeAndOidAndUserType(String code, String oid, OrganizationUserType userType);
+
+    BookInfo findTopByIdCardAndOidAndUserType(String idCard, String oid, OrganizationUserType userType);
 }

+ 2 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/base/SuperService.java

@@ -91,11 +91,11 @@ public abstract class SuperService {
      * @param param
      */
     public void initDefaultUserAndOid(SuperParam param) {
-        initDefaultParam(param);
+        initDefaultUserParam(param);
         initOid(param);
     }
 
-    public void initDefaultParam(SuperParam param) {
+    public void initDefaultUserParam(SuperParam param) {
         if (authHelper != null && authHelper.getCurrentUser() != null) {
             param.setCreateUserId(authHelper.getCurrentUser().getUserId());
             param.setCreateUserName(authHelper.getCurrentUser().getUserName());

+ 91 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/school/BookInfoServiceImpl.java

@@ -1,18 +1,30 @@
 package com.zhongshu.card.server.core.service.school;
 
-import com.zhongshu.card.client.model.school.BookInfoModel;
+import com.github.microservice.components.data.base.util.PageEntityUtil;
+import com.zhongshu.card.client.model.school.*;
+import com.zhongshu.card.client.ret.ResultContent;
+import com.zhongshu.card.client.ret.ResultMessage;
 import com.zhongshu.card.client.service.school.BookInfoService;
+import com.zhongshu.card.client.utils.type.OrganizationUserType;
 import com.zhongshu.card.server.core.dao.org.DepartmentDao;
 import com.zhongshu.card.server.core.dao.org.OrganizationDao;
 import com.zhongshu.card.server.core.dao.org.UserCountDao;
 import com.zhongshu.card.server.core.dao.school.BookInfoDao;
 import com.zhongshu.card.server.core.domain.org.Department;
 import com.zhongshu.card.server.core.domain.org.Organization;
+import com.zhongshu.card.server.core.domain.org.OrganizationUser;
 import com.zhongshu.card.server.core.domain.school.BookInfo;
+import com.zhongshu.card.server.core.domain.school.NoticeInfo;
 import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.util.BeanUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
+import org.springframework.util.Assert;
 
 /**
  * @author TRX
@@ -34,7 +46,85 @@ public class BookInfoServiceImpl extends SuperService implements BookInfoService
     @Autowired
     UserCountDao userCountDao;
 
+    @Override
+    public ResultContent addBookInfo(BookInfoAddParam param) {
+        initDefaultUserAndOid(param);
+        Assert.hasText(param.getPhone(), "phone不能为空");
+        Assert.hasText(param.getIdCard(), "idCard不能为空");
+        Assert.hasText(param.getName(), "name不能为空");
+        String oid = param.getOid();
+        OrganizationUserType userType = param.getUserType();
 
+        BookInfo bookInfo = null;
+        if (StringUtils.isEmpty(param.getId())) {
+            bookInfo = bookInfoDao.findTopById(param.getId());
+            if (ObjectUtils.isEmpty(bookInfo)) {
+                return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
+            }
+            BookInfo temp = bookInfoDao.findTopByPhoneAndOidAndUserType(param.getPhone(), oid, userType);
+            if (ObjectUtils.isNotEmpty(temp) && temp.getId().equals(bookInfo.getId())) {
+                return ResultContent.buildFail(String.format("%s 电话号码已存在", param.getPhone()));
+            }
+            temp = bookInfoDao.findTopByIdCardAndOidAndUserType(param.getIdCard(), oid, userType);
+            if (ObjectUtils.isNotEmpty(temp) && temp.getId().equals(bookInfo.getId())) {
+                return ResultContent.buildFail(String.format("%s 身份证号已存在", param.getIdCard()));
+            }
+        } else {
+            bookInfo = new BookInfo();
+            BookInfo temp = bookInfoDao.findTopByPhoneAndOidAndUserType(param.getPhone(), oid, userType);
+            if (ObjectUtils.isNotEmpty(temp)) {
+                return ResultContent.buildFail(String.format("%s 电话号码已存在", param.getPhone()));
+            }
+            temp = bookInfoDao.findTopByIdCardAndOidAndUserType(param.getIdCard(), oid, userType);
+            if (ObjectUtils.isNotEmpty(temp)) {
+                return ResultContent.buildFail(String.format("%s 身份证号已存在", param.getIdCard()));
+            }
+        }
+        BeanUtils.copyProperties(param, bookInfo);
+        if (StringUtils.isNotEmpty(param.getDepartmentId())) {
+            Department department = departmentDao.findTopById(param.getDepartmentId());
+            if (ObjectUtils.isEmpty(department)) {
+                return ResultContent.buildFail(String.format("部门ID不存在: %s", param.getDepartmentId()));
+            }
+            bookInfo.setDepartment(department);
+        }
+
+        bookInfoDao.save(bookInfo);
+
+        //todo 初始账号信息?
+        initUserCountInfo(bookInfo);
+        return ResultContent.buildSuccess();
+    }
+
+    public ResultContent initUserCountInfo(BookInfo bookInfo) {
+
+        return ResultContent.buildSuccess();
+    }
+
+    @Override
+    public ResultContent<Page<BookInfoModel>> page(BookInfoSearch param, Pageable pageable) {
+        initOidSearchParam(param);
+        Page<BookInfo> page = bookInfoDao.page(pageable, param);
+        return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
+    }
+
+    public ResultContent<BookInfoModel> getByDetailById(String id) {
+        BookInfo bookInfo = bookInfoDao.findTopById(id);
+        if (ObjectUtils.isEmpty(bookInfo)) {
+            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
+        }
+        BookInfoModel model = toModel(bookInfo);
+        return ResultContent.buildSuccess(model);
+    }
+
+    public ResultContent deleteById(String id) {
+        BookInfo bookInfo = bookInfoDao.findTopById(id);
+        if (ObjectUtils.isEmpty(bookInfo)) {
+            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
+        }
+        bookInfoDao.delete(bookInfo);
+        return ResultContent.buildSuccess();
+    }
 
     public BookInfoModel toModel(BookInfo entity) {
         BookInfoModel model = new BookInfoModel();