Commit 18d885fa authored by lwy's avatar lwy

工时管理

parent 080b9ad0
package com.ruoyi.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.domain.TimesheetVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
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.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
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.core.page.TableDataInfo;
/**
* 工时记录Controller
*
* @author ruoyi
* @date 2025-02-28
*/
@RestController
@RequestMapping("/timesheet/timesheet")
public class TimesheetController extends BaseController
{
@Autowired
private ITimesheetService timesheetService;
/**
* 查询工时记录列表
*/
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:list')")
@GetMapping("/list")
public TableDataInfo list(Timesheet timesheet)
{
startPage();
List<TimesheetVo> list = timesheetService.selectTimesheetList(timesheet);
return getDataTable(list);
}
/**
* 导出工时记录列表
*/
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:export')")
@Log(title = "工时记录", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Timesheet timesheet)
{
List<TimesheetVo> list = timesheetService.selectTimesheetList(timesheet);
ExcelUtil<TimesheetVo> util = new ExcelUtil<TimesheetVo>(TimesheetVo.class);
util.exportExcel(response, list, "工时记录数据");
}
/**
* 获取工时记录详细信息
*/
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(timesheetService.selectTimesheetById(id));
}
/**
* 新增工时记录
*/
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:add')")
@Log(title = "工时记录", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody Timesheet timesheet)
{
return toAjax(timesheetService.insertTimesheet(timesheet));
}
/**
* 修改工时记录
*/
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:edit')")
@Log(title = "工时记录", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody Timesheet timesheet)
{
return toAjax(timesheetService.updateTimesheet(timesheet));
}
/**
* 删除工时记录
*/
@PreAuthorize("@ss.hasPermi('timesheet:timesheet:remove')")
@Log(title = "工时记录", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(timesheetService.deleteTimesheetByIds(ids));
}
}
package com.ruoyi.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 工时记录对象 timesheet
*
* @author ruoyi
* @date 2025-02-28
*/
public class Timesheet extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键ID */
private Long id;
/** 员工编号 */
private Long employId;
/** 员工姓名 */
@Excel(name = "员工姓名")
private String employName;
/** 项目编号 */
@Excel(name = "项目编号")
private String projectNumber;
/** 项目名称 */
@Excel(name = "项目名称")
private String projectName;
/** 项目经理编号 */
private Long managerId;
/** 事业部负责人编号 */
private Long departmentLeaderId;
/** 工作内容 */
private String description;
/** 工时 */
@Excel(name = "工时")
private BigDecimal hours;
/** 工作日期 */
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;
/** 周标识 */
private String workWeek;
/** 审批时间 */
private Date approvalTime;
/** 审批意见备注 */
private String approvalNote;
/** 审批状态 */
@Excel(name = "审批状态")
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()
{
return employName;
}
public void setProjectNumber(String projectNumber)
{
this.projectNumber = projectNumber;
}
public String getProjectNumber()
{
return projectNumber;
}
public void setProjectName(String projectName)
{
this.projectName = projectName;
}
public String getProjectName()
{
return projectName;
}
public void setManagerId(Long managerId)
{
this.managerId = managerId;
}
public Long getManagerId()
{
return managerId;
}
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()
{
return approvalNote;
}
public void setApprovalState(String approvalState)
{
this.approvalState = approvalState;
}
public String getApprovalState()
{
return approvalState;
}
public void setFlag(Long flag)
{
this.flag = flag;
}
public Long getFlag()
{
return flag;
}
public void setDeleted(Long deleted)
{
this.deleted = deleted;
}
public Long getDeleted()
{
return deleted;
}
@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.mapper;
import java.util.List;
import com.ruoyi.domain.Timesheet;
/**
* 工时记录Mapper接口
*
* @author ruoyi
* @date 2025-02-28
*/
public interface TimesheetMapper
{
/**
* 查询工时记录
*
* @param id 工时记录主键
* @return 工时记录
*/
public Timesheet selectTimesheetById(Long id);
/**
* 查询工时记录列表
*
* @param timesheet 工时记录
* @return 工时记录集合
*/
public List<Timesheet> selectTimesheetList(Timesheet timesheet);
/**
* 新增工时记录
*
* @param timesheet 工时记录
* @return 结果
*/
public int insertTimesheet(Timesheet timesheet);
/**
* 修改工时记录
*
* @param timesheet 工时记录
* @return 结果
*/
public int updateTimesheet(Timesheet timesheet);
/**
* 删除工时记录
*
* @param id 工时记录主键
* @return 结果
*/
public int deleteTimesheetById(Long id);
/**
* 批量删除工时记录
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteTimesheetByIds(Long[] ids);
}
package com.ruoyi.service;
import java.util.List;
import com.ruoyi.domain.Timesheet;
import com.ruoyi.domain.TimesheetVo;
/**
* 工时记录Service接口
*
* @author ruoyi
* @date 2025-02-28
*/
public interface ITimesheetService
{
/**
* 查询工时记录
*
* @param id 工时记录主键
* @return 工时记录
*/
public Timesheet selectTimesheetById(Long id);
/**
* 查询工时记录列表
*
* @param timesheet 工时记录
* @return 工时记录集合
*/
public List<TimesheetVo> selectTimesheetList(Timesheet timesheet);
/**
* 新增工时记录
*
* @param timesheet 工时记录
* @return 结果
*/
public int insertTimesheet(Timesheet timesheet);
/**
* 修改工时记录
*
* @param timesheet 工时记录
* @return 结果
*/
public int updateTimesheet(Timesheet timesheet);
/**
* 批量删除工时记录
*
* @param ids 需要删除的工时记录主键集合
* @return 结果
*/
public int deleteTimesheetByIds(Long[] ids);
/**
* 删除工时记录信息
*
* @param id 工时记录主键
* @return 结果
*/
public int deleteTimesheetById(Long id);
}
package com.ruoyi.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.domain.TimesheetVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mapper.TimesheetMapper;
import com.ruoyi.domain.Timesheet;
import com.ruoyi.service.ITimesheetService;
/**
* 工时记录Service业务层处理
*
* @author ruoyi
* @date 2025-02-28
*/
@Service
public class TimesheetServiceImpl implements ITimesheetService
{
@Autowired
private TimesheetMapper timesheetMapper;
/**
* 查询工时记录
*
* @param id 工时记录主键
* @return 工时记录
*/
@Override
public Timesheet selectTimesheetById(Long id)
{
return timesheetMapper.selectTimesheetById(id);
}
/**
* 查询工时记录列表
*
* @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);
}
/**
* 新增工时记录
*
* @param timesheet 工时记录
* @return 结果
*/
@Override
public int insertTimesheet(Timesheet timesheet)
{
timesheet.setCreateTime(DateUtils.getNowDate());
return timesheetMapper.insertTimesheet(timesheet);
}
/**
* 修改工时记录
*
* @param timesheet 工时记录
* @return 结果
*/
@Override
public int updateTimesheet(Timesheet timesheet)
{
timesheet.setUpdateTime(DateUtils.getNowDate());
return timesheetMapper.updateTimesheet(timesheet);
}
/**
* 批量删除工时记录
*
* @param ids 需要删除的工时记录主键
* @return 结果
*/
@Override
public int deleteTimesheetByIds(Long[] ids)
{
return timesheetMapper.deleteTimesheetByIds(ids);
}
/**
* 删除工时记录信息
*
* @param id 工时记录主键
* @return 结果
*/
@Override
public int deleteTimesheetById(Long id)
{
return timesheetMapper.deleteTimesheetById(id);
}
private String determineProjectType(Timesheet timesheet) {
// 根据业务逻辑确定projectType
return "A型"; // 示例值
}
private String getDepartmentLeaderName(Timesheet timesheet) {
// 根据业务逻辑获取部门领导的名字
return "李四"; // 示例值
}
private BigDecimal calculateSumHours(Timesheet timesheet) {
// 根据业务逻辑计算sumHours
return new BigDecimal(16); // 示例值
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.mapper.TimesheetMapper">
<resultMap type="Timesheet" id="TimesheetResult">
<result property="id" column="id" />
<result property="employId" column="employ_id" />
<result property="employName" column="employ_name" />
<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="description" column="description" />
<result property="hours" column="hours" />
<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="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
<result property="approvalTime" column="approval_time" />
<result property="approvalNote" column="approval_note" />
<result property="approvalState" column="approval_state" />
<result property="flag" column="flag" />
<result property="deleted" column="deleted" />
</resultMap>
<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
</sql>
<select id="selectTimesheetList" parameterType="Timesheet" resultMap="TimesheetResult">
<include refid="selectTimesheetVo"/>
<where>
<if test="projectNumber != null "> and project_number = #{projectNumber}</if>
<if test="projectName != null and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
<if test="startTime != null "> and start_time = #{startTime}</if>
<if test="endTime != null "> and end_time = #{endTime}</if>
</where>
</select>
<select id="selectTimesheetById" parameterType="Long" resultMap="TimesheetResult">
<include refid="selectTimesheetVo"/>
where id = #{id}
</select>
<insert id="insertTimesheet" parameterType="Timesheet" useGeneratedKeys="true" keyProperty="id">
insert into timesheet
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="employId != null">employ_id,</if>
<if test="employName != null and employName != ''">employ_name,</if>
<if test="projectNumber != null">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="description != null">description,</if>
<if test="hours != null">hours,</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="createTime != null">create_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="approvalState != null">approval_state,</if>
<if test="flag != null">flag,</if>
<if test="deleted != null">deleted,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="employId != null">#{employId},</if>
<if test="employName != null and employName != ''">#{employName},</if>
<if test="projectNumber != null">#{projectNumber},</if>
<if test="projectName != null and projectName != ''">#{projectName},</if>
<if test="managerId != null">#{managerId},</if>
<if test="departmentLeaderId != null">#{departmentLeaderId},</if>
<if test="description != null">#{description},</if>
<if test="hours != null">#{hours},</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="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="approvalTime != null">#{approvalTime},</if>
<if test="approvalNote != null">#{approvalNote},</if>
<if test="approvalState != null">#{approvalState},</if>
<if test="flag != null">#{flag},</if>
<if test="deleted != null">#{deleted},</if>
</trim>
</insert>
<update id="updateTimesheet" parameterType="Timesheet">
update timesheet
<trim prefix="SET" suffixOverrides=",">
<if test="employId != null">employ_id = #{employId},</if>
<if test="employName != null and employName != ''">employ_name = #{employName},</if>
<if test="projectNumber != null">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="description != null">description = #{description},</if>
<if test="hours != null">hours = #{hours},</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="createTime != null">create_time = #{createTime},</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="approvalState != null">approval_state = #{approvalState},</if>
<if test="flag != null">flag = #{flag},</if>
<if test="deleted != null">deleted = #{deleted},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteTimesheetById" parameterType="Long">
delete from timesheet where id = #{id}
</delete>
<delete id="deleteTimesheetByIds" parameterType="String">
delete from timesheet where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</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