Commit 5ae275e1 authored by lwy's avatar lwy

填报工时、工时查询

parent 07a4ef90
...@@ -46,6 +46,12 @@ ...@@ -46,6 +46,12 @@
<artifactId>ooxml-schemas</artifactId> <artifactId>ooxml-schemas</artifactId>
<version>1.4</version> <version>1.4</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
</dependencies> </dependencies>
<properties> <properties>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
......
package com.ruoyi.controller; package com.ruoyi.controller;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.ruoyi.domain.Timesheet;
import com.ruoyi.domain.dto.AddTimesheetDTO;
import com.ruoyi.domain.dto.TimesheetDTO;
import com.ruoyi.service.ITimesheetService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.Timesheet;
import com.ruoyi.service.ITimesheetService;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
...@@ -27,7 +25,7 @@ import com.ruoyi.common.core.page.TableDataInfo; ...@@ -27,7 +25,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
* 工时记录Controller * 工时记录Controller
* *
* @author ruoyi * @author ruoyi
* @date 2025-02-28 * @date 2025-03-11
*/ */
@RestController @RestController
@RequestMapping("/timesheet/timesheet") @RequestMapping("/timesheet/timesheet")
...@@ -36,57 +34,71 @@ public class TimesheetController extends BaseController ...@@ -36,57 +34,71 @@ public class TimesheetController extends BaseController
@Autowired @Autowired
private ITimesheetService timesheetService; private ITimesheetService timesheetService;
/*查询个人工时*/
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:list')")
@GetMapping("/pTimesheetList")
public ResponseEntity<List<TimesheetDTO>> getProjectTimesheetList(
@ModelAttribute Timesheet timesheet,
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime,
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime,
@RequestParam(required = false) String managerName // 添加 managerName 参数
) {
// 设置查询条件
timesheet.setStartTime(startTime);
timesheet.setEndTime(endTime);
timesheet.setManagerName(managerName); // 设置 managerName
/** List<TimesheetDTO> result = timesheetService.getProjectTimesheetList(timesheet);
* 查询工时记录列表 return ResponseEntity.ok(result);
}
/*
* 填报工时--查询个人填报
*/ */
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:list')") @PreAuthorize("@ss.hasPermi('timesheet:timesheet:list')")
@GetMapping("/list") @GetMapping("/personalTimesheet/{employId}")
public TableDataInfo list(Timesheet timesheet) public ResponseEntity<List<AddTimesheetDTO>> getPersonalTimesheet(@PathVariable("employId") Long employId) {
{ List<AddTimesheetDTO> result = timesheetService.getPersonalTimesheet(employId);
startPage(); return ResponseEntity.ok(result);
List<Timesheet> list = timesheetService.selectTimesheetList(timesheet);
return getDataTable(list);
} }
/** /**
* 导出工时记录列表 * 批量插入工时记录
*
*/ */
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:export')") @PreAuthorize("@ss.hasPermi('timesheet:timesheet:add')")
@Log(title = "工时记录", businessType = BusinessType.EXPORT) @Log(title = "插入工时记录", businessType = BusinessType.INSERT)
@PostMapping("/export") @PostMapping("/batchInsert")
public void export(HttpServletResponse response, Timesheet timesheet) public AjaxResult batchInsertTimesheet(@RequestBody AddTimesheetDTO addTimesheetDTO) {
{ logger.info("Received batch insert request: {}", addTimesheetDTO);
List<Timesheet> list = timesheetService.selectTimesheetList(timesheet); int result = timesheetService.insertTimesheetList(addTimesheetDTO);
ExcelUtil<Timesheet> util = new ExcelUtil<Timesheet>(Timesheet.class); return toAjax(result);
util.exportExcel(response, list, "工时记录数据");
} }
/** /**
* 查询工时记录列表 * 查询工时记录列表
*/ */
/*@PreAuthorize("@ss.hasPermi('timesheet:timesheet:list')") @PreAuthorize("@ss.hasPermi('timesheet:timesheet:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(Timesheet timesheet) public TableDataInfo list(Timesheet timesheet)
{ {
startPage(); startPage();
List<TimesheetVo> list = timesheetService.selectTimesheetList(timesheet); List<Timesheet> list = timesheetService.selectTimesheetList(timesheet);
return getDataTable(list); return getDataTable(list);
}*/ }
/** /**
* 导出工时记录列表 * 导出工时记录列表
*/ */
/* @PreAuthorize("@ss.hasPermi('timesheet:timesheet:export')") @PreAuthorize("@ss.hasPermi('timesheet:timesheet:export')")
@Log(title = "工时记录", businessType = BusinessType.EXPORT) @Log(title = "工时记录", businessType = BusinessType.EXPORT)
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, Timesheet timesheet) public void export(HttpServletResponse response, Timesheet timesheet)
{ {
List<TimesheetVo> list = timesheetService.selectTimesheetList(timesheet); List<Timesheet> list = timesheetService.selectTimesheetList(timesheet);
ExcelUtil<TimesheetVo> util = new ExcelUtil<TimesheetVo>(TimesheetVo.class); ExcelUtil<Timesheet> util = new ExcelUtil<Timesheet>(Timesheet.class);
util.exportExcel(response, list, "工时记录数据"); util.exportExcel(response, list, "工时记录数据");
}*/ }
/** /**
* 获取工时记录详细信息 * 获取工时记录详细信息
......
...@@ -3,7 +3,9 @@ package com.ruoyi.domain; ...@@ -3,7 +3,9 @@ package com.ruoyi.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
...@@ -15,6 +17,7 @@ import com.ruoyi.common.core.domain.BaseEntity; ...@@ -15,6 +17,7 @@ import com.ruoyi.common.core.domain.BaseEntity;
* @author ruoyi * @author ruoyi
* @date 2025-02-28 * @date 2025-02-28
*/ */
@Data
public class Timesheet extends BaseEntity public class Timesheet extends BaseEntity
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -23,6 +26,7 @@ public class Timesheet extends BaseEntity ...@@ -23,6 +26,7 @@ public class Timesheet extends BaseEntity
private Long id; private Long id;
/** 员工编号 */ /** 员工编号 */
@Excel(name = "员工编号")
private Long employId; private Long employId;
/** 员工姓名 */ /** 员工姓名 */
...@@ -38,239 +42,67 @@ public class Timesheet extends BaseEntity ...@@ -38,239 +42,67 @@ public class Timesheet extends BaseEntity
private String projectName; private String projectName;
/** 项目经理编号 */ /** 项目经理编号 */
@Excel(name = "项目经理编号")
private Long managerId; private Long managerId;
/** 事业部负责人编号 */ /** 事业部负责人编号 */
@Excel(name = "事业部负责人编号")
private Long departmentLeaderId; private Long departmentLeaderId;
/** 工作内容 */
private String description;
/** 工时 */ /** 工时 */
@Excel(name = "工时") @Excel(name = "工时")
private BigDecimal hours; private BigDecimal hours;
/** 工作日期 */ /** 工作日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "工作日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date workTime; private Date workTime;
/** 工作开始时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "工作开始时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date startTime;
/** 工作结束时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "工作结束时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date endTime;
/** 周标识 */ /** 周标识 */
@Excel(name = "周标识")
private String workWeek; private String workWeek;
/** 审批时间 */
private Date approvalTime;
/** 审批意见备注 */ /** 审批意见备注 */
@Excel(name = "审批意见备注")
private String approvalNote; private String approvalNote;
/** 审批状态 */ /** 审批状态 0-被驳回 1-已通过 2-待填报 3-审核中*/
@Excel(name = "审批状态") @Excel(name = "审批状态")
private String approvalState; private String approvalState;
/** 草稿标识 */
private Long flag;
/** 删除标识 */
private Long deleted;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setEmployId(Long employId)
{
this.employId = employId;
}
public Long getEmployId()
{
return employId;
}
public void setEmployName(String employName)
{
this.employName = employName;
}
public String getEmployName() // 事业部负责人名称(查询列表)
{ @TableField(exist = false)
return employName; private String departmentLeaderName;
}
public void setProjectNumber(String projectNumber)
{
this.projectNumber = projectNumber;
}
public String getProjectNumber() // 项目经理名称(查询列表)
{ @TableField(exist = false)
return projectNumber; private String managerName;
}
public void setProjectName(String projectName)
{
this.projectName = projectName;
}
public String getProjectName() @TableField(exist = false)
{ private BigDecimal totalHours;
return projectName;
}
public void setManagerId(Long managerId)
{
this.managerId = managerId;
}
public Long getManagerId() //开始时间(查询条件)
{ @JsonFormat(pattern = "yyyy-MM-dd")
return managerId; @TableField(exist = false)
} private Date startTime;
public void setDepartmentLeaderId(Long departmentLeaderId)
{
this.departmentLeaderId = departmentLeaderId;
}
public Long getDepartmentLeaderId()
{
return departmentLeaderId;
}
public void setDescription(String description)
{
this.description = description;
}
public String getDescription()
{
return description;
}
public void setHours(BigDecimal hours)
{
this.hours = hours;
}
public BigDecimal getHours()
{
return hours;
}
public void setWorkTime(Date workTime)
{
this.workTime = workTime;
}
public Date getWorkTime()
{
return workTime;
}
public void setStartTime(Date startTime)
{
this.startTime = startTime;
}
public Date getStartTime()
{
return startTime;
}
public void setEndTime(Date endTime)
{
this.endTime = endTime;
}
public Date getEndTime()
{
return endTime;
}
public void setWorkWeek(String workWeek)
{
this.workWeek = workWeek;
}
public String getWorkWeek()
{
return workWeek;
}
public void setApprovalTime(Date approvalTime)
{
this.approvalTime = approvalTime;
}
public Date getApprovalTime()
{
return approvalTime;
}
public void setApprovalNote(String approvalNote)
{
this.approvalNote = approvalNote;
}
public String getApprovalNote() //结束时间(查询条件)
{ @JsonFormat(pattern = "yyyy-MM-dd")
return approvalNote; @TableField(exist = false)
} private Date endTime;
public void setApprovalState(String approvalState)
{
this.approvalState = approvalState;
}
public String getApprovalState() /* @TableField(exist = false)
{ private Date startTime;
return approvalState;
}
public void setFlag(Long flag)
{
this.flag = flag;
}
public Long getFlag() @TableField(exist = false)
{ private Date endTime;*/
return flag;
}
public void setDeleted(Long deleted)
{
this.deleted = deleted;
}
public Long getDeleted() /** 删除标识 0-正常 1-已删除 */
{ private Long deleted;
return deleted;
}
public static final long NO_DELETE = 0;
public static final long DELETE = 1;
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("employId", getEmployId())
.append("employName", getEmployName())
.append("projectNumber", getProjectNumber())
.append("projectName", getProjectName())
.append("managerId", getManagerId())
.append("departmentLeaderId", getDepartmentLeaderId())
.append("description", getDescription())
.append("hours", getHours())
.append("workTime", getWorkTime())
.append("startTime", getStartTime())
.append("endTime", getEndTime())
.append("workWeek", getWorkWeek())
.append("createTime", getCreateTime())
.append("updateTime", getUpdateTime())
.append("approvalTime", getApprovalTime())
.append("approvalNote", getApprovalNote())
.append("approvalState", getApprovalState())
.append("flag", getFlag()).append("deleted", getDeleted())
.toString();
}
} }
package com.ruoyi.domain.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.util.Date;
@Data
@JsonIgnoreProperties(ignoreUnknown = true) // 忽略未知字段
public class WorkingDayDTO {
private String date;
private String name;
private boolean isOffDay;
}
package com.ruoyi.mapper; package com.ruoyi.mapper;
import java.util.Date;
import java.util.List; import java.util.List;
import com.ruoyi.domain.Timesheet; import com.ruoyi.domain.Timesheet;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/** /**
* 工时记录Mapper接口 * 工时记录Mapper接口
...@@ -9,8 +12,23 @@ import com.ruoyi.domain.Timesheet; ...@@ -9,8 +12,23 @@ import com.ruoyi.domain.Timesheet;
* @author ruoyi * @author ruoyi
* @date 2025-02-28 * @date 2025-02-28
*/ */
@Mapper
public interface TimesheetMapper public interface TimesheetMapper
{ {
/**
* 工时查询--个人工时
* @param query
* @return
*/
public List<Timesheet> selectTimesheetGroupByProject(Timesheet query);
/**
* 填报工时--个人工时查询
* @return
*/
List<Timesheet> selectPersonalTimesheet(@Param("employId") Long employId, @Param("workTime") Date workTime, @Param("projectNumber") String projectNumber);
/** /**
* 查询工时记录 * 查询工时记录
* *
......
package com.ruoyi.service; package com.ruoyi.service;
import java.util.List;
import com.ruoyi.domain.Timesheet; import com.ruoyi.domain.Timesheet;
import com.ruoyi.domain.dto.AddTimesheetDTO;
import com.ruoyi.domain.dto.TimesheetDTO;
import java.util.Date;
import java.util.List;
/** /**
* 工时记录Service接口 * 工时记录Service接口
* *
* @author ruoyi * @author ruoyi
* @date 2025-02-28 * @date 2025-03-11
*/ */
public interface ITimesheetService public interface ITimesheetService
{ {
/** /**
* 查询工时记录 * 工时查询--查询个人工时记录
* *
* @param id 工时记录主键 * @param query 工时记录主键
* @return 工时记录 * @return 工时记录
*/ */
public Timesheet selectTimesheetById(Long id); public List<TimesheetDTO> getProjectTimesheetList(Timesheet query);
/** /**
* 查询工时记录列表 * 填报工时--查询个人填报
* *
* @param timesheet 工时记录 * @param
* @return 工时记录集合 * @return 工时记录
*/
List<AddTimesheetDTO> getPersonalTimesheet(Long employId);
/**
* 填报工时--获取法定节假日
*/ */
// public List<TimesheetVo> selectTimesheetList(Timesheet timesheet); public List<Date> getWorkingDaysFromAPI();
/**
* 查询工时记录
*
* @param id 工时记录主键
* @return 工时记录
*/
public Timesheet selectTimesheetById(Long id);
/** /**
* 查询工时记录列表 * 查询工时记录列表
* *
...@@ -35,8 +52,8 @@ public interface ITimesheetService ...@@ -35,8 +52,8 @@ public interface ITimesheetService
* @return 工时记录集合 * @return 工时记录集合
*/ */
public List<Timesheet> selectTimesheetList(Timesheet timesheet); public List<Timesheet> selectTimesheetList(Timesheet timesheet);
/** /**
*
* 新增工时记录 * 新增工时记录
* *
* @param timesheet 工时记录 * @param timesheet 工时记录
...@@ -44,6 +61,14 @@ public interface ITimesheetService ...@@ -44,6 +61,14 @@ public interface ITimesheetService
*/ */
public int insertTimesheet(Timesheet timesheet); public int insertTimesheet(Timesheet timesheet);
/**
* 批量加入工时记录
*
* @param
* @return 结果
*/
public int insertTimesheetList(AddTimesheetDTO addTimesheetDTO);
/** /**
* 修改工时记录 * 修改工时记录
* *
...@@ -67,4 +92,9 @@ public interface ITimesheetService ...@@ -67,4 +92,9 @@ public interface ITimesheetService
* @return 结果 * @return 结果
*/ */
public int deleteTimesheetById(Long id); public int deleteTimesheetById(Long id);
// 自定义方法获取星期几
public String getDayOfWeek(Date date);
} }
package com.ruoyi.service.impl; package com.ruoyi.service.impl;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.text.ParseException;
import java.util.List; import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.domain.dto.*;
import com.ruoyi.service.ITimesheetService;
import com.ruoyi.system.domain.ProjectManage;
import com.ruoyi.system.domain.ProjectMember;
import com.ruoyi.system.mapper.ProjectManageMapper;
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.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.mapper.TimesheetMapper; import com.ruoyi.mapper.TimesheetMapper;
import com.ruoyi.domain.Timesheet; import com.ruoyi.domain.Timesheet;
import com.ruoyi.service.ITimesheetService;
/** /**
* 工时记录Service业务层处理 * 工时记录Service业务层处理
...@@ -23,6 +41,214 @@ public class TimesheetServiceImpl implements ITimesheetService ...@@ -23,6 +41,214 @@ public class TimesheetServiceImpl implements ITimesheetService
@Autowired @Autowired
private TimesheetMapper timesheetMapper; private TimesheetMapper timesheetMapper;
@Autowired
private SysUserMapper sysUserMapper;
@Autowired
private ProjectManageMapper projectManageMapper;
@Autowired
private ProjectMemberMapper projectMemberMapper;
private static final String API_URL = "https://api.jiejiariapi.com/v1/workdays/2025";
@Override
public List<TimesheetDTO> getProjectTimesheetList(Timesheet query) {
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());
}
/*
* 填报工时--获取法定工作日
*/
@Override
public List<Date> getWorkingDaysFromAPI() {
List<Date> workingDays = new ArrayList<>();
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet request = new HttpGet(API_URL);
try (CloseableHttpResponse response = httpClient.execute(request)) {
if (response.getStatusLine().getStatusCode() == 200) {
String jsonResult = EntityUtils.toString(response.getEntity());
ObjectMapper objectMapper = new ObjectMapper();
// 添加日志输出,方便调试
System.out.println("API Response: " + jsonResult);
try {
Map<String, WorkingDayDTO> apiResponse = objectMapper.readValue(jsonResult, new TypeReference<Map<String, WorkingDayDTO>>() {});
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for (Map.Entry<String, WorkingDayDTO> entry : apiResponse.entrySet()) {
WorkingDayDTO workingDay = entry.getValue();
if (!workingDay.isOffDay()) {
Date date = sdf.parse(workingDay.getDate().toString());
workingDays.add(date);
}
}
} catch (JsonProcessingException e) {
e.printStackTrace();
// 处理 JSON 格式错误
System.err.println("JSON Parsing Error: " + e.getMessage());
} catch (ParseException e) {
e.printStackTrace();
// 处理日期解析错误
System.err.println("Date Parsing Error: " + e.getMessage());
}
} else {
System.err.println("API Request Failed with Status Code: " + response.getStatusLine().getStatusCode());
}
} catch (IOException e) {
e.printStackTrace();
// 处理 IO 异常
System.err.println("IO Error: " + e.getMessage());
}
} catch (IOException e) {
e.printStackTrace();
// 处理 IO 异常
System.err.println("IO Error: " + e.getMessage());
}
return workingDays;
}
/**
* 填报工时--获取填报列表
* @return 个人工时记录列表
*/
@Override
public List<AddTimesheetDTO> getPersonalTimesheet(Long employId) {
String employName = sysUserMapper.selectUserById(employId).getNickName();
// 获取当前日期和本周的起始日期(周一)与结束日期(周日)
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
Date startOfWeek = calendar.getTime();
calendar.add(Calendar.DAY_OF_WEEK, 6);
Date endOfWeek = calendar.getTime();
// 获取所有工作日
List<Date> workingDays = getWorkingDaysFromAPI();
// 过滤本周的工作日
List<Date> thisWeekWorkingDays = workingDays.stream()
.filter(workingDay -> !workingDay.before(startOfWeek) && !workingDay.after(endOfWeek))
.collect(Collectors.toList());
//System.out.println("This Week Working Days: " + thisWeekWorkingDays);
// 获取员工的项目列表
ProjectMember projectMember = new ProjectMember();
projectMember.setUserId(employId);
List<ProjectMember> projectMembers = projectMemberMapper.selectProjectMemberList(projectMember);
List<ProjectManage> projects = projectMembers.stream()
.map(member -> projectManageMapper.selectPersonalProjectManageList(member.getProjectId()))
.flatMap(List::stream) // 将嵌套的List<ProjectManage>扁平化为Stream<ProjectManage>
.filter(Objects::nonNull) // 过滤掉可能为 null 的结果
.distinct() // 去重
.collect(Collectors.toList());
List<AddTimesheetDTO> addTimesheetList = new ArrayList<>();
// 遍历每个项目
for (ProjectManage project : projects) {
AddTimesheetDTO addTimesheetDTO = new AddTimesheetDTO();
addTimesheetDTO.setEmployId(employId);
addTimesheetDTO.setEmployName(employName);
addTimesheetDTO.setProjectNumber(project.getProjectNumber());
addTimesheetDTO.setProjectName(project.getProjectName());
addTimesheetDTO.setManagerId(project.getProjectManagerId());
addTimesheetDTO.setManagerName(project.getProjectManagerName());
addTimesheetDTO.setDepartmentLeaderId(project.getDepartmentLeaderId());
addTimesheetDTO.setDepartmentLeaderName(project.getDepartmentLeaderName());
addTimesheetDTO.setApprovalState("2"); // 默认审批状态
addTimesheetDTO.setApprovalNote(""); // 默认审批备注
addTimesheetDTO.setTotalHours(BigDecimal.ZERO); // 初始化总工时为0
List<AddWorkDTO> addWorkList = new ArrayList<>();
// 遍历本周的每个工作日
for (Date workTime : thisWeekWorkingDays) {
// System.out.println("workTime Day: " + workTime+"//////////////////////");
// 查询该工作日的工时记录
List<Timesheet> timesheets = timesheetMapper.selectPersonalTimesheet(employId, workTime, project.getProjectNumber());
AddWorkDTO addWorkDTO = new AddWorkDTO();
addWorkDTO.setWorkTime(workTime);
addWorkDTO.setWorkWeek(getDayOfWeek(workTime)); // 获取星期几
if (!timesheets.isEmpty()) {
// 如果有工时记录,设置工时并从第一条记录中获取审批状态和备注
addWorkDTO.setHours(timesheets.get(0).getHours());
addTimesheetDTO.setApprovalState(timesheets.get(0).getApprovalState());
addTimesheetDTO.setApprovalNote(timesheets.get(0).getApprovalNote());
// 累加总工时
addTimesheetDTO.setTotalHours(addTimesheetDTO.getTotalHours().add(timesheets.get(0).getHours()));
} else {
// 如果没有工时记录,设置工时为0,并保留默认审批状态和备注
addWorkDTO.setHours(BigDecimal.ZERO);
}
addWorkList.add(addWorkDTO);
}
addTimesheetDTO.setAddWorkList(addWorkList);
addTimesheetList.add(addTimesheetDTO);
}
return addTimesheetList;
}
/** /**
* 查询工时记录 * 查询工时记录
* *
...@@ -89,6 +315,37 @@ public class TimesheetServiceImpl implements ITimesheetService ...@@ -89,6 +315,37 @@ public class TimesheetServiceImpl implements ITimesheetService
return timesheetMapper.insertTimesheet(timesheet); return timesheetMapper.insertTimesheet(timesheet);
} }
/**
* 批量插入工时记录
*
*/
@Override
public int insertTimesheetList(AddTimesheetDTO addTimesheetDTO) {
int result = 0;
// 检查 addWorkList 是否为空
if (addTimesheetDTO.getAddWorkList() == null || addTimesheetDTO.getAddWorkList().isEmpty()) {
throw new IllegalArgumentException("addWorkList cannot be empty");
}
for (AddWorkDTO addWorkDTO : addTimesheetDTO.getAddWorkList()) {
Timesheet timesheet = new Timesheet();
timesheet.setEmployId(addTimesheetDTO.getEmployId());
timesheet.setEmployName(addTimesheetDTO.getEmployName());
timesheet.setProjectNumber(addTimesheetDTO.getProjectNumber());
timesheet.setProjectName(addTimesheetDTO.getProjectName());
timesheet.setManagerId(addTimesheetDTO.getManagerId());
timesheet.setDepartmentLeaderId(addTimesheetDTO.getDepartmentLeaderId());
timesheet.setHours(addWorkDTO.getHours());
timesheet.setWorkTime(addWorkDTO.getWorkTime());
timesheet.setWorkWeek(addWorkDTO.getWorkWeek());
timesheet.setApprovalState("3");
timesheet.setApprovalNote(addTimesheetDTO.getApprovalNote());
timesheet.setDeleted(Timesheet.NO_DELETE);
result += timesheetMapper.insertTimesheet(timesheet);
}
return result;
}
/** /**
* 修改工时记录 * 修改工时记录
* *
...@@ -126,18 +383,15 @@ public class TimesheetServiceImpl implements ITimesheetService ...@@ -126,18 +383,15 @@ public class TimesheetServiceImpl implements ITimesheetService
return timesheetMapper.deleteTimesheetById(id); return timesheetMapper.deleteTimesheetById(id);
} }
private String determineProjectType(Timesheet timesheet) { @Override
// 根据业务逻辑确定projectType public String getDayOfWeek(Date date) {
return "A型"; // 示例值 Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
// 调整数组顺序,使其与 Calendar.DAY_OF_WEEK 的值对应
String[] days = new String[]{"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
return days[dayOfWeek - 1]; // 因为数组索引从0开始,所以需要减1
} }
private String getDepartmentLeaderName(Timesheet timesheet) {
// 根据业务逻辑获取部门领导的名字
return "李四"; // 示例值
}
private BigDecimal calculateSumHours(Timesheet timesheet) {
// 根据业务逻辑计算sumHours
return new BigDecimal(16); // 示例值
}
} }
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.mapper.TimesheetMapper"> <mapper namespace="com.ruoyi.mapper.TimesheetMapper">
<resultMap type="Timesheet" id="TimesheetResult"> <resultMap type="Timesheet" id="TimesheetResult">
...@@ -12,33 +12,75 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -12,33 +12,75 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="projectName" column="project_name" /> <result property="projectName" column="project_name" />
<result property="managerId" column="manager_id" /> <result property="managerId" column="manager_id" />
<result property="departmentLeaderId" column="department_leader_id" /> <result property="departmentLeaderId" column="department_leader_id" />
<result property="description" column="description" />
<result property="hours" column="hours" /> <result property="hours" column="hours" />
<result property="workTime" column="work_time" /> <result property="workTime" column="work_time" />
<result property="startTime" column="start_time" />
<result property="endTime" column="end_time" />
<result property="workWeek" column="work_week" /> <result property="workWeek" column="work_week" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
<result property="approvalTime" column="approval_time" />
<result property="approvalNote" column="approval_note" /> <result property="approvalNote" column="approval_note" />
<result property="approvalState" column="approval_state" /> <result property="approvalState" column="approval_state" />
<result property="flag" column="flag" />
<result property="deleted" column="deleted" /> <result property="deleted" column="deleted" />
</resultMap> </resultMap>
<sql id="selectTimesheetVo"> <sql id="selectTimesheetVo">
select id, employ_id, employ_name, project_number, project_name, manager_id, department_leader_id, description, hours, work_time, start_time, end_time, work_week, create_time, update_time, approval_time, approval_note, approval_state, flag, deleted from timesheet select id, employ_id, employ_name, project_number, project_name, manager_id, department_leader_id, hours, work_time, work_week, create_time, update_time, approval_note, approval_state, deleted from timesheet
</sql> </sql>
<select id="selectTimesheetList" parameterType="Timesheet" resultMap="TimesheetResult"> <!--查询工时-->
<include refid="selectTimesheetVo"/> <select id="selectTimesheetGroupByProject" parameterType="Timesheet" resultMap="TimesheetResult">
<where> 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,
<if test="projectNumber != null "> and project_number = #{projectNumber}</if> 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
<if test="projectName != null and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if> from timesheet tm
<if test="startTime != null "> and start_time = #{startTime}</if> left join sys_user su1 on su1.user_id = tm.manager_id
<if test="endTime != null "> and end_time = #{endTime}</if> left join sys_user su2 on su2.user_id = tm.department_leader_id
</where> left join project_manage pm on pm.project_number = tm.project_number
left join project_member pmem on pmem.user_id = tm.employ_id
where tm.deleted = 0 and tm.approval_state = '1'
<if test="projectName != null and projectName != ''" >
and tm.project_name like concat('%', #{projectName}, '%')
</if>
<if test="managerName != null and managerName != ''">
and su1.nick_name like concat('%', #{managerName}, '%')
</if>
<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="startTime != null and startTime.id != ''">
and tm.work_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime.id != ''">
and tm.work_time &lt;= #{endTime}
</if>-->
order by tm.work_time asc
</select>
<!--获取工时填报基本信息-->
<select id="selectPersonalTimesheet" 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, 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_member pmem ON pmem.user_id = tm.employ_id
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 su2 ON su2.user_id = tm.department_leader_id
WHERE tm.deleted = 0
<if test="employId != null and employId != ''">
and pmem.user_id = #{employId}
</if>
<if test="workTime != null">
and tm.work_time = #{workTime}
</if>
<if test="projectNumber != null and projectNumber != ''">
and tm.project_number = #{projectNumber}
</if>
ORDER BY tm.work_time ASC
</select> </select>
<select id="selectTimesheetById" parameterType="Long" resultMap="TimesheetResult"> <select id="selectTimesheetById" parameterType="Long" resultMap="TimesheetResult">
...@@ -51,43 +93,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -51,43 +93,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<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">project_number,</if> <if test="projectNumber != null and projectNumber != ''">project_number,</if>
<if test="projectName != null and projectName != ''">project_name,</if> <if test="projectName != null and projectName != ''">project_name,</if>
<if test="managerId != null">manager_id,</if> <if test="managerId != null">manager_id,</if>
<if test="departmentLeaderId != null">department_leader_id,</if> <if test="departmentLeaderId != null">department_leader_id,</if>
<if test="description != null">description,</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="startTime != null">start_time,</if>
<if test="endTime != null">end_time,</if>
<if test="workWeek != null and workWeek != ''">work_week,</if> <if test="workWeek != null and workWeek != ''">work_week,</if>
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if> <if test="updateTime != null">update_time,</if>
<if test="approvalTime != null">approval_time,</if>
<if test="approvalNote != null">approval_note,</if> <if test="approvalNote != null">approval_note,</if>
<if test="approvalState != null">approval_state,</if> <if test="approvalState != null">approval_state,</if>
<if test="flag != null">flag,</if>
<if test="deleted != null">deleted,</if> <if test="deleted != null">deleted,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<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">#{projectNumber},</if> <if test="projectNumber != null and projectNumber != ''">#{projectNumber},</if>
<if test="projectName != null and projectName != ''">#{projectName},</if> <if test="projectName != null and projectName != ''">#{projectName},</if>
<if test="managerId != null">#{managerId},</if> <if test="managerId != null">#{managerId},</if>
<if test="departmentLeaderId != null">#{departmentLeaderId},</if> <if test="departmentLeaderId != null">#{departmentLeaderId},</if>
<if test="description != null">#{description},</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="startTime != null">#{startTime},</if>
<if test="endTime != null">#{endTime},</if>
<if test="workWeek != null and workWeek != ''">#{workWeek},</if> <if test="workWeek != null and workWeek != ''">#{workWeek},</if>
<if test="createTime != null">#{createTime},</if> <if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if> <if test="updateTime != null">#{updateTime},</if>
<if test="approvalTime != null">#{approvalTime},</if>
<if test="approvalNote != null">#{approvalNote},</if> <if test="approvalNote != null">#{approvalNote},</if>
<if test="approvalState != null">#{approvalState},</if> <if test="approvalState != null">#{approvalState},</if>
<if test="flag != null">#{flag},</if>
<if test="deleted != null">#{deleted},</if> <if test="deleted != null">#{deleted},</if>
</trim> </trim>
</insert> </insert>
...@@ -97,22 +129,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -97,22 +129,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<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">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="projectName != null and projectName != ''">project_name = #{projectName},</if>
<if test="managerId != null">manager_id = #{managerId},</if> <if test="managerId != null">manager_id = #{managerId},</if>
<if test="departmentLeaderId != null">department_leader_id = #{departmentLeaderId},</if> <if test="departmentLeaderId != null">department_leader_id = #{departmentLeaderId},</if>
<if test="description != null">description = #{description},</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="startTime != null">start_time = #{startTime},</if>
<if test="endTime != null">end_time = #{endTime},</if>
<if test="workWeek != null and workWeek != ''">work_week = #{workWeek},</if> <if test="workWeek != null and workWeek != ''">work_week = #{workWeek},</if>
<if test="createTime != null">create_time = #{createTime},</if> <if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if> <if test="updateTime != null">update_time = #{updateTime},</if>
<if test="approvalTime != null">approval_time = #{approvalTime},</if>
<if test="approvalNote != null">approval_note = #{approvalNote},</if> <if test="approvalNote != null">approval_note = #{approvalNote},</if>
<if test="approvalState != null">approval_state = #{approvalState},</if> <if test="approvalState != null">approval_state = #{approvalState},</if>
<if test="flag != null">flag = #{flag},</if>
<if test="deleted != null">deleted = #{deleted},</if> <if test="deleted != null">deleted = #{deleted},</if>
</trim> </trim>
where id = #{id} where id = #{id}
......
...@@ -68,4 +68,8 @@ public interface ProjectManageMapper ...@@ -68,4 +68,8 @@ public interface ProjectManageMapper
List<ProjectManage> selectProjectManageByProjectName(@Param("projectName") String projectName); List<ProjectManage> selectProjectManageByProjectName(@Param("projectName") String projectName);
/*
* 个人正在进行中的项目
* */
public List<ProjectManage> selectPersonalProjectManageList(@Param("projectId") Long projectId);
} }
...@@ -74,4 +74,12 @@ public interface ProjectMemberMapper ...@@ -74,4 +74,12 @@ public interface ProjectMemberMapper
* @param memberId 成员 ID * @param memberId 成员 ID
* */ * */
public void deleteProjectMember(@Param("projectId") Long projectId, @Param("memberId") Long memberId); public void deleteProjectMember(@Param("projectId") Long projectId, @Param("memberId") Long memberId);
/**
* 根据用户 ID 查询项目成员列表
*
* @param userId 用户 ID
* @return 项目成员列表
*/
List<ProjectMember> selectProjectMemberListByUserId(@Param("userId") Long userId);
} }
...@@ -184,4 +184,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -184,4 +184,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select * from project_manage where project_name = #{projectName} and del_flag = '0' select * from project_manage where project_name = #{projectName} and del_flag = '0'
</select> </select>
<!--获取个人正在进行中的项目-->
<select id="selectPersonalProjectManageList" parameterType="ProjectManage" resultMap="ProjectManageResult">
select pm.id,
pm.project_number,
pm.project_name,
pm.department_leader_id,
pm.project_manager_id,
pm.project_type,
pm.start_date,
pm.end_date,
pm.project_cost,
pm.project_describe,
pm.project_status,
pm.create_date,
pm.update_date,
su1.nick_name as departmentLeaderName,
su2.nick_name as projectManagerName
from project_manage pm
left join sys_user su1 on su1.user_id = pm.department_leader_id
left join sys_user su2 on su2.user_id = pm.project_manager_id
left join project_member pmem on pmem.project_id = pm.id
left join sys_user su on su.user_id = pmem.user_id
where pm.del_flag = '0'
and pm.draft = '1'
and pm.id = #{projectId}
and pm.project_status = '0'
group by pm.id,
su1.nick_name, su2.nick_name
</select>
</mapper> </mapper>
...@@ -66,4 +66,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -66,4 +66,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<delete id="deleteProjectMember"> <delete id="deleteProjectMember">
delete from project_member where project_id = #{projectId} and user_id = #{memberId} delete from project_member where project_id = #{projectId} and user_id = #{memberId}
</delete> </delete>
<!-- 根据用户ID查询项目成员列表 -->
<select id="selectProjectMemberListByUserId" parameterType="Long" resultType="com.ruoyi.system.domain.ProjectMember">
<include refid="selectProjectMemberVo"/>
<where>
<if test="userId != null">user_id = #{userId}</if>
</where>
</select>
</mapper> </mapper>
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