eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceBusinessTravelServiceImpl.java
@@ -19,18 +19,13 @@ import me.zhengjie.modules.attendance.domain.*; import me.zhengjie.modules.attendance.repository.AttendanceGoOutRepository; import me.zhengjie.modules.attendance.repository.AttendanceLeaveRepository; import me.zhengjie.modules.attendance.repository.AttendanceRepository; import me.zhengjie.modules.attendance.service.AttendanceService; import me.zhengjie.modules.attendance.service.dto.AttendanceGoOutDto; import me.zhengjie.modules.constant.Constant; import me.zhengjie.modules.quartz.service.OpaiDingTalkService; import me.zhengjie.modules.quartz.service.impl.DingTalkServiceImpl; import me.zhengjie.modules.system.domain.Job; import me.zhengjie.modules.system.domain.DictDetail; import me.zhengjie.modules.system.domain.Role; import me.zhengjie.modules.system.domain.SysConfigHoliday; import me.zhengjie.modules.system.domain.User; import me.zhengjie.modules.system.repository.DictDetailRepository; import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; import me.zhengjie.modules.system.repository.UserRepository; import me.zhengjie.modules.system.service.UserService; import me.zhengjie.modules.system.service.dto.UserDto; @@ -50,15 +45,13 @@ import java.math.BigDecimal; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.*; import java.io.IOException; import javax.servlet.http.HttpServletResponse; import java.util.function.Function; import java.util.stream.Collectors; /** * @website https://eladmin.vip @@ -76,9 +69,6 @@ private final UserService userService; private final OpaiDingTalkService opaiDingTalkService; private final AttendanceLeaveServiceImpl attendanceLeaveService; private final SysConfigHolidayRepository sysConfigHolidayRepository; private final AttendanceService attendanceService; private final AttendanceRepository attendanceRepository; private final AttendanceLeaveRepository attendanceLeaveRepository; private final AttendanceGoOutRepository attendanceGoOutRepository; private final DictDetailRepository dictDetailRepository; @@ -340,26 +330,22 @@ @Override public void download(List<AttendanceBusinessTravelDto> all, HttpServletResponse response) throws IOException { List<Map<String, Object>> list = new ArrayList<>(); Map<String, String> bussDurationUnitMap = dictDetailRepository.findByDictName(Constant.LEAVE_TIME_TYPE).stream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel)); Map<String, String> bussStatusMap = dictDetailRepository.findByDictName(Constant.BUSSINESS_APPROVE_STATUS).stream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel)); for (AttendanceBusinessTravelDto attendanceBusinessTravel : all) { String bussDurationUnit = attendanceBusinessTravel.getDurationUnit() != null ? dictDetailRepository.findByDictNameAndValue(Constant.LEAVE_TIME_TYPE, attendanceBusinessTravel.getDurationUnit()).getLabel() : ""; String bussStatus = attendanceBusinessTravel.getApprovalStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.BUSSINESS_APPROVE_STATUS, attendanceBusinessTravel.getApprovalStatus()).getLabel() : ""; Map<String,Object> map = new LinkedHashMap<>(); map.put("用户", attendanceBusinessTravel.getUserName()); map.put("审批用户", attendanceBusinessTravel.getAppUserName()); map.put("用户", attendanceBusinessTravel.getUserName()); map.put("审批用户", attendanceBusinessTravel.getAppUserName()); map.put("出差开始时间", attendanceBusinessTravel.getTravelStartTime()); map.put("出差结束时间", attendanceBusinessTravel.getTravelEndTime()); map.put("出差时长", attendanceBusinessTravel.getTravelDuration()); map.put("时长单位", bussDurationUnit); map.put("时长单位", attendanceBusinessTravel.getDurationUnit() != null ? bussDurationUnitMap.get(attendanceBusinessTravel.getDurationUnit()) : ""); map.put("出差原因", attendanceBusinessTravel.getTravelReason()); map.put("出发城市", attendanceBusinessTravel.getDepartureCity()); map.put("到达城市", attendanceBusinessTravel.getArrivalCity()); map.put("审批状态", bussStatus); map.put("审批状态", attendanceBusinessTravel.getApprovalStatus() != null ? bussStatusMap.get(attendanceBusinessTravel.getApprovalStatus()) : ""); map.put("审批说明", attendanceBusinessTravel.getApprovalDescription()); map.put("备注", attendanceBusinessTravel.getRemarks()); map.put("创建者", attendanceBusinessTravel.getCreateBy()); map.put("创建时间", attendanceBusinessTravel.getCreateTime()); map.put("更新者", attendanceBusinessTravel.getUpdateBy()); map.put("更新时间", attendanceBusinessTravel.getUpdateTime()); list.add(map); } FileUtil.downloadExcel(list, response); eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/DeptAndUser.java
@@ -7,7 +7,7 @@ @Data public class DeptAndUser { private Long id; private Long value; String label; boolean flag = false; List<DeptAndUser> children; eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/DeptRepository.java
@@ -73,4 +73,7 @@ @Modifying @Query(value = " update sys_dept set sub_count = ?1 where dept_id = ?2 ",nativeQuery = true) void updateSubCntById(Integer count, Long id); @Query(value = "select pid from sys_dept where dept_id = ?1",nativeQuery = true) Long findPidIdByDeptId(Long deptId); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/UserRepository.java
@@ -15,6 +15,7 @@ */ package me.zhengjie.modules.system.repository; import io.swagger.models.auth.In; import me.zhengjie.modules.system.domain.Dept; import me.zhengjie.modules.system.domain.User; import org.springframework.data.jpa.repository.JpaRepository; @@ -189,4 +190,7 @@ @Query(value = "select * from sys_user where dept_id = ?1 and enabled=?2", nativeQuery = true) List<User> findByDeptIdInAndEnabledWithSingle(Long deptId, Boolean enabled); @Query(value = "select dept_id from sys_user where user_id = ?1",nativeQuery = true) Long findDeptIdByUserId(Long userId); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java
@@ -279,4 +279,14 @@ public ResponseEntity<Object> getAllUserDetail(){ return new ResponseEntity<>(userService.getUserDept(),HttpStatus.OK); } @GetMapping("/getUserPidDept") public ResponseEntity<Object> getUserPidDept(Long[] ids) { List<Long[]> result = new ArrayList<>(); for (Long id : ids) { result.add(userService.getUserPidDept(id)); } return new ResponseEntity<>(result,HttpStatus.OK); } } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/UserService.java
@@ -150,4 +150,5 @@ List<DeptAndUser> getUserDept(); Long[] getUserPidDept(Long id); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
@@ -175,6 +175,7 @@ } @Override @Cacheable(key = "'AllUser'") public List<DeptAndUser> getUserDept() { List<Dept> all = deptRepository.findAll(); List<DeptAndUser> result = new ArrayList<>(); @@ -183,7 +184,7 @@ if (dept.getPid() == null) { //没有上级部门,他们就是最顶级的菜单 DeptAndUser deptAndUser = new DeptAndUser(); deptAndUser.setId(dept.getId()); deptAndUser.setValue(dept.getId()); deptAndUser.setLabel(dept.getName()); result.add(deptAndUser); } @@ -193,10 +194,10 @@ for (Dept dept : all) { // 一级节点 if (dept.getPid() != null) { if (dept.getPid().equals(result.get(0).getId())) { if (dept.getPid().equals(result.get(0).getValue())) { DeptAndUser deptAndUser = new DeptAndUser(); deptAndUser.setLabel(dept.getName()); deptAndUser.setId(dept.getId()); deptAndUser.setValue(dept.getId()); list.add(deptAndUser); } } @@ -208,10 +209,10 @@ List<DeptAndUser> list_two = new ArrayList<>(); for (Dept dept : all) { if (dept.getPid() != null) { if (dept.getPid().equals(result.get(0).getChildren().get(i).getId())) { if (dept.getPid().equals(result.get(0).getChildren().get(i).getValue())) { DeptAndUser deptAndUser = new DeptAndUser(); deptAndUser.setLabel(dept.getName()); deptAndUser.setId(dept.getId()); deptAndUser.setValue(dept.getId()); list_two.add(deptAndUser); } } @@ -224,10 +225,10 @@ 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).getId())) { if (dept.getPid().equals(result.get(0).getChildren().get(i).getChildren().get(j).getValue())) { DeptAndUser deptAndUser = new DeptAndUser(); deptAndUser.setLabel(dept.getName()); deptAndUser.setId(dept.getId()); deptAndUser.setValue(dept.getId()); list_three.add(deptAndUser); } } @@ -240,13 +241,13 @@ 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).getId()).get().getSubCount() == 0)) { 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).getId())) { if (dept.getPid().equals(result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getValue())) { DeptAndUser deptAndUser = new DeptAndUser(); deptAndUser.setId(dept.getId()); deptAndUser.setValue(dept.getId()); deptAndUser.setLabel(dept.getName()); list_four.add(deptAndUser); } @@ -260,33 +261,33 @@ for (int i = 0; i < result.get(0).getChildren().size(); i++) { if (result.get(0).getChildren().get(i).getChildren() != null) { for (User user : userRepository.findByDeptIdInAndEnabledWithSingle(result.get(0).getChildren().get(i).getId(), true)) { for (User user : userRepository.findByDeptIdInAndEnabledWithSingle(result.get(0).getChildren().get(i).getValue(), true)) { DeptAndUser deptAndUser = new DeptAndUser(); deptAndUser.setFlag(true); deptAndUser.setLabel(user.getNickName()); deptAndUser.setId(user.getId()); deptAndUser.setValue(user.getId()); result.get(0).getChildren().get(i).getChildren().add(deptAndUser); } for (int j = 0; j < result.get(0).getChildren().get(i).getChildren().size(); j++) { if (result.get(0).getChildren().get(i).getChildren().get(j).getChildren() != null) { for (int r = 0; r < result.get(0).getChildren().get(i).getChildren().get(j).getChildren().size(); r++) { if (result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getChildren() != null) { for (User user : userRepository.findByDeptIdInAndEnabledWithSingle(result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getId(), true)) { for (User user : userRepository.findByDeptIdInAndEnabledWithSingle(result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getValue(), true)) { DeptAndUser deptAndUser = new DeptAndUser(); deptAndUser.setLabel(user.getNickName()); deptAndUser.setId(user.getId()); deptAndUser.setValue(user.getId()); deptAndUser.setFlag(true); result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getChildren().add(deptAndUser); } for (int s = 0; s < result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getChildren().size(); s++) { if (result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getChildren().get(s).getChildren() == null) { if (!result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getChildren().get(s).isFlag()) { List<User> byDeptIdInAndEnabledWithSingle = userRepository.findByDeptIdInAndEnabledWithSingle(result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getChildren().get(s).getId(), true); List<User> byDeptIdInAndEnabledWithSingle = userRepository.findByDeptIdInAndEnabledWithSingle(result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getChildren().get(s).getValue(), true); List<DeptAndUser> newList = new ArrayList<>(); for (User user : byDeptIdInAndEnabledWithSingle) { DeptAndUser deptAndUser = new DeptAndUser(); deptAndUser.setLabel(user.getNickName()); deptAndUser.setId(user.getId()); deptAndUser.setValue(user.getId()); newList.add(deptAndUser); } result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getChildren().get(s).setChildren(newList); @@ -294,12 +295,12 @@ } } } else if (!result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).isFlag()) { List<User> byDeptIdInAndEnabledWithSingle = userRepository.findByDeptIdInAndEnabledWithSingle(result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getId(), true); List<User> byDeptIdInAndEnabledWithSingle = userRepository.findByDeptIdInAndEnabledWithSingle(result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).getValue(), true); List<DeptAndUser> newList = new ArrayList<>(); for (User user : byDeptIdInAndEnabledWithSingle) { DeptAndUser deptAndUser = new DeptAndUser(); deptAndUser.setLabel(user.getNickName()); deptAndUser.setId(user.getId()); deptAndUser.setValue(user.getId()); newList.add(deptAndUser); } result.get(0).getChildren().get(i).getChildren().get(j).getChildren().get(r).setChildren(newList); @@ -313,6 +314,25 @@ return result; } @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()]); } 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'") eladmin-web-master/src/api/system/user.js
@@ -116,4 +116,11 @@ }) } export default { getAll, add, edit, del, get, getApprovalUsers, getUserCalendarInfo, getUserBaseInfo, getByDept, getProjectUser, getUserDept } export function getUserPidDept(param) { return request({ url: 'api/users/getUserPidDept?ids=' + param, method: 'get' }) } export default { getAll, add, edit, del, get, getApprovalUsers, getUserCalendarInfo, getUserBaseInfo, getByDept, getProjectUser, getUserDept, getUserPidDept } eladmin-web-master/src/views/task/task/index.vue
@@ -59,10 +59,12 @@ </el-select> <div class="block"> <el-cascader v-model="queryUser" :options="options" :props="props" collapse-tags clearable placeholder="任务负责人" :show-all-levels="false" style="width: 185px;" /> </div> <rrOperation :crud="crud" /> @@ -141,31 +143,34 @@ </el-input> </el-form-item> <el-form-item label="任务成员" prop="containUserList"> <el-select v-model="form.containUserList" multiple filterable clearable placeholder="请选择" style="width: 340px;" @change="getContainUserList"> <el-option v-for="item in users" :key="item.id" :label="item.nickName" :value="item.id" > <span style="float: left">{{ item.nickName }}</span> <span style="float: right; color: #8492a6; font-size: 13px">{{ item.levelName }}</span> </el-option> </el-select> <div class="block"> <el-cascader v-model="selectedValue" :filterable="true" :options="options" :props="props" clearable placeholder="任务负责人" :show-all-levels="false" style="width: 340px;" /> </div> </el-form-item> <el-form-item label="任务负责人" prop="userId"> <el-select v-model="form.userIdList" :no-data-text=" '没有任务成员' " multiple filterable clearable placeholder="请选择" style="width: 340px;"> <el-select v-if="form.containUserList" v-model="form.userIdList" :no-data-text=" '没有任务成员' " multiple filterable clearable placeholder="请选择" style="width: 340px;"> <el-option v-for="item in users" v-show="form.containUserList != undefined && form.containUserList.some(animal => animal === item.id)" :key="item.id" :label="item.nickName" :value="item.id" :show-all-levels="false" > <span style="float: left">{{ item.nickName }}</span> <span style="float: right; color: #8492a6; font-size: 13px">{{ item.levelName }}</span> </el-option> </el-select> <el-select v-else v-model="form.userIdList" :no-data-text=" '没有任务成员' " multiple filterable clearable placeholder="请选择" style="width: 340px;" /> </el-form-item> </el-form> <div slot="footer" class="dialog-footer"> @@ -356,10 +361,28 @@ inputVisible: false, inputValue: null, containUserList: [], userList: [], options: [], deptList: [], jobList: [], userList: [] selectedValue: [], queryUser: [], selectedValue_flag: false } }, watch: { 'selectedValue': function(newVal) { this.form.containUserList = [] for (let i = 0; i < newVal.length; i++) { var temp = [] temp = newVal[i] if (!this.form.containUserList.includes(temp[newVal[i].length - 1])) { // 如果不在 this.form.containUserList.push(temp[newVal[i].length - 1]) } } }, 'queryUser': function(newVal) { // this.query.userId = newVal[newVal.length - 1] } }, created() { @@ -374,25 +397,26 @@ }, methods: { [CRUD.HOOK.afterSubmit]() { this.form.containUserList = null this.form.containUserList = [] this.selectedValue = null }, [CRUD.HOOK.afterEditError]() { this.form.containUserList = null this.form.containUserList = [] this.selectedValue = null }, [CRUD.HOOK.afterEditCancel]() { this.form.containUserList = null this.form.containUserList = [] this.selectedValue = null }, [CRUD.HOOK.afterAddCancel]() { this.form.containUserList = null this.form.containUserList = [] this.selectedValue = null }, [CRUD.HOOK.afterAddError]() { this.form.containUserList = null }, [CRUD.HOOK.beforeToCU]() { this.form.containUserList = null this.form.containUserList = [] this.selectedValue = null }, getContainUserList(e) { console.log(e) this.form.containUserList = e }, getTags() { @@ -411,6 +435,11 @@ this.userRolesLevelMin = Math.min(...userRolesLevel) return true }, [CRUD.HOOK.beforeToEdit]() { crudUser.getUserPidDept(this.form.containUserList).then(res => { this.selectedValue = res }) }, [CRUD.HOOK.beforeSubmit]() { if (!this.form.taskStatus) { @@ -464,7 +493,8 @@ }, handleInputConfirm() { const inputValue = this.inputValue if (inputValue !== '') { console.log(inputValue) if (inputValue !== '' && inputValue !== null && inputValue !== ' ') { this.form.tagList.push(inputValue) } this.inputVisible = false @@ -584,4 +614,15 @@ margin-left: 10px; vertical-align: bottom; } .block{ display: inline-block; vertical-align: middle; margin: 0 3px 10px 0; input { height: 30.5px; line-height: 30.5px; } } </style>