From 0766c42639d0e9b12d8dc2f93589b4713ced57a6 Mon Sep 17 00:00:00 2001
From: weicd <weicd@yhzhg.cn>
Date: Fri, 27 Dec 2024 07:19:36 +0000
Subject: [PATCH] 修改
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/SysUserLevelOtherServiceImpl.java | 111 ++++++++++++++++++++++++++-----------------------------
1 files changed, 53 insertions(+), 58 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/SysUserLevelOtherServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/SysUserLevelOtherServiceImpl.java
index 8337a54..babbb61 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/SysUserLevelOtherServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/SysUserLevelOtherServiceImpl.java
@@ -1,18 +1,18 @@
/*
-* 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.
-*/
+ * 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;
@@ -21,6 +21,8 @@
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;
@@ -41,11 +43,11 @@
import java.util.function.Function;
/**
-* @website https://eladmin.vip
-* @description 服务实现
-* @author 赵士淞
-* @date 2022-12-26
-**/
+ * @author 赵士淞
+ * @website https://eladmin.vip
+ * @description 服务实现
+ * @date 2022-12-26
+ **/
@Service
@RequiredArgsConstructor
public class SysUserLevelOtherServiceImpl implements SysUserLevelOtherService {
@@ -54,24 +56,25 @@
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);
+ 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>(){
+ 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());
+ 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());
+ CmnLevel sysLevel = cmnLevelRepository.findById(sysUserLevelOtherDto.getLevelId()).orElseGet(CmnLevel::new);
+ ValidationUtil.isNull(sysLevel.getId(), "SysLevel", "id", sysUserLevelOtherDto.getLevelId());
// 级别名称
sysUserLevelOtherDto.setLevelName(sysLevel.getName());
// 返回处理好的DTO
@@ -82,27 +85,20 @@
}
@Override
- public List<SysUserLevelOtherDto> queryAll(SysUserLevelOtherQueryCriteria criteria){
- return sysUserLevelOtherMapper.toDto(sysUserLevelOtherRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
+ 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){
- // 国际时间转中国时间
- String targetYearMonth = DateUtil.internationalTimeToChinaTime(criteria.getTargetYearMonth());
- // 获取某年某月最后一天
- String lastDayOfTargetYearMonth = DateUtil.getLastDayOfMonth(targetYearMonth);
-// // 根据用户ID、指定年月查询
-// SysUserLevelOther sysUserLevelOther = sysUserLevelOtherRepository.findTargetYearMonth(criteria.getUserId(), lastDayOfTargetYearMonth);
+ public SysUserLevelOtherDto queryTargetYearMonth(SysUserLevelOtherQueryCriteria criteria) {
- // 根据用户ID、指定年月查询(新)
- SysUserLevelOther sysUserLevelOther = sysUserLevelOtherRepository.findYearMonth(criteria.getUserId(), lastDayOfTargetYearMonth);
-
- // 判断查询结果
+ // 明年月初
+ // 查询级别其他,year_month大于等于选中的日期小于明年月初的日期
+ SysUserLevelOther sysUserLevelOther = sysUserLevelOtherRepository.findByUserIdAndData(criteria.getUserId(), criteria.getTargetYearMonth().substring(0,7) );
if (sysUserLevelOther == null) {
throw new BadRequestException("没有获取到当前员工的级别信息!");
}
- // 返回
+
return sysUserLevelOtherMapper.toDto(sysUserLevelOther);
}
@@ -110,7 +106,7 @@
@Transactional
public SysUserLevelOtherDto findById(Long id) {
SysUserLevelOther sysUserLevelOther = sysUserLevelOtherRepository.findById(id).orElseGet(SysUserLevelOther::new);
- ValidationUtil.isNull(sysUserLevelOther.getId(),"SysUserLevelOther","id",id);
+ ValidationUtil.isNull(sysUserLevelOther.getId(), "SysUserLevelOther", "id", id);
return sysUserLevelOtherMapper.toDto(sysUserLevelOther);
}
@@ -144,20 +140,18 @@
// 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("日期必须大于最新用户级别其他日期,请更换日期再试!");
- }
- // 保存
-// 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));
}
@@ -223,14 +217,14 @@
// 设置当前时间
nowCalendar.setTime(nowDate);
// 新日期字符串
- String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0,7);
+ 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()) {
+// 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("未找到最新用户级别其他,请稍后再试!");
}
@@ -249,7 +243,7 @@
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<String, Object> map = new LinkedHashMap<>();
map.put("用户昵称", nickName);
map.put("级别名称", levelName);
map.put("开始日期", sysUserLevelOther.getStartDate());
@@ -268,6 +262,7 @@
/**
* 查询旧用户级别其他
+ *
* @param userId
* @return
*/
--
Gitblit v1.9.3