赵士淞
2022-12-26 251a76ff08c80e3c023b99b892dc612ff9614681
用户级别其他
10 files added
2 files modified
1030 ■■■■■ changed files
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/SysUserLevelOther.java 82 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/SysUserLevelOtherRepository.java 37 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/SysUserLevelOtherController.java 95 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/SysUserLevelOtherService.java 83 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/SysUserLevelOtherDto.java 62 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/SysUserLevelOtherQueryCriteria.java 37 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/SysUserLevelOtherServiceImpl.java 223 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java 59 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapstruct/SysUserLevelOtherMapper.java 32 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/api/system/userLevelOther.js 35 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/views/system/user/index.vue 16 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/views/system/userLevelOther/index.vue 269 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/SysUserLevelOther.java
New file
@@ -0,0 +1,82 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import me.zhengjie.base.BaseEntity;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://eladmin.vip
* @description /
* @author 赵士淞
* @date 2022-12-26
**/
@Entity
@Data
@Table(name="sys_user_level_other")
public class SysUserLevelOther extends BaseEntity implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    @ApiModelProperty(value = "ID")
    private Long id;
    @Column(name = "`user_id`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "用户ID")
    private Long userId;
    @Column(name = "`level_id`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "级别ID")
    private Long levelId;
    @Column(name = "`start_date`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "开始日期")
    private Timestamp startDate;
    @Column(name = "`end_date`")
    @ApiModelProperty(value = "结束日期")
    private Timestamp endDate;
    @Column(name = "`personal_performance_proportion`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "个人业绩比例")
    private Double personalPerformanceProportion;
    @Column(name = "`annual_leave_days`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "年假天数")
    private Integer annualLeaveDays;
    @Column(name = "`remarks`")
    @ApiModelProperty(value = "备注")
    private String remarks;
    public void copy(SysUserLevelOther source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/SysUserLevelOtherRepository.java
New file
@@ -0,0 +1,37 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.repository;
import me.zhengjie.modules.system.domain.SysUserLevelOther;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
/**
* @website https://eladmin.vip
* @author 赵士淞
* @date 2022-12-26
**/
public interface SysUserLevelOtherRepository extends JpaRepository<SysUserLevelOther, Long>, JpaSpecificationExecutor<SysUserLevelOther> {
    /**
     * 根据用户ID查询最新记录
     * @param userId /
     * @return /
     */
    @Query(value = "SELECT * FROM sys_user_level_other WHERE user_id = ?1 ORDER BY start_date DESC, create_time DESC LIMIT 1", nativeQuery = true)
    SysUserLevelOther findLastByUserId(Long userId);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/SysUserLevelOtherController.java
New file
@@ -0,0 +1,95 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.rest;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.system.domain.SysUserLevelOther;
import me.zhengjie.modules.system.service.SysUserLevelOtherService;
import me.zhengjie.modules.system.service.dto.SysUserLevelOtherQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @author 赵士淞
* @date 2022-12-26
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "用户级别其他管理")
@RequestMapping("/api/sysUserLevelOther")
public class SysUserLevelOtherController {
    private final SysUserLevelOtherService sysUserLevelOtherService;
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sysUserLevelOther:download')")
    public void exportSysUserLevelOther(HttpServletResponse response, SysUserLevelOtherQueryCriteria criteria) throws IOException {
        sysUserLevelOtherService.download(sysUserLevelOtherService.queryAll(criteria), response);
    }
    @GetMapping
    @Log("查询用户级别其他")
    @ApiOperation("查询用户级别其他")
    @PreAuthorize("@el.check('sysUserLevelOther:list')")
    public ResponseEntity<Object> querySysUserLevelOther(SysUserLevelOtherQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(sysUserLevelOtherService.queryAll(criteria,pageable),HttpStatus.OK);
    }
    @GetMapping(value = "/all")
    @Log("查询用户级别其他")
    @ApiOperation("查询用户级别其他")
    @PreAuthorize("@el.check('sysUserLevelOther:list')")
    public ResponseEntity<Object> querySysUserLevelOther(SysUserLevelOtherQueryCriteria criteria){
        return new ResponseEntity<>(sysUserLevelOtherService.queryAll(criteria),HttpStatus.OK);
    }
    @PostMapping
    @Log("新增用户级别其他")
    @ApiOperation("新增用户级别其他")
    @PreAuthorize("@el.check('sysUserLevelOther:add')")
    public ResponseEntity<Object> createSysUserLevelOther(@Validated @RequestBody SysUserLevelOther resources) throws Exception{
        return new ResponseEntity<>(sysUserLevelOtherService.create(resources),HttpStatus.CREATED);
    }
    @PutMapping
    @Log("修改用户级别其他")
    @ApiOperation("修改用户级别其他")
    @PreAuthorize("@el.check('sysUserLevelOther:edit')")
    public ResponseEntity<Object> updateSysUserLevelOther(@Validated @RequestBody SysUserLevelOther resources) throws Exception{
        sysUserLevelOtherService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    @DeleteMapping
    @Log("删除用户级别其他")
    @ApiOperation("删除用户级别其他")
    @PreAuthorize("@el.check('sysUserLevelOther:del')")
    public ResponseEntity<Object> deleteSysUserLevelOther(@RequestBody Long[] ids) {
        sysUserLevelOtherService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/SysUserLevelOtherService.java
New file
@@ -0,0 +1,83 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.SysUserLevelOther;
import me.zhengjie.modules.system.service.dto.SysUserLevelOtherDto;
import me.zhengjie.modules.system.service.dto.SysUserLevelOtherQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @description 服务接口
* @author 赵士淞
* @date 2022-12-26
**/
public interface SysUserLevelOtherService {
    /**
    * 查询数据分页
    * @param criteria 条件
    * @param pageable 分页参数
    * @return Map<String,Object>
    */
    Map<String,Object> queryAll(SysUserLevelOtherQueryCriteria criteria, Pageable pageable);
    /**
    * 查询所有数据不分页
    * @param criteria 条件参数
    * @return List<SysUserLevelOtherDto>
    */
    List<SysUserLevelOtherDto> queryAll(SysUserLevelOtherQueryCriteria criteria);
    /**
     * 根据ID查询
     * @param id ID
     * @return SysUserLevelOtherDto
     */
    SysUserLevelOtherDto findById(Long id);
    /**
    * 创建
    * @param resources /
    * @return SysUserLevelOtherDto
    */
    SysUserLevelOtherDto create(SysUserLevelOther resources) throws Exception;
    /**
    * 编辑
    * @param resources /
    */
    void update(SysUserLevelOther resources) throws Exception;
    /**
    * 多选删除
    * @param ids /
    */
    void deleteAll(Long[] ids);
    /**
    * 导出数据
    * @param all 待导出的数据
    * @param response /
    * @throws IOException /
    */
    void download(List<SysUserLevelOtherDto> all, HttpServletResponse response) throws IOException;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/SysUserLevelOtherDto.java
New file
@@ -0,0 +1,62 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.service.dto;
import lombok.Data;
import me.zhengjie.base.BaseDTO;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://eladmin.vip
* @description /
* @author 赵士淞
* @date 2022-12-26
**/
@Data
public class SysUserLevelOtherDto extends BaseDTO implements Serializable {
    /** ID */
    private Long id;
    /** 用户ID */
    private Long userId;
    /** 级别ID */
    private Long levelId;
    /** 开始日期 */
    private Timestamp startDate;
    /** 结束日期 */
    private Timestamp endDate;
    /** 个人业绩比例 */
    private Double personalPerformanceProportion;
    /** 年假天数 */
    private Integer annualLeaveDays;
    /** 备注 */
    private String remarks;
    /** 用户昵称 */
    private String userNickName;
    /** 级别名称 */
    private String levelName;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/SysUserLevelOtherQueryCriteria.java
New file
@@ -0,0 +1,37 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.service.dto;
import lombok.Data;
import java.util.List;
import me.zhengjie.annotation.Query;
/**
* @website https://eladmin.vip
* @author 赵士淞
* @date 2022-12-26
**/
@Data
public class SysUserLevelOtherQueryCriteria{
    /** 精确 */
    @Query
    private Long userId;
    /** 精确 */
    @Query
    private Long levelId;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/SysUserLevelOtherServiceImpl.java
New file
@@ -0,0 +1,223 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.SysLevel;
import me.zhengjie.modules.system.domain.SysUserLevelOther;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.repository.SysLevelRepository;
import me.zhengjie.modules.system.repository.UserRepository;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.system.repository.SysUserLevelOtherRepository;
import me.zhengjie.modules.system.service.SysUserLevelOtherService;
import me.zhengjie.modules.system.service.dto.SysUserLevelOtherDto;
import me.zhengjie.modules.system.service.dto.SysUserLevelOtherQueryCriteria;
import me.zhengjie.modules.system.service.mapstruct.SysUserLevelOtherMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.function.Function;
/**
* @website https://eladmin.vip
* @description 服务实现
* @author 赵士淞
* @date 2022-12-26
**/
@Service
@RequiredArgsConstructor
public class SysUserLevelOtherServiceImpl implements SysUserLevelOtherService {
    private final SysUserLevelOtherRepository sysUserLevelOtherRepository;
    private final SysUserLevelOtherMapper sysUserLevelOtherMapper;
    private final UserRepository userRepository;
    private final SysLevelRepository sysLevelRepository;
    @Override
    public Map<String,Object> queryAll(SysUserLevelOtherQueryCriteria criteria, Pageable pageable){
        Page<SysUserLevelOther> page = sysUserLevelOtherRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
        // 将实体类转换为DTO(重写)
        Function<SysUserLevelOther, SysUserLevelOtherDto> func = new Function<SysUserLevelOther, SysUserLevelOtherDto>(){
            @Override
            public SysUserLevelOtherDto apply(SysUserLevelOther t) {
                // 将实体类转换成DTO
                SysUserLevelOtherDto sysUserLevelOtherDto = sysUserLevelOtherMapper.toDto(t);
                // 根据用户ID查询用户信息
                User user = userRepository.findById(sysUserLevelOtherDto.getUserId()).orElseGet(User::new);
                ValidationUtil.isNull(user.getId(),"User","id",sysUserLevelOtherDto.getUserId());
                // 用户昵称
                sysUserLevelOtherDto.setUserNickName(user.getNickName());
                // 根据级别ID查询级别信息
                SysLevel sysLevel = sysLevelRepository.findById(sysUserLevelOtherDto.getLevelId()).orElseGet(SysLevel::new);
                ValidationUtil.isNull(sysLevel.getId(),"SysLevel","id",sysUserLevelOtherDto.getLevelId());
                // 级别名称
                sysUserLevelOtherDto.setLevelName(sysLevel.getName());
                // 返回处理好的DTO
                return sysUserLevelOtherDto;
            }
        };
        return PageUtil.toPage(page.map(func));
    }
    @Override
    public List<SysUserLevelOtherDto> queryAll(SysUserLevelOtherQueryCriteria criteria){
        return sysUserLevelOtherMapper.toDto(sysUserLevelOtherRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
    }
    @Override
    @Transactional
    public SysUserLevelOtherDto findById(Long id) {
        SysUserLevelOther sysUserLevelOther = sysUserLevelOtherRepository.findById(id).orElseGet(SysUserLevelOther::new);
        ValidationUtil.isNull(sysUserLevelOther.getId(),"SysUserLevelOther","id",id);
        return sysUserLevelOtherMapper.toDto(sysUserLevelOther);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public SysUserLevelOtherDto create(SysUserLevelOther resources) throws Exception {
        // 查询旧用户级别其他
        SysUserLevelOther oldSysUserLevelOther = selectOldUserLevelOther(resources.getUserId());
        // 判断旧用户级别其他是否为空
        if (oldSysUserLevelOther != null) {
            // 旧日期字符串
            String oldDateString = oldSysUserLevelOther.getStartDate().toString().substring(0,10);
            // 新日期字符串
            String newDateString = resources.getStartDate().toString().substring(0,10);
            // 判断新、旧日期字符串
            if (oldDateString.equals(newDateString)) {
                throw new BadRequestException("每天只能调整一次用户级别其他,请更换日期再试!");
            }
            if (new SimpleDateFormat("yyyy-MM-dd").parse(oldDateString).getTime() >= new SimpleDateFormat("yyyy-MM-dd").parse(newDateString).getTime()) {
                throw new BadRequestException("日期必须大于最新用户级别其他日期,请更换日期再试!");
            }
            // 创建Calendar实例
            Calendar previousCalendar = Calendar.getInstance();
            // 设置新日期时间
            previousCalendar.setTime(resources.getStartDate());
            // 设置前一天时间
            previousCalendar.add(Calendar.DATE, -1);
            // 旧用户级别其他
            oldSysUserLevelOther.setEndDate(new Timestamp(previousCalendar.getTime().getTime()));
            // 保存
            sysUserLevelOtherRepository.save(oldSysUserLevelOther);
        }
        // 保存
        return sysUserLevelOtherMapper.toDto(sysUserLevelOtherRepository.save(resources));
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(SysUserLevelOther resources) throws Exception {
        // 查询旧用户级别其他
        SysUserLevelOther oldSysUserLevelOther = selectOldUserLevelOther(resources.getUserId());
        // 判断旧用户级别其他是否为空
        if (oldSysUserLevelOther != null) {
            // 判断修改的是否是最新履历
            if (oldSysUserLevelOther.getId() != resources.getId()) {
                throw new BadRequestException("旧用户级别其他无法进行修改,请选择最新用户级别其他再试!");
            }
            // 旧日期字符串
            String oldDateString = oldSysUserLevelOther.getStartDate().toString().substring(0,10);
            // 获取当前日期
            Date nowDate = new Date();
            // 创建Calendar实例
            Calendar nowCalendar = Calendar.getInstance();
            // 设置当前时间
            nowCalendar.setTime(nowDate);
            // 新日期字符串
            String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0,10);
            // 判断新、旧日期字符串
            if (new SimpleDateFormat("yyyy-MM-dd").parse(oldDateString).getTime() >= new SimpleDateFormat("yyyy-MM-dd").parse(nowDateString).getTime()) {
                // 复制
                oldSysUserLevelOther.copy(resources);
                // 保存
                sysUserLevelOtherRepository.save(oldSysUserLevelOther);
            } else {
                // 新用户级别其他
                resources.setId(null);
                resources.setStartDate(new Timestamp(nowCalendar.getTime().getTime()));
                // 保存
                sysUserLevelOtherRepository.save(resources);
                // 设置前一天时间
                nowCalendar.add(Calendar.DATE, -1);
                // 旧用户级别其他
                oldSysUserLevelOther.setEndDate(new Timestamp(nowCalendar.getTime().getTime()));
                // 保存
                sysUserLevelOtherRepository.save(oldSysUserLevelOther);
            }
        } else {
            throw new BadRequestException("未找到最新用户级别其他,请稍后再试!");
        }
    }
    @Override
    public void deleteAll(Long[] ids) {
        for (Long id : ids) {
            sysUserLevelOtherRepository.deleteById(id);
        }
    }
    @Override
    public void download(List<SysUserLevelOtherDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (SysUserLevelOtherDto sysUserLevelOther : all) {
            String nickName = sysUserLevelOther.getUserId() != null ? userRepository.findById(sysUserLevelOther.getUserId()).orElseGet(User::new).getNickName() : "";
            String levelName = sysUserLevelOther.getLevelId() != null ? sysLevelRepository.findById(sysUserLevelOther.getLevelId()).orElseGet(SysLevel::new).getName() : "";
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("用户昵称", nickName);
            map.put("级别名称", levelName);
            map.put("开始日期", sysUserLevelOther.getStartDate());
            map.put("结束日期", sysUserLevelOther.getEndDate());
            map.put("个人业绩比例", sysUserLevelOther.getPersonalPerformanceProportion());
            map.put("年假天数", sysUserLevelOther.getAnnualLeaveDays());
            map.put("备注", sysUserLevelOther.getRemarks());
            map.put("创建者", sysUserLevelOther.getCreateBy());
            map.put("创建时间", sysUserLevelOther.getCreateTime());
            map.put("更新者", sysUserLevelOther.getUpdateBy());
            map.put("更新时间", sysUserLevelOther.getUpdateTime());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
    /**
     * 查询旧用户级别其他
     * @param userId
     * @return
     */
    private SysUserLevelOther selectOldUserLevelOther(Long userId) {
        // 旧用户级别其他
        SysUserLevelOther oldSysUserLevelOther = sysUserLevelOtherRepository.findLastByUserId(userId);
        // 判断旧用户级别其他是否为空
        if (oldSysUserLevelOther != null && oldSysUserLevelOther.getId() != null) {
            return oldSysUserLevelOther;
        } else {
            return null;
        }
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
@@ -20,16 +20,10 @@
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.security.service.OnlineUserService;
import me.zhengjie.modules.security.service.UserCacheManager;
import me.zhengjie.modules.system.domain.SysLevel;
import me.zhengjie.modules.system.domain.SysUserLevelInsurance;
import me.zhengjie.modules.system.domain.SysUserLevelWage;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.domain.*;
import me.zhengjie.exception.EntityExistException;
import me.zhengjie.exception.EntityNotFoundException;
import me.zhengjie.modules.system.repository.SysLevelRepository;
import me.zhengjie.modules.system.repository.SysUserLevelInsuranceRepository;
import me.zhengjie.modules.system.repository.SysUserLevelWageRepository;
import me.zhengjie.modules.system.repository.UserRepository;
import me.zhengjie.modules.system.repository.*;
import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.*;
import me.zhengjie.modules.system.service.mapstruct.SysUserLevelWageMapper;
@@ -70,6 +64,7 @@
    private final SysLevelRepository sysLevelRepository;
    private final SysUserLevelWageRepository sysUserLevelWageRepository;
    private final SysUserLevelInsuranceRepository sysUserLevelInsuranceRepository;
    private final SysUserLevelOtherRepository sysUserLevelOtherRepository;
    @Override
    public Object queryAll(UserQueryCriteria criteria, Pageable pageable) {
@@ -319,6 +314,8 @@
            createSysUserLevelWage(userId, newLevelId);
            // 创建用户级别保险
            createSysUserLevelInsurance(userId, newLevelId);
            // 创建用户级别其他
            createSysUserLevelOther(userId, newLevelId);
        } else if (oldLevelId != newLevelId) {
            // 旧用户级别工资
            SysUserLevelWage oldSysUserLevelWage = sysUserLevelWageRepository.findLastByUserId(userId);
@@ -374,6 +371,33 @@
            }
            // 创建用户级别保险
            createSysUserLevelInsurance(userId, newLevelId);
            // 旧用户级别其他
            SysUserLevelOther oldSysUserLevelOther = sysUserLevelOtherRepository.findLastByUserId(userId);
            // 判断旧用户级别其他是否为空
            if (oldSysUserLevelOther != null && oldSysUserLevelOther.getId() != null) {
                // 旧日期字符串
                String oldDateString = oldSysUserLevelOther.getStartDate().toString().substring(0,10);
                // 获取当前日期
                Date nowDate = new Date();
                // 创建Calendar实例
                Calendar nowCalendar = Calendar.getInstance();
                // 设置当前时间
                nowCalendar.setTime(nowDate);
                // 新日期字符串
                String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0,10);
                // 判断新、旧日期字符串
                if (oldDateString.equals(nowDateString)) {
                    throw new BadRequestException("每天只能调整一次级别,请明日再试!");
                }
                // 设置前一天时间
                nowCalendar.add(Calendar.DATE, -1);
                // 旧用户级别保险
                oldSysUserLevelOther.setEndDate(new Timestamp(nowCalendar.getTime().getTime()));
                // 保存
                sysUserLevelOtherRepository.save(oldSysUserLevelOther);
            }
            // 创建用户级别其他
            createSysUserLevelOther(userId, newLevelId);
        } else {
        }
@@ -431,4 +455,23 @@
        // 保存
        sysUserLevelInsuranceRepository.save(sysUserLevelInsurance);
    }
    /**
     * 创建用户级别其他
     * @param userId
     * @param levelId
     */
    private void createSysUserLevelOther(Long userId, Long levelId) {
        // 级别
        SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new);
        // 用户级别其他
        SysUserLevelOther sysUserLevelOther = new SysUserLevelOther();
        sysUserLevelOther.setUserId(userId);
        sysUserLevelOther.setLevelId(levelId);
        sysUserLevelOther.setStartDate(new Timestamp(new Date().getTime()));
        sysUserLevelOther.setPersonalPerformanceProportion(sysLevel.getPersonalPerformanceProportion());
        sysUserLevelOther.setAnnualLeaveDays(sysLevel.getAnnualLeaveDays());
        // 保存
        sysUserLevelOtherRepository.save(sysUserLevelOther);
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapstruct/SysUserLevelOtherMapper.java
New file
@@ -0,0 +1,32 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.service.mapstruct;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.system.domain.SysUserLevelOther;
import me.zhengjie.modules.system.service.dto.SysUserLevelOtherDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @website https://eladmin.vip
* @author 赵士淞
* @date 2022-12-26
**/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface SysUserLevelOtherMapper extends BaseMapper<SysUserLevelOtherDto, SysUserLevelOther> {
}
eladmin-web-master/src/api/system/userLevelOther.js
New file
@@ -0,0 +1,35 @@
import request from '@/utils/request'
export function getAll(params) {
  return request({
    url: 'api/sysUserLevelOther/all',
    method: 'get',
    params
  })
}
export function add(data) {
  return request({
    url: 'api/sysUserLevelOther',
    method: 'post',
    data
  })
}
export function del(ids) {
  return request({
    url: 'api/sysUserLevelOther/',
    method: 'delete',
    data: ids
  })
}
export function edit(data) {
  return request({
    url: 'api/sysUserLevelOther',
    method: 'put',
    data
  })
}
export default { getAll, add, edit, del }
eladmin-web-master/src/views/system/user/index.vue
@@ -79,6 +79,17 @@
            >
              用户级别保险
            </el-button>
            <el-button
              slot="right"
              class="filter-item"
              size="mini"
              type="info"
              icon="el-icon-view"
              style="margin-left: 4px !important;"
              @click="toLevelOther"
            >
              用户级别其他
            </el-button>
          </crudOperation>
        </div>
        <!--表单渲染-->
@@ -602,6 +613,11 @@
    toLevelInsurance() {
      // 跳转页面
      this.$router.push({ path: '/system/sysUserLevelInsurance' })
    },
    // 去用户级别其他
    toLevelOther() {
      // 跳转页面
      this.$router.push({ path: '/system/sysUserLevelOther' })
    }
  }
}
eladmin-web-master/src/views/system/userLevelOther/index.vue
New file
@@ -0,0 +1,269 @@
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-select v-model="query.userId" filterable clearable placeholder="所属用户" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in users"
            :key="item.id"
            :label="item.nickName"
            :value="item.id"
          />
        </el-select>
        <el-select v-model="query.levelId" filterable clearable placeholder="所属级别" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in levels"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">
          <el-form-item label="所属用户" prop="userId">
            <el-select v-model="form.userId" filterable clearable placeholder="所属用户" style="width: 340px;">
              <el-option
                v-for="item in users"
                :key="item.id"
                :label="item.nickName"
                :value="item.id"
                :disabled="!item.enabled"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="所属级别" prop="levelId">
            <el-select v-model="form.levelId" filterable clearable placeholder="所属级别" style="width: 340px;" @change="levelChange">
              <el-option
                v-for="item in levels"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="开始日期" prop="startDate">
            <el-date-picker v-model="form.startDate" type="date" :picker-options="startDatePickerOptions" :disabled="crud.status.edit == crudStatusPrepared" style="width: 340px;" />
          </el-form-item>
          <el-form-item label="结束日期">
            <el-date-picker v-model="form.endDate" type="date" :picker-options="endDatePickerOptions" style="width: 340px;" />
          </el-form-item>
          <el-form-item label="个人业绩比例" prop="personalPerformanceProportion">
            <el-input v-model="form.personalPerformanceProportion" style="width: 340px;">
              <template slot="append">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="年假天数" prop="annualLeaveDays">
            <el-input v-model="form.annualLeaveDays" style="width: 340px;">
              <template slot="append">天</template>
            </el-input>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 340px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column :show-overflow-tooltip="true" prop="userNickName" label="所属用户">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.userNickName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="levelName" label="所属级别">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.levelName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="startDate" label="开始日期">
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.startDate) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="endDate" label="结束日期">
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.endDate) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="personalPerformanceProportion" label="个人业绩比例">
          <template slot-scope="scope">
            {{ scope.row.personalPerformanceProportion }}%
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="annualLeaveDays" label="年假天数">
          <template slot-scope="scope">
            {{ scope.row.annualLeaveDays }}天
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注" />
        <el-table-column :show-overflow-tooltip="true" prop="createTime" label="创建时间" />
        <el-table-column v-if="checkPer(['admin','sysUserLevelOther:edit','sysUserLevelOther:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
<script>
import crudSysUserLevelOther from '@/api/system/userLevelOther'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import crudUser from '@/api/system/user'
import crudLevel from '@/api/system/level'
const defaultForm = { id: null, userId: null, levelId: null, startDate: null, endDate: null, personalPerformanceProportion: null, annualLeaveDays: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
  name: 'SysUserLevelOther',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '用户级别其他', url: 'api/sysUserLevelOther', idField: 'id', sort: 'id,desc', crudMethod: { ...crudSysUserLevelOther }})
  },
  data() {
    // 指针重指向
    const _this = this
    // 比例(百内)验证
    var proportionValidate = (rule, value, callback) => {
      const reg = /^([0-9]|[1-9]\d)(\.\d{1,2})?$|100$/
      if (value != null && value !== '' && !reg.test(value)) {
        callback(new Error('请输入 一百 以内的正整数或两位小数'))
      } else {
        callback()
      }
    }
    // 天数(二十内)验证
    var daysValidate = (rule, value, callback) => {
      const reg = /^([0-9]|1\d)$|20$/
      if (value != null && value !== '' && !reg.test(value)) {
        callback(new Error('请输入 二十 以内的正整数'))
      } else {
        callback()
      }
    }
    return {
      permission: {
        add: ['admin', 'sysUserLevelOther:add'],
        edit: ['admin', 'sysUserLevelOther:edit'],
        del: ['admin', 'sysUserLevelOther:del'],
        download: ['admin', 'sysUserLevelOther:download']
      },
      rules: {
        userId: [
          { required: true, message: '所属用户不能为空', trigger: 'change' }
        ],
        levelId: [
          { required: true, message: '所属级别不能为空', trigger: 'change' }
        ],
        startDate: [
          { required: true, message: '开始日期不能为空', trigger: 'change' }
        ],
        personalPerformanceProportion: [
          { required: true, message: '个人业绩比例不能为空', trigger: 'blur' },
          { validator: proportionValidate, trigger: 'blur' }
        ],
        annualLeaveDays: [
          { required: true, message: '年假天数不能为空', trigger: 'blur' },
          { validator: daysValidate, trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'userId', display_name: '所属用户' },
        { key: 'levelId', display_name: '所属级别' }
      ],
      // 开始日期选项
      startDatePickerOptions: {
        // 禁用日期
        disabledDate(time) {
          return _this.form.endDate != null && _this.form.endDate !== '' ? time.getTime() > _this.form.endDate : false
        }
      },
      // 结束日期选项
      endDatePickerOptions: {
        // 禁用日期
        disabledDate(time) {
          return _this.form.startDate != null && _this.form.startDate !== '' ? time.getTime() < _this.form.startDate : false
        }
      },
      // CRUD状态
      crudStatusPrepared: CRUD.STATUS.PREPARED,
      // 用户列表
      users: [],
      // 级别列表
      levels: [],
      // 随机数
      random: 0
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      // 获取用户
      this.getUser()
      // 获取级别
      this.getLevel()
      return true
    },
    // 获取用户
    getUser() {
      // 获取用户
      crudUser.getAll().then(res => {
        // 用户列表
        this.users = res
      })
    },
    // 获取级别
    getLevel() {
      // 获取级别
      crudLevel.getAll().then(res => {
        // 级别列表
        this.levels = res
      })
    },
    // 钩子: 开始 "新建/编辑" - 之前
    [CRUD.HOOK.beforeToCU]() {
      // 随机数
      this.random = Math.random()
    },
    // 级别改变
    levelChange() {
      // 循环级别列表
      for (const item in this.levels) {
        // 判断级别
        if (this.levels[item].id === this.form.levelId) {
          // 表单赋值
          this.form.personalPerformanceProportion = this.levels[item].personalPerformanceProportion
          this.form.annualLeaveDays = this.levels[item].annualLeaveDays
          // 随机数
          this.random = Math.random()
        }
      }
    }
  }
}
</script>
<style scoped>
</style>