Эх сурвалжийг харах

feat: create dept and search dept

Blizzard 1 жил өмнө
parent
commit
3a92f3933a
18 өөрчлөгдсөн 351 нэмэгдсэн , 10 устгасан
  1. 7 1
      blade-service-api/wt-okr-api/pom.xml
  2. 22 0
      blade-service-api/wt-okr-api/src/main/java/com/wtkj/entity/AuthUserInfo.java
  3. 62 0
      blade-service-api/wt-okr-api/src/main/java/com/wtkj/entity/DeptToDept.java
  4. 4 0
      blade-service-api/wt-okr-api/src/main/java/com/wtkj/entity/ProjectAuth.java
  5. 4 3
      blade-service/wt-okr/pom.xml
  6. 2 0
      blade-service/wt-okr/src/main/java/com/wtkj/OKRServiceApplication.java
  7. 7 1
      blade-service/wt-okr/src/main/java/com/wtkj/config/MagicValue.java
  8. 58 0
      blade-service/wt-okr/src/main/java/com/wtkj/controller/CommonController.java
  9. 15 0
      blade-service/wt-okr/src/main/java/com/wtkj/mapper/DeptToDeptMapper.java
  10. 9 0
      blade-service/wt-okr/src/main/java/com/wtkj/mapper/DeptToDeptMapper.xml
  11. 2 0
      blade-service/wt-okr/src/main/java/com/wtkj/mapper/ProjectAuthMapper.java
  12. 10 0
      blade-service/wt-okr/src/main/java/com/wtkj/mapper/ProjectAuthMapper.xml
  13. 22 0
      blade-service/wt-okr/src/main/java/com/wtkj/service/IDeptToDeptService.java
  14. 2 0
      blade-service/wt-okr/src/main/java/com/wtkj/service/IProjectAuthService.java
  15. 16 0
      blade-service/wt-okr/src/main/java/com/wtkj/service/impl/AsyncServiceImpl.java
  16. 89 0
      blade-service/wt-okr/src/main/java/com/wtkj/service/impl/DeptToDeptServiceImpl.java
  17. 5 0
      blade-service/wt-okr/src/main/java/com/wtkj/service/impl/ProjectAuthServiceImpl.java
  18. 15 5
      blade-service/wt-okr/src/main/java/com/wtkj/service/impl/ProjectServiceImpl.java

+ 7 - 1
blade-service-api/wt-okr-api/pom.xml

@@ -13,5 +13,11 @@
 
     <name>wt-okr-api</name>
 
-
+    <dependencies>
+        <dependency>
+            <groupId>org.springblade</groupId>
+            <artifactId>blade-system-api</artifactId>
+            <version>2.9.1.RELEASE</version>
+        </dependency>
+    </dependencies>
 </project>

+ 22 - 0
blade-service-api/wt-okr-api/src/main/java/com/wtkj/entity/AuthUserInfo.java

@@ -0,0 +1,22 @@
+package com.wtkj.entity;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springblade.core.secure.BladeUser;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-14 11:25
+ * @describe
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class AuthUserInfo extends BladeUser {
+
+	@ApiModelProperty(value = "当前登录用户的顶级部门ID")
+	private Long topDept;
+
+	@ApiModelProperty(value = "机构类别")
+	private Integer deptCategory;
+}

+ 62 - 0
blade-service-api/wt-okr-api/src/main/java/com/wtkj/entity/DeptToDept.java

