龚焕茏
2024-05-06 24c9d860ced4d058b866a9fb548a8ef1d1412c20
新增标签菜单添加、查询、删除、修改,学生绑定、展示、修改
3个文件已修改
8个文件已添加
353 ■■■■■ 已修改文件
src/main/java/com/mindskip/xzs/controller/admin/TagController.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/controller/admin/UserController.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/Tag.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/UserTag.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/vo/TagVO.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/repository/TagMapper.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/service/TagService.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/service/impl/TagServiceImpl.java 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/viewmodel/admin/user/UserCreateVM.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/viewmodel/admin/user/UserResponseVM.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/TagMapper.xml 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/controller/admin/TagController.java
New file
@@ -0,0 +1,60 @@
package com.mindskip.xzs.controller.admin;
import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.domain.Tag;
import com.mindskip.xzs.domain.vo.TagVO;
import com.mindskip.xzs.service.TagService;
import lombok.Data;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * @author gonghl
 * @since 2024/5/6 上午 11:45
 */
@RestController
@RequestMapping(value = "/api/admin/tag")
@Data
public class TagController {
    private final TagService tagService;
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public RestResponse<List<Tag>> pageList() {
        List<Tag> list = tagService.list();
        return RestResponse.ok(list);
    }
    @RequestMapping(value = "/page/list", method = RequestMethod.POST)
    public RestResponse<PageInfo<Tag>> pageList(@RequestBody TagVO tag) {
        PageInfo<Tag> page = tagService.tagPage(tag);
        return RestResponse.ok(page);
    }
    @RequestMapping(value = "/select/{id}", method = RequestMethod.POST)
    public RestResponse<Tag> select(@PathVariable Integer id) {
        Tag tag = tagService.getById(id);
        return RestResponse.ok(tag);
    }
    @RequestMapping(value = "/selectCount/{id}", method = RequestMethod.POST)
    public RestResponse<List<String>> selectCount(@PathVariable Integer id) {
        return RestResponse.ok(tagService.selectCount(id));
    }
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public RestResponse<Tag> update(@RequestBody Tag tag) {
        tagService.saveOrUpdate(tag);
        return RestResponse.ok(tag);
    }
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    public RestResponse<Integer> delete(@PathVariable Integer id) {
        tagService.removeById(id);
        return RestResponse.ok(id);
    }
}
src/main/java/com/mindskip/xzs/controller/admin/UserController.java
@@ -2,18 +2,12 @@
import com.mindskip.xzs.base.BaseApiController;
import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.domain.Department;
import com.mindskip.xzs.domain.UserDepartment;
import com.mindskip.xzs.domain.*;
import com.mindskip.xzs.domain.other.KeyValue;
import com.mindskip.xzs.domain.User;
import com.mindskip.xzs.domain.UserEventLog;
import com.mindskip.xzs.domain.enums.UserStatusEnum;
import com.mindskip.xzs.domain.vo.UserVO;
import com.mindskip.xzs.repository.UserDepartmentMapper;
import com.mindskip.xzs.service.AuthenticationService;
import com.mindskip.xzs.service.DepartmentService;
import com.mindskip.xzs.service.UserEventLogService;
import com.mindskip.xzs.service.UserService;
import com.mindskip.xzs.service.*;
import com.mindskip.xzs.utility.DateTimeUtil;
import com.mindskip.xzs.utility.convert.UserClassConvert;
import com.mindskip.xzs.utility.excel.ExcelUtils;
@@ -21,12 +15,14 @@
import com.mindskip.xzs.utility.PageInfoHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@@ -42,14 +38,16 @@
    private final AuthenticationService authenticationService;
    private final DepartmentService departmentService;
    private final UserDepartmentMapper userDepartmentMapper;
    private final TagService tagService;
    @Autowired
    public UserController(UserService userService, UserEventLogService userEventLogService, AuthenticationService authenticationService, DepartmentService departmentService, UserDepartmentMapper userDepartmentMapper) {
    public UserController(UserService userService, UserEventLogService userEventLogService, AuthenticationService authenticationService, DepartmentService departmentService, UserDepartmentMapper userDepartmentMapper, TagService tagService) {
        this.userService = userService;
        this.userEventLogService = userEventLogService;
        this.authenticationService = authenticationService;
        this.departmentService = departmentService;
        this.userDepartmentMapper = userDepartmentMapper;
        this.tagService = tagService;
    }
@@ -69,6 +67,7 @@
                }
            }
            e.setDeptNames(deptIds);
            e.setTagNames(tagService.selectTagNamesByUserId(e.getId()));
            return e;
        }).collect(Collectors.toList()));
        return RestResponse.ok(page);
