| | |
| | | |
| | | import javax.sql.rowset.serial.SerialArray; |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | public class Department implements Serializable { |
| | |
| | | /** |
| | | * 部门管理员 |
| | | */ |
| | | private Integer adminId; |
| | | private List<Integer> adminId; |
| | | |
| | | private String deleted; |
| | | |
| | |
| | | private Date lastActiveTime; |
| | | |
| | | /** |
| | | * 是否删除 |
| | | * 是否删除:0未删除 1删除 |
| | | */ |
| | | private Boolean deleted; |
| | | |
| | |
| | | private Integer userId; |
| | | private Integer departmentId; |
| | | |
| | | |
| | | /** |
| | | * 是否部门管理员 |
| | | */ |
| | | private String deptAdmin; |
| | | } |
| | |
| | | import lombok.Data; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.NotEmpty; |
| | | import javax.validation.constraints.NotNull; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 修改部门管理员 |
| | |
| | | /** |
| | | * 管理员,userId |
| | | */ |
| | | @NotNull(message = "部门管理员不能为空") |
| | | private Integer adminId; |
| | | @NotEmpty(message = "部门管理员不能为空") |
| | | private List<Integer> adminIds; |
| | | |
| | | } |
| | |
| | | |
| | | /** |
| | | * 修改部门管理员标识 |
| | | * @param id |
| | | * @param ids |
| | | * @param deptAdmin |
| | | */ |
| | | void updateDeptAdmin(Integer id, String deptAdmin); |
| | | void updateDeptAdmin(@Param("ids") List<Integer> ids, @Param("deptAdmin") String deptAdmin, @Param("deptId") Integer deptId); |
| | | |
| | | |
| | | List<ExamPaperAnswer> getUserByDept(@Param("query") ExamPaperGradeQuery query); |
| | | |
| | | void setStatus(UserVO user); |
| | | |
| | | /** |
| | | * 清除某部门的用户管理员标识 |
| | | * |
| | | * @param userIds |
| | | * @param deptId |
| | | */ |
| | | void clearDeptAdmin(List<Integer> userIds, @Param("deptId") Integer deptId); |
| | | } |
| | |
| | | import org.modelmapper.ModelMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class DepartmentServiceImpl extends BaseServiceImpl<Department> implements DepartmentService { |
| | |
| | | if (Objects.isNull(entity)) { |
| | | throw new RuntimeException("该部门不存在"); |
| | | } |
| | | if (Objects.nonNull(department.getAdminId())) { |
| | | Integer adminNum = departmentMapper.countByAdminId(department.getAdminId(), department.getId()); |
| | | if (adminNum > 0) { |
| | | throw new RuntimeException("一个用户只能是一个单位的管理员"); |
| | | } |
| | | if (! Objects.equals(entity.getAdminId(), department.getAdminId())) { |
| | | // 取消原先的管理员标识 |
| | | userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue()); |
| | | if (! CollectionUtils.isEmpty(department.getAdminId())) { |
| | | List<BaseSelect> deptUserList = userDepartmentMapper.getDeptUserList(entity.getId()); |
| | | List<Integer> userIds = deptUserList.stream().map(BaseSelect::getId).collect(Collectors.toList()); |
| | | if (! CollectionUtils.isEmpty(userIds)) { |
| | | // 先清除之前的管理员标识 |
| | | userMapper.clearDeptAdmin(userIds, entity.getId()); |
| | | } |
| | | // 标识部门管理员 |
| | | userMapper.updateDeptAdmin(department.getAdminId(), DeptAdminEnum.YES.getValue()); |
| | | userMapper.updateDeptAdmin(department.getAdminId(), DeptAdminEnum.YES.getValue(), entity.getId()); |
| | | } |
| | | Integer update = departmentMapper.update(department); |
| | | return update; |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateAdmin(UpdateDeptAdminVO form) { |
| | | Department entity = departmentMapper.getById(form.getId()); |
| | | if (Objects.isNull(form)) { |
| | | if (Objects.isNull(entity)) { |
| | | throw new RuntimeException("该部门不存在"); |
| | | } |
| | | if (Objects.nonNull(form.getAdminId())) { |
| | | Integer adminNum = departmentMapper.countByAdminId(form.getAdminId(), form.getId()); |
| | | if (adminNum > 0) { |
| | | throw new RuntimeException("一个用户只能是一个单位的管理员"); |
| | | } |
| | | if (! Objects.equals(entity.getAdminId(), form.getAdminId())) { |
| | | // 取消原先的管理员标识 |
| | | userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue()); |
| | | if (! CollectionUtils.isEmpty(form.getAdminIds())) { |
| | | List<BaseSelect> deptUserList = userDepartmentMapper.getDeptUserList(entity.getId()); |
| | | List<Integer> userIds = deptUserList.stream().map(BaseSelect::getId).collect(Collectors.toList()); |
| | | if (! CollectionUtils.isEmpty(userIds)) { |
| | | // 先清除之前的管理员标识 |
| | | userMapper.clearDeptAdmin(userIds, entity.getId()); |
| | | } |
| | | // 标识部门管理员 |
| | | userMapper.updateDeptAdmin(form.getAdminId(), DeptAdminEnum.YES.getValue()); |
| | | userMapper.updateDeptAdmin(form.getAdminIds(), DeptAdminEnum.YES.getValue(), entity.getId()); |
| | | } |
| | | entity.setAdminId(form.getAdminId()); |
| | | departmentMapper.update(entity); |
| | | } |
| | | } |
| | |
| | | Map<Integer, Integer> multiple = new HashMap<>(); |
| | | //多选 |
| | | Map<Integer, Integer> multipleMap = list.stream() |
| | | .filter(e -> e.getQuestionType().equals(QuestionTypeEnum.MultipleChoice.getCode())) |
| | | .filter(e -> Objects.equals(QuestionTypeEnum.MultipleChoice.getCode(), e.getQuestionType())) |
| | | .collect(Collectors.toMap(Question::getId, Question::getScore)); |
| | | Integer multipleSource = questionTypeVM.getMultipleChoice() * 2; |
| | | selectRandomScores(multiple, multipleMap, questionTypeVM.getMultipleChoice(), multipleSource); |
| | | |
| | | |
| | | //判断 |
| | | List<Question> collect1 = list.stream().filter(e -> e.getQuestionType().equals(QuestionTypeEnum.TrueFalse.getCode())).collect(Collectors.toList()); |
| | | List<Question> collect1 = list.stream().filter(e -> Objects.equals(e.getQuestionType(), QuestionTypeEnum.TrueFalse.getCode())).collect(Collectors.toList()); |
| | | Map<Integer, Integer> judgmentMap = collect1.stream().collect(Collectors.toMap(Question::getId, Question::getScore)); |
| | | Integer trueFalse1 = questionTypeVM.getTrueFalse(); |
| | | Integer trueFalse = trueFalse1 * 2; |
| | |
| | | Integer radioSource = questionTypeVM.getSingleChoice() * 4; |
| | | //单选 |
| | | Map<Integer, Integer> radioMap = list.stream() |
| | | .filter(e -> e.getQuestionType().equals(QuestionTypeEnum.SingleChoice.getCode())) |
| | | .filter(e -> Objects.equals(e.getQuestionType(), QuestionTypeEnum.SingleChoice.getCode())) |
| | | .collect(Collectors.toMap(Question::getId, Question::getScore)); |
| | | selectRandomScores(multiple, radioMap, questionTypeVM.getSingleChoice(), radioSource); |
| | | |
| | |
| | | import com.mindskip.xzs.base.BasePage; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | public class DepartmentResponseVM extends BasePage { |
| | | |
| | |
| | | /** |
| | | * 管理员 |
| | | */ |
| | | private Integer adminId; |
| | | private String adminName; |
| | | private List<Integer> adminIds; |
| | | private List<String> adminNames; |
| | | |
| | | } |
| | |
| | | <select id="gets" resultMap="BaseResultMap"> |
| | | SELECT |
| | | td.id, |
| | | td.name, |
| | | td.admin_id as adminId, |
| | | tu.real_name as adminName |
| | | td.name |
| | | FROM |
| | | t_department td |
| | | LEFT JOIN t_user tu ON td.admin_id = tu.id AND tu.deleted = 0 |
| | | WHERE |
| | | td.deleted = 0 |
| | | <if test="deptId != null"> |
| | |
| | | <select id="getById" resultMap="BaseResultMap"> |
| | | SELECT |
| | | td.id, |
| | | td.name, |
| | | td.admin_id as adminId, |
| | | tu.real_name as adminName |
| | | td.name |
| | | FROM |
| | | t_department td |
| | | LEFT JOIN t_user tu ON td.admin_id = tu.id AND tu.deleted = 0 |
| | | WHERE |
| | | td.id = #{id} AND td.deleted = 0 |
| | | </select> |
| | | |
| | | <select id="page" resultType="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM" |
| | | <resultMap id="pageResult" type="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM"> |
| | | <id column="id" property="id"/> |
| | | <result column="name" property="name"/> |
| | | <collection column="id" property="adminIds" ofType="integer" select="selectUserIdsByDeptId"></collection> |
| | | <collection column="id" property="adminNames" ofType="integer" select="selectUserNamesByDeptId"></collection> |
| | | </resultMap> |
| | | |
| | | <select id="selectUserIdsByDeptId" resultType="integer"> |
| | | SELECT |
| | | tu.id |
| | | FROM |
| | | t_user_department tud |
| | | INNER JOIN t_user tu ON tud.user_id = tu.id AND tud.department_id = #{deptId} AND tu.status = 1 AND deleted = 0 AND tud.dept_admin = 1 |
| | | </select> |
| | | |
| | | <select id="selectUserNamesByDeptId" resultType="string"> |
| | | SELECT |
| | | tu.real_name |
| | | FROM |
| | | t_user_department tud |
| | | INNER JOIN t_user tu ON tud.user_id = tu.id AND tud.department_id = #{deptId} AND tu.status = 1 AND deleted = 0 AND tud.dept_admin = 1 |
| | | </select> |
| | | |
| | | <select id="page" resultMap="pageResult" |
| | | parameterType="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM"> |
| | | SELECT |
| | | td.id, |
| | | td.name, |
| | | td.admin_id as adminId, |
| | | tu.real_name as adminName |
| | | td.name |
| | | FROM |
| | | t_department td |
| | | LEFT JOIN t_user tu ON td.admin_id = tu.id AND tu.deleted = 0 |
| | | <where> |
| | | AND td.deleted = 0 |
| | | <if test="id != null "> |
| | |
| | | </insert> |
| | | |
| | | <select id="list" resultType="com.mindskip.xzs.domain.vo.ExamTemplatesUserCountVO" parameterType="com.mindskip.xzs.viewmodel.admin.exam.ExamPaperPageRequestVM"> |
| | | SELECT u.exam_templates_id as id, count(*) as count, u.user_id as userId FROM `t_exam_templates_user_count` u |
| | | left join t_exam_templates e on u.exam_templates_id = e.id |
| | | SELECT |
| | | e.id as id, |
| | | count(u.user_id) as count, |
| | | u.user_id as userId |
| | | FROM |
| | | t_exam_templates e |
| | | left join `t_exam_templates_user_count` u on u.exam_templates_id = e.id <if test="userId != null">and u.user_id = #{userId}</if> |
| | | <where> |
| | | <if test="templatesId != null"> |
| | | and u.exam_templates_id = #{templatesId} |
| | | </if> |
| | | <if test="userId != null"> |
| | | and u.user_id = #{userId} |
| | | </if> |
| | | |
| | | <if test="status != null"> |
| | | and e.status = 0 |
| | | </if> |
| | |
| | | </update> |
| | | |
| | | |
| | | |
| | | <select id="getAllUser" resultMap="BaseResultMap"> |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | |
| | | </select> |
| | | |
| | | <select id="getUserByLevel" resultMap="BaseResultMap"> |
| | | select |
| | | id,real_name |
| | | from t_user where deleted=0 and user_level = #{userLevel} |
| | | select id, |
| | | real_name |
| | | from t_user |
| | | where deleted = 0 |
| | | and user_level = #{userLevel} |
| | | </select> |
| | | |
| | | <select id="getUserById" resultMap="BaseResultMap"> |
| | |
| | | </select> |
| | | |
| | | |
| | | <select id="userPage" resultMap="BaseResultMap" parameterType="com.mindskip.xzs.viewmodel.admin.user.UserPageRequestVM"> |
| | | <select id="userPage" resultMap="BaseResultMap" |
| | | parameterType="com.mindskip.xzs.viewmodel.admin.user.UserPageRequestVM"> |
| | | SELECT |
| | | <include refid="Base_Column_List"/> |
| | | FROM t_user |
| | |
| | | </select> |
| | | |
| | | |
| | | |
| | | <insert id="insertUser" parameterType="com.mindskip.xzs.domain.User" |
| | | useGeneratedKeys="true" keyProperty="id"> |
| | | insert into t_user |
| | | (user_uuid,user_name,password,real_name,age, last_active_time) |
| | | values |
| | | (#{userUuid,jdbcType=VARCHAR},#{userName},#{password},#{realName},#{age},#{lastActiveTime}) |
| | | values (#{userUuid,jdbcType=VARCHAR}, #{userName}, #{password}, #{realName}, #{age}, #{lastActiveTime}) |
| | | </insert> |
| | | |
| | | <insert id="insertUsers" parameterType="java.util.List" |
| | |
| | | </delete> |
| | | |
| | | <select id="selectAllCount" resultType="java.lang.Integer"> |
| | | SELECT count(*) from t_user where deleted=0 |
| | | SELECT count(*) |
| | | from t_user |
| | | where deleted = 0 |
| | | </select> |
| | | |
| | | |
| | | <select id="selectByUserName" resultType="com.mindskip.xzs.domain.other.KeyValue"> |
| | | SELECT id as value,user_name as name |
| | | from t_user |
| | | where deleted=0 and user_name like concat('%',#{value},'%') |
| | | where deleted=0 |
| | | and user_name like concat('%' |
| | | , #{value} |
| | | , '%') |
| | | limit 5 |
| | | </select> |
| | | |
| | |
| | | |
| | | |
| | | <update id="updateDeptAdmin"> |
| | | UPDATE t_user SET dept_admin = #{deptAdmin} WHERE id = #{id} AND deleted = 0 |
| | | UPDATE t_user_department SET dept_admin = #{deptAdmin} |
| | | <where> |
| | | <if test="ids != null and ids.size > 0"> |
| | | AND user_id in |
| | | <foreach collection="ids" open="(" separator="," close=")" item="id"> |
| | | #{id} |
| | | </foreach> |
| | | </if> |
| | | AND department_id = #{deptId} |
| | | </where> |
| | | </update> |
| | | |
| | | <update id="setStatus"> |
| | |
| | | AND deleted = 0 |
| | | </update> |
| | | |
| | | <update id="clearDeptAdmin"> |
| | | update |
| | | t_user_department set dept_admin = 0 |
| | | WHERE |
| | | user_id IN <foreach collection="userIds" open="(" separator="," close=")" item="id">#{id}</foreach> |
| | | AND dept_admin = 1 AND department_id = #{deptId} |
| | | </update> |
| | | |
| | | <select id="getUserByDept" resultType="com.mindskip.xzs.domain.ExamPaperAnswer"> |
| | | SELECT |
| | | tu.id as createUser, tu.real_name as userName, count(tepa.id) as counts |