@@ -0,0 +1,62 @@
+package com.wtkj.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springblade.core.mp.base.BaseEntity;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-14 10:54
+ * @describe
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@TableName("blade_dept_to_dept")
+public class DeptToDept extends BaseEntity {
+
+	@JsonSerialize(using = ToStringSerializer.class)
+	@TableField("org_dept_id")
+	@ApiModelProperty(value = "服务机构顶级id")
+	private Long orgDeptId;
+
+	@ApiModelProperty("租户ID")
+	private String tenantId;
+	@JsonSerialize(using = ToStringSerializer.class)
+
+	@ApiModelProperty("父主键")
+	private Long parentId;
+
+	@ApiModelProperty("机构名")
+	private String deptName;
+
+	@ApiModelProperty("机构全称")
+	private String fullName;
+
+	@ApiModelProperty("地区编码")
+	private String areaCode;
+
+	@ApiModelProperty("祖级机构主键")
+	private String ancestors;
+
+	@ApiModelProperty("机构类型")
+	private Integer deptCategory;
+
+	@ApiModelProperty("排序")
+	private Integer sort;
+
+	@ApiModelProperty("备注")
+	private String remark;
+
+	@TableField("social_credit_code")
+	private String socialCreditCode;
+
+	@TableField("license_file_id")
+	@JsonSerialize(using = ToStringSerializer.class)
+	private Long licenseFileId;
+
+}

+ 4 - 0
blade-service-api/wt-okr-api/src/main/java/com/wtkj/entity/ProjectAuth.java

