lixuesong пре 3 година
родитељ
комит
9ee11e7c06

+ 7 - 2
db/v2.0/1207.sql

@@ -6,11 +6,16 @@ CREATE TABLE `wm_team_manage`
     `name`        VARCHAR(50)  NOT NULL COMMENT '团队名称',
     `leader`      int(11)               DEFAULT NULL COMMENT '团队负责人',
     `member`      VARCHAR(128) NOT NULL COMMENT '团队成员',
-    `enable_flag` char(1)      NOT NULL DEFAULT '0' COMMENT '是否禁用',
+    `enable_flag` char(1)      NOT NULL DEFAULT '0' COMMENT '是否禁用(0-企业,1-禁用)',
+    `del_flag`    char(1)      NOT NULL DEFAULT '0' COMMENT '是否删除(0-正常,1-已删除)',
     `create_time` datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
     `create_user` int(11)               DEFAULT NULL COMMENT '创建人',
     `update_time` datetime              DEFAULT NULL COMMENT '更新时间',
     `update_user` int(11)               DEFAULT NULL COMMENT '更新人',
     PRIMARY KEY (`id`)
 ) ENGINE = InnoDB
-  DEFAULT CHARSET = utf8mb4 COMMENT ='团队管理';
+  DEFAULT CHARSET = utf8mb4 COMMENT ='团队管理';
+
+-- 积分包表新增字段
+ALTER TABLE `wm_score_package`
+    ADD COLUMN `team_id` int NULL DEFAULT NULL COMMENT '团队id' AFTER `p2p_amount`;

+ 158 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmTeamController.java

@@ -0,0 +1,158 @@
+package com.qunzhixinxi.hnqz.admin.controller;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
+import com.qunzhixinxi.hnqz.admin.entity.WmScorePackage;
+import com.qunzhixinxi.hnqz.admin.entity.WmTeam;
+import com.qunzhixinxi.hnqz.admin.entity.base.BaseEntity;
+import com.qunzhixinxi.hnqz.admin.enums.DelEnum;
+import com.qunzhixinxi.hnqz.admin.enums.EnableEnum;
+import com.qunzhixinxi.hnqz.admin.enums.PackageUserScopeEnum;
+import com.qunzhixinxi.hnqz.admin.enums.ScorePackageStatusEnum;
+import com.qunzhixinxi.hnqz.admin.mapper.SysUserMapper;
+import com.qunzhixinxi.hnqz.admin.service.WmScorePackageService;
+import com.qunzhixinxi.hnqz.admin.service.WmTeamService;
+import com.qunzhixinxi.hnqz.common.core.util.R;
+import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 团队管理控制层
+ *
+ * @author lixuesong
+ * @date 2021年12月08日 13:57
+ */
+@RestController
+@RequestMapping("/team")
+@AllArgsConstructor
+public class WmTeamController {
+
+	private final WmTeamService wmTeamService;
+
+	private final WmScorePackageService wmScorePackageService;
+
+	private final SysUserMapper sysUserMapper;
+
+	/**
+	 * 保存
+	 *
+	 * @param wmTeam
+	 * @return
+	 */
+	@PostMapping
+	public R<?> save(@RequestBody @Validated({BaseEntity.Create.class}) WmTeam wmTeam) {
+		if (StrUtil.containsBlank(wmTeam.getName())) {
+			return R.failed("团队名称不能包含空格");
+		}
+		int count = wmTeamService.count(Wrappers.<WmTeam>lambdaQuery()
+				.eq(WmTeam::getDelFlag, DelEnum.NOT_DEL.val())
+				.eq(WmTeam::getName, wmTeam.getName()));
+		if (count > 0) {
+			return R.failed("团队名称已存在");
+		}
+		wmTeam.setDeptId(SecurityUtils.getUser().getDeptId());
+		wmTeam.setCreateTime(LocalDateTime.now());
+		wmTeam.setCreateUser(SecurityUtils.getUser().getId());
+		if (wmTeam.getLeader() != null) {
+			wmTeam.setEnableFlag(EnableEnum.ENABLE.val());
+		}
+		wmTeam.setDelFlag(DelEnum.NOT_DEL.val());
+		wmTeamService.save(wmTeam);
+		return R.ok();
+	}
+
+	/**
+	 * 更新
+	 *
+	 * @param wmTeam
+	 * @return
+	 */
+	@PutMapping
+	public R<?> update(@RequestBody @Validated({BaseEntity.Update.class}) WmTeam wmTeam) {
+		if (StrUtil.isNotBlank(wmTeam.getName()) && StrUtil.containsBlank(wmTeam.getName())) {
+			return R.failed("团队名称不能包含空格");
+		}
+		int count = wmTeamService.count(Wrappers.<WmTeam>lambdaQuery()
+				.ne(WmTeam::getId, wmTeam.getId())
+				.eq(WmTeam::getDelFlag, DelEnum.NOT_DEL.val())
+				.eq(WmTeam::getName, wmTeam.getName()));
+		if (count > 0) {
+			return R.failed("团队名称已存在");
+		}
+		if (wmTeam.getLeader() != null) {
+			wmTeam.setEnableFlag(EnableEnum.ENABLE.val());
+		}
+		wmTeam.setUpdateTime(LocalDateTime.now());
+		wmTeam.setUpdateUser(SecurityUtils.getUser().getId());
+		wmTeamService.updateById(wmTeam);
+		return R.ok();
+	}
+
+	/**
+	 * 解散团队
+	 *
+	 * @param id
+	 * @return
+	 */
+	@PostMapping("/{id}")
+	public R<?> dissolve(@PathVariable("id") Integer id) {
+		// 查询团队是否还有任务在进行
+		int packageCount = wmScorePackageService.count(Wrappers.<WmScorePackage>lambdaQuery()
+				.eq(WmScorePackage::getPackageUserScope, PackageUserScopeEnum.TEAM.getVal())
+				.eq(WmScorePackage::getTeamId, id)
+				.gt(WmScorePackage::getScorePackageStatus, ScorePackageStatusEnum.IN_PROGRESS.val()));
+		if (packageCount > 0) {
+			return R.failed("该团队还有任务在进行,不能解散");
+		}
+		// 设置为禁用
+		wmTeamService.update(Wrappers.<WmTeam>lambdaUpdate()
+				.eq(WmTeam::getId, id)
+				.set(WmTeam::getDelFlag, DelEnum.DELETED.val()));
+		return R.ok();
+	}
+
+	/**
+	 * 查询团队列表
+	 *
+	 * @param page
+	 * @return
+	 */
+	@GetMapping("/list")
+	public R<IPage<WmTeam>> list(Page<WmTeam> page) {
+		Page<WmTeam> teamManagePage = wmTeamService.page(page, Wrappers.<WmTeam>lambdaQuery()
+				.eq(WmTeam::getDeptId, SecurityUtils.getUser().getDeptId())
+				.eq(WmTeam::getDelFlag, DelEnum.NOT_DEL.val()));
+		teamManagePage.getRecords().forEach(wmTeamManage -> {
+			List<SysUser> userList = sysUserMapper.selectBatchIds(CollectionUtil.toList(wmTeamManage.getMember()));
+			wmTeamManage.setMemberName(userList.stream().toArray(String[]::new));
+		});
+		return R.ok(teamManagePage);
+	}
+
+	/**
+	 * TODO
+	 * @param teamId
+	 * @return
+	 */
+	@GetMapping("/list-selectable-user")
+	public R<?> listSelectableUser(Integer teamId) {
+		Map<String, Object> map = wmTeamService.listSelectableUser(teamId);
+		return R.ok(map);
+	}
+}