@@ -96,6 +95,7 @@
            deptIds = deptIds + userDepartment.getDepartmentId().toString() + ",";
        }
        userVm.setDeptIds(deptIds.equals("") ? "" : deptIds.substring(0,deptIds.length()-1));
        userVm.setTagIds(tagService.selectTagIdsByUserId(user.getId()));
        return RestResponse.ok(userVm);
    }
@@ -147,6 +147,15 @@
            userDepartment.setDepartmentId(Integer.parseInt(s));
            userDepartmentMapper.insert(userDepartment);
        }
        if (ObjectUtils.isNotEmpty(model.getTagIds())) {
            tagService.removeUserTagByUserId(user.getId());
            tagService.saveBatchUserTag(model.getTagIds().stream().map(
                    tagId -> new UserTag() {{
                        setUserId(user.getId());
                        setTagId(tagId);
                    }}
            ).collect(Collectors.toList()));
        }
        user.setDeptIds(model.getDeptIds());
        return RestResponse.ok(user);
    }
src/main/java/com/mindskip/xzs/domain/Tag.java
New file
@@ -0,0 +1,28 @@
package com.mindskip.xzs.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
 * @author gonghl
 * @TableName t_tag
 */
@TableName(value = "t_tag")
@Data
public class Tag implements Serializable {
    @TableId(value="id",type = IdType.AUTO)
    private Integer id;
    private String name;
    @TableLogic
    private Boolean deleted;
    private static final long serialVersionUID = 1L;
}
src/main/java/com/mindskip/xzs/domain/UserTag.java
New file
@@ -0,0 +1,23 @@
package com.mindskip.xzs.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
 * @author gonghl
 * @TableName t_tag
 */
@TableName(value = "t_user_tag")
@Data
public class UserTag implements Serializable {
    private Integer id;
    private Integer userId;
    private Integer tagId;
    private static final long serialVersionUID = 1L;
}
src/main/java/com/mindskip/xzs/domain/vo/TagVO.java
New file
@@ -0,0 +1,22 @@
package com.mindskip.xzs.domain.vo;
import com.mindskip.xzs.base.BasePage;
import lombok.Data;
import java.io.Serializable;
/**
 * @author gonghl
 * @TableName t_tag
 */
@Data
public class TagVO extends BasePage implements Serializable {
    private Integer id;
    private String name;
    private Boolean deleted;
    private static final long serialVersionUID = 1L;
}
src/main/java/com/mindskip/xzs/repository/TagMapper.java
New file
@@ -0,0 +1,32 @@
package com.mindskip.xzs.repository;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mindskip.xzs.domain.Tag;
import com.mindskip.xzs.domain.UserTag;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
 * @author gonghl
 * @description 针对表【t_tag(用户标签)】的数据库操作Mapper
 * @createDate 2024-05-06 11:19:57
 * @Entity com.mindskip.xzs.tag.Tag
 */
@Mapper
public interface TagMapper extends BaseMapper<Tag> {
    void saveBatchUserTag(List<UserTag> list);
    void removeUserTagByUserId(Integer id);
    List<Integer> selectTagIdsByUserId(Integer id);
    List<String> selectTagNamesByUserId(Integer id);
    List<String> selectCountById(Integer id);
}
src/main/java/com/mindskip/xzs/service/TagService.java
New file
@@ -0,0 +1,29 @@
package com.mindskip.xzs.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.domain.Tag;
import com.mindskip.xzs.domain.UserTag;
import com.mindskip.xzs.domain.vo.TagVO;
import java.util.List;
/**
 * @author gonghl
 * @description 针对表【t_tag(用户标签)】的数据库操作Service
 * @createDate 2024-05-06 11:19:57
 */