@@ -22,6 +22,10 @@ public class ProjectAuth extends BaseEntity {
 	@JsonSerialize(using = ToStringSerializer.class)
 	private Long userId;
 
+	@TableField("top_dept")
+	@JsonSerialize(using = ToStringSerializer.class)
+	private Long topDept;
+
 	@TableField("user_dept")
 	@JsonSerialize(using = ToStringSerializer.class)
 	private Long userDept;

+ 4 - 3
blade-service/wt-okr/pom.xml

@@ -28,13 +28,14 @@
         </dependency>
         <dependency>
             <groupId>org.springblade</groupId>
-            <artifactId>blade-system-api</artifactId>
+            <artifactId>blade-user-api</artifactId>
             <version>2.9.1.RELEASE</version>
         </dependency>
+
+        <!--        分布式事务-->
         <dependency>
             <groupId>org.springblade</groupId>
-            <artifactId>blade-user-api</artifactId>
-            <version>2.9.1.RELEASE</version>
+            <artifactId>blade-starter-transaction</artifactId>
         </dependency>
     </dependencies>
 

+ 2 - 0
blade-service/wt-okr/src/main/java/com/wtkj/OKRServiceApplication.java

@@ -3,6 +3,7 @@ package com.wtkj;
 import org.springblade.common.constant.LauncherConstant;
 import org.springblade.core.cloud.feign.EnableBladeFeign;
 import org.springblade.core.launch.BladeApplication;
+import org.springblade.core.transaction.annotation.SeataCloudApplication;
 import org.springframework.cloud.client.SpringCloudApplication;
 
 /**
@@ -12,6 +13,7 @@ import org.springframework.cloud.client.SpringCloudApplication;
  */
 @SpringCloudApplication
 @EnableBladeFeign
+@SeataCloudApplication
 public class OKRServiceApplication {
 	public static void main(String[] args) {
 		BladeApplication.run(LauncherConstant.APPLICATION_SERVICE_NAME, OKRServiceApplication.class);

+ 7 - 1
blade-service/wt-okr/src/main/java/com/wtkj/MagicValue.java → blade-service/wt-okr/src/main/java/com/wtkj/config/MagicValue.java

@@ -1,4 +1,4 @@
-package com.wtkj;
+package com.wtkj.config;
 
 /**
  * @author Blizzard
@@ -16,4 +16,10 @@ public interface MagicValue {
 	 * 服务机构管理员
 	 */
 	String STAFF_ADMIN = "admin";
+
+	Integer ZERO = 0;
+
+	Integer ONE = 1;
+
+	Integer TWO = 2;
 }

+ 58 - 0
blade-service/wt-okr/src/main/java/com/wtkj/controller/CommonController.java

@@ -0,0 +1,58 @@
+package com.wtkj.controller;
+
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import com.wtkj.entity.AuthUserInfo;
+import com.wtkj.entity.DeptToDept;
+import com.wtkj.service.IDeptToDeptService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springblade.core.tool.api.R;
+import org.springblade.system.entity.Dept;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-14 11:13
+ * @describe
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("/common")
+@Api(value = "公共模块", tags = "公共模块")
+public class CommonController {
+
+	private final IDeptToDeptService deptToDeptService;
+
+	/**
+	 * 当前登录用户信息
+	 */
+	@GetMapping("/user-info")
+	@ApiOperation(value = "当前登录用户信息", notes = "")
+	@ApiOperationSupport(order = 1)
+	public R<AuthUserInfo> userInfo() {
+		return R.data(deptToDeptService.userInfo());
+	}
+
+	/**
+	 * 新建机构
+	 */
+	@PostMapping("/sava-dept")
+	@ApiOperation(value = "新建政府机构", notes = "传入DeptToDept")
+	@ApiOperationSupport(order = 2)
+	public R<Boolean> createDept(@RequestBody DeptToDept dept) {
+		return R.status(deptToDeptService.saveOrUpdate(dept));
+	}
+
+	/**
+	 * 机构搜索
+	 */
+	@GetMapping("/get-dept")
+	@ApiOperation(value = "当前登录用户信息", notes = "")
+	@ApiOperationSupport(order = 3)
+	public R<List<Dept>> list(Long topDept, String areaCode, String name, Integer category) {
+		return R.data(deptToDeptService.getDept(topDept, areaCode, name, category));
+	}
+}

+ 15 - 0
blade-service/wt-okr/src/main/java/com/wtkj/mapper/DeptToDeptMapper.java

@@ -0,0 +1,15 @@
+package com.wtkj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.wtkj.entity.DeptToDept;
+
+import java.util.List;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-14 11:00
+ * @describe
+ */
+public interface DeptToDeptMapper extends BaseMapper<DeptToDept> {
+	List<DeptToDept> selectByTopDept(Long topDept);
+}

+ 9 - 0
blade-service/wt-okr/src/main/java/com/wtkj/mapper/DeptToDeptMapper.xml

@@ -0,0 +1,9 @@
+<?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="com.wtkj.mapper.DeptToDeptMapper">
+
+
+    <select id="selectByTopDept" resultType="com.wtkj.entity.DeptToDept">
+        select * from blade_dept_to_dept where is_deleted = 0 and org_dept_id = #{param}
+    </select>
+</mapper>

+ 2 - 0
blade-service/wt-okr/src/main/java/com/wtkj/mapper/ProjectAuthMapper.java

@@ -12,4 +12,6 @@ import java.util.List;
  */
 public interface ProjectAuthMapper extends BaseMapper<ProjectAuth> {
 	List<ProjectAuth> selectByDeptAndUser(Long deptId, Long userId);
+
+	List<ProjectAuth> selectByTopDeptAndUser(Long topDept, Long userId);
 }

+ 10 - 0
blade-service/wt-okr/src/main/java/com/wtkj/mapper/ProjectAuthMapper.xml

@@ -12,4 +12,14 @@
             and user_id = #{param2}
         </if>
     </select>
+
+    <select id="selectByTopDeptAndUser" resultType="com.wtkj.entity.ProjectAuth">
+        select * from blade_project_auth where is_deleted = 0
+        <if test="param1 != null">
+            and top_dept = #{param1}
+        </if>
+        <if test="param2 != null">
+            and user_id = #{param2}
+        </if>
+    </select>
 </mapper>

+ 22 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/IDeptToDeptService.java

@@ -0,0 +1,22 @@
+package com.wtkj.service;
+
+import com.wtkj.entity.AuthUserInfo;
+import com.wtkj.entity.DeptToDept;
+import org.springblade.core.mp.base.BaseService;
+import org.springblade.system.entity.Dept;
+
+import java.util.List;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-14 11:10
+ * @describe
+ */
+public interface IDeptToDeptService extends BaseService<DeptToDept> {
+
+	AuthUserInfo userInfo();
+
+	List<Dept> getDept(Long topDept, String areaCode, String name, Integer category);
+
+	List<DeptToDept> getByTopDept(Long topDept);
+}

+ 2 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/IProjectAuthService.java

@@ -12,4 +12,6 @@ import java.util.List;
  */
 public interface IProjectAuthService extends BaseService<ProjectAuth> {
 	List<ProjectAuth> getByDeptAndUser(Long deptId, Long userId);
+
+	List<ProjectAuth> getByTopDept(Long topDept, Long userId);
 }

+ 16 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/impl/AsyncServiceImpl.java

@@ -10,8 +10,11 @@ import com.wtkj.service.IProjectStageService;
 import com.wtkj.service.ITypeAndStageService;
 import lombok.AllArgsConstructor;
 import org.springblade.core.secure.BladeUser;
+import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.DateUtil;
 import org.springblade.core.tool.utils.Func;
+import org.springblade.system.entity.Dept;
+import org.springblade.system.feign.ISysClient;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
@@ -19,6 +22,8 @@ import org.springframework.util.CollectionUtils;
 import java.util.ArrayList;
 import java.util.List;
 
+import static com.wtkj.config.MagicValue.ZERO;
+
 /**
  * @author Blizzard
  * @create at 2023-09-13 16:32
@@ -31,6 +36,7 @@ public class AsyncServiceImpl implements IAsyncService {
 	private final ITypeAndStageService typeAndStageService;
 	private final IProjectStageService stageService;
 	private final IProjectAuthService projectAuthService;
+	private final ISysClient sysClient;
 
 
 	@Override
@@ -67,6 +73,16 @@ public class AsyncServiceImpl implements IAsyncService {
 			if (!deptId.equals(project.getCompetentUnit())) {
 				ProjectAuth auth = new ProjectAuth();
 				auth.setUserId(user.getUserId());
+				R<Dept> rpc = sysClient.getDept(deptId);
+				if (rpc.isSuccess()) {
+					String ancestors = rpc.getData().getAncestors();
+					if (ancestors != null && ancestors.contains(String.valueOf(ZERO))) {
+						List<Long> longList = Func.toLongList(ancestors);
+						if (!CollectionUtils.isEmpty(longList) && longList.size() > 2) {
+							auth.setTopDept(longList.get(1));
+						}
+					}
+				}
 				auth.setUserDept(deptId);
 				auth.setProjectId(project.getId());
 				projectAuthService.save(auth);

+ 89 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/impl/DeptToDeptServiceImpl.java

@@ -0,0 +1,89 @@
+package com.wtkj.service.impl;
+
+import com.wtkj.entity.AuthUserInfo;
+import com.wtkj.entity.DeptToDept;
+import com.wtkj.mapper.DeptToDeptMapper;
+import com.wtkj.service.IDeptToDeptService;
+import lombok.AllArgsConstructor;
+import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springblade.core.secure.BladeUser;
+import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.BeanUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springblade.system.entity.Dept;
+import org.springblade.system.feign.ISysClient;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import static com.wtkj.config.MagicValue.ZERO;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-14 11:11
+ * @describe
+ */
+@Service
+@AllArgsConstructor
+public class DeptToDeptServiceImpl extends BaseServiceImpl<DeptToDeptMapper, DeptToDept> implements IDeptToDeptService {
+
+	private ISysClient sysClient;
+
+	@Override
+	public AuthUserInfo userInfo() {
+		BladeUser user = AuthUtil.getUser();
+		if (user != null) {
+			AuthUserInfo userInfo = Objects.requireNonNull(BeanUtil.copy(user, AuthUserInfo.class));
+			String deptIdStr = userInfo.getDeptId();
+			if (StringUtil.isNotBlank(deptIdStr)) {
+				R<Dept> rpc = sysClient.getDept(Long.valueOf(deptIdStr));
+				if (rpc.isSuccess()) {
+					userInfo.setDeptCategory(rpc.getData().getDeptCategory());
+					String ancestors = rpc.getData().getAncestors();
+					// ancestors 0,1689540492698267649
+					if (ancestors != null && ancestors.contains(String.valueOf(ZERO))) {
+						List<Long> longList = Func.toLongList(ancestors);
+						if (!CollectionUtils.isEmpty(longList) && longList.size() > 2) {
+							userInfo.setTopDept(longList.get(1));
+						}
+					}
+				}
+			}
+			return userInfo;
+		}
+		return null;
+	}
+
+	@Override
+	public List<Dept> getDept(Long topDept, String areaCode, String name, Integer category) {
+		List<Dept> result = new ArrayList<>();
+		R<List<Dept>> rpc = sysClient.getDeptByAreaCodeAndCategory(areaCode, name, category);
+		if (rpc.isSuccess()) {
+			List<Dept> data = rpc.getData();
+			if (!CollectionUtils.isEmpty(data)) {
+				result.addAll(data);
+			}
+		}
+		//机构关联的机构
+		if (topDept != null) {
+			List<DeptToDept> list = this.getByTopDept(topDept);
+			if (!CollectionUtils.isEmpty(list)) {
+				List<Dept> deptList = Objects.requireNonNull(BeanUtil.copy(list, Dept.class));
+				result.addAll(deptList);
+			}
+		}
+		return result;
+	}
+
+	@Override
+	public List<DeptToDept> getByTopDept(Long topDept) {
+		return baseMapper.selectByTopDept(topDept);
+	}
+
+
+}

+ 5 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/impl/ProjectAuthServiceImpl.java

@@ -21,4 +21,9 @@ public class ProjectAuthServiceImpl extends BaseServiceImpl<ProjectAuthMapper, P
 	public List<ProjectAuth> getByDeptAndUser(Long deptId, Long userId) {
 		return baseMapper.selectByDeptAndUser(deptId, userId);
 	}
+
+	@Override
+	public List<ProjectAuth> getByTopDept(Long topDept, Long userId) {
+		return baseMapper.selectByTopDeptAndUser(topDept, userId);
+	}
 }

+ 15 - 5
blade-service/wt-okr/src/main/java/com/wtkj/service/impl/ProjectServiceImpl.java

@@ -14,6 +14,7 @@ import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.secure.BladeUser;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.StringUtil;
 import org.springblade.system.entity.Dept;
 import org.springblade.system.feign.ISysClient;
@@ -24,7 +25,8 @@ import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
 
-import static com.wtkj.MagicValue.STAFF_ADMIN;
+import static com.wtkj.config.MagicValue.STAFF_ADMIN;
+import static com.wtkj.config.MagicValue.ZERO;
 
 /**
  * @author Blizzard
@@ -81,10 +83,18 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectMapper, Project>
 				//如果不是业主 ---> 判断是否是服务商的管理员  服务商管理员可以查看所有的项目
 				String userRole = AuthUtil.getUserRole();
 				if (userRole != null && userRole.equals(STAFF_ADMIN)) {
-					List<ProjectAuth> auths = projectAuthService.getByDeptAndUser(deptId, null);
-					if (!CollectionUtils.isEmpty(auths)) {
-						Set<Long> projectIds = auths.stream().map(ProjectAuth::getProjectId).collect(Collectors.toSet());
-						lqw.in(Project::getId, projectIds);
+					String ancestors = rpc.getData().getAncestors();
+					// ancestors 0,1689540492698267649
+					if (ancestors != null && ancestors.contains(String.valueOf(ZERO))) {
+						List<Long> longList = Func.toLongList(ancestors);
+						if (!CollectionUtils.isEmpty(longList) && longList.size() > 2) {
+							Long topDept = longList.get(1);
+							List<ProjectAuth> auths = projectAuthService.getByTopDept(topDept, null);
+							if (!CollectionUtils.isEmpty(auths)) {
+								Set<Long> projectIds = auths.stream().map(ProjectAuth::getProjectId).collect(Collectors.toSet());
+								lqw.in(Project::getId, projectIds);
+							}
+						}
 					}
 				} else {
 					//不是服务机构管理员 则会是项目经理或者任务执行人  从项目权限表里取