+ 5 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmScorePackage.java

@@ -474,6 +474,11 @@ public class WmScorePackage extends Model<WmScorePackage> {
 	 */
 	private String projectNum;
 
+	/**
+	 * 团队id
+	 */
+	private Integer teamId;
+
 	/**
 	 * 药企是否存在审核记录
 	 */

+ 87 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmTeam.java

@@ -0,0 +1,87 @@
+package com.qunzhixinxi.hnqz.admin.entity;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.qunzhixinxi.hnqz.admin.entity.base.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.time.LocalDateTime;
+
+/**
+ * 团队管理实体
+ *
+ * @author lixuesong
+ * @date 2021年12月08日 13:34
+ */
+@Data
+@TableName("wm_team")
+@EqualsAndHashCode(callSuper = true)
+public class WmTeam extends Model<WmTeam> {
+
+	/**
+	 * 主键id
+	 */
+	@NotNull(groups = {BaseEntity.Update.class})
+	@TableId
+	private Integer id;
+
+	/**
+	 * 组织机构id
+	 */
+	private Integer deptId;
+
+	/**
+	 * 团队名称
+	 */
+	@NotBlank(groups = {BaseEntity.Create.class})
+	private String name;
+
+	/**
+	 * 团队负责人
+	 */
+	private Integer leader;
+
+	/**
+	 * 团队成员
+	 */
+	private String[] member;
+
+	/**
+	 * 团队成员名称
+	 */
+	private String[] memberName;
+
+	/**
+	 * 是否禁用(0-企业,1-禁用)
+	 */
+	private String enableFlag;
+
+	/**
+	 * 是否删除(0-正常,1-已删除)
+	 */
+	private String delFlag;
+
+	/**
+	 * 创建时间
+	 */
+	private LocalDateTime createTime;
+
+	/**
+	 * 更新时间
+	 */
+	private LocalDateTime updateTime;
+
+	/**
+	 * 创建人
+	 */
+	private Integer createUser;
+
+	/**
+	 * 更新人
+	 */
+	private Integer updateUser;
+}

+ 23 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/enums/PackageUserScopeEnum.java

@@ -0,0 +1,23 @@
+package com.qunzhixinxi.hnqz.admin.enums;
+
+/**
+ * 积分包在接单用户中的可见范围
+ *
+ * @author lixuesong
+ * @date 2021年12月08日 16:58
+ */
+public enum PackageUserScopeEnum {
+
+	// 可见范围:1-仅内部可见,2-全部可见,3-团队内部可见
+	INTERNAL("1"), ALL("2"), TEAM("3");
+
+	private String val;
+
+	PackageUserScopeEnum(String val) {
+		this.val = val;
+	}
+
+	public String getVal() {
+		return val;
+	}
+}

+ 9 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/mapper/SysUserMapper.java

@@ -98,4 +98,13 @@ public interface SysUserMapper extends DataScopeMapper<SysUser> {
 	SysUser selectUserByName(SysUser sysUser);
 
 	List<SysUser> selectUserById(SysUser sysUser);
+
+	/**
+	 * 根据部门id和角色id查询
+	 *
+	 * @param deptId
+	 * @param roleList
+	 * @return
+	 */
+	List<SysUser> selectByDeptIdAndRoleId(@Param("deptId") Integer deptId, @Param("roleList") List<Integer> roleList);
 }

+ 15 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/mapper/WmTeamMapper.java

@@ -0,0 +1,15 @@
+package com.qunzhixinxi.hnqz.admin.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qunzhixinxi.hnqz.admin.entity.WmTeam;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 团队管理Mapper
+ *
+ * @author lixuesong
+ * @date 2021年12月08日 13:49
+ */
+@Mapper
+public interface WmTeamMapper extends BaseMapper<WmTeam> {
+}

+ 23 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmTeamService.java

@@ -0,0 +1,23 @@
+package com.qunzhixinxi.hnqz.admin.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qunzhixinxi.hnqz.admin.entity.WmTeam;
+
+import java.util.Map;
+
+/**
+ * 团队管理服务
+ *
+ * @author lixuesong
+ * @date 2021年12月08日 13:50
+ */
+public interface WmTeamService extends IService<WmTeam> {
+
+	/**
+	 * 查询可选择的人员
+	 *
+	 * @param teamId
+	 * @return
+	 */
+	Map<String, Object> listSelectableUser(Integer teamId);
+}

+ 99 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmTeamServiceImpl.java

@@ -0,0 +1,99 @@
+package com.qunzhixinxi.hnqz.admin.service.impl;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
+import com.qunzhixinxi.hnqz.admin.entity.WmTeam;
+import com.qunzhixinxi.hnqz.admin.enums.DelEnum;
+import com.qunzhixinxi.hnqz.admin.mapper.SysUserMapper;
+import com.qunzhixinxi.hnqz.admin.mapper.WmTeamMapper;
+import com.qunzhixinxi.hnqz.admin.service.WmTeamService;
+import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * 团队管理服务
+ *
+ * @author lixuesong
+ * @date 2021年12月08日 13:51
+ */
+@Service
+@AllArgsConstructor
+public class WmTeamServiceImpl extends ServiceImpl<WmTeamMapper, WmTeam> implements WmTeamService {
+
+	private final SysUserMapper sysUserMapper;
+
+	/**
+	 * 查询可选择的人员
+	 *
+	 * @param teamId
+	 * @return
+	 */
+	@Override
+	public Map<String, Object> listSelectableUser(Integer teamId) {
+		Map<String, Object> resultMap = MapUtil.newHashMap(3);
+		Integer deptId = SecurityUtils.getUser().getDeptId();
+		// 查询负责人user(药企管理员或CSO管理员)
+		List<SysUser> leaderUserList = sysUserMapper.selectByDeptIdAndRoleId(deptId, CollectionUtil.toList(3, 4));
+		// 查询组成人员user(兼职学术信息沟通专员)
+		List<SysUser> memberList = sysUserMapper.selectByDeptIdAndRoleId(deptId, CollectionUtil.toList(6));
+		// 该企业下所有团队的已配置人员
+		List<WmTeam> deptTeamList = this.list(Wrappers.<WmTeam>lambdaQuery()
+				.eq(WmTeam::getDeptId, deptId)
+				.eq(WmTeam::getDelFlag, DelEnum.NOT_DEL.val()));
+		Set<Integer> assignedUserSet = new HashSet<>();
+		deptTeamList.forEach(wmTeam -> {
+			if (StrUtil.isAllNotBlank(wmTeam.getMember())) {
+				Set<Integer> memberSet = Stream.of(wmTeam.getMember())
+						.map(s -> Integer.parseInt(s))
+						.collect(Collectors.toSet());
+				assignedUserSet.addAll(memberSet);
+			}
+		});
+		// 负责人列表
+		List<Map<String, Object>> leaderList = leaderUserList.stream()
+				.map(sysUser -> {
+					Map<String, Object> userMap = MapUtil.newHashMap(3);
+					userMap.put("realName", sysUser.getRealname());
+					userMap.put("phone", sysUser.getUsername());
+					userMap.put("userId", sysUser.getUserId());
+					return userMap;
+				}).collect(Collectors.toList());
+		// 未分配人员列表
+		List<Map<String, Object>> notAssignedUserList = memberList.stream()
+				.filter(sysUser -> !assignedUserSet.contains(sysUser.getUserId()))
+				.map(sysUser -> {
+					Map<String, Object> userMap = MapUtil.newHashMap(3);
+					userMap.put("realName", sysUser.getRealname());
+					userMap.put("phone", sysUser.getUsername());
+					userMap.put("userId", sysUser.getUserId());
+					return userMap;
+				}).collect(Collectors.toList());
+		// 已分配人员列表
+		List<Map<String, Object>> assignedUserList = memberList.stream()
+				.filter(sysUser -> assignedUserSet.contains(sysUser.getUserId()))
+				.map(sysUser -> {
+					Map<String, Object> userMap = MapUtil.newHashMap(3);
+					userMap.put("realName", sysUser.getRealname());
+					userMap.put("phone", sysUser.getUsername());
+					userMap.put("userId", sysUser.getUserId());
+					return userMap;
+				}).collect(Collectors.toList());
+		resultMap.put("leaders", leaderList);
+		resultMap.put("notAssignedMembers", notAssignedUserList);
+		resultMap.put("assignedMembers", assignedUserList);
+
+		return resultMap;
+	}
+}

+ 25 - 0
hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/SysUserMapper.xml

@@ -660,6 +660,31 @@
 		</where>
 		ORDER BY u.create_time DESC
 	</select>
+
+	<!-- 根据部门id和角色id查询 -->
+	<select id="selectByDeptIdAndRoleId" resultMap="userResultMap">
+		SELECT
+			u.user_id,
+			u.username,
+			u.phone,
+			u.avatar,
+			u.dept_id,
+			u.create_time,
+			u.update_time,
+			r.role_id,
+			u.realname
+		FROM
+			sys_user u
+				LEFT JOIN sys_user_role r ON r.user_id = u.user_id
+		WHERE
+			u.dept_id = #{deptId}
+		  AND r.role_id IN (
+			<foreach collection="roleList" item="roleId" index="index" separator=",">
+				#{roleId}
+			</foreach>
+			)
+	</select>
+
 	<update id="updateByPrimaryKeySelective" parameterType="com.qunzhixinxi.hnqz.admin.api.entity.SysUser" >
 		update sys_user
 		<set >

+ 39 - 0
hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/WmTeamMapper.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~
+  ~      Copyright (c) 2018-2025, hnqz All rights reserved.
+  ~
+  ~  Redistribution and use in source and binary forms, with or without
+  ~  modification, are permitted provided that the following conditions are met:
+  ~
+  ~ Redistributions of source code must retain the above copyright notice,
+  ~  this list of conditions and the following disclaimer.
+  ~  Redistributions in binary form must reproduce the above copyright
+  ~  notice, this list of conditions and the following disclaimer in the
+  ~  documentation and/or other materials provided with the distribution.
+  ~  Neither the name of the pig4cloud.com developer nor the names of its
+  ~  contributors may be used to endorse or promote products derived from
+  ~  this software without specific prior written permission.
+  ~  Author: hnqz
+  ~
+  -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.qunzhixinxi.hnqz.admin.mapper.WmTeamMapper">
+	<resultMap id="baseMap" type="com.qunzhixinxi.hnqz.admin.entity.WmTeam">
+		<id property="id" column="id"/>
+		<result property="deptId" column="dept_id"/>
+		<result property="name" column="name"/>
+		<result property="leader" column="leader"/>
+		<result property="member" column="member"/>
+		<result property="enableFlag" column="enable_flag"/>
+		<result property="delFlag" column="del_flag"/>
+		<result property="createTime" column="create_time"/>
+		<result property="createUser" column="create_user"/>
+		<result property="updateTime" column="update_time"/>
+		<result property="updateUser" column="update_user"/>
+	</resultMap>
+
+</mapper>