| | |
| | | /* |
| | | * 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.*; |
| | | 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 java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.function.Function; |
| | | |
| | | /** |
| | | * @author 赵士淞 |
| | | * @website https://eladmin.vip |
| | | * @description 服务实现 |
| | | * @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 |
| | | public SysUserLevelOtherDto queryTargetYearMonth(SysUserLevelOtherQueryCriteria criteria) { |
| | | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.add(Calendar.YEAR, 1); |
| | | calendar.set(Calendar.MONTH, Calendar.JANUARY); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // 明年月初 |
| | | String nextYearMonth = sdf.format(calendar.getTime()); |
| | | // 查询级别其他,year_month大于等于选中的日期小于明年月初的日期 |
| | | SysUserLevelOther sysUserLevelOther = sysUserLevelOtherRepository.findByUserIdAndData(criteria.getUserId(), criteria.getTargetYearMonth().substring(0,7), nextYearMonth); |
| | | if (sysUserLevelOther == null) { |
| | | throw new BadRequestException("没有获取到当前员工的级别信息!"); |
| | | } |
| | | |
| | | return sysUserLevelOtherMapper.toDto(sysUserLevelOther); |
| | | } |
| | | |
| | | @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); |
| | | // } |
| | | |
| | | // 查询旧用户级别其他(新) |
| | | SysUserLevelOther oldSysUserLevelOther = selectOldUserLevelOther(resources.getUserId()); |
| | | // 判断旧用户级别其他是否为空 |
| | | if (oldSysUserLevelOther != null) { |
| | | // 旧日期字符串 |
| | | String oldDateString = oldSysUserLevelOther.getYearMonth(); |
| | | // 新日期字符串 |
| | | String newDateString = resources.getYearMonth(); |
| | | if (new SimpleDateFormat("yyyy-MM").parse(oldDateString).getTime() >= new SimpleDateFormat("yyyy-MM").parse(newDateString).getTime()) { |
| | | throw new BadRequestException("日期必须大于最新用户级别其他日期,请更换日期再试!"); |
| | | } |
| | | } |
| | | // 保存 |
| | | 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("未找到最新用户级别其他,请稍后再试!"); |
| | | // } |
| | | |
| | | // 查询旧用户级别其他(新) |
| | | SysUserLevelOther oldSysUserLevelOther = selectOldUserLevelOther(resources.getUserId()); |
| | | // 判断旧用户级别其他是否为空 |
| | | if (oldSysUserLevelOther != null) { |
| | | // 判断修改的是否是最新履历 |
| | | if (oldSysUserLevelOther.getId() != resources.getId()) { |
| | | throw new BadRequestException("旧用户级别其他无法进行修改,请选择最新用户级别其他再试!"); |
| | | } |
| | | // 旧日期字符串 |
| | | String oldDateString = oldSysUserLevelOther.getYearMonth(); |
| | | // 获取当前日期 |
| | | Date nowDate = new Date(); |
| | | // 创建Calendar实例 |
| | | Calendar nowCalendar = Calendar.getInstance(); |
| | | // 设置当前时间 |
| | | nowCalendar.setTime(nowDate); |
| | | // 新日期字符串 |
| | | String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0, 7); |
| | | // 判断新、旧日期字符串 |
| | | if (new SimpleDateFormat("yyyy-MM").parse(oldDateString).getTime() >= new SimpleDateFormat("yyyy-MM").parse(nowDateString).getTime()) { |
| | | // 复制 |
| | | oldSysUserLevelOther.copy(resources); |
| | | // 保存 |
| | | 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); |
| | | |
| | | // 旧用户级别其他(新) |
| | | SysUserLevelOther oldSysUserLevelOther = sysUserLevelOtherRepository.findByNewUserId(userId); |
| | | |
| | | // 判断旧用户级别其他是否为空 |
| | | if (oldSysUserLevelOther != null && oldSysUserLevelOther.getId() != null) { |
| | | return oldSysUserLevelOther; |
| | | } else { |
| | | return null; |
| | | } |
| | | } |
| | | /*
|
| | | * 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.modules.treatment.domain.CmnLevel;
|
| | | import me.zhengjie.modules.treatment.repository.CmnLevelRepository;
|
| | | import me.zhengjie.utils.*;
|
| | | 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 java.sql.Timestamp;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.*;
|
| | | import java.io.IOException;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import java.util.function.Function;
|
| | |
|
| | | /**
|
| | | * @author 赵士淞
|
| | | * @website https://eladmin.vip
|
| | | * @description 服务实现
|
| | | * @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;
|
| | | private final CmnLevelRepository cmnLevelRepository;
|
| | |
|
| | | @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查询级别信息
|
| | | CmnLevel sysLevel = cmnLevelRepository.findById(sysUserLevelOtherDto.getLevelId()).orElseGet(CmnLevel::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
|
| | | public SysUserLevelOtherDto queryTargetYearMonth(SysUserLevelOtherQueryCriteria criteria) {
|
| | |
|
| | | // 明年月初
|
| | | // 查询级别其他,year_month大于等于选中的日期小于明年月初的日期
|
| | | SysUserLevelOther sysUserLevelOther = sysUserLevelOtherRepository.findByUserIdAndData(criteria.getUserId(), criteria.getTargetYearMonth().substring(0,7) );
|
| | | if (sysUserLevelOther == null) {
|
| | | throw new BadRequestException("没有获取到当前员工的级别信息!");
|
| | | }
|
| | |
|
| | | return sysUserLevelOtherMapper.toDto(sysUserLevelOther);
|
| | | }
|
| | |
|
| | | @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);
|
| | | // }
|
| | |
|
| | | // // 查询旧用户级别其他(新)
|
| | | // SysUserLevelOther oldSysUserLevelOther = selectOldUserLevelOther(resources.getUserId());
|
| | | // // 判断旧用户级别其他是否为空
|
| | | // if (oldSysUserLevelOther != null) {
|
| | | // // 旧日期字符串
|
| | | // String oldDateString = oldSysUserLevelOther.getYearMonth();
|
| | | // // 新日期字符串
|
| | | // String newDateString = resources.getYearMonth();
|
| | | // if (new SimpleDateFormat("yyyy-MM").parse(oldDateString).getTime() >= new SimpleDateFormat("yyyy-MM").parse(newDateString).getTime()) {
|
| | | // throw new BadRequestException("日期必须大于最新用户级别其他日期,请更换日期再试!");
|
| | | // }
|
| | | // }
|
| | | // 保存
|
| | | resources.setStartDate(new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse(resources.getYearMonth() + "-01").getTime()));
|
| | | 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("未找到最新用户级别其他,请稍后再试!");
|
| | | // }
|
| | |
|
| | | // 查询旧用户级别其他(新)
|
| | | SysUserLevelOther oldSysUserLevelOther = selectOldUserLevelOther(resources.getUserId());
|
| | | // 判断旧用户级别其他是否为空
|
| | | if (oldSysUserLevelOther != null) {
|
| | | // 判断修改的是否是最新履历
|
| | | if (oldSysUserLevelOther.getId() != resources.getId()) {
|
| | | throw new BadRequestException("旧用户级别其他无法进行修改,请选择最新用户级别其他再试!");
|
| | | }
|
| | | // 旧日期字符串
|
| | | String oldDateString = oldSysUserLevelOther.getYearMonth();
|
| | | // 获取当前日期
|
| | | Date nowDate = new Date();
|
| | | // 创建Calendar实例
|
| | | Calendar nowCalendar = Calendar.getInstance();
|
| | | // 设置当前时间
|
| | | nowCalendar.setTime(nowDate);
|
| | | // 新日期字符串
|
| | | String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0, 7);
|
| | | // 判断新、旧日期字符串
|
| | | // if (new SimpleDateFormat("yyyy-MM").parse(oldDateString).getTime() >= new SimpleDateFormat("yyyy-MM").parse(nowDateString).getTime()) {
|
| | | // 复制
|
| | | oldSysUserLevelOther.copy(resources);
|
| | | // 保存
|
| | | 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);
|
| | |
|
| | | // 旧用户级别其他(新)
|
| | | SysUserLevelOther oldSysUserLevelOther = sysUserLevelOtherRepository.findByNewUserId(userId);
|
| | |
|
| | | // 判断旧用户级别其他是否为空
|
| | | if (oldSysUserLevelOther != null && oldSysUserLevelOther.getId() != null) {
|
| | | return oldSysUserLevelOther;
|
| | | } else {
|
| | | return null;
|
| | | }
|
| | | }
|
| | | } |