public interface TagService extends IService<Tag> {
    PageInfo<Tag> tagPage(TagVO tag);
    void saveBatchUserTag(List<UserTag> list);
    void removeUserTagByUserId(Integer id);
    List<Integer> selectTagIdsByUserId(Integer id);
    List<String> selectTagNamesByUserId(Integer id);
    List<String> selectCount(Integer id);
}
src/main/java/com/mindskip/xzs/service/impl/TagServiceImpl.java
New file
@@ -0,0 +1,64 @@
package com.mindskip.xzs.service.impl;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.domain.Tag;
import com.mindskip.xzs.domain.UserTag;
import com.mindskip.xzs.domain.vo.TagVO;
import com.mindskip.xzs.repository.TagMapper;
import com.mindskip.xzs.service.TagService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.stream.Collectors;
/**
 * @author gonghl
 * @description 针对表【t_tag(用户标签)】的数据库操作Service实现
 * @createDate 2024-05-06 11:19:57
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {
    @Override
    public PageInfo<Tag> tagPage(TagVO tag) {
        return PageHelper.startPage(tag.getPageIndex(), tag.getPageSize(), "id desc").doSelectPageInfo(() ->
                new LambdaQueryChainWrapper<>(baseMapper)
                        .like(StringUtils.hasText(tag.getName()), Tag::getName, tag.getName())
                        .eq(Tag::getDeleted, false)
                        .list()
        );
    }
    @Override
    public void saveBatchUserTag(List<UserTag> list) {
        baseMapper.saveBatchUserTag(list);
    }
    @Override
    public void removeUserTagByUserId(Integer id) {
        baseMapper.removeUserTagByUserId(id);
    }
    @Override
    public List<Integer> selectTagIdsByUserId(Integer id) {
        return baseMapper.selectTagIdsByUserId(id);
    }
    @Override
    public List<String> selectTagNamesByUserId(Integer id) {
        return baseMapper.selectTagNamesByUserId(id);
    }
    @Override
    public List<String> selectCount(Integer id) {
        return baseMapper.selectCountById(id);
    }
}
src/main/java/com/mindskip/xzs/viewmodel/admin/user/UserCreateVM.java
@@ -3,6 +3,7 @@
import javax.validation.constraints.NotBlank;
import java.util.List;
public class UserCreateVM {
@@ -32,6 +33,8 @@
    private Integer userLevel;
    private String deptIds;
    private List<Integer> tagIds;
    public Integer getId() {
        return id;
@@ -128,4 +131,12 @@
    public void setDeptIds(String deptIds) {
        this.deptIds = deptIds;
    }
    public List<Integer> getTagIds() {
        return tagIds;
    }
    public void setTagIds(List<Integer> tagIds) {
        this.tagIds = tagIds;
    }
}
src/main/java/com/mindskip/xzs/viewmodel/admin/user/UserResponseVM.java
@@ -4,6 +4,8 @@
import com.mindskip.xzs.utility.DateTimeUtil;
import com.mindskip.xzs.viewmodel.BaseVM;
import java.util.List;
public class UserResponseVM extends BaseVM {
@@ -40,6 +42,10 @@
    private String deptIds;
    private String deptNames;
    private List<Integer> tagIds;
    private List<String> tagNames;
    public static UserResponseVM from(User user) {
        UserResponseVM vm = modelMapper.map(user, UserResponseVM.class);
@@ -185,4 +191,20 @@
    public void setDeptNames(String deptNames) {
        this.deptNames = deptNames;
    }
    public List<Integer> getTagIds() {
        return tagIds;
    }
    public void setTagIds(List<Integer> tagIds) {
        this.tagIds = tagIds;
    }
    public List<String> getTagNames() {
        return tagNames;
    }
    public void setTagNames(List<String> tagNames) {
        this.tagNames = tagNames;
    }
}
src/main/resources/mapper/TagMapper.xml
New file
@@ -0,0 +1,35 @@
<?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.mindskip.xzs.repository.TagMapper">
    <resultMap id="BaseResultMap" type="com.mindskip.xzs.domain.Tag">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="deleted" column="deleted" jdbcType="BIT"/>
    </resultMap>
    <insert id="saveBatchUserTag">
        insert into t_user_tag (user_id, tag_id) values
        <foreach collection="list" item="item" separator=",">
            (#{item.userId},#{item.tagId})
        </foreach>
    </insert>
    <delete id="removeUserTagByUserId">
        delete from t_user_tag where user_id = #{id}
    </delete>
    <select id="selectTagIdsByUserId" resultType="java.lang.Integer">
        select tag_id from t_user_tag where user_id = #{id}
    </select>
    <select id="selectTagNamesByUserId" resultType="java.lang.String">
        select name from t_tag where deleted = 0 and id in (select tag_id from t_user_tag where user_id = #{id})
    </select>
    <select id="selectCountById" resultType="java.lang.String">
        select user_name from t_user where id in (select user_id from t_user_tag where tag_id = #{id}) and deleted = 0
    </select>
</mapper>