package com.ruoyi.web.controller.api;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.BaseModel;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.applet.dto.*;
import com.ruoyi.system.applet.query.AppealListQuery;
import com.ruoyi.system.applet.query.KnowledgeListUserQuery;
import com.ruoyi.system.applet.query.LeaveListUserQuery;
import com.ruoyi.system.applet.query.TaskUserListQuery;
import com.ruoyi.system.applet.vo.*;
import com.ruoyi.system.dto.KnowledgeDTO;
import com.ruoyi.system.dto.TTaskAuditBatchDTO;
import com.ruoyi.system.dto.TTaskAuditDTO;
import com.ruoyi.system.dto.TTaskDTO;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.InsepectorListQuery;
import com.ruoyi.system.query.KnowledgeListQuery;
import com.ruoyi.system.query.TaskListQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.system.*;
import com.sun.jna.platform.win32.LMAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
*
* 任务记录 前端控制器
*
*
* @author xiaochen
* @since 2025-05-28
*/
@Api(tags = "个人中心")
@RestController
@RequestMapping("/t-user")
public class TUserController {
@Resource
private TTaskCleanService taskCleanerService;
@Resource
private TTaskDetailService taskDetailService;
@Resource
private TLocationTypeService locationTypeService;
@Resource
private TLocationService locationService;
@Resource
private TProjectDeptService projectDeptService;
@Resource
private TTaskDetailService tTaskDetailService;
@Resource
private TDeptService deptService;
@Resource
private ISysUserService sysUserService;
@Resource
private ISysRoleService roleService;
@Resource
private TDictDataService dictDataService;
@Resource
private TLeaveService leaveService;
@Resource
private TLeaveAuditService leaveAuditService;
@Resource
private TokenService tokenService;
@Resource
private TAppealService appealService;
@Resource
private TInspectorService inspectorService;
@Resource
private TFeedbackService feedbackService;
@Resource
private TProblemEscalationService problemEscalationService;
/**
* 生成数据
* @param id
* @return
*/
@ApiOperation(value = "测试接口不要调")
@GetMapping(value = "/testData")
public R testData(@RequestParam String id) {
List tAppeals = new ArrayList<>();
for (int i = 0; i < 25; i++) {
TAppeal tAppeal = new TAppeal();
tAppeal.setTaskId("1938536771253641217");
tAppeal.setAppealPerson("152");
tAppeal.setStatus(1);
tAppeal.setAppealContent("申诉");
tAppeal.setPictures("https://bjxj.oss-cn-guangzhou.aliyuncs.com/bjxj/88d2d5614fe6492bba5666a7ab01e76b.png");
tAppeals.add(tAppeal);
}
appealService.saveBatch(tAppeals);
List tAppeals1 = new ArrayList<>();
for (int i = 0; i < 25; i++) {
TAppeal tAppeal = new TAppeal();
tAppeal.setTaskId("1938536771253641217");
tAppeal.setAppealPerson("152");
tAppeal.setStatus(2);
tAppeal.setAppealContent("申诉");
tAppeal.setPictures("https://bjxj.oss-cn-guangzhou.aliyuncs.com/bjxj/88d2d5614fe6492bba5666a7ab01e76b.png");
tAppeal.setAuditPerson("162");
tAppeal.setAuditRemark("备注");
tAppeal.setAuditTime(LocalDateTime.now());
tAppeals1.add(tAppeal);
}
appealService.saveBatch(tAppeals1);
List tAppeals2 = new ArrayList<>();
for (int i = 0; i < 25; i++) {
TAppeal tAppeal = new TAppeal();
tAppeal.setTaskId("1938536771253641217");
tAppeal.setAppealPerson("152");
tAppeal.setStatus(3);
tAppeal.setAppealContent("申诉");
tAppeal.setPictures("https://bjxj.oss-cn-guangzhou.aliyuncs.com/bjxj/88d2d5614fe6492bba5666a7ab01e76b.png");
tAppeal.setAuditPerson("162");
tAppeal.setAuditRemark("备注");
tAppeal.setAuditTime(LocalDateTime.now());
tAppeals2.add(tAppeal);
}
appealService.saveBatch(tAppeals2);
List tAppeals3 = new ArrayList<>();
for (int i = 0; i < 25; i++) {
TAppeal tAppeal = new TAppeal();
tAppeal.setTaskId("1938536771253641217");
tAppeal.setAppealPerson("152");
tAppeal.setStatus(4);
tAppeal.setAppealContent("申诉");
tAppeal.setPictures("https://bjxj.oss-cn-guangzhou.aliyuncs.com/bjxj/88d2d5614fe6492bba5666a7ab01e76b.png");
tAppeals3.add(tAppeal);
}
appealService.saveBatch(tAppeals3);
return R.ok();
}
@ApiOperation(value = "个人中心-首页")
@PostMapping(value = "/userIndex")
public R userIndex() {
UserIndexVO userIndexVO = new UserIndexVO();
Long userId = tokenService.getLoginUserApplet().getUserId();
SysUser sysUser = sysUserService.selectUserById(userId);
userIndexVO.setAvatar(sysUser.getAvatar());
userIndexVO.setNickName(sysUser.getNickName());
userIndexVO.setPhonenumber(sysUser.getPhonenumber());
if (sysUser.getDeptType() == 1){
TProjectDept tProjectDept = projectDeptService.getById(sysUser.getDeptId());
if (!tProjectDept.getParentId().equals("0")){
TProjectDept tProjectDept1 = projectDeptService.getById(tProjectDept.getParentId());
userIndexVO.setDeptName(tProjectDept1.getProjectName()+">"+tProjectDept.getProjectName());
}else{
userIndexVO.setDeptName(tProjectDept.getProjectName());
}
}else{
TDept tDept = deptService.getById(sysUser.getDeptId());
userIndexVO.setDeptName(tDept.getDeptName());
}
// 查询请假状态
List list = leaveService.lambdaQuery().eq(TLeave::getLeavePerson, userId)
.eq(TLeave::getAuditStatus, 2)
.list();
userIndexVO.setIsLeave(0);
for (TLeave tLeave : list) {
LocalDate now = LocalDate.now();
LocalDate startDate = tLeave.getStartTime().toLocalDate();
LocalDate endDate = tLeave.getStartTime().toLocalDate();
if (now.isAfter(startDate) && now.isBefore(endDate)) {
userIndexVO.setIsLeave(1);
}else if (now.isEqual(startDate)|| now.isEqual(endDate)){
userIndexVO.setIsLeave(1);
}
}
// 获取本月第一天凌晨00:00:00 和本月最后一天23:59:59 类型为LocalDateTime
// 获取当前日期
LocalDate now = LocalDate.now();
// 本月第一天
LocalDate firstDayOfMonth = now.withDayOfMonth(1);
// 本月最后一天
LocalDate lastDayOfMonth = now.withDayOfMonth(now.lengthOfMonth());
// 转换为 LocalDateTime:第一天的 00:00:00
LocalDateTime startOfMonth = LocalDateTime.of(firstDayOfMonth, LocalTime.MIN);
// 转换为 LocalDateTime:最后一天的 23:59:59
LocalDateTime endOfMonth = LocalDateTime.of(lastDayOfMonth, LocalTime.MAX);
List finishTask = taskCleanerService.lambdaQuery().eq(TTask::getPatrolInspector, userId)
.ge(TTask::getImplementTime, startOfMonth)
.le(TTask::getImplementTime, endOfMonth).list();
List taskIds = finishTask.stream().map(TTask::getId).collect(Collectors.toList());
List taskDetails = taskDetailService.lambdaQuery()
.eq(TTaskDetail::getAuditStatus,1).in(TTaskDetail::getTaskId, taskIds)
.isNotNull(TTaskDetail::getClearStatus)
.groupBy(TTaskDetail::getTaskId)
.orderByDesc(TTaskDetail::getCreateTime).list();
int size = (int) finishTask.stream().filter(e -> e.getStatus() == 5 || e.getStatus() == 6).count();
userIndexVO.setFinishCount(size);
List status1 = taskDetails.stream().filter(e -> e.getClearStatus() == 1).collect(Collectors.toList());
List status2 = taskDetails.stream().filter(e -> e.getClearStatus() == 2).collect(Collectors.toList());
if (status1.size()+status2.size()!=0){
BigDecimal divide = new BigDecimal(status1.size()+status2.size())
.divide(new BigDecimal(status1.size()), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100));
userIndexVO.setRate(divide);
}else{
userIndexVO.setRate(new BigDecimal(0));
}
// todo 月排名
userIndexVO.setRanking(0);
return R.ok(userIndexVO);
}
@ApiOperation(value = "任务记录分页列表")
@PostMapping(value = "/taskList")
public R> pageList(@RequestBody TaskUserListQuery query) {
Long userId = tokenService.getLoginUserApplet().getUserId();
query.setUserId(userId+"");
return R.ok(taskCleanerService.pageListUser(query));
}
@ApiOperation(value = "详情任务")
@GetMapping(value = "/detail")
public R detail(@RequestParam String id) {
List list = taskDetailService.lambdaQuery().eq(TTaskDetail::getTaskId, id)
.orderByDesc(BaseModel::getCreateTime).list();
TaskDetailVO taskDetailVO = new TaskDetailVO();
TTask byId = taskCleanerService.getById(id);
BeanUtils.copyProperties(byId, taskDetailVO);
TLocation byId1 = locationService.getById(byId.getLocationId());
TLocationType byId2 = locationTypeService.getById(byId1.getLocationType());
taskDetailVO.setLocationAddress(byId1.getLocationAddress());
taskDetailVO.setLocationIcon(byId2.getLocationIcon());
taskDetailVO.setLocationName(byId2.getLocationName());
TTaskDetail tTaskDetail = list.stream().filter(e -> e.getHandleType() == 1).findFirst().orElse(null);
if (tTaskDetail!=null && tTaskDetail.getUnqualified()!=null){
TDictData byId3 = dictDataService.getById(tTaskDetail.getUnqualified());
if (byId3!=null){
tTaskDetail.setUnqualifiedName(byId3.getDataContent());
}
}
taskDetailVO.setTaskDetail(tTaskDetail);
taskDetailVO.setRecords(list);
return R.ok(taskDetailVO);
}
@ApiOperation(value = "详情任务-操作记录-详情")
@GetMapping(value = "/detailRecord")
public R detailRecord(@RequestParam String id) {
TaskRecordDetailVO taskDetailVO = new TaskRecordDetailVO();
TTaskDetail byId4 = taskDetailService.getById(id);
TTask byId = taskCleanerService.getById(byId4.getTaskId());
BeanUtils.copyProperties(byId, taskDetailVO);
TLocation byId1 = locationService.getById(byId.getLocationId());
TLocationType byId2 = locationTypeService.getById(byId1.getLocationType());
taskDetailVO.setLocationAddress(byId1.getLocationAddress());
taskDetailVO.setLocationIcon(byId2.getLocationIcon());
taskDetailVO.setLocationName(byId2.getLocationName());
if ( byId4.getUnqualified()!=null){
TDictData byId3 = dictDataService.getById(byId4.getUnqualified());
if (byId3!=null){
byId4.setUnqualifiedName(byId3.getDataContent());
}
}
SysUser sysUser = sysUserService.selectUserById(Long.valueOf(byId4.getAuditPerson()));
if (sysUser!=null){
byId4.setAuditPersonName(sysUser.getUserName());
}
taskDetailVO.setTaskDetail(byId4);
return R.ok(taskDetailVO);
}
@ApiOperation(value = "申诉记录分页列表")
@PostMapping(value = "/appealList")
public R> pageListUser(@RequestBody AppealListQuery query) {
query.setUserId(tokenService.getLoginUserApplet().getUserId()+"");
return R.ok(appealService.pageListUser(query));
}
@ApiOperation(value = "详情申诉记录")
@GetMapping(value = "/appealDetail")
public R appealDetail(@RequestParam String id) {
AppealDetailVO appealDetailVO = new AppealDetailVO();
TAppeal appeal = appealService.getById(id);
BeanUtils.copyProperties(appeal,appealDetailVO);
TTask byId = taskCleanerService.getById(appeal.getTaskId());
TLocation byId1 = locationService.getById(byId.getLocationId());
TLocationType byId2 = locationTypeService.getById(byId1.getLocationType());
appealDetailVO.setLocationAddress(byId1.getLocationAddress());
appealDetailVO.setLocationIcon(byId2.getLocationIcon());
appealDetailVO.setLocationName(byId2.getLocationName());
appealDetailVO.setTaskId(byId.getId());
if (StringUtils.hasLength(appeal.getAuditPerson())){
SysUser sysUser = sysUserService.selectUserById(Long.valueOf(appeal.getAuditPerson()));
if (sysUser!=null){
appealDetailVO.setAuditPersonName(sysUser.getUserName());
}
}
appealDetailVO.setTaskName(byId.getTaskName());
appealDetailVO.setTaskCode(byId.getTaskCode());
return R.ok(appealDetailVO);
}
@Log(title = "取消申诉记录", businessType = BusinessType.OTHER)
@ApiOperation(value = "取消申诉记录")
@GetMapping(value = "/cancelAppeal")
public R cancelAppeal(@RequestParam String id) {
TAppeal byId = appealService.getById(id);
byId.setStatus(4);
appealService.updateById(byId);
return R.ok();
}
@ApiOperation(value = "获取距离最近的任务列表")
@PostMapping(value = "/listAllTask")
public R> listAllTask(@RequestBody AppealListDTO appealListDTO) {
List res = appealService.listAllTask(appealListDTO);
return R.ok(res);
}
@ApiOperation(value = "不合格原因列表")
@PostMapping(value = "/unqualifiedList")
public R> unqualifiedList() {
List list = dictDataService.list(
new LambdaQueryWrapper()
.eq(TDictData::getDataType,2)
);
return R.ok(list);
}
@ApiOperation(value = "上传督察任务")
@PostMapping(value = "/addInspector")
public R addInspector(@RequestBody InspectorAddDTO dto) {
dto.setCommitPerson(tokenService.getLoginUserApplet().getUserId()+"");
if (dto.getClearStatus()==1){
dto.setStatus(4);
}else{
dto.setStatus(1);
}
inspectorService.save(dto);
return R.ok();
}
@ApiOperation(value = "上传意见反馈")
@PostMapping(value = "/addFeedback")
public R addFeedback(@RequestBody FeedbackDTO dto) {
dto.setFeedbackPerson(tokenService.getLoginUserApplet().getUserId()+"");
feedbackService.save(dto);
return R.ok();
}
@ApiOperation(value = "上传问题上报")
@PostMapping(value = "/addProblem")
public R addProblem(@RequestBody ProblemDTO dto) {
dto.setEscalationId(tokenService.getLoginUserApplet().getUserId()+"");
problemEscalationService.save(dto);
return R.ok();
}
@ApiOperation(value = "问题类型列表")
@PostMapping(value = "/problemList")
public R> problemList() {
List list = dictDataService.list(
new LambdaQueryWrapper()
.eq(TDictData::getDataType,3)
);
return R.ok(list);
}
@Resource
private TKnowledgeService knowledgeService;
@ApiOperation(value = "环卫知识分页列表")
@PostMapping(value = "/pageList")
public R> pageList(@RequestBody KnowledgeListUserQuery query) {
return R.ok( knowledgeService.pageListUser(query));
}
@ApiOperation(value = "详情环卫知识")
@GetMapping(value = "/detailKnowledge")
public R detailKnowledge(@RequestParam String id) {
TKnowledge byId = knowledgeService.getById(id);
int i = byId.getViews() + 1;
byId.setViews(i);
knowledgeService.updateById(byId);
return R.ok(byId);
}
@ApiOperation(value = "发起请假-获取审批流程")
@GetMapping(value = "/leaveAuditList")
public R leaveAuditList() {
LeaveAuditListVO res = new LeaveAuditListVO();
Long userId = tokenService.getLoginUserApplet().getUserId();
SysUser user = sysUserService.selectUserById(userId);
Long userRole = sysUserService.getUserRole(userId);
SysRole sysRole = roleService.selectRoleById(userRole);
List sysUsers = sysUserService.selectAllList();
SysUser auditPerson = sysUserService.selectUserById(999L);
//项目负责人、部门负责人、公司成员提交由最终审批人审批;
if (user.getDeptType()==2 ||sysRole.getRoleName().contains("项目负责人")||sysRole.getRoleName().contains("部门负责人")){
LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
tLeaveAudit.setAvatar(auditPerson.getAvatar());
tLeaveAudit.setNickName(auditPerson.getNickName());
res.setAuditPerson(tLeaveAudit);
res.setAuditPersonId("999");
}else if (!sysRole.getRoleName().equals("部门助理")){
// 审批人根据当前角色类型来
if (sysRole.getRoleName().contains("现场负责人")||sysRole.getRoleName().contains("组长")){
List collect = sysUsers.stream().filter(e -> e.getDeptType() == 1 &&
e.getDeptId().equals(user.getDeptId())).collect(Collectors.toList());
for (SysUser sysUser : collect) {
Long userRole1 = sysUserService.getUserRole(sysUser.getUserId());
SysRole sysRole1 = roleService.selectRoleById(userRole1);
if (sysRole1!=null&&sysRole1.getRoleName().equals("项目负责人")){
LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
tLeaveAudit.setAvatar(sysUser.getAvatar());
tLeaveAudit.setNickName(sysUser.getNickName());
res.setAuditPerson(tLeaveAudit);
res.setAuditPersonId(sysUser.getUserId()+"");
break;
}
}
}
}else{
List collect = sysUsers.stream().filter(e -> e.getDeptType() == 1 &&
e.getDeptId().equals(user.getDeptId())).collect(Collectors.toList());
for (SysUser sysUser : collect) {
Long userRole1 = sysUserService.getUserRole(sysUser.getUserId());
SysRole sysRole1 = roleService.selectRoleById(userRole1);
if (sysRole1!=null&&sysRole1.getRoleName().equals("部门负责人")){
LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
tLeaveAudit.setAvatar(sysUser.getAvatar());
tLeaveAudit.setNickName(sysUser.getNickName());
res.setAuditPerson(tLeaveAudit);
res.setAuditPersonId(sysUser.getUserId()+"");
break;
}
}
}
List leaveAuditVOS = new ArrayList<>();
// 当前登陆人-抄送人
LeaveAuditVO leaveAuditVO1 = new LeaveAuditVO();
leaveAuditVO1.setAvatar(user.getAvatar());
leaveAuditVO1.setNickName(user.getNickName());
// 最终审核人-抄送人
LeaveAuditVO leaveAuditVO = new LeaveAuditVO();
leaveAuditVO.setAvatar(auditPerson.getAvatar());
leaveAuditVO.setNickName(auditPerson.getNickName());
leaveAuditVOS.add(leaveAuditVO);
leaveAuditVOS.add(leaveAuditVO1);
res.setCopyPerson(leaveAuditVOS);
return R.ok(res);
}
public static void main(String[] args) {
String temp = "2025-06-30 00:00:00";
// 轉化爲localdateTime
LocalDateTime parse = LocalDateTime.parse(temp, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
System.out.println(parse);
}
@ApiOperation(value = "发起请假")
@PostMapping(value = "/addLeave")
public R addLeave(@RequestBody LeaveDTO leaveDTO) {
// String startTime1 = leaveDTO.getStartTime1();
// // 轉化爲LocalDateTime類型
// leaveDTO.setStartTime(LocalDateTime.parse(startTime1, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
// String endTime1 = leaveDTO.getEndTime1();
// // 轉化爲LocalDateTime類型
// leaveDTO.setStartTime(LocalDateTime.parse(endTime1, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
Long userId = tokenService.getLoginUserApplet().getUserId();
SysUser user = sysUserService.selectUserById(userId);
Long userRole = sysUserService.getUserRole(userId);
SysRole sysRole = roleService.selectRoleById(userRole);
List sysUsers = sysUserService.selectAllList();
SysUser auditPerson = sysUserService.selectUserById(999L);
leaveDTO.setAuditStatus(1);
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
// 生成随机数字6位
String format = simpleDateFormat.format(date);
leaveDTO.setCode(format+ RandomUtil.randomNumbers(6));
leaveDTO.setTemplateId(user.getTemplateId());
leaveDTO.setLeavePerson(userId+"");
leaveService.save(leaveDTO);
//项目负责人、部门负责人、公司成员提交由最终审批人审批;
if (user.getDeptType()==2 ||sysRole.getRoleName().contains("项目负责人")||sysRole.getRoleName().contains("部门负责人")){
TLeaveAudit tLeaveAudit1 = new TLeaveAudit();
tLeaveAudit1.setLeaveId(leaveDTO.getId());
tLeaveAudit1.setAuditStatus(1);
tLeaveAudit1.setAuditId(auditPerson.getUserId()+"");
tLeaveAudit1.setAuditType(1);
leaveAuditService.save(tLeaveAudit1);
}else if (!sysRole.getRoleName().equals("部门助理")){
// 审批人根据当前角色类型来
if (sysRole.getRoleName().contains("现场负责人")||sysRole.getRoleName().contains("组长")){
List collect = sysUsers.stream().filter(e -> e.getDeptType() == 1 &&
e.getDeptId().equals(user.getDeptId())).collect(Collectors.toList());
for (SysUser sysUser : collect) {
Long userRole1 = sysUserService.getUserRole(sysUser.getUserId());
SysRole sysRole1 = roleService.selectRoleById(userRole1);
if (sysRole1!=null&&sysRole1.getRoleName().equals("项目负责人")){
TLeaveAudit tLeaveAudit1 = new TLeaveAudit();
tLeaveAudit1.setLeaveId(leaveDTO.getId());
tLeaveAudit1.setAuditStatus(1);
tLeaveAudit1.setAuditId(sysUser.getUserId()+"");
tLeaveAudit1.setAuditType(1);
leaveAuditService.save(tLeaveAudit1);
}
}
}
}else{
List collect = sysUsers.stream().filter(e -> e.getDeptType() == 1 &&
e.getDeptId().equals(user.getDeptId())).collect(Collectors.toList());
for (SysUser sysUser : collect) {
Long userRole1 = sysUserService.getUserRole(sysUser.getUserId());
SysRole sysRole1 = roleService.selectRoleById(userRole1);
if (sysRole1!=null&&sysRole1.getRoleName().equals("部门负责人")){
TLeaveAudit tLeaveAudit1 = new TLeaveAudit();
tLeaveAudit1.setLeaveId(leaveDTO.getId());
tLeaveAudit1.setAuditStatus(1);
tLeaveAudit1.setAuditId(sysUser.getUserId()+"");
tLeaveAudit1.setAuditType(1);
leaveAuditService.save(tLeaveAudit1);
}
}
}
TLeaveAudit tLeaveAudit2 = new TLeaveAudit();
tLeaveAudit2.setLeaveId(leaveDTO.getId());
tLeaveAudit2.setAuditStatus(2);
tLeaveAudit2.setAuditId(user.getUserId()+","+auditPerson.getUserId());
tLeaveAudit2.setAuditType(2);
tLeaveAudit2.setAuditTime(LocalDateTime.now());
leaveAuditService.save(tLeaveAudit2);
return R.ok();
}
@ApiOperation(value = "我的审批-我的申请")
@PostMapping(value = "/leaveList")
public R> leaveList(@RequestBody LeaveListUserQuery query) {
query.setUserId(tokenService.getLoginUserApplet().getUserId()+"");
return R.ok( leaveService.leaveList(query));
}
@ApiOperation(value = "我的审批-审批")
@PostMapping(value = "/auditLeave")
public R auditLeave(@RequestBody LeaveAuditDTO dto) {
dto.setAuditId(tokenService.getLoginUserApplet().getUserId()+"");
dto.setAuditTime(LocalDateTime.now());
leaveService.updateById(dto);
return R.ok();
}
@ApiOperation(value = "我的审批-详情")
@GetMapping(value = "/leaveDetail")
public R leaveDetail(@RequestParam String id) {
TLeave leave = leaveService.getById(id);
LeaveUserDetailVO leaveUserDetailVO = new LeaveUserDetailVO();
SysUser sysUser = sysUserService.selectUserById(Long.parseLong(leave.getLeavePerson()));
Long userRole = sysUserService.getUserRole(sysUser.getUserId());
SysRole sysRole = roleService.selectRoleById(userRole);
if (sysRole.getRoleName().contains("现场负责人")||sysRole.getRoleName().equals("组长")){
if (sysUser.getDeptType() == 1){
TProjectDept tProjectDept = projectDeptService.getById(sysUser.getDeptId());
if (!tProjectDept.getParentId().equals("0")){
TProjectDept tProjectDept1 = projectDeptService.getById(tProjectDept.getParentId());
leaveUserDetailVO.setDeptName(tProjectDept1.getProjectName()+">"+tProjectDept.getProjectName());
}else{
leaveUserDetailVO.setDeptName(tProjectDept.getProjectName());
}
}else{
TDept tDept = deptService.getById(sysUser.getDeptId());
leaveUserDetailVO.setDeptName(tDept.getDeptName());
}
}else if (sysRole.getRoleName().contains("项目负责人")){
TProjectDept tProjectDept = projectDeptService.getById(sysUser.getDeptId());
leaveUserDetailVO.setDeptName(tProjectDept.getProjectName());
}
if (sysUser.getDeptType() == 2){
TDept byId = deptService.getById(sysUser.getDeptId());
leaveUserDetailVO.setDeptName(byId.getDeptName());
}
leaveUserDetailVO.setLeavePersonName(sysUser.getNickName());
LeaveAuditListVO leaveAuditListVO = new LeaveAuditListVO();
List list = leaveAuditService.list(new LambdaQueryWrapper()
.eq(TLeaveAudit::getAuditId, leave.getId()));
for (TLeaveAudit tLeaveAudit : list) {
if (tLeaveAudit.getAuditType()==1){
LeaveAuditVO leaveAuditVO = new LeaveAuditVO();
SysUser sysUser1 = sysUserService.selectUserById(Long.valueOf(tLeaveAudit.getAuditId()));
if (sysUser1!=null){
leaveAuditVO.setAvatar(sysUser1.getAvatar());
leaveAuditVO.setNickName(sysUser1.getNickName());
}
leaveAuditVO.setCreateTime(tLeaveAudit.getAuditTime());
leaveAuditVO.setAuditStatus(tLeaveAudit.getAuditStatus());
leaveAuditListVO.setAuditPerson(leaveAuditVO);
}else{
List leaveAuditVOS = new ArrayList<>();
// 抄送人
LeaveAuditVO leaveAuditVO = new LeaveAuditVO();
SysUser sysUser1 = sysUserService.selectUserById(Long.valueOf(tLeaveAudit.getAuditId().split(",")[0]));
leaveAuditVO.setAvatar(sysUser1.getAvatar());
leaveAuditVO.setNickName(sysUser1.getNickName());
leaveAuditVO.setCreateTime(tLeaveAudit.getCreateTime());
leaveAuditVO.setAuditStatus(tLeaveAudit.getAuditStatus());
leaveAuditVOS.add(leaveAuditVO);
LeaveAuditVO leaveAuditVO1 = new LeaveAuditVO();
SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(tLeaveAudit.getAuditId().split(",")[1]));
leaveAuditVO1.setAvatar(sysUser2.getAvatar());
leaveAuditVO1.setNickName(sysUser2.getNickName());
leaveAuditVO1.setCreateTime(tLeaveAudit.getCreateTime());
leaveAuditVO1.setAuditStatus(tLeaveAudit.getAuditStatus());
leaveAuditVOS.add(leaveAuditVO1);
leaveAuditListVO.setCopyPerson(leaveAuditVOS);
}
}
leaveUserDetailVO.setAudit(leaveAuditListVO);
leaveUserDetailVO.setId(leave.getId());
leaveUserDetailVO.setLeavePerson(leave.getLeavePerson());
leaveUserDetailVO.setStartTime(leave.getStartTime());
leaveUserDetailVO.setEndTime(leave.getEndTime());
leaveUserDetailVO.setLeaveType(leave.getLeaveType());
leaveUserDetailVO.setLeaveDay(leave.getLeaveDay());
leaveUserDetailVO.setLeaveCause(leave.getLeaveCause());
leaveUserDetailVO.setPictures(leave.getPictures());
leaveUserDetailVO.setAuditStatus(leave.getAuditStatus());
leaveUserDetailVO.setAuditId(leave.getAuditId());
leaveUserDetailVO.setAuditTime(leave.getAuditTime());
leaveUserDetailVO.setAuditRemark(leave.getAuditRemark());
leaveUserDetailVO.setCode(leave.getCode());
return R.ok(leaveUserDetailVO);
}
}