From eaf14dd28b5c95a08d433c6b6ccb5d2c0de2a2d4 Mon Sep 17 00:00:00 2001
From: weicd <weicd@yhzhg.cn>
Date: Thu, 04 Jan 2024 01:51:15 +0000
Subject: [PATCH] 首页跳转日报
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java | 1115 +++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 899 insertions(+), 216 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
index 5d2acc3..5920753 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
@@ -39,25 +39,39 @@
import me.zhengjie.modules.system.service.dto.*;
import me.zhengjie.modules.system.service.mapstruct.UserLoginMapper;
import me.zhengjie.modules.system.service.mapstruct.UserMapper;
-import me.zhengjie.modules.task.domain.TaskDaliy;
+import me.zhengjie.modules.task.domain.TaskDaliyMongo;
+import me.zhengjie.modules.task.domain.TaskMongo;
import me.zhengjie.modules.task.repository.TaskDaliyRepository;
import me.zhengjie.modules.task.service.TaskDaliyService;
import me.zhengjie.modules.task.service.dto.TaskDaliyQueryCriteria;
+import me.zhengjie.modules.treatment.domain.*;
+import me.zhengjie.modules.treatment.repository.*;
+import me.zhengjie.modules.treatment.rest.CmnInsuranceController;
import me.zhengjie.utils.*;
import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheConfig;
+import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
+
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.sql.Timestamp;
+import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
@@ -99,6 +113,18 @@
private final SysCompanyRepository sysCompanyRepository;
private final TaskDaliyService taskDaliyService;
private final DeptRepository deptRepository;
+ private final MeritLevelRepository meritLevelRepository;
+ private final CmnLevelRepository cmnLevelRepository;
+ private final MeritWageRepository meritWageRepository;
+ private final CmnLevelRankRepository cmnLevelRankRepository;
+ private final CmnInsuranceRepository cmnInsuranceRepository;
+
+ private final MongoTemplate mongoTemplate;
+ private final UserLevelWageRepository userLevelWageRepository;
+ private final UserInsuranceRepository userInsuranceRepository;
+
+ @Autowired
+ private CacheManager cacheManager;
@Override
public Object queryAll(UserQueryCriteria criteria, Pageable pageable) {
@@ -108,34 +134,582 @@
@Override
public List<DeptUserNodeDto> queryDeptUserByDeptId(Long deptId) {
- List<DeptUserNodeDto> result = new ArrayList<DeptUserNodeDto>();
- Optional<Dept> deptOpt = deptRepository.findById(deptId);
- if (deptOpt.isPresent()) {
- Dept dept = deptOpt.get();
- List<Dept> subDeptList = deptRepository.findByPid(deptId);
- subDeptList.forEach(subDept -> {
- DeptUserNodeDto deptUserNodeDto = new DeptUserNodeDto();
- deptUserNodeDto.setId(subDept.getId());
- deptUserNodeDto.setLabel(subDept.getName());
- deptUserNodeDto.setLeaf(false);
- result.add(deptUserNodeDto);
- });
- List<User> userList = userRepository.findByDeptAndEnabled(dept, true);
- userList.forEach(user -> {
- DeptUserNodeDto deptUserNodeDto = new DeptUserNodeDto();
- deptUserNodeDto.setId(user.getId());
- deptUserNodeDto.setLabel(user.getNickName());
- deptUserNodeDto.setLeaf(true);
- result.add(deptUserNodeDto);
- });
- }
- return result;
+ List<DeptUserNodeDto> result = new ArrayList<DeptUserNodeDto>();
+ Optional<Dept> deptOpt = deptRepository.findById(deptId);
+ if (deptOpt.isPresent()) {
+ Dept dept = deptOpt.get();
+ List<Dept> subDeptList = deptRepository.findByPid(deptId);
+ subDeptList.forEach(subDept -> {
+ DeptUserNodeDto deptUserNodeDto = new DeptUserNodeDto();
+ deptUserNodeDto.setId(subDept.getId());
+ deptUserNodeDto.setLabel(subDept.getName());
+ deptUserNodeDto.setLeaf(false);
+ result.add(deptUserNodeDto);
+ });
+ List<User> userList = userRepository.findByDeptAndEnabled(dept, true);
+ userList.forEach(user -> {
+ DeptUserNodeDto deptUserNodeDto = new DeptUserNodeDto();
+ deptUserNodeDto.setId(user.getId());
+ deptUserNodeDto.setLabel(user.getNickName());
+ deptUserNodeDto.setLeaf(true);
+ result.add(deptUserNodeDto);
+ });
+ }
+ return result;
}
@Override
+ public List<UserDto> getUserByTaskId(String taskId) {
+ // 日历类
+ Calendar calendar = Calendar.getInstance();
+ // 日期格式化
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ // 日历字符串
+ String calendarStr = sdf.format(calendar.getTime());
+
+ TaskMongo taskMongo = mongoTemplate.findById(taskId, TaskMongo.class);
+
+ List<Long> containUserList = taskMongo.getContainUserList();
+ List<User> userList = new ArrayList<>();
+ if (containUserList.size() != 0) {
+ for (Long userId : containUserList) {
+ userList.add(userRepository.findById(userId).get());
+ }
+ }
+ List<UserDto> userDto = userMapper.toDto(userList);
+ for (int i = 0; i < userDto.size(); i++) {
+ // 根据用户ID、指定年月查询用户级别工资
+ SysUserLevelWage sysUserLevelWage = sysUserLevelWageRepository.findTargetYearMonth(userDto.get(i).getId(), calendarStr);
+ // 判断用户级别工资是否为空
+ if (sysUserLevelWage != null) {
+ // 根据ID查询用户级别
+ SysLevel sysLevel = sysLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(SysLevel::new);
+ // 用户
+ userDto.get(i).setLevelName(sysLevel.getName());
+ } else {
+ // 用户
+ userDto.get(i).setLevelName(null);
+ }
+ }
+ return userDto;
+ }
+
+ @Override
+ public List<UserDto> getAllUserByTaskId(String taskId) {
+ // 日历类
+ Calendar calendar = Calendar.getInstance();
+ // 日期格式化
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ // 日历字符串
+ String calendarStr = sdf.format(calendar.getTime());
+
+ TaskMongo taskMongo = mongoTemplate.findById(taskId, TaskMongo.class);
+ List<Long> containUserList = taskMongo.getContainUserList();
+
+ //递归添加
+ addSubTaskUserList(taskMongo, containUserList);
+
+ containUserList = containUserList.stream().distinct().collect(Collectors.toList());
+
+ List<User> userList = new ArrayList<>();
+ if (containUserList.size() != 0) {
+ for (Long userId : containUserList) {
+ userList.add(userRepository.findById(userId).get());
+ }
+ }
+ List<UserDto> userDto = userMapper.toDto(userList);
+ for (int i = 0; i < userDto.size(); i++) {
+ // 根据用户ID、指定年月查询用户级别工资
+ SysUserLevelWage sysUserLevelWage = sysUserLevelWageRepository.findTargetYearMonth(userDto.get(i).getId(), calendarStr);
+ // 判断用户级别工资是否为空
+ if (sysUserLevelWage != null) {
+ // 根据ID查询用户级别
+ SysLevel sysLevel = sysLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(SysLevel::new);
+ // 用户
+ userDto.get(i).setLevelName(sysLevel.getName());
+ } else {
+ // 用户
+ userDto.get(i).setLevelName(null);
+ }
+ }
+ return userDto;
+ }
+
+ /**
+ * 任务下的所有子级
+ *
+ * @param taskMongo
+ * @param containUserList
+ */
+ public void addSubTaskUserList(TaskMongo taskMongo, List<Long> containUserList) {
+ List<TaskMongo> subTasks = mongoTemplate.find(Query.query(Criteria.where("pid").is(taskMongo.getOld_id())), TaskMongo.class);
+ for (TaskMongo subTask : subTasks) {
+ containUserList.addAll(subTask.getContainUserList());
+ addSubTaskUserList(subTask, containUserList);
+ }
+ }
+
+ @Override
+ @Cacheable(key = "'AllUser'")
+ public List<DeptAndUser> getUserDept() {
+ List<Dept> all = deptRepository.findAll();
+ List<DeptAndUser> result = new ArrayList<>();
+ // 根节点
+ for (Dept dept : all) {
+ if (dept.getPid() == null) {
+ //没有上级部门,他们就是最顶级的菜单
+ DeptAndUser deptAndUser = new DeptAndUser();
+ deptAndUser.setValue(dept.getId());
+ deptAndUser.setLabel(dept.getName());
+ result.add(deptAndUser);
+ }
+ }
+ List<DeptAndUser> list = new ArrayList<>();
+
+ for (Dept dept : all) {
+ // 一级节点
+ if (dept.getPid() != null) {
+ if (dept.getPid().equals(result.get(0).getValue())) {
+ DeptAndUser deptAndUser = new DeptAndUser();
+ deptAndUser.setLabel(dept.getName());
+ deptAndUser.setValue(dept.getId());
+ list.add(deptAndUser);
+ }
+ }
+ }
+ result.get(0).setChildren(list);
+
+ for (int i = 0; i < list.size(); i++) {
+ // 二级节点
+ List<DeptAndUser> list_two = new ArrayList<>();
+ for (Dept dept : all) {
+ if (dept.getPid() != null) {
+ if (dept.getPid().equals(result.get(0).getChildren().get(i).getValue())) {
+ DeptAndUser deptAndUser = new DeptAndUser();
+ deptAndUser.setLabel(dept.getName());
+ deptAndUser.setValue(dept.getId());
+ list_two.add(deptAndUser);
+ }
+ }
+ }
+ result.get(0).getChildren().get(i).setChildren(list_two);
+ }
+
+ for (int i = 0; i < result.get(0).getChildren().size(); i++) {
+ for (int j = 0; j < result.get(0).getChildren().get(i).getChildren().size(); j++) {
+ ArrayList<DeptAndUser> list_three = new ArrayList<>();
+ for (Dept dept : all) {
+ if (dept.getPid() != null) {
+ if (dept.getPid().equals(result.get(0).getChildren().get(i).getChildren().get(j).getValue())) {
+ DeptAndUser deptAndUser = new DeptAndUser();
+ deptAndUser.setLabel(dept.getName());
+ deptAndUser.setValue(dept.getId());
+ list_three.add(deptAndUser);
+ }
+ }
+ }
+ result.get(0).getChildren().get(i).getChildren().get(j).setChildren(list_three);
+ }
+ }
+
+ for (int i = 0; i < result.get(0).getChildren().size(); i++) {
+ for (int j = 0; j < result.get(0).getChildren().get(i).getChildren().size(); j++) {
+ for (int r = 0; r < result.get(0).getChildren().get(i).getChildren().get(j).getChildren().size(); r++) {
+ ArrayList<DeptAndUser> list_four = new ArrayList<>();
+ if (!(deptRepository.findById(result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getValue()).get().getSubCount() == 0)) {
+ // 当前节点不是叶子节点
+ for (Dept dept : all) {
+ if (dept.getPid() != null) {
+ if (dept.getPid().equals(result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getValue())) {
+ DeptAndUser deptAndUser = new DeptAndUser();
+ deptAndUser.setValue(dept.getId());
+ deptAndUser.setLabel(dept.getName());
+ list_four.add(deptAndUser);
+ }
+ }
+ }
+ result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).setChildren(list_four);
+ }
+ }
+ }
+ }
+
+ //return result;
+ recursionGetData(result);
+ return result;
+ }
+
+
+ public void recursionGetData(List<DeptAndUser> list) {
+ for (DeptAndUser deptAndUser : list) {
+ if (deptAndUser.getChildren() == null) {
+ deptAndUser.setChildren(new ArrayList<DeptAndUser>());
+ }
+ if (deptAndUser.getChildren().size() > 0) {
+ recursionGetData(deptAndUser.getChildren());
+ }
+ List<User> users = userRepository.findByDeptIdInAndEnabledWithSingle(deptAndUser.getValue(), true);
+ for (User user : users) {
+ DeptAndUser result_deptAndUser = new DeptAndUser();
+ result_deptAndUser.setValue(user.getId());
+ result_deptAndUser.setLabel(user.getNickName());
+ deptAndUser.getChildren().add(result_deptAndUser);
+ }
+ }
+ }
+
+ @Override
+ public Long[] getUserPidDept(Long id) {
+ ArrayList<Long> list = new ArrayList<>();
+ Long deptId_leaf = userRepository.findDeptIdByUserId(id);
+ list.add(id);
+ list.add(0, deptId_leaf);
+ list = getPidNode(list, deptId_leaf);
+ return list.toArray(new Long[list.size()]);
+ }
+
+ @Override
+ public List<Map> getPerformanceDetail(Long nextMonth) throws ParseException {
+
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
+ // 月初日期
+ String nextMonth_ = df.format(new Date(nextMonth)).substring(0,7) + "-01";
+ // 月末日期
+ String sdfLastDate = DateUtil.getLastDayOfMonthFull(nextMonth_);
+
+ // 查询当前用户
+ User user = userRepository.findById(SecurityUtils.getCurrentUserId()).orElseGet(User::new);
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
+ String startTime = nextMonth_.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkStartTime());
+ String endTime = sdfLastDate.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkEndTime());
+
+ List<Map> resultList = new ArrayList<>();
+ resultList = getPerformanceInfo(startTime, endTime);
+
+ return resultList;
+ }
+
+ /**
+ * 获取详细绩效数据
+ * @param startTime
+ * @param endTime
+ * @return
+ */
+ public List<Map> getPerformanceInfo(String startTime,String endTime) throws ParseException {
+
+ DecimalFormat decimalFormat = new DecimalFormat("#");
+ decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
+
+ List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime))), TaskDaliyMongo.class);
+ //根据日报中任务分配字段的id去重,并保留日报进度最高的
+ Map<Object, TaskDaliyMongo> uniqueMap = daliyMongoList.stream()
+ .collect(Collectors.toMap(
+ taskDaliyMongo -> taskDaliyMongo.getTaskUserMongo().getId(),
+ taskDaliyMongo -> taskDaliyMongo,
+ (existing, replacement) -> existing.getTaskProgress() > replacement.getTaskProgress() ? existing : replacement));
+ List<TaskDaliyMongo> taskDaliyMongoList = new ArrayList<>(uniqueMap.values());
+
+ List<Map> resultList = new ArrayList<>();
+ for (TaskDaliyMongo taskDaliyMongo : taskDaliyMongoList) {
+ Double completedWork = 0D;
+ String taskName = taskDaliyMongo.getTaskUserMongo().getTask().getName();
+ Map map = new HashMap();
+ map.put("name", taskName);
+ if (taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) {
+ // 查询日报表是否存在小于当前月填写的当前任务的日报
+ List<TaskDaliyMongo> taskDaliyMongoSm = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("old_task_id").is(taskDaliyMongo.getOld_task_id()).and("fillDate").lte(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTime))).with(Sort.by(Sort.Direction.DESC, "fillDate")), TaskDaliyMongo.class);
+ //跨月
+ if (taskDaliyMongoSm.size() > 0) {
+// Double horseValue1 = Double.valueOf(decimalFormat.format((taskDaliyMongoSm.get(0).getTaskProgress() / 100) * taskDaliyMongo.getTaskUserMongo().getPerformanceHours()));
+// horseValue1 = taskDaliyMongo.getTaskUserMongo().getPerformanceHours() - horseValue1;
+ // 跨月的话计算最后一次填写距离现在最新的进度相差多少
+ Double newProgress = taskDaliyMongo.getTaskProgress() - taskDaliyMongoSm.get(0).getTaskProgress();
+ // 进度乘总
+ Double horseValue1 = Double.valueOf((newProgress / 100) * taskDaliyMongo.getTaskUserMongo().getPerformanceHours());
+ BigDecimal horseValue2 = new BigDecimal(horseValue1);
+ double horseValue3 = horseValue2.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
+ completedWork = horseValue3;
+ } else {
+ completedWork = taskDaliyMongo.getTaskUserMongo().getPerformanceHours();
+ }
+ } else {
+ // 非绩效(查询非绩效任务的总消耗工时)
+ List<TaskDaliyMongo> noPerformanceLists = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime)).and("taskUserMongo.id").is(taskDaliyMongo.getTaskUserMongo().getId())), TaskDaliyMongo.class);
+ // 计算所有的非绩效的消耗工时的值
+ completedWork = noPerformanceLists.stream()
+ .mapToDouble(TaskDaliyMongo::getConsumedHours)
+ .sum();
+ }
+
+ map.put("value", completedWork);
+ // 设置为0待定
+ map.put(taskDaliyMongo.getTaskUserMongo().getName(), 0);
+ resultList.add(map);
+ }
+
+
+
+ for (Map map : resultList) {
+ ArrayList<Map> list = new ArrayList<>();
+ for (Object key : map.keySet()) {
+ if (!key.equals("name") && !key.equals("value")) {
+ Map innerMap = new HashMap();
+ innerMap.put(key, map.get(key));
+ list.add(innerMap);
+ }
+ }
+ map.put("list", list);
+ }
+
+ return resultList;
+ }
+
+ /**
+ * 获取用户基础信息
+ *
+ * @return
+ * @throws ParseException
+ */
+ @Override
+ public Map getUserBaseInfo(Date yearMonth) throws ParseException {
+ // 返回集合
+ Map returnData = new HashMap();
+ // 当前登录用户
+ Long userId = SecurityUtils.getCurrentUserId();
+ // 目标年月字符串
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ String sdfDate = sdf.format(yearMonth);
+ // 目标年月初字符串
+ String sdfFirstDate = DateUtil.getFirstDayOfMonthFull(sdfDate);
+ // 目标年月末字符串
+ String sdfLastDate = DateUtil.getLastDayOfMonthFull(sdfDate);
+ // 出勤天数
+ List<Attendance> attendanceRecordList = attendanceRepository.findAllByUserAndDate(userId, sdfFirstDate, sdfLastDate);
+ int numDay = 0;
+ for (Attendance attendance : attendanceRecordList) {
+ if (!attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_REST) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_REST)) {
+ numDay++;
+ }
+ }
+ returnData.put("onDutyDays", numDay);
+ // 剩余年假
+ Double yearTimes = attendanceLeaveService.getYearTimeLength(userId);
+ returnData.put("annualLeave", yearTimes);
+ // 查询当月的补卡记录的条数
+ Integer count = attendanceCardreplacementRepository.count(userId, sdfDate.substring(0, 7));
+ // 查询配置表的每月补卡次数
+ SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("每月可补卡次数");
+ if (count >= sysConfigProportion.getProportion()) {
+ returnData.put("cardLeft", 0);
+ } else {
+ returnData.put("cardLeft", (sysConfigProportion.getProportion() - count));
+ }
+
+ // 法定节假日
+ List<String> holiday = new ArrayList<>();
+ // 天数
+ int shouldWordDays = 0;
+ List<SysConfigHoliday> holidayConfigurationList = sysConfigHolidayRepository.findAll();
+ for (SysConfigHoliday holidayConfiguration : holidayConfigurationList) {
+ if (holidayConfiguration.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) {
+ holiday.add(sdf.format(holidayConfiguration.getHolidayDate()));
+ }
+ }
+ // 获取当月所有日期
+ List<String> dateList = DateTimeUtil.getDayByMonth(sdfDate.substring(0, 4), sdfDate.substring(5, 7));
+ Date date1 = new Date();
+ String todayDay = sdf.format(date1);
+ if (!todayDay.substring(0, 7).equals(sdfDate.substring(0, 7))) {
+ todayDay = sdfLastDate;
+ }
+ // 工作日的天数
+ for (String date : dateList) {
+ Date isWeekEnd = sdf.parse(date);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(isWeekEnd);
+ if (isWeekEnd.compareTo(sdf.parse(todayDay)) <= 0) {
+ if (!holiday.contains(date) && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
+ shouldWordDays += 1;
+ }
+ }
+ }
+ int num = shouldWordDays * 8;
+ // 月初到今天应工作时长
+ returnData.put("Time", num);
+
+ DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+ User user = userRepository.getById(userId);
+ // 考勤上午时间
+ Double attCheckOnDuration = 0.0;
+ // 考勤下午时间
+ Double attCheckOffDuration = 0.0;
+ for (Attendance attendance : attendanceRecordList) {
+ // 上班打卡时间不为空并且打卡状态不为出差外出的考勤记录
+ if (ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) && !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) && !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)) {
+ LocalDateTime attCheckOnTime = attendance.getActualWorkStartTime().toLocalDateTime();
+ LocalDateTime scheduleStartTime = LocalDateTime.parse(attendance.getAttendanceDate().toString().substring(0, 10) + " " + user.getSysRostering().getLunchStartTime().toString() + ":00", formatter2);
+ if (attCheckOnTime.compareTo(scheduleStartTime) <= 0) {
+ // 获得两个时间之间的相差值
+ Duration duration = Duration.between(attCheckOnTime, scheduleStartTime);
+ Long minutes = duration.toMinutes();
+ Double hour = Double.valueOf(String.valueOf(new BigDecimal(Double.valueOf(minutes) / 60).setScale(2, BigDecimal.ROUND_HALF_UP)));
+ attCheckOnDuration = attCheckOnDuration + hour;
+ }
+ }
+ // 下班打卡时间不为空并且打卡状态不为出差外出的考勤记录
+ if (ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)) {
+ LocalDateTime attCheckOffTime = attendance.getActualWorkEndTime().toLocalDateTime();
+ LocalDateTime scheduleEndTime = LocalDateTime.parse(attendance.getAttendanceDate().toString().substring(0, 10) + " " + user.getSysRostering().getLunchEndTime().toString() + ":00", formatter2);
+ if (attCheckOffTime.compareTo(scheduleEndTime) > 0) {
+ // 获得两个时间之间的相差值
+ Duration duration = Duration.between(scheduleEndTime, attCheckOffTime);
+ Long minutes = duration.toMinutes();
+ Double hour = Double.valueOf(String.valueOf(new BigDecimal(Double.valueOf(minutes) / 60).setScale(2, BigDecimal.ROUND_HALF_UP)));
+ attCheckOffDuration = attCheckOffDuration + hour;
+ }
+ }
+ }
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
+ String startTime = sdfFirstDate.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkStartTime());
+ String endTime = todayDay.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkEndTime());
+ // 外出时长
+ Double goOutTimes = 0.0;
+ // 查询外出表
+ List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(userId, Timestamp.valueOf(startTime).toLocalDateTime(), Timestamp.valueOf(endTime).toLocalDateTime());
+ for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) {
+ goOutTimes = goOutTimes + attendanceGoOut.getOutDuration();
+ }
+ // 出差时长
+ Double bussTimes = 0.0;
+ // 查询出差表
+ List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(userId, Timestamp.valueOf(sdfFirstDate).toLocalDateTime(), Timestamp.valueOf(todayDay.substring(0, 10) + " " + "00:00:00").toLocalDateTime());
+ for (AttendanceBusinessTravel attendanceBusinessTravel : attendanceBusinessTravelList) {
+ bussTimes = bussTimes + attendanceBusinessTravel.getTravelDuration();
+ }
+ returnData.put("Times", attCheckOnDuration + attCheckOffDuration + goOutTimes + (bussTimes * 8));
+
+ // 任务日报查询类
+ TaskDaliyQueryCriteria taskDaliyQueryCriteria = new TaskDaliyQueryCriteria();
+ taskDaliyQueryCriteria.setUserId(userId);
+ taskDaliyQueryCriteria.setTargetYearMonth(sdfDate.substring(0, 7));
+ taskDaliyQueryCriteria.setTargetYearMonth(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(yearMonth));
+
+// // 查询某月已完成工时
+// Double completedWork = 0D;
+//
+// DecimalFormat decimalFormat = new DecimalFormat("#");
+// decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
+//
+// List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime))), TaskDaliyMongo.class);
+//
+// //根据日报中任务分配字段的id去重,并保留日报进度最高的
+// Map<Object, TaskDaliyMongo> uniqueMap = daliyMongoList.stream()
+// .collect(Collectors.toMap(
+// taskDaliyMongo -> taskDaliyMongo.getTaskUserMongo().getId(),
+// taskDaliyMongo -> taskDaliyMongo,
+// infoement));
+//
+// List<TaskDaliyMongo> taskDaliyMongoList = new ArrayList<>(uniqueMap.values());
+// for (TaskDaliyMongo taskDaliyMongo : taskDaliyMongoList) {
+// //绩效
+// if (taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) {
+// // 查询日报表是否存在小于当前月填写的当前任务的日报
+// List<TaskDaliyMongo> taskDaliyMongoSm = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("old_task_id").is(taskDaliyMongo.getOld_task_id()).and("fillDate").lte(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTime))).with(Sort.by(Sort.Direction.DESC, "fillDate")), TaskDaliyMongo.class);
+// //跨月
+// if (taskDaliyMongoSm.size() > 0) {
+// Double horseValue1 = Double.valueOf(decimalFormat.format((taskDaliyMongoSm.get(0).getTaskProgress() / 100) * taskDaliyMongo.getTaskUserMongo().getPerformanceHours()));
+// horseValue1 = taskDaliyMongo.getTaskUserMongo().getPerformanceHours() - horseValue1;
+// completedWork += horseValue1;
+// } else {
+// completedWork += taskDaliyMongo.getTaskUserMongo().getPerformanceHours();
+// }
+// }
+// }
+//
+// // 非绩效
+// for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) {
+// //非绩效
+// if (!taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) {
+// completedWork += taskDaliyMongo.getConsumedHours();
+// }
+// }
+
+ List<Map> resList = getPerformanceInfo(startTime,endTime);
+ double sum = resList.stream()
+ .filter(map -> map.containsKey("value"))
+ .mapToDouble(map -> Double.valueOf(map.get("value").toString()))
+ .sum();
+
+ // 月初到今天绩效时长
+ returnData.put("achievementsTime", sum);
+
+ return returnData;
+ }
+
+ @Override
+ public List<User> getUserInfose() {
+ List<User> userList = new ArrayList<>();
+ //获取当前登入人信息
+ User user1 = userRepository.getOne(SecurityUtils.getCurrentUserId());
+ Role role = user1.getRoles().iterator().next();
+ //超管、总经理,痛苦哦经理查看全部
+ if (Long.valueOf(role.getLevel()) == Constant.ROLE_LEVEL_SUPER || Long.valueOf(role.getLevel()) == Constant.ROLE_LEVEL_GENERAL) {
+ userList = userRepository.findAllByEnabled(true);
+ } else {
+ userList = userRepository.findByUserId(user1.getId());
+ }
+ return userList;
+ }
+
+ /*
+ 方法作用:
+ 遍历resultList 集合将集合中的元素逐个遍历,如果有元素与当前任务的任务名称相等
+ 如果任务名称相等,取出当前元素并且将当前任务的消耗工时添加进元素中
+ */
+ private static void findList(List<Map> resultList, TaskDaliyMongo taskDaliyMongo) {
+ boolean flag = false;
+ for (Map map : resultList) {
+ if (map.get("name").equals(taskDaliyMongo.getTaskUserMongo().getTask().getName())) {
+ // 有
+ Double value = (Double) map.get("value");
+ value += taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours();
+ map.put("value", value);
+ map.put(taskDaliyMongo.getTaskUserMongo().getName(), taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours());
+ flag = true;
+ }
+ }
+ // 无
+ if (!flag) {
+ Map newMap = new HashMap();
+ if (taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) {
+ newMap.put("name", taskDaliyMongo.getTaskUserMongo().getTask().getName());
+ newMap.put("value", taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours());
+ newMap.put(taskDaliyMongo.getTaskUserMongo().getName(), taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours());
+ } else {
+ newMap.put("name", taskDaliyMongo.getTaskUserMongo().getTask().getName());
+ newMap.put("value", taskDaliyMongo.getConsumedHours());
+ newMap.put(taskDaliyMongo.getTaskUserMongo().getName(), taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours());
+ }
+ resultList.add(newMap);
+ }
+ }
+
+ private ArrayList<Long> getPidNode(ArrayList<Long> list, Long deptId_leaf) {
+ Long pidId = deptRepository.findPidIdByDeptId(deptId_leaf);
+ if (pidId != null) {
+ list.add(0, pidId);
+ getPidNode(list, pidId);
+ }
+ return list;
+ }
+
+
+ @Override
@Cacheable(key = "'total'")
+// @CacheEvict(value = "total", allEntries = true)
@Transactional(rollbackFor = Exception.class)
public List<UserDto> queryAll(UserQueryCriteria criteria) {
+ criteria.setEnabled(true);
// 日历类
Calendar calendar = Calendar.getInstance();
// 日期格式化
@@ -146,7 +720,7 @@
List<User> users = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder));
List<UserDto> usersDto = userMapper.toDto(users);
// 循环用户
- for (int i= 0; i < usersDto.size(); i ++) {
+ for (int i = 0; i < usersDto.size(); i++) {
// 根据用户ID、指定年月查询用户级别工资
SysUserLevelWage sysUserLevelWage = sysUserLevelWageRepository.findTargetYearMonth(usersDto.get(i).getId(), calendarStr);
// 判断用户级别工资是否为空
@@ -185,9 +759,12 @@
throw new EntityExistException(User.class, "phone", resources.getPhone());
}
redisUtils.del(CacheKey.TOTAL_USER);
+ redisUtils.del("user::AllUser");
userRepository.save(resources);
// 判断用户级别变更
checkUserLevel(resources.getId(), null, resources.getLevelId());
+ // 判断用户级别变更(新)
+ checkUserLevelNew(resources);
}
@Override
@@ -214,15 +791,16 @@
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId());
}
// 修改部门会影响 数据权限
- if (!Objects.equals(resources.getDept(),user.getDept())) {
+ if (!Objects.equals(resources.getDept(), user.getDept())) {
redisUtils.del(CacheKey.DATA_USER + resources.getId());
}
// 如果用户被禁用,则清除用户登录信息
- if(!resources.getEnabled()){
+ if (!resources.getEnabled()) {
onlineUserService.kickOutForUsername(resources.getUsername());
}
// 临时旧用户级别ID
- Long tempOldLevelId = user.getLevelId();;
+ Long tempOldLevelId = user.getLevelId();
+ ;
user.setUsername(resources.getUsername());
user.setEmail(resources.getEmail());
user.setEnabled(resources.getEnabled());
@@ -240,9 +818,12 @@
user.setLevelId(resources.getLevelId());
// 临时新用户级别ID
Long tempNewLevelId = user.getLevelId();
+ redisUtils.del("user::AllUser");
userRepository.save(user);
// 判断用户级别变更
checkUserLevel(user.getId(), tempOldLevelId, tempNewLevelId);
+// // 判断用户级别变更(新)
+// checkUserLevelNew(resources, tempOldLevelId, tempNewLevelId);
// 清除缓存
delCaches(user.getId(), user.getUsername());
}
@@ -265,6 +846,7 @@
/**
* 获取日历信息
+ *
* @param month
* @return
* @throws Exception
@@ -281,8 +863,8 @@
//当前登录人
Long userId = SecurityUtils.getCurrentUserId();
//查询这个范围的考勤记录
- List<Attendance> attendanceList = attendanceRepository.findAllByUserAndDate(userId,startDate.toString(),endDate.toString());
- for(Attendance attendance : attendanceList){
+ List<Attendance> attendanceList = attendanceRepository.findAllByUserAndDate(userId, startDate.toString(), endDate.toString());
+ for (Attendance attendance : attendanceList) {
CalendarVo onDuty = new CalendarVo();
onDuty.setDate(df.format(attendance.getAttendanceDate()));
onDuty.setTitle(Constant.ATTENDANCE_STATE_NORMAL.equals(formateResult(attendance.getStartClockResults()).get("msg")) ? "上班打卡时间:" + attendance.getActualWorkStartTime().toString() : "上班:" + formateResult(attendance.getStartClockResults()).get("msg"));
@@ -303,38 +885,58 @@
Long duration = (Duration.between(user.getSysRostering().getWorkStartTime(), user.getSysRostering().getWorkEndTime())).toHours();
//查询日志表
- List<TaskDaliy> taskDaliyList = taskDaliyRepository.findAllByUserAndDate(userId,startDate,endDate);
- for (TaskDaliy taskDaliy : taskDaliyList) {
- CalendarVo daily = new CalendarVo();
- daily.setDate(taskDaliy.getFillDate().toString());
- if (dateList.contains(taskDaliy.getFillDate().toString())) {
- dateList.remove(taskDaliy.getFillDate().toString());
+ List<TaskDaliyMongo> taskDaliyList = mongoTemplate.find(Query.query(new Criteria("userId").is(userId).and("fillDate").gte(startDate).lte(endDate)), TaskDaliyMongo.class);
+ Map<String, Double> map = new HashMap<>();
+ for (TaskDaliyMongo taskDaliy : taskDaliyList) {
+ if (map.get(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate())) != null) {
+ // 如果已经有了
+ Double todayHours = map.get(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate()));
+ todayHours += taskDaliy.getConsumedHours();
+ map.put(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate()), todayHours);
+ } else {
+ map.put(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate()), taskDaliy.getConsumedHours());
}
- daily.setIsOk(taskDaliy.getConsumedHours().compareTo(new Double(duration - 1)) >= 0 ? true : false);
- daily.setTitle(taskDaliy.getConsumedHours().compareTo(new Double(duration - 1)) >= 0 ? "工时: " + taskDaliy.getConsumedHours().toString() : "已填工时:" + taskDaliy.getConsumedHours().toString() + " 不满8小时,请补充日报");
- daily.setType(2);
- calendarInfo.add(daily);
+ }
+ for (Map.Entry<String, Double> entry : map.entrySet()) {
+ CalendarVo calendarVo = new CalendarVo();
+ if (entry.getValue() >= 8) {
+ calendarVo.setDate(entry.getKey());
+ calendarVo.setIsOk(true);
+ calendarVo.setTitle("工时:" + entry.getValue());
+ calendarVo.setType(2);
+ } else {
+ calendarVo.setDate(entry.getKey());
+ calendarVo.setIsOk(false);
+ calendarVo.setTitle("已填工时:" + entry.getValue() + " 不足8小时,请补充日报");
+ calendarVo.setType(2);
+ }
+ calendarInfo.add(calendarVo);
}
for (String date : dateList) {
String type1 = "";
String type2 = "";
+ System.out.println(date);
CalendarVo dailyVo = new CalendarVo();
+ if (map.get(date) != null) {
+ // 如果在map中找到了它的值,说明用户填写过日报
+ continue;
+ }
dailyVo.setDate(date);
for (Attendance attendanceRecord : attendanceList) {
type1 = attendanceRecord.getStartClockResults();
type2 = attendanceRecord.getEndClockResults();
- date = date.substring(0,10);
- if(date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_LEAVE) && type2.equals(Constant.ATTENDANCE_STATE_LEAVE)){
+ date = date.substring(0, 10);
+ if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_LEAVE) && type2.equals(Constant.ATTENDANCE_STATE_LEAVE)) {
dailyVo.setTitle("请假");
dailyVo.setIsOk(true);
- }else if(date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_BUSINESS) && type2.equals(Constant.ATTENDANCE_STATE_BUSINESS)){
+ } else if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_BUSINESS) && type2.equals(Constant.ATTENDANCE_STATE_BUSINESS)) {
dailyVo.setTitle("出差");
dailyVo.setIsOk(true);
- }else if(date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_REST) && type2.equals(Constant.ATTENDANCE_STATE_REST)){
+ } else if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_REST) && type2.equals(Constant.ATTENDANCE_STATE_REST)) {
dailyVo.setTitle("休息");
dailyVo.setIsOk(true);
- }else if(date.equals(df.format(attendanceRecord.getAttendanceDate()))){
+ } else if (date.equals(df.format(attendanceRecord.getAttendanceDate()))) {
dailyVo.setTitle("日报未填写,请补充日报");
dailyVo.setIsOk(false);
}
@@ -347,6 +949,7 @@
/**
* 判断状态
+ *
* @param result
* @return
*/
@@ -393,141 +996,6 @@
returnData.put("msg", result);
returnData.put("status", true);
}
- return returnData;
- }
-
- /**
- *获取用户基础信息
- * @return
- * @throws ParseException
- */
- @Override
- public Map getUserBaseInfo(Date yearMonth) throws ParseException {
- // 返回集合
- Map returnData = new HashMap();
- // 当前登录用户
- Long userId = SecurityUtils.getCurrentUserId();
- // 目标年月字符串
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- String sdfDate = sdf.format(yearMonth);
- // 目标年月初字符串
- String sdfFirstDate = DateUtil.getFirstDayOfMonthFull(sdfDate);
- // 目标年月末字符串
- String sdfLastDate = DateUtil.getLastDayOfMonthFull(sdfDate);
- // 出勤天数
- List<Attendance> attendanceRecordList = attendanceRepository.findAllByUserAndDate(userId, sdfFirstDate, sdfLastDate);
- int numDay = 0;
- for(Attendance attendance : attendanceRecordList){
- if(!attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_REST) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_REST)){
- numDay++;
- }
- }
- returnData.put("onDutyDays", numDay);
- // 剩余年假
- Double yearTimes = attendanceLeaveService.getYearTimeLength(userId);
- returnData.put("annualLeave", yearTimes);
- // 查询当月的补卡记录的条数
- Integer count = attendanceCardreplacementRepository.count(userId, sdfDate.substring(0,7));
- // 查询配置表的每月补卡次数
- SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("每月可补卡次数");
- if(count >= sysConfigProportion.getProportion()){
- returnData.put("cardLeft", 0);
- }else{
- returnData.put("cardLeft", (sysConfigProportion.getProportion() - count));
- }
-
- // 法定节假日
- List<String> holiday = new ArrayList<>();
- // 天数
- int shouldWordDays = 0;
- List<SysConfigHoliday> holidayConfigurationList = sysConfigHolidayRepository.findAll();
- for (SysConfigHoliday holidayConfiguration : holidayConfigurationList) {
- if (holidayConfiguration.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) {
- holiday.add(sdf.format(holidayConfiguration.getHolidayDate()));
- }
- }
- // 获取当月所有日期
- List<String> dateList = DateTimeUtil.getDayByMonth(sdfDate.substring(0,4), sdfDate.substring(5,7));
- Date date1 = new Date();
- String todayDay = sdf.format(date1);
- if (!todayDay.substring(0,7).equals(sdfDate.substring(0,7))) {
- todayDay = sdfLastDate;
- }
- // 工作日的天数
- for(String date : dateList){
- Date isWeekEnd = sdf.parse(date);
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(isWeekEnd);
- if(isWeekEnd.compareTo(sdf.parse(todayDay)) <= 0){
- if(!holiday.contains(date) && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY){
- shouldWordDays += 1;
- }
- }
- }
- int num = shouldWordDays * 8;
- // 月初到今天应工作时长
- returnData.put("Time", num);
-
- DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- User user = userRepository.getById(userId);
- // 考勤上午时间
- Double attCheckOnDuration = 0.0;
- // 考勤下午时间
- Double attCheckOffDuration = 0.0;
- for(Attendance attendance : attendanceRecordList){
- // 上班打卡时间不为空并且打卡状态不为出差外出的考勤记录
- if(ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) && !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) && !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)){
- LocalDateTime attCheckOnTime = attendance.getActualWorkStartTime().toLocalDateTime();
- LocalDateTime scheduleStartTime = LocalDateTime.parse(attendance.getAttendanceDate().toString().substring(0,10) +" " + user.getSysRostering().getLunchStartTime().toString() + ":00",formatter2);
- if(attCheckOnTime.compareTo(scheduleStartTime) <= 0){
- // 获得两个时间之间的相差值
- Duration duration = Duration.between(attCheckOnTime, scheduleStartTime);
- Long minutes = duration.toMinutes();
- Double hour = Double.valueOf(String.valueOf(new BigDecimal(Double.valueOf(minutes) / 60).setScale(2, BigDecimal.ROUND_HALF_UP)));
- attCheckOnDuration = attCheckOnDuration + hour;
- }
- }
- // 下班打卡时间不为空并且打卡状态不为出差外出的考勤记录
- if(ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)){
- LocalDateTime attCheckOffTime = attendance.getActualWorkEndTime().toLocalDateTime();
- LocalDateTime scheduleEndTime = LocalDateTime.parse(attendance.getAttendanceDate().toString().substring(0,10) +" " + user.getSysRostering().getLunchEndTime().toString() + ":00",formatter2);
- if(attCheckOffTime.compareTo(scheduleEndTime) > 0){
- // 获得两个时间之间的相差值
- Duration duration = Duration.between(scheduleEndTime, attCheckOffTime);
- Long minutes = duration.toMinutes();
- Double hour = Double.valueOf(String.valueOf(new BigDecimal(Double.valueOf(minutes) / 60 ).setScale(2, BigDecimal.ROUND_HALF_UP)));
- attCheckOffDuration = attCheckOffDuration + hour;
- }
- }
- }
- DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
- String startTime = sdfFirstDate.substring(0,10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkStartTime());
- String endTime = todayDay.substring(0,10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkEndTime());
- // 外出时长
- Double goOutTimes = 0.0;
- // 查询外出表
- List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(userId,Timestamp.valueOf(startTime).toLocalDateTime(),Timestamp.valueOf(endTime).toLocalDateTime());
- for(AttendanceGoOut attendanceGoOut : attendanceGoOutList){
- goOutTimes = goOutTimes + attendanceGoOut.getOutDuration();
- }
- // 出差时长
- Double bussTimes = 0.0;
- // 查询出差表
- List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(userId,Timestamp.valueOf(sdfFirstDate).toLocalDateTime(),Timestamp.valueOf(todayDay.substring(0,10) + " " + "00:00:00").toLocalDateTime());
- for(AttendanceBusinessTravel attendanceBusinessTravel : attendanceBusinessTravelList){
- bussTimes = bussTimes + attendanceBusinessTravel.getTravelDuration();
- }
- returnData.put("Times", attCheckOnDuration + attCheckOffDuration + goOutTimes + (bussTimes * 8));
-
- // 任务日报查询类
- TaskDaliyQueryCriteria taskDaliyQueryCriteria = new TaskDaliyQueryCriteria();
- taskDaliyQueryCriteria.setUserId(userId);
- taskDaliyQueryCriteria.setTargetYearMonth(sdfDate.substring(0,7));
- // 查询某月已完成工时
- Double completedWork = taskDaliyService.queryCompletedWork(taskDaliyQueryCriteria, true);
- // 月初到今天绩效时长
- returnData.put("achievementsTime", completedWork);
-
return returnData;
}
@@ -578,8 +1046,8 @@
// 验证文件上传的格式
String image = "gif jpg png jpeg";
String fileType = FileUtil.getExtensionName(multipartFile.getOriginalFilename());
- if(fileType != null && !image.contains(fileType)){
- throw new BadRequestException("文件格式错误!, 仅支持 " + image +" 格式");
+ if (fileType != null && !image.contains(fileType)) {
+ throw new BadRequestException("文件格式错误!, 仅支持 " + image + " 格式");
}
User user = userRepository.findByUsername(SecurityUtils.getCurrentUsername());
String oldPath = user.getAvatarPath();
@@ -652,26 +1120,28 @@
/**
* 判断用户级别变更
+ *
* @param userId
* @param oldLevelId
* @param newLevelId
*/
private void checkUserLevel(Long userId, Long oldLevelId, Long newLevelId) {
+ // 查询级别表
+ SysLevel sysLevel = sysLevelRepository.findById(newLevelId).orElseGet(SysLevel::new);
// 判断新旧用户级别ID是否相等
if (oldLevelId == null) {
- // 创建用户级别工资
+ // 创建用户级别工资(旧)
createSysUserLevelWage(userId, newLevelId);
- // 创建用户级别保险
+ // 创建用户级别保险(旧)
createSysUserLevelInsurance(userId, newLevelId);
- // 创建用户级别其他
- createSysUserLevelOther(userId, newLevelId);
+
} else if (oldLevelId != newLevelId) {
// 旧用户级别工资
SysUserLevelWage oldSysUserLevelWage = sysUserLevelWageRepository.findLastByUserId(userId);
// 判断旧用户级别工资是否为空
if (oldSysUserLevelWage != null && oldSysUserLevelWage.getId() != null) {
// 旧日期字符串
- String oldDateString = oldSysUserLevelWage.getStartDate().toString().substring(0,10);
+ String oldDateString = oldSysUserLevelWage.getStartDate().toString().substring(0, 10);
// 获取当前日期
Date nowDate = new Date();
// 创建Calendar实例
@@ -679,7 +1149,7 @@
// 设置当前时间
nowCalendar.setTime(nowDate);
// 新日期字符串
- String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0,10);
+ String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0, 10);
// 判断新、旧日期字符串
if (oldDateString.equals(nowDateString)) {
throw new BadRequestException("每天只能调整一次级别,请明日再试!");
@@ -691,14 +1161,14 @@
// 保存
sysUserLevelWageRepository.save(oldSysUserLevelWage);
}
- // 创建用户级别工资
+ // 创建用户级别工资(旧)
createSysUserLevelWage(userId, newLevelId);
// 旧用户级别保险
SysUserLevelInsurance oldSysUserLevelInsurance = sysUserLevelInsuranceRepository.findLastByUserId(userId);
// 判断旧用户级别保险是否为空
if (oldSysUserLevelInsurance != null && oldSysUserLevelInsurance.getId() != null) {
// 旧日期字符串
- String oldDateString = oldSysUserLevelInsurance.getStartDate().toString().substring(0,10);
+ String oldDateString = oldSysUserLevelInsurance.getStartDate().toString().substring(0, 10);
// 获取当前日期
Date nowDate = new Date();
// 创建Calendar实例
@@ -706,7 +1176,7 @@
// 设置当前时间
nowCalendar.setTime(nowDate);
// 新日期字符串
- String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0,10);
+ String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0, 10);
// 判断新、旧日期字符串
if (oldDateString.equals(nowDateString)) {
throw new BadRequestException("每天只能调整一次级别,请明日再试!");
@@ -718,14 +1188,14 @@
// 保存
sysUserLevelInsuranceRepository.save(oldSysUserLevelInsurance);
}
- // 创建用户级别保险
+ // 创建用户级别保险(旧)
createSysUserLevelInsurance(userId, newLevelId);
// 旧用户级别其他
SysUserLevelOther oldSysUserLevelOther = sysUserLevelOtherRepository.findLastByUserId(userId);
// 判断旧用户级别其他是否为空
if (oldSysUserLevelOther != null && oldSysUserLevelOther.getId() != null) {
// 旧日期字符串
- String oldDateString = oldSysUserLevelOther.getStartDate().toString().substring(0,10);
+ String oldDateString = oldSysUserLevelOther.getStartDate().toString().substring(0, 10);
// 获取当前日期
Date nowDate = new Date();
// 创建Calendar实例
@@ -733,7 +1203,7 @@
// 设置当前时间
nowCalendar.setTime(nowDate);
// 新日期字符串
- String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0,10);
+ String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0, 10);
// 判断新、旧日期字符串
if (oldDateString.equals(nowDateString)) {
throw new BadRequestException("每天只能调整一次级别,请明日再试!");
@@ -745,15 +1215,247 @@
// 保存
sysUserLevelOtherRepository.save(oldSysUserLevelOther);
}
- // 创建用户级别其他
- createSysUserLevelOther(userId, newLevelId);
} else {
}
}
/**
- * 创建用户级别工资
+ * 判断用户级别变更
+ *
+ * @param resources
+ */
+ private void checkUserLevelNew(User resources) {
+ // 查询级别管理表
+ CmnLevel cmnLevel = cmnLevelRepository.findById(resources.getLevelId()).orElseGet(CmnLevel::new);
+ for (int i = 0; i < 2; i++) {
+ if (i == 1) {
+ // 创建第二条用户级别工资(新)
+ createNewSysUserLevelWage(resources, cmnLevel, EnumerationType.SECOND_ENUM);
+ // 创建第二条用户级别保险 (新)
+ createNewSysUserLevelInsurance(resources, EnumerationType.SECOND_ENUM);
+ } else {
+ // 创建第一条用户级别工资(新)
+ createNewSysUserLevelWage(resources, cmnLevel, EnumerationType.FIRST_ENUM);
+ // 创建第一条用户级别保险 (新)
+ createNewSysUserLevelInsurance(resources, EnumerationType.FIRST_ENUM);
+ }
+ }
+ // 创建用户级别其他(新)
+ createSysUserLevelOther(resources, cmnLevel);
+ }
+
+ /**
+ * 创建用户级别工资(新)
+ *
+ * @param resources
+ * @param cmnLevel
+ */
+ private void createNewSysUserLevelWage(User resources, CmnLevel cmnLevel, EnumerationType enumType) {
+ Calendar calendar = Calendar.getInstance();
+ // 用户级别工资
+ UserLevelWage userLevelWage = new UserLevelWage();
+ userLevelWage.setUserId(resources.getId());
+ userLevelWage.setLevel(cmnLevel.getId());
+ // 获取试用期结束的月初时间
+ Timestamp result1 = getConfirmationTime(resources);
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+ String resultValue = sdf.format(result1);
+ if (enumType.equals(EnumerationType.FIRST_ENUM)) {
+ userLevelWage.setYearMonth(sdf.format(new Timestamp(calendar.getTimeInMillis())));
+ } else {
+ userLevelWage.setYearMonth(resultValue);
+ }
+ // 查询最小的等级
+ MeritLevel meritLevel = meritLevelRepository.findMinMeritStandardByLevelId(cmnLevel.getId());
+ userLevelWage.setRank(meritLevel.getId());
+ userLevelWage.setBasicWage(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(cmnLevel.getBasicWage().doubleValue() * 0.8) :cmnLevel.getBasicWage());
+ userLevelWage.setRankWage(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(cmnLevel.getRankWage().doubleValue() * 0.8) : cmnLevel.getRankWage());
+ userLevelWage.setPerformanceWage(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(cmnLevel.getPerformanceWage().doubleValue() * 0.8) : cmnLevel.getPerformanceWage());
+ // 查询绩效系数
+ CmnLevelRank cmnLevelRank = cmnLevelRankRepository.findbylevelSm(cmnLevel.getId());
+ userLevelWage.setPerformanceCoefficient(new BigDecimal(cmnLevelRank.getPerformanceCoefficient()));
+ // 保存
+ userLevelWageRepository.save(userLevelWage);
+ }
+
+ /**
+ * 创建用户级别保险 (新)
+ *
+ * @param resources
+ */
+ public void createNewSysUserLevelInsurance(User resources, EnumerationType enumType) {
+ Calendar calendar = Calendar.getInstance();
+ // 用户级别工资
+ UserInsurance userInsurance = new UserInsurance();
+ userInsurance.setUserId(resources.getId());
+ // 获取试用期结束的月初时间
+ Timestamp result = getConfirmationTime(resources);
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+ String resultValue = sdf.format(result);
+ if (enumType.equals(EnumerationType.FIRST_ENUM)) {
+ userInsurance.setYearMonth(sdf.format(new Timestamp(calendar.getTimeInMillis())));
+ } else {
+ userInsurance.setYearMonth(resultValue);
+ }
+ // 根据选择的公司查询五险一金
+ CmnInsurance cmnInsurance = cmnInsuranceRepository.findByCompany(resources.getCompany()).orElseGet(CmnInsurance::new);
+ userInsurance.setAccumulationFund(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getAccumulationFund());
+ userInsurance.setAccumulationFundPersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getAccumulationFundPersonal());
+ userInsurance.setAccumulationFundCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getAccumulationFundCompany());
+ userInsurance.setRetirementInsurance(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getRetirementInsurance());
+ userInsurance.setRetirementInsurancePersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getRetirementInsurancePersonal());
+ userInsurance.setRetirementInsuranceCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getRetirementInsuranceCompany());
+ userInsurance.setMedicalInsurance(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getMedicalInsurance());
+ userInsurance.setMedicalInsurancePersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getMedicalInsurancePersonal());
+ userInsurance.setMedicalInsuranceCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getMedicalInsuranceCompany());
+ userInsurance.setUnemploymentInsurance(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getUnemploymentInsurance());
+ userInsurance.setUnemploymentInsurancePersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getUnemploymentInsurancePersonal());
+ userInsurance.setUnemploymentInsuranceCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getUnemploymentInsuranceCompany());
+ userInsurance.setBirthInsurance(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getBirthInsurance());
+ userInsurance.setBirthInsurancePersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getBirthInsurancePersonal());
+ userInsurance.setBirthInsuranceCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getBirthInsuranceCompany());
+ userInsurance.setEmploymentInsurance(enumType.equals(EnumerationType.FIRST_ENUM) ? new BigDecimal(0) : cmnInsurance.getEmploymentInsurance());
+ userInsurance.setEmploymentInsurancePersonal(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getEmploymentInsurancePersonal());
+ userInsurance.setEmploymentInsuranceCompany(enumType.equals(EnumerationType.FIRST_ENUM) ? new Double(0) : cmnInsurance.getEmploymentInsuranceCompany());
+ // 保存
+ userInsuranceRepository.save(userInsurance);
+ }
+
+ /**
+ * 创建用户级别其他(新)
+ * @param resources
+ * @param cmnLevel
+ */
+ private void createSysUserLevelOther(User resources, CmnLevel cmnLevel) {
+ SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM");
+ // 获取试用期结束的月初时间
+ Timestamp result = getConfirmationTime(resources);
+ // 获取实习期结束的年份
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(result);
+ int formalYear = calendar.get(Calendar.YEAR);
+ // 获取当前年份
+ int currentYear = Calendar.getInstance().get(Calendar.YEAR);
+
+// for (int i = 0; i < 2; i++) {
+// // 第一条记录
+// SysUserLevelOther sysUserLevelOther = new SysUserLevelOther();
+// sysUserLevelOther.setUserId(resources.getId());
+// sysUserLevelOther.setLevelId(cmnLevel.getId());
+// sysUserLevelOther.setPersonalPerformanceProportion(Double.valueOf(0));
+//
+// if (i == 1) {
+// // 计算剩余年假
+// Double annualLeave = getAnnualLeave(calendar);
+// sysUserLevelOther.setAnnualLeaveDays(annualLeave);
+// } else {
+// calendar.add(Calendar.YEAR, 1);
+// // 设置月份为一月
+// calendar.set(Calendar.MONTH, Calendar.JANUARY);
+// // 设置月份为一日
+// calendar.set(Calendar.DAY_OF_MONTH, 1);
+//
+// sysUserLevelOther.setAnnualLeaveDays(5.0);
+// }
+// // 年月
+// sysUserLevelOther.setYearMonth(sdf.format(calendar.getTime()));
+//
+//
+// sysUserLevelOtherRepository.save(sysUserLevelOther);
+// }
+
+ // 添加两条数据
+ for (int i = 0; i < 2; i++) {
+ if (i == 0) {
+ // 第一条记录
+ SysUserLevelOther sysUserLevelOther = new SysUserLevelOther();
+ sysUserLevelOther.setUserId(resources.getId());
+ sysUserLevelOther.setLevelId(cmnLevel.getId());
+ sysUserLevelOther.setPersonalPerformanceProportion(Double.valueOf(0));
+ // 计算剩余年假
+ Double annualLeave = getAnnualLeave(calendar);
+ sysUserLevelOther.setAnnualLeaveDays(annualLeave);
+ // 判断为今年设置为当前日期
+ if (formalYear == currentYear) {
+ sysUserLevelOther.setYearMonth(sdf.format(new Date()));
+ } else {
+ // 设置为明年转正日期
+ sysUserLevelOther.setYearMonth(sdf.format(calendar.getTime()));
+ }
+ sysUserLevelOtherRepository.save(sysUserLevelOther);
+ } else {
+ // 第二条记录
+ SysUserLevelOther sysUserLevelOther1 = new SysUserLevelOther();
+ sysUserLevelOther1.setUserId(resources.getId());
+ sysUserLevelOther1.setLevelId(cmnLevel.getId());
+ Calendar calendar1 = Calendar.getInstance();
+ calendar1.add(Calendar.YEAR, 1);
+ // 设置月份为一月
+ calendar1.set(Calendar.MONTH, Calendar.JANUARY);
+ calendar1.set(Calendar.DAY_OF_MONTH, 1);
+ sysUserLevelOther1.setPersonalPerformanceProportion(Double.valueOf(0));
+ sysUserLevelOther1.setAnnualLeaveDays(5.0);
+ // 判断实习期结束日期的年份不是今年,年份加1
+ if (formalYear != currentYear) {
+ // 在增加一年
+ calendar1.add(Calendar.YEAR, 1);
+ }
+ // 日期设置为 明年/后年 年初
+ sysUserLevelOther1.setYearMonth(sdf.format(calendar1.getTime()));
+ sysUserLevelOtherRepository.save(sysUserLevelOther1);
+ }
+ }
+ }
+
+ /**
+ * 获取转正的月初时间
+ *
+ * @return
+ */
+ private Timestamp getConfirmationTime(User resources) {
+ Calendar calendar = Calendar.getInstance();
+ // 获取 Calendar 对象所代表的时间
+ calendar.setTime(new Timestamp(calendar.getTimeInMillis()));
+ // 获取是一个月中的哪一天
+ int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
+ // 获取这个月有多少天
+ int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
+ Timestamp result;
+ if (dayOfMonth <= daysInMonth / 2) {
+ // 实习时间为空默认三个月,用户是在前半个月加入的,算上本月获取两个月之后的日期
+ calendar.add(Calendar.MONTH, resources.getInternshipTime() == null ? 3 : resources.getInternshipTime());
+ } else {
+ // 用户是在后半个月加入的,不算本月获取三个月之后的日期
+ calendar.add(Calendar.MONTH, resources.getInternshipTime() == null ? 4 : resources.getInternshipTime() + 1);
+ }
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
+ result = new Timestamp(calendar.getTimeInMillis());
+ return result;
+ }
+
+ /**
+ * 获取年假
+ * @param calendar
+ * @return
+ */
+ private Double getAnnualLeave(Calendar calendar) {
+ // 转正的月份
+ int joinMonth = calendar.get(Calendar.MONTH);
+ Double annualLeave = 0.0;
+ int remainingMonths = 12 - joinMonth;
+ // 计算年假天数
+ annualLeave = (5.0 / 12) * remainingMonths;
+ BigDecimal big = new BigDecimal(annualLeave);
+ big = big.setScale(1, BigDecimal.ROUND_HALF_UP);
+ annualLeave = big.doubleValue();
+ return annualLeave;
+ }
+
+
+ /**
+ * 创建用户级别工资(旧)
+ *
* @param userId
* @param levelId
*/
@@ -774,7 +1476,7 @@
sysUserLevelWageRepository.save(sysUserLevelWage);
}
- // 创建用户级别保险
+ // 创建用户级别保险(旧)
private void createSysUserLevelInsurance(Long userId, Long levelId) {
// 级别
SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new);
@@ -803,24 +1505,5 @@
sysUserLevelInsurance.setIndustrialInjuryCompanyProportion(sysLevel.getIndustrialInjuryCompanyProportion());
// 保存
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);
}
}
--
Gitblit v1.9.3