Commit 394170c5 authored by lwy's avatar lwy

工时管理

parent 64b120e5
...@@ -6,8 +6,11 @@ import javax.servlet.http.HttpServletResponse; ...@@ -6,8 +6,11 @@ import javax.servlet.http.HttpServletResponse;
import com.ruoyi.domain.Timesheet; import com.ruoyi.domain.Timesheet;
import com.ruoyi.domain.dto.AddTimesheetDTO; import com.ruoyi.domain.dto.AddTimesheetDTO;
import com.ruoyi.domain.dto.CheckTimesheetDTO;
import com.ruoyi.domain.dto.TimesheetDTO; import com.ruoyi.domain.dto.TimesheetDTO;
import com.ruoyi.service.ITimesheetService; import com.ruoyi.service.ITimesheetService;
import com.ruoyi.system.domain.ProjectMember;
import com.ruoyi.system.service.IProjectMemberService;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
...@@ -27,6 +30,7 @@ import com.ruoyi.common.core.page.TableDataInfo; ...@@ -27,6 +30,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
* @author ruoyi * @author ruoyi
* @date 2025-03-11 * @date 2025-03-11
*/ */
@RestController @RestController
@RequestMapping("/timesheet/timesheet") @RequestMapping("/timesheet/timesheet")
public class TimesheetController extends BaseController public class TimesheetController extends BaseController
...@@ -34,8 +38,11 @@ public class TimesheetController extends BaseController ...@@ -34,8 +38,11 @@ public class TimesheetController extends BaseController
@Autowired @Autowired
private ITimesheetService timesheetService; private ITimesheetService timesheetService;
/*查询个人工时*/ @Autowired
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:list')") private IProjectMemberService projectMemberService;
/*查询工时*/
//@PreAuthorize("@ss.hasPermi('timesheet:timesheet:list')")
@GetMapping("/pTimesheetList") @GetMapping("/pTimesheetList")
public ResponseEntity<List<TimesheetDTO>> getProjectTimesheetList( public ResponseEntity<List<TimesheetDTO>> getProjectTimesheetList(
@ModelAttribute Timesheet timesheet, @ModelAttribute Timesheet timesheet,
...@@ -47,7 +54,7 @@ public class TimesheetController extends BaseController ...@@ -47,7 +54,7 @@ public class TimesheetController extends BaseController
timesheet.setStartTime(startTime); timesheet.setStartTime(startTime);
timesheet.setEndTime(endTime); timesheet.setEndTime(endTime);
timesheet.setManagerName(managerName); // 设置 managerName timesheet.setManagerName(managerName); // 设置 managerName
System.out.println("timesheet.getManagerName()---------------"+timesheet.getManagerName());
List<TimesheetDTO> result = timesheetService.getProjectTimesheetList(timesheet); List<TimesheetDTO> result = timesheetService.getProjectTimesheetList(timesheet);
return ResponseEntity.ok(result); return ResponseEntity.ok(result);
} }
...@@ -55,7 +62,7 @@ public class TimesheetController extends BaseController ...@@ -55,7 +62,7 @@ public class TimesheetController extends BaseController
/* /*
* 填报工时--查询个人填报 * 填报工时--查询个人填报
*/ */
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:list')") // @PreAuthorize("@ss.hasPermi('timesheet:timesheet:submit')")
@GetMapping("/personalTimesheet/{employId}") @GetMapping("/personalTimesheet/{employId}")
public ResponseEntity<List<AddTimesheetDTO>> getPersonalTimesheet(@PathVariable("employId") Long employId) { public ResponseEntity<List<AddTimesheetDTO>> getPersonalTimesheet(@PathVariable("employId") Long employId) {
List<AddTimesheetDTO> result = timesheetService.getPersonalTimesheet(employId); List<AddTimesheetDTO> result = timesheetService.getPersonalTimesheet(employId);
...@@ -66,15 +73,47 @@ public class TimesheetController extends BaseController ...@@ -66,15 +73,47 @@ public class TimesheetController extends BaseController
* 批量插入工时记录 * 批量插入工时记录
* *
*/ */
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:add')") //@PreAuthorize("@ss.hasPermi('timesheet:timesheet:add')")
@Log(title = "插入工时记录", businessType = BusinessType.INSERT) @Log(title = "插入工时记录", businessType = BusinessType.INSERT)
@PostMapping("/batchInsert") @PostMapping("/batchInsert")
public AjaxResult batchInsertTimesheet(@RequestBody AddTimesheetDTO addTimesheetDTO) { public AjaxResult batchInsertTimesheet(@RequestBody AddTimesheetDTO addTimesheetDTO) {
logger.info("Received batch insert request: {}", addTimesheetDTO); System.out.println("批量插入对象 = " + addTimesheetDTO);
int result = timesheetService.insertTimesheetList(addTimesheetDTO); int result = timesheetService.insertTimesheetList(addTimesheetDTO);
return toAjax(result); return toAjax(result);
} }
/**
* 工时审批--按周分组查询
*
* @return 按周分组的工时审批列表
*/
//@PreAuthorize("@ss.hasPermi('timesheet:timesheet:check')")
@GetMapping("/checkTimesheetList")
public ResponseEntity<List<CheckTimesheetDTO>> getTimesheetCheck(@ModelAttribute Timesheet query) {
// query.setManagerId(Long.valueOf(query.getManagerId()));
List<CheckTimesheetDTO> result = timesheetService.getTimesheetCheck(query);
return ResponseEntity.ok(result);
}
/**
* 根据项目编号和经理ID查询项目成员的用户ID和昵称
*
* @param projectNumber 项目编号
* @param managerId 经理ID
* @return 项目成员列表
*/
@GetMapping("/getEmployNameListByManagerId")
public AjaxResult selectEmployNameListByManagerId(
@RequestParam(required = false) String projectNumber,
@RequestParam Long managerId)
{
logger.info("Received projectNumber: {}", projectNumber);
logger.info("Received managerId: {}", managerId);
// 处理逻辑
List<ProjectMember> list = projectMemberService.selectEmployNameListByManagerId(projectNumber, managerId);
return success(list);
}
/** /**
* 查询工时记录列表 * 查询工时记录列表
*/ */
...@@ -132,6 +171,14 @@ public class TimesheetController extends BaseController ...@@ -132,6 +171,14 @@ public class TimesheetController extends BaseController
return toAjax(timesheetService.updateTimesheet(timesheet)); return toAjax(timesheetService.updateTimesheet(timesheet));
} }
// @PreAuthorize("@ss.hasPermi('timesheet:timesheet:edit')")
@Log(title = "更新审批状态和备注", businessType = BusinessType.UPDATE)
@PutMapping("/updateApprovalStateAndNote")
public AjaxResult updateApprovalStateAndNote(@RequestBody CheckTimesheetDTO checkTimesheetDTO) {
int result = timesheetService.updateWeekTimesheet(checkTimesheetDTO);
return toAjax(result);
}
/** /**
* 删除工时记录 * 删除工时记录
*/ */
......
...@@ -39,14 +39,16 @@ public class Timesheet extends BaseEntity ...@@ -39,14 +39,16 @@ public class Timesheet extends BaseEntity
/** 项目名称 */ /** 项目名称 */
@Excel(name = "项目名称") @Excel(name = "项目名称")
@TableField(exist = false)
private String projectName; private String projectName;
/** 项目经理编号 */ /** 项目经理编号 */
@Excel(name = "项目经理编号") /* @Excel(name = "项目经理编号")
private Long managerId; private Long managerId;*/
/** 事业部负责人编号 */ /** 事业部负责人编号 */
@Excel(name = "事业部负责人编号") @Excel(name = "事业部负责人编号")
@TableField(exist = false)
private Long departmentLeaderId; private Long departmentLeaderId;
/** 工时 */ /** 工时 */
...@@ -92,6 +94,9 @@ public class Timesheet extends BaseEntity ...@@ -92,6 +94,9 @@ public class Timesheet extends BaseEntity
@TableField(exist = false) @TableField(exist = false)
private Date endTime; private Date endTime;
@TableField(exist = false)
private Long projectManagerId;
/* @TableField(exist = false) /* @TableField(exist = false)
private Date startTime; private Date startTime;
......
package com.ruoyi.domain.dto; package com.ruoyi.domain.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
import java.util.List; import java.util.List;
@Data @Data
public class AddTimesheetDTO { public class AddTimesheetDTO {
...@@ -26,6 +28,12 @@ public class AddTimesheetDTO { ...@@ -26,6 +28,12 @@ public class AddTimesheetDTO {
private String approvalNote; private String approvalNote;
@JsonFormat(pattern = "yyyy/MM/dd")
private Date startTime;
@JsonFormat(pattern = "yyyy/MM/dd")
private Date endTime;
private BigDecimal totalHours; private BigDecimal totalHours;
......
...@@ -8,7 +8,7 @@ import java.math.BigDecimal; ...@@ -8,7 +8,7 @@ import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
@Data @Data
public class AddWorkDTO { public class AddWorkDTO {
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy/MM/dd")
@Excel(name = "工作日期", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "工作日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date workTime; private Date workTime;
......
package com.ruoyi.domain.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class CheckTimesheetDTO {
private String projectNumber;
private String projectName;
@JsonFormat(pattern = "yyyy/MM/dd")
private Date startTime;
@JsonFormat(pattern = "yyyy/MM/dd")
private Date endTime;
private List<EmployeeTimesheetDTO> employeeTimesheetList;
}
package com.ruoyi.domain.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Data
public class EmployeeTimesheetDTO {
private Long employId;
private String employName;
private String approvalState;
private String approvalNote;
private BigDecimal totalHours;
@JsonFormat(pattern = "yyyy/MM/dd")
private Date startTime;
@JsonFormat(pattern = "yyyy/MM/dd")
private Date endTime;
private List<WorkDetailDTO> workDetailList;
}
...@@ -9,7 +9,9 @@ import java.util.Date; ...@@ -9,7 +9,9 @@ import java.util.Date;
@Data @Data
public class WorkDetailDTO { public class WorkDetailDTO {
@JsonFormat(pattern = "MM-dd") private Long id;
@JsonFormat(pattern = "MM/dd")
@Excel(name = "工作日期", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "工作日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date workTime; private Date workTime;
...@@ -19,4 +21,8 @@ public class WorkDetailDTO { ...@@ -19,4 +21,8 @@ public class WorkDetailDTO {
this.workTime = workTime; this.workTime = workTime;
this.hours = hours; this.hours = hours;
} }
public WorkDetailDTO() {
// 默认构造函数
}
} }
...@@ -29,6 +29,13 @@ public interface TimesheetMapper ...@@ -29,6 +29,13 @@ public interface TimesheetMapper
List<Timesheet> selectPersonalTimesheet(@Param("employId") Long employId, @Param("workTime") Date workTime, @Param("projectNumber") String projectNumber); List<Timesheet> selectPersonalTimesheet(@Param("employId") Long employId, @Param("workTime") Date workTime, @Param("projectNumber") String projectNumber);
/**
* 工时审批--获取审批
* @return
*/
List<Timesheet> selectTimesheetByManagerId(Timesheet query);
/** /**
* 查询工时记录 * 查询工时记录
* *
......
...@@ -2,6 +2,7 @@ package com.ruoyi.service; ...@@ -2,6 +2,7 @@ package com.ruoyi.service;
import com.ruoyi.domain.Timesheet; import com.ruoyi.domain.Timesheet;
import com.ruoyi.domain.dto.AddTimesheetDTO; import com.ruoyi.domain.dto.AddTimesheetDTO;
import com.ruoyi.domain.dto.CheckTimesheetDTO;
import com.ruoyi.domain.dto.TimesheetDTO; import com.ruoyi.domain.dto.TimesheetDTO;
import java.util.Date; import java.util.Date;
...@@ -37,6 +38,10 @@ public interface ITimesheetService ...@@ -37,6 +38,10 @@ public interface ITimesheetService
public List<Date> getWorkingDaysFromAPI(); public List<Date> getWorkingDaysFromAPI();
/*
* 工时审批--获取审批
* */
public List<CheckTimesheetDTO> getTimesheetCheck(Timesheet query);
/** /**
* 查询工时记录 * 查询工时记录
* *
...@@ -77,6 +82,13 @@ public interface ITimesheetService ...@@ -77,6 +82,13 @@ public interface ITimesheetService
*/ */
public int updateTimesheet(Timesheet timesheet); public int updateTimesheet(Timesheet timesheet);
/**
* 按周修改工时记录
*
* @return 结果
*/
public int updateWeekTimesheet(CheckTimesheetDTO checkTimesheetDTO);
/** /**
* 批量删除工时记录 * 批量删除工时记录
* *
...@@ -97,4 +109,6 @@ public interface ITimesheetService ...@@ -97,4 +109,6 @@ public interface ITimesheetService
// 自定义方法获取星期几 // 自定义方法获取星期几
public String getDayOfWeek(Date date); public String getDayOfWeek(Date date);
} }
...@@ -10,14 +10,13 @@ import java.util.stream.Collectors; ...@@ -10,14 +10,13 @@ import java.util.stream.Collectors;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.domain.dto.*; import com.ruoyi.domain.dto.*;
import com.ruoyi.service.ITimesheetService; import com.ruoyi.service.ITimesheetService;
import com.ruoyi.system.domain.ProjectManage; import com.ruoyi.system.domain.ProjectManage;
import com.ruoyi.system.domain.ProjectMember; import com.ruoyi.system.domain.ProjectMember;
import com.ruoyi.system.mapper.ProjectManageMapper; import com.ruoyi.system.mapper.*;
import com.ruoyi.system.mapper.ProjectMemberMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
...@@ -44,16 +43,78 @@ public class TimesheetServiceImpl implements ITimesheetService ...@@ -44,16 +43,78 @@ public class TimesheetServiceImpl implements ITimesheetService
@Autowired @Autowired
private SysUserMapper sysUserMapper; private SysUserMapper sysUserMapper;
@Autowired
private SysUserRoleMapper sysUserRoleMapper;
@Autowired @Autowired
private ProjectManageMapper projectManageMapper; private ProjectManageMapper projectManageMapper;
@Autowired @Autowired
private ProjectMemberMapper projectMemberMapper; private ProjectMemberMapper projectMemberMapper;
private static final String API_URL = "https://api.jiejiariapi.com/v1/workdays/2025"; private static final String API_URL = "https://api.jiejiariapi.com/v1/workdays/{year}";
@Override @Override
public List<TimesheetDTO> getProjectTimesheetList(Timesheet query) { public List<TimesheetDTO> getProjectTimesheetList(Timesheet query) {
// 获取用户角色
List<Long> roles = sysUserRoleMapper.selectRoleIdsByUserId(query.getEmployId());
if (roles.contains(2L)) {
query.setManagerName(query.getManagerName()); // 确保传递 managerName
List<Timesheet> timesheets = timesheetMapper.selectTimesheetGroupByProject(query);
Map<String, TimesheetDTO> projectMap = new LinkedHashMap<>();
for (Timesheet timesheet : timesheets) {
String projectNumber = timesheet.getProjectNumber();
if (!projectMap.containsKey(projectNumber)) {
TimesheetDTO dto = new TimesheetDTO();
dto.setProjectNumber(timesheet.getProjectNumber());
dto.setProjectName(timesheet.getProjectName());
dto.setManagerName(timesheet.getManagerName());
dto.setDepartmentLeaderName(timesheet.getDepartmentLeaderName());
dto.setTotalHours(BigDecimal.ZERO); // 初始化 totalHours 为 0
dto.setWorkDetails(new ArrayList<>());
projectMap.put(projectNumber, dto);
}
TimesheetDTO dto = projectMap.get(projectNumber);
// 检查是否已存在相同的 workTime 和 hours
boolean isDuplicate = dto.getWorkDetails().stream()
.anyMatch(workDetail -> workDetail.getWorkTime().equals(timesheet.getWorkTime())
&& workDetail.getHours().equals(timesheet.getHours()));
if (!isDuplicate) {
dto.getWorkDetails().add(new WorkDetailDTO(
timesheet.getWorkTime(),
timesheet.getHours()
));
// 累加 totalHours
dto.setTotalHours(dto.getTotalHours().add(timesheet.getHours()));
}
}
// 计算 startTime 和 endTime
for (TimesheetDTO dto : projectMap.values()) {
if (!dto.getWorkDetails().isEmpty()) {
// 找到最早和最晚的时间
Date startTime = dto.getWorkDetails().stream()
.map(WorkDetailDTO::getWorkTime)
.min(Date::compareTo)
.orElse(null);
Date endTime = dto.getWorkDetails().stream()
.map(WorkDetailDTO::getWorkTime)
.max(Date::compareTo)
.orElse(null);
dto.setStartTime(startTime);
dto.setEndTime(endTime);
}
}
return new ArrayList<>(projectMap.values());
}else if (roles.contains(1L)){
query.setEmployId(null);
query.setManagerName(query.getManagerName()); // 确保传递 managerName query.setManagerName(query.getManagerName()); // 确保传递 managerName
List<Timesheet> timesheets = timesheetMapper.selectTimesheetGroupByProject(query); List<Timesheet> timesheets = timesheetMapper.selectTimesheetGroupByProject(query);
...@@ -107,6 +168,72 @@ public class TimesheetServiceImpl implements ITimesheetService ...@@ -107,6 +168,72 @@ public class TimesheetServiceImpl implements ITimesheetService
} }
return new ArrayList<>(projectMap.values()); return new ArrayList<>(projectMap.values());
}else if (roles.contains(100L)|| roles.contains(104L)){
if (roles.contains(100L)){
query.setProjectManagerId(query.getEmployId());
query.setEmployId(null);
} else if (roles.contains(104L)) {
query.setDepartmentLeaderId(query.getEmployId());
query.setEmployId(null);
}
query.setManagerName(query.getManagerName()); // 确保传递 managerName
System.out.println(query);
List<Timesheet> timesheets = timesheetMapper.selectTimesheetGroupByProject(query);
Map<String, TimesheetDTO> projectMap = new LinkedHashMap<>();
for (Timesheet timesheet : timesheets) {
String projectNumber = timesheet.getProjectNumber();
if (!projectMap.containsKey(projectNumber)) {
TimesheetDTO dto = new TimesheetDTO();
dto.setProjectNumber(timesheet.getProjectNumber());
dto.setProjectName(timesheet.getProjectName());
dto.setManagerName(timesheet.getManagerName());
dto.setDepartmentLeaderName(timesheet.getDepartmentLeaderName());
dto.setTotalHours(BigDecimal.ZERO); // 初始化 totalHours 为 0
dto.setWorkDetails(new ArrayList<>());
projectMap.put(projectNumber, dto);
}
TimesheetDTO dto = projectMap.get(projectNumber);
// 检查是否已存在相同的 workTime 和 hours
boolean isDuplicate = dto.getWorkDetails().stream()
.anyMatch(workDetail -> workDetail.getWorkTime().equals(timesheet.getWorkTime())
&& workDetail.getHours().equals(timesheet.getHours()));
if (!isDuplicate) {
dto.getWorkDetails().add(new WorkDetailDTO(
timesheet.getWorkTime(),
timesheet.getHours()
));
// 累加 totalHours
dto.setTotalHours(dto.getTotalHours().add(timesheet.getHours()));
}
}
// 计算 startTime 和 endTime
for (TimesheetDTO dto : projectMap.values()) {
if (!dto.getWorkDetails().isEmpty()) {
// 找到最早和最晚的时间
Date startTime = dto.getWorkDetails().stream()
.map(WorkDetailDTO::getWorkTime)
.min(Date::compareTo)
.orElse(null);
Date endTime = dto.getWorkDetails().stream()
.map(WorkDetailDTO::getWorkTime)
.max(Date::compareTo)
.orElse(null);
dto.setStartTime(startTime);
dto.setEndTime(endTime);
}
}
return new ArrayList<>(projectMap.values());
}
else {
return new ArrayList<>();
}
} }
...@@ -116,9 +243,16 @@ public class TimesheetServiceImpl implements ITimesheetService ...@@ -116,9 +243,16 @@ public class TimesheetServiceImpl implements ITimesheetService
*/ */
@Override @Override
public List<Date> getWorkingDaysFromAPI() { public List<Date> getWorkingDaysFromAPI() {
// 获取当前年份
Calendar calendar = Calendar.getInstance();
int currentYear = calendar.get(Calendar.YEAR);
// 动态生成 URL
String apiUrl = API_URL.replace("{year}", String.valueOf(currentYear));
List<Date> workingDays = new ArrayList<>(); List<Date> workingDays = new ArrayList<>();
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet request = new HttpGet(API_URL); HttpGet request = new HttpGet(apiUrl);
try (CloseableHttpResponse response = httpClient.execute(request)) { try (CloseableHttpResponse response = httpClient.execute(request)) {
if (response.getStatusLine().getStatusCode() == 200) { if (response.getStatusLine().getStatusCode() == 200) {
String jsonResult = EntityUtils.toString(response.getEntity()); String jsonResult = EntityUtils.toString(response.getEntity());
...@@ -160,6 +294,90 @@ public class TimesheetServiceImpl implements ITimesheetService ...@@ -160,6 +294,90 @@ public class TimesheetServiceImpl implements ITimesheetService
return workingDays; return workingDays;
} }
/*
* 工时审批--获取审批
* */
@Override
public List<CheckTimesheetDTO> getTimesheetCheck(Timesheet query) {
String managerName = sysUserMapper.selectUserById(query.getProjectManagerId()).getNickName();
// 查询该员工的所有工时记录
List<Timesheet> timesheets = timesheetMapper.selectTimesheetByManagerId(query);
// 按项目分组,再按周分组
Map<String, Map<String, List<Timesheet>>> projectWeeklyTimesheets = new HashMap<>();
for (Timesheet timesheet : timesheets) {
String projectNumber = timesheet.getProjectNumber();
String weekRange = getWeekRange(timesheet.getWorkTime()); // 获取周范围
projectWeeklyTimesheets
.computeIfAbsent(projectNumber, k -> new HashMap<>())
.computeIfAbsent(weekRange, k -> new ArrayList<>())
.add(timesheet);
}
List<CheckTimesheetDTO> checkTimesheetList = new ArrayList<>();
for (Map.Entry<String, Map<String, List<Timesheet>>> projectEntry : projectWeeklyTimesheets.entrySet()) {
String projectNumber = projectEntry.getKey();
Map<String, List<Timesheet>> weeklyTimesheets = projectEntry.getValue();
CheckTimesheetDTO checkTimesheetDTO = new CheckTimesheetDTO();
checkTimesheetDTO.setProjectNumber(projectNumber);
checkTimesheetDTO.setProjectName(weeklyTimesheets.values().iterator().next().get(0).getProjectName()); // 修改为当前 timesheet 的 projectName
List<EmployeeTimesheetDTO> employeeTimesheetList = new ArrayList<>();
for (Map.Entry<String, List<Timesheet>> weekEntry : weeklyTimesheets.entrySet()) {
String weekRange = weekEntry.getKey();
List<Timesheet> timesheetList = weekEntry.getValue();
EmployeeTimesheetDTO employeeTimesheetDTO = new EmployeeTimesheetDTO();
employeeTimesheetDTO.setEmployId(timesheetList.get(0).getEmployId());
employeeTimesheetDTO.setEmployName(timesheetList.get(0).getEmployName());
employeeTimesheetDTO.setApprovalState(timesheetList.get(0).getApprovalState());
employeeTimesheetDTO.setApprovalNote(timesheetList.get(0).getApprovalNote());
employeeTimesheetDTO.setTotalHours(BigDecimal.ZERO);
List<WorkDetailDTO> workDetailList = new ArrayList<>();
// 找到最早的 workTime 和最晚的 workTime
Date startTime = timesheetList.stream()
.map(Timesheet::getWorkTime)
.min(Date::compareTo)
.orElse(null);
Date endTime = timesheetList.stream()
.map(Timesheet::getWorkTime)
.max(Date::compareTo)
.orElse(null);
employeeTimesheetDTO.setStartTime(startTime);
employeeTimesheetDTO.setEndTime(endTime);
for (Timesheet timesheet : timesheetList) {
WorkDetailDTO workDetailDTO = new WorkDetailDTO(timesheet.getWorkTime(), timesheet.getHours());
workDetailDTO.setId(timesheet.getId());
workDetailDTO.setWorkTime(timesheet.getWorkTime());
workDetailDTO.setHours(timesheet.getHours());
workDetailList.add(workDetailDTO);
// 累加总工时
employeeTimesheetDTO.setTotalHours(employeeTimesheetDTO.getTotalHours().add(timesheet.getHours()));
}
employeeTimesheetDTO.setWorkDetailList(workDetailList);
employeeTimesheetList.add(employeeTimesheetDTO);
}
checkTimesheetDTO.setEmployeeTimesheetList(employeeTimesheetList);
checkTimesheetList.add(checkTimesheetDTO);
}
return checkTimesheetList;
}
/** /**
* 填报工时--获取填报列表 * 填报工时--获取填报列表
* @return 个人工时记录列表 * @return 个人工时记录列表
...@@ -273,34 +491,7 @@ public class TimesheetServiceImpl implements ITimesheetService ...@@ -273,34 +491,7 @@ public class TimesheetServiceImpl implements ITimesheetService
return timesheetMapper.selectTimesheetList(timesheet); return timesheetMapper.selectTimesheetList(timesheet);
} }
/**
* 查询工时记录列表
*
* @param timesheet 工时记录
* @return 工时记录
*/
/* @Override
public List<TimesheetVo> selectTimesheetList(Timesheet timesheet)
{
// 执行查询
List<Timesheet> timesheets = timesheetMapper.selectTimesheetList(timesheet);
// 将Timesheet列表转换为TimesheetVo列表
List<TimesheetVo> timesheetVos = new ArrayList<>();
for (Timesheet ts : timesheets) {
TimesheetVo vo = new TimesheetVo();
BeanUtils.copyProperties(ts, vo); // 使用BeanUtils或其他工具复制属性
// 设置额外的字段
vo.setProjectType(determineProjectType(ts)); // 示例方法
vo.setDepartmentLeaderName(getDepartmentLeaderName(ts)); // 示例方法
vo.setSumHours(calculateSumHours(ts)); // 示例方法
timesheetVos.add(vo);
}
return timesheetVos;
// return timesheetMapper.selectTimesheetList(timesheet);
}*/
/** /**
* 新增工时记录 * 新增工时记录
...@@ -332,7 +523,7 @@ public class TimesheetServiceImpl implements ITimesheetService ...@@ -332,7 +523,7 @@ public class TimesheetServiceImpl implements ITimesheetService
timesheet.setEmployName(addTimesheetDTO.getEmployName()); timesheet.setEmployName(addTimesheetDTO.getEmployName());
timesheet.setProjectNumber(addTimesheetDTO.getProjectNumber()); timesheet.setProjectNumber(addTimesheetDTO.getProjectNumber());
timesheet.setProjectName(addTimesheetDTO.getProjectName()); timesheet.setProjectName(addTimesheetDTO.getProjectName());
timesheet.setManagerId(addTimesheetDTO.getManagerId()); timesheet.setProjectManagerId(addTimesheetDTO.getManagerId());
timesheet.setDepartmentLeaderId(addTimesheetDTO.getDepartmentLeaderId()); timesheet.setDepartmentLeaderId(addTimesheetDTO.getDepartmentLeaderId());
timesheet.setHours(addWorkDTO.getHours()); timesheet.setHours(addWorkDTO.getHours());
timesheet.setWorkTime(addWorkDTO.getWorkTime()); timesheet.setWorkTime(addWorkDTO.getWorkTime());
...@@ -359,6 +550,42 @@ public class TimesheetServiceImpl implements ITimesheetService ...@@ -359,6 +550,42 @@ public class TimesheetServiceImpl implements ITimesheetService
return timesheetMapper.updateTimesheet(timesheet); return timesheetMapper.updateTimesheet(timesheet);
} }
/**
*一键驳回/通过
*
* @return 结果
*/
@Override
public int updateWeekTimesheet(CheckTimesheetDTO checkTimesheetDTO) {
int result = 0;
// 添加空值检查
if (checkTimesheetDTO.getEmployeeTimesheetList() == null) {
throw new IllegalArgumentException("EmployeeTimesheetList cannot be null");
}
for (EmployeeTimesheetDTO employeeTimesheetDTO : checkTimesheetDTO.getEmployeeTimesheetList()) {
// 检查 workDetailList 是否为空
if (employeeTimesheetDTO.getWorkDetailList() != null) {
for (WorkDetailDTO workDetailDTO : employeeTimesheetDTO.getWorkDetailList()) {
Timesheet timesheet = new Timesheet();
timesheet.setId(workDetailDTO.getId());
timesheet.setApprovalState(employeeTimesheetDTO.getApprovalState()); // 设置审批状态
timesheet.setApprovalNote(employeeTimesheetDTO.getApprovalNote()); // 设置审批备注
timesheet.setUpdateTime(DateUtils.getNowDate()); // 设置更新时间
result += timesheetMapper.updateTimesheet(timesheet); // 更新工时记录
}
}
}
// 如果没有记录被更新,抛出异常或返回特定错误信息
if (result == 0) {
throw new RuntimeException("无可审批的申请");
}
return result;
}
/** /**
* 批量删除工时记录 * 批量删除工时记录
* *
...@@ -393,5 +620,15 @@ public class TimesheetServiceImpl implements ITimesheetService ...@@ -393,5 +620,15 @@ public class TimesheetServiceImpl implements ITimesheetService
return days[dayOfWeek - 1]; // 因为数组索引从0开始,所以需要减1 return days[dayOfWeek - 1]; // 因为数组索引从0开始,所以需要减1
} }
private String getWeekRange(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // 设置为一周的起始日(周一)
Date startOfWeek = calendar.getTime();
calendar.add(Calendar.DAY_OF_WEEK, 6); // 设置为一周的结束日(周日)
Date endOfWeek = calendar.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
return sdf.format(startOfWeek) + "-" + sdf.format(endOfWeek);
}
} }
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
<result property="employId" column="employ_id" /> <result property="employId" column="employ_id" />
<result property="employName" column="employ_name" /> <result property="employName" column="employ_name" />
<result property="projectNumber" column="project_number" /> <result property="projectNumber" column="project_number" />
<result property="projectName" column="project_name" />
<result property="managerId" column="manager_id" />
<result property="departmentLeaderId" column="department_leader_id" />
<result property="hours" column="hours" /> <result property="hours" column="hours" />
<result property="workTime" column="work_time" /> <result property="workTime" column="work_time" />
<result property="workWeek" column="work_week" /> <result property="workWeek" column="work_week" />
...@@ -28,16 +25,18 @@ ...@@ -28,16 +25,18 @@
<!--查询工时--> <!--查询工时-->
<select id="selectTimesheetGroupByProject" parameterType="Timesheet" resultMap="TimesheetResult"> <select id="selectTimesheetGroupByProject" parameterType="Timesheet" resultMap="TimesheetResult">
select tm.id, tm.employ_id, tm.employ_name, tm.project_number, tm.project_name, tm.manager_id, tm.department_leader_id, tm.hours, tm.work_time, select tm.id, tm.employ_id, tm.employ_name, tm.project_number, pm.project_name as projectName,
tm.work_week, tm.create_time, tm.update_time, tm.approval_note, tm.approval_state, su1.nick_name as managerName, su2.nick_name as departmentLeaderName pm.project_manager_id as projectManagerId, tm.hours, tm.work_time, pm.department_leader_id as departmentLeaderId,
tm.work_week, tm.create_time, tm.update_time, tm.approval_note, tm.approval_state, su1.nick_name as managerName,
su2.nick_name as departmentLeaderName
from timesheet tm from timesheet tm
left join sys_user su1 on su1.user_id = tm.manager_id join project_manage pm on pm.project_number = tm.project_number
left join sys_user su2 on su2.user_id = tm.department_leader_id join project_member pmem on pmem.user_id = tm.employ_id
left join project_manage pm on pm.project_number = tm.project_number left join sys_user su1 on su1.user_id = pm.project_manager_id
left join project_member pmem on pmem.user_id = tm.employ_id left join sys_user su2 on su2.user_id = pm.department_leader_id
where tm.deleted = 0 and tm.approval_state = '1' where tm.deleted = 0 and tm.approval_state = '1'
<if test="projectName != null and projectName != ''" > <if test="projectName != null and projectName != ''" >
and tm.project_name like concat('%', #{projectName}, '%') and pm.project_name like concat('%', #{projectName}, '%')
</if> </if>
<if test="managerName != null and managerName != ''"> <if test="managerName != null and managerName != ''">
and su1.nick_name like concat('%', #{managerName}, '%') and su1.nick_name like concat('%', #{managerName}, '%')
...@@ -51,25 +50,26 @@ ...@@ -51,25 +50,26 @@
<if test="endTime != null"> <if test="endTime != null">
and tm.work_time &lt;= #{endTime} and tm.work_time &lt;= #{endTime}
</if> </if>
<!-- <if test="startTime != null and startTime.id != ''"> <if test="endTime != null">
and tm.work_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime.id != ''">
and tm.work_time &lt;= #{endTime} and tm.work_time &lt;= #{endTime}
</if>--> </if>
<if test="departmentLeaderId != null">
and pm.department_leader_id = #{departmentLeaderId}
</if>
order by tm.work_time asc order by tm.work_time asc
</select> </select>
<!--获取工时填报基本信息--> <!--获取工时填报基本信息-->
<select id="selectPersonalTimesheet" resultMap="TimesheetResult"> <select id="selectPersonalTimesheet" resultMap="TimesheetResult">
SELECT tm.id, tm.employ_id, tm.employ_name, tm.project_number, tm.project_name, tm.manager_id, SELECT tm.id, tm.employ_id, tm.employ_name as employName, tm.project_number, pm.project_name as projectName, pm.project_manager_id as projectManagerId,
tm.department_leader_id, tm.hours, tm.work_time, tm.work_week, tm.create_time, pm.department_leader_id as departmentLeaderId, tm.hours, tm.work_time, tm.work_week, tm.create_time,
tm.update_time, tm.approval_note, tm.approval_state, su1.nick_name as managerName, su2.nick_name as departmentLeaderName tm.update_time, tm.approval_note, tm.approval_state, su1.nick_name as managerName, su2.nick_name as departmentLeaderName
FROM timesheet tm FROM timesheet tm
JOIN project_member pmem ON pmem.user_id = tm.employ_id JOIN project_member pmem ON pmem.user_id = tm.employ_id
JOIN project_manage pm ON pm.project_number = tm.project_number JOIN project_manage pm ON pm.project_number = tm.project_number
LEFT JOIN sys_user su1 ON su1.user_id = tm.manager_id LEFT JOIN sys_user su1 ON su1.user_id = pm.project_manager_id
LEFT JOIN sys_user su2 ON su2.user_id = tm.department_leader_id LEFT JOIN sys_user su2 ON su2.user_id = pm.department_leader_id
WHERE tm.deleted = 0 WHERE tm.deleted = 0
<if test="employId != null and employId != ''"> <if test="employId != null and employId != ''">
and pmem.user_id = #{employId} and pmem.user_id = #{employId}
...@@ -83,6 +83,34 @@ ...@@ -83,6 +83,34 @@
ORDER BY tm.work_time ASC ORDER BY tm.work_time ASC
</select> </select>
<!-- 根据 manager 查询工时记录 -->
<select id="selectTimesheetByManagerId" parameterType="Timesheet" resultMap="TimesheetResult">
SELECT tm.id, tm.employ_id, tm.employ_name, tm.project_number, pm.project_name as projectName, pm.project_manager_id as projectManagerId,
tm.hours, tm.work_time, tm.work_week, tm.create_time,
tm.update_time, tm.approval_note, tm.approval_state, su1.nick_name as managerName, su2.nick_name as departmentLeaderName
FROM timesheet tm
JOIN project_manage pm ON pm.project_number = tm.project_number
LEFT JOIN sys_user su1 ON su1.user_id = pm.project_manager_id
LEFT JOIN sys_user su2 ON su2.user_id = tm.department_leader_id
WHERE tm.deleted = 0
<if test="employId != null and employId != ''">
and tm.employ_id = #{employId}
</if>
<if test="startTime != null">
and tm.work_time &gt;= #{startTime}
</if>
<if test="endTime != null">
and tm.work_time &lt;= #{endTime}
</if>
<if test="projectManagerId != null and projectManagerId != ''">
and pm.project_manager_id = #{projectManagerId}
</if>
<if test="employName != null and employName != ''">
and tm.employ_name like concat('%', #{employName}, '%')
</if>
ORDER BY tm.work_time ASC
</select>
<select id="selectTimesheetById" parameterType="Long" resultMap="TimesheetResult"> <select id="selectTimesheetById" parameterType="Long" resultMap="TimesheetResult">
<include refid="selectTimesheetVo"/> <include refid="selectTimesheetVo"/>
where id = #{id} where id = #{id}
...@@ -94,9 +122,6 @@ ...@@ -94,9 +122,6 @@
<if test="employId != null">employ_id,</if> <if test="employId != null">employ_id,</if>
<if test="employName != null and employName != ''">employ_name,</if> <if test="employName != null and employName != ''">employ_name,</if>
<if test="projectNumber != null and projectNumber != ''">project_number,</if> <if test="projectNumber != null and projectNumber != ''">project_number,</if>
<if test="projectName != null and projectName != ''">project_name,</if>
<if test="managerId != null">manager_id,</if>
<if test="departmentLeaderId != null">department_leader_id,</if>
<if test="hours != null">hours,</if> <if test="hours != null">hours,</if>
<if test="workTime != null">work_time,</if> <if test="workTime != null">work_time,</if>
<if test="workWeek != null and workWeek != ''">work_week,</if> <if test="workWeek != null and workWeek != ''">work_week,</if>
...@@ -110,9 +135,6 @@ ...@@ -110,9 +135,6 @@
<if test="employId != null">#{employId},</if> <if test="employId != null">#{employId},</if>
<if test="employName != null and employName != ''">#{employName},</if> <if test="employName != null and employName != ''">#{employName},</if>
<if test="projectNumber != null and projectNumber != ''">#{projectNumber},</if> <if test="projectNumber != null and projectNumber != ''">#{projectNumber},</if>
<if test="projectName != null and projectName != ''">#{projectName},</if>
<if test="managerId != null">#{managerId},</if>
<if test="departmentLeaderId != null">#{departmentLeaderId},</if>
<if test="hours != null">#{hours},</if> <if test="hours != null">#{hours},</if>
<if test="workTime != null">#{workTime},</if> <if test="workTime != null">#{workTime},</if>
<if test="workWeek != null and workWeek != ''">#{workWeek},</if> <if test="workWeek != null and workWeek != ''">#{workWeek},</if>
...@@ -130,9 +152,6 @@ ...@@ -130,9 +152,6 @@
<if test="employId != null">employ_id = #{employId},</if> <if test="employId != null">employ_id = #{employId},</if>
<if test="employName != null and employName != ''">employ_name = #{employName},</if> <if test="employName != null and employName != ''">employ_name = #{employName},</if>
<if test="projectNumber != null and projectNumber != ''">project_number = #{projectNumber},</if> <if test="projectNumber != null and projectNumber != ''">project_number = #{projectNumber},</if>
<if test="projectName != null and projectName != ''">project_name = #{projectName},</if>
<if test="managerId != null">manager_id = #{managerId},</if>
<if test="departmentLeaderId != null">department_leader_id = #{departmentLeaderId},</if>
<if test="hours != null">hours = #{hours},</if> <if test="hours != null">hours = #{hours},</if>
<if test="workTime != null">work_time = #{workTime},</if> <if test="workTime != null">work_time = #{workTime},</if>
<if test="workWeek != null and workWeek != ''">work_week = #{workWeek},</if> <if test="workWeek != null and workWeek != ''">work_week = #{workWeek},</if>
...@@ -143,6 +162,9 @@ ...@@ -143,6 +162,9 @@
<if test="deleted != null">deleted = #{deleted},</if> <if test="deleted != null">deleted = #{deleted},</if>
</trim> </trim>
where id = #{id} where id = #{id}
<if test="approvalState != null">
and approval_state = 3
</if>
</update> </update>
<delete id="deleteTimesheetById" parameterType="Long"> <delete id="deleteTimesheetById" parameterType="Long">
......
package com.ruoyi.system.domain; package com.ruoyi.system.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.BaseEntity;
...@@ -20,4 +22,12 @@ public class ProjectMember extends BaseEntity ...@@ -20,4 +22,12 @@ public class ProjectMember extends BaseEntity
/** 用户id关联用户表主键id */ /** 用户id关联用户表主键id */
private Long userId; private Long userId;
@TableField(exist = false)
private String employName;
@TableField(exist = false)
private Integer employId;
@TableField(exist = false)
private String projectNumber;
} }
...@@ -82,4 +82,14 @@ public interface ProjectMemberMapper ...@@ -82,4 +82,14 @@ public interface ProjectMemberMapper
* @return 项目成员列表 * @return 项目成员列表
*/ */
List<ProjectMember> selectProjectMemberListByUserId(@Param("userId") Long userId); List<ProjectMember> selectProjectMemberListByUserId(@Param("userId") Long userId);
/**
* 根据项目编号和经理ID查询项目成员的用户ID和昵称
*
* @param projectNumber 项目编号
* @param managerId 经理ID
* @return 项目成员列表
*/
List<ProjectMember> selectEmployNameListByManagerId(@Param("projectNumber") String projectNumber, @Param("managerId") Long managerId);
} }
...@@ -59,4 +59,13 @@ public interface SysUserRoleMapper ...@@ -59,4 +59,13 @@ public interface SysUserRoleMapper
* @return 结果 * @return 结果
*/ */
public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds); public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
/**
* 通过用户ID查询角色ID
*
* @param userId 用户ID
* @return 角色ID列表
*/
public List<Long> selectRoleIdsByUserId(Long userId);
} }
...@@ -66,4 +66,13 @@ public interface IProjectMemberService ...@@ -66,4 +66,13 @@ public interface IProjectMemberService
* */ * */
public void batchInsertProjectMembers(Long projectId, List<Long> memberIds); public void batchInsertProjectMembers(Long projectId, List<Long> memberIds);
/**
* 根据项目编号和经理ID查询项目成员的用户ID和昵称
*
* @param projectNumber 项目编号
* @param managerId 经理ID
* @return 项目成员列表
*/
public List<ProjectMember> selectEmployNameListByManagerId(String projectNumber, Long managerId);
} }
...@@ -98,4 +98,9 @@ public class ProjectMemberServiceImpl implements IProjectMemberService ...@@ -98,4 +98,9 @@ public class ProjectMemberServiceImpl implements IProjectMemberService
projectMemberMapper.batchInsertProjectMembers(projectId, memberIds); projectMemberMapper.batchInsertProjectMembers(projectId, memberIds);
} }
} }
@Override
public List<ProjectMember> selectEmployNameListByManagerId(String projectNumber, Long managerId) {
return projectMemberMapper.selectEmployNameListByManagerId(projectNumber, managerId);
}
} }
...@@ -74,4 +74,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -74,4 +74,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="userId != null">user_id = #{userId}</if> <if test="userId != null">user_id = #{userId}</if>
</where> </where>
</select> </select>
<!--根据项目经理ID查询成员姓名-->
<select id="selectEmployNameListByManagerId" resultType="com.ruoyi.system.domain.ProjectMember">
SELECT su.user_id as employId, su.nick_name as employName, p.project_number as projectNumber
FROM sys_user su
JOIN project_member pm ON su.user_id = pm.user_id
JOIN project_manage p ON pm.project_id = p.id
<where>
<if test="managerId != null">
p.project_manager_id = #{managerId}
</if>
<if test="projectNumber != null">
AND p.project_number = #{projectNumber}
</if>
</where>
</select>
</mapper> </mapper>
...@@ -41,4 +41,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -41,4 +41,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{userId} #{userId}
</foreach> </foreach>
</delete> </delete>
<select id="selectRoleIdsByUserId" parameterType="Long" resultType="Long">
SELECT role_id
FROM sys_user_role
WHERE user_id = #{userId}
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment