小久哥
3 years ago
15 changed files with 569 additions and 1 deletions
@ -0,0 +1,100 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.workHour; |
||||
|
||||
import org.springframework.web.bind.annotation.*; |
||||
import javax.annotation.Resource; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.security.access.prepost.PreAuthorize; |
||||
import io.swagger.annotations.*; |
||||
|
||||
import javax.validation.constraints.*; |
||||
import javax.validation.*; |
||||
import javax.servlet.http.*; |
||||
import java.util.*; |
||||
import java.io.IOException; |
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
||||
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; |
||||
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.*; |
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO; |
||||
import cn.iocoder.yudao.module.farm.convert.workHour.WorkHourConvert; |
||||
import cn.iocoder.yudao.module.farm.service.workHour.WorkHourService; |
||||
|
||||
@Api(tags = "管理后台 - ") |
||||
@RestController |
||||
@RequestMapping("/farm/work-hour") |
||||
@Validated |
||||
public class WorkHourController { |
||||
|
||||
@Resource |
||||
private WorkHourService workHourService; |
||||
|
||||
@PostMapping("/create") |
||||
@ApiOperation("创建") |
||||
@PreAuthorize("@ss.hasPermission('farm:work-hour:create')") |
||||
public CommonResult<Long> createWorkHour(@Valid @RequestBody WorkHourCreateReqVO createReqVO) { |
||||
return success(workHourService.createWorkHour(createReqVO)); |
||||
} |
||||
|
||||
@PutMapping("/update") |
||||
@ApiOperation("更新") |
||||
@PreAuthorize("@ss.hasPermission('farm:work-hour:update')") |
||||
public CommonResult<Boolean> updateWorkHour(@Valid @RequestBody WorkHourUpdateReqVO updateReqVO) { |
||||
workHourService.updateWorkHour(updateReqVO); |
||||
return success(true); |
||||
} |
||||
|
||||
@DeleteMapping("/delete") |
||||
@ApiOperation("删除") |
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) |
||||
@PreAuthorize("@ss.hasPermission('farm:work-hour:delete')") |
||||
public CommonResult<Boolean> deleteWorkHour(@RequestParam("id") Long id) { |
||||
workHourService.deleteWorkHour(id); |
||||
return success(true); |
||||
} |
||||
|
||||
@GetMapping("/get") |
||||
@ApiOperation("获得") |
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) |
||||
@PreAuthorize("@ss.hasPermission('farm:work-hour:query')") |
||||
public CommonResult<WorkHourRespVO> getWorkHour(@RequestParam("id") Long id) { |
||||
WorkHourDO workHour = workHourService.getWorkHour(id); |
||||
return success(WorkHourConvert.INSTANCE.convert(workHour)); |
||||
} |
||||
|
||||
@GetMapping("/list") |
||||
@ApiOperation("获得列表") |
||||
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) |
||||
@PreAuthorize("@ss.hasPermission('farm:work-hour:query')") |
||||
public CommonResult<List<WorkHourRespVO>> getWorkHourList(@RequestParam("ids") Collection<Long> ids) { |
||||
List<WorkHourDO> list = workHourService.getWorkHourList(ids); |
||||
return success(WorkHourConvert.INSTANCE.convertList(list)); |
||||
} |
||||
|
||||
@GetMapping("/page") |
||||
@ApiOperation("获得分页") |
||||
@PreAuthorize("@ss.hasPermission('farm:work-hour:query')") |
||||
public CommonResult<PageResult<WorkHourRespVO>> getWorkHourPage(@Valid WorkHourPageReqVO pageVO) { |
||||
PageResult<WorkHourDO> pageResult = workHourService.getWorkHourPage(pageVO); |
||||
return success(WorkHourConvert.INSTANCE.convertPage(pageResult)); |
||||
} |
||||
|
||||
@GetMapping("/export-excel") |
||||
@ApiOperation("导出 Excel") |
||||
@PreAuthorize("@ss.hasPermission('farm:work-hour:export')") |
||||
@OperateLog(type = EXPORT) |
||||
public void exportWorkHourExcel(@Valid WorkHourExportReqVO exportReqVO, |
||||
HttpServletResponse response) throws IOException { |
||||
List<WorkHourDO> list = workHourService.getWorkHourList(exportReqVO); |
||||
// 导出 Excel
|
||||
List<WorkHourExcelVO> datas = WorkHourConvert.INSTANCE.convertList02(list); |
||||
ExcelUtils.write(response, ".xls", "数据", WorkHourExcelVO.class, datas); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.workHour.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
import javax.validation.constraints.*; |
||||
|
||||
/** |
||||
* Base VO,提供给添加、修改、详细的子 VO 使用 |
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 |
||||
*/ |
||||
@Data |
||||
public class WorkHourBaseVO { |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Integer userId; |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Integer projectId; |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Integer taskId; |
||||
|
||||
@ApiModelProperty(value = "", required = true) |
||||
@NotNull(message = "不能为空") |
||||
private Integer hour; |
||||
|
||||
} |
@ -0,0 +1,14 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.workHour.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
import javax.validation.constraints.*; |
||||
|
||||
@ApiModel("管理后台 - 创建 Request VO") |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ToString(callSuper = true) |
||||
public class WorkHourCreateReqVO extends WorkHourBaseVO { |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.workHour.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
||||
/** |
||||
* Excel VO |
||||
* |
||||
* @author 吴蓉 |
||||
*/ |
||||
@Data |
||||
public class WorkHourExcelVO { |
||||
|
||||
@ExcelProperty("") |
||||
private Long id; |
||||
|
||||
@ExcelProperty("") |
||||
private Integer userId; |
||||
|
||||
@ExcelProperty("") |
||||
private Integer projectId; |
||||
|
||||
@ExcelProperty("") |
||||
private Integer taskId; |
||||
|
||||
@ExcelProperty("") |
||||
private Integer hour; |
||||
|
||||
@ExcelProperty("") |
||||
private Date createTime; |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.workHour.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
||||
|
||||
@ApiModel(value = "管理后台 - Excel 导出 Request VO", description = "参数和 WorkHourPageReqVO 是一致的") |
||||
@Data |
||||
public class WorkHourExportReqVO { |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Integer userId; |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Integer projectId; |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Integer taskId; |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Integer hour; |
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
||||
@ApiModelProperty(value = "开始") |
||||
private Date beginCreateTime; |
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
||||
@ApiModelProperty(value = "结束") |
||||
private Date endCreateTime; |
||||
|
||||
} |
@ -0,0 +1,37 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.workHour.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
||||
|
||||
@ApiModel("管理后台 - 分页 Request VO") |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ToString(callSuper = true) |
||||
public class WorkHourPageReqVO extends PageParam { |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Integer userId; |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Integer projectId; |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Integer taskId; |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Integer hour; |
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
||||
@ApiModelProperty(value = "开始") |
||||
private Date beginCreateTime; |
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
||||
@ApiModelProperty(value = "结束") |
||||
private Date endCreateTime; |
||||
|
||||
} |
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.workHour.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
|
||||
@ApiModel("管理后台 - Response VO") |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ToString(callSuper = true) |
||||
public class WorkHourRespVO extends WorkHourBaseVO { |
||||
|
||||
@ApiModelProperty(value = "", required = true) |
||||
private Long id; |
||||
|
||||
@ApiModelProperty(value = "") |
||||
private Date createTime; |
||||
|
||||
} |
@ -0,0 +1,18 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.workHour.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
import javax.validation.constraints.*; |
||||
|
||||
@ApiModel("管理后台 - 更新 Request VO") |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ToString(callSuper = true) |
||||
public class WorkHourUpdateReqVO extends WorkHourBaseVO { |
||||
|
||||
@ApiModelProperty(value = "", required = true) |
||||
@NotNull(message = "不能为空") |
||||
private Long id; |
||||
|
||||
} |
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.yudao.module.farm.convert.workHour; |
||||
|
||||
import java.util.*; |
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
||||
import org.mapstruct.Mapper; |
||||
import org.mapstruct.factory.Mappers; |
||||
import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.*; |
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO; |
||||
|
||||
/** |
||||
* Convert |
||||
* |
||||
* @author 吴蓉 |
||||
*/ |
||||
@Mapper |
||||
public interface WorkHourConvert { |
||||
|
||||
WorkHourConvert INSTANCE = Mappers.getMapper(WorkHourConvert.class); |
||||
|
||||
WorkHourDO convert(WorkHourCreateReqVO bean); |
||||
|
||||
WorkHourDO convert(WorkHourUpdateReqVO bean); |
||||
|
||||
WorkHourRespVO convert(WorkHourDO bean); |
||||
|
||||
List<WorkHourRespVO> convertList(List<WorkHourDO> list); |
||||
|
||||
PageResult<WorkHourRespVO> convertPage(PageResult<WorkHourDO> page); |
||||
|
||||
List<WorkHourExcelVO> convertList02(List<WorkHourDO> list); |
||||
|
||||
} |
@ -0,0 +1,44 @@
|
||||
package cn.iocoder.yudao.module.farm.dal.dataobject.workHour; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
||||
|
||||
/** |
||||
* DO |
||||
* |
||||
* @author 吴蓉 |
||||
*/ |
||||
@TableName("farm_work_hour") |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ToString(callSuper = true) |
||||
@Builder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class WorkHourDO extends BaseDO { |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
@TableId |
||||
private Long id; |
||||
/** |
||||
* |
||||
*/ |
||||
private Integer userId; |
||||
/** |
||||
* |
||||
*/ |
||||
private Integer projectId; |
||||
/** |
||||
* |
||||
*/ |
||||
private Integer taskId; |
||||
/** |
||||
* |
||||
*/ |
||||
private Integer hour; |
||||
|
||||
} |
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.farm.dal.mysql.workHour; |
||||
|
||||
import java.util.*; |
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.*; |
||||
|
||||
/** |
||||
* Mapper |
||||
* |
||||
* @author 吴蓉 |
||||
*/ |
||||
@Mapper |
||||
public interface WorkHourMapper extends BaseMapperX<WorkHourDO> { |
||||
|
||||
default PageResult<WorkHourDO> selectPage(WorkHourPageReqVO reqVO) { |
||||
return selectPage(reqVO, new LambdaQueryWrapperX<WorkHourDO>() |
||||
.eqIfPresent(WorkHourDO::getUserId, reqVO.getUserId()) |
||||
.eqIfPresent(WorkHourDO::getProjectId, reqVO.getProjectId()) |
||||
.eqIfPresent(WorkHourDO::getTaskId, reqVO.getTaskId()) |
||||
.eqIfPresent(WorkHourDO::getHour, reqVO.getHour()) |
||||
.betweenIfPresent(WorkHourDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) |
||||
.orderByDesc(WorkHourDO::getId)); |
||||
} |
||||
|
||||
default List<WorkHourDO> selectList(WorkHourExportReqVO reqVO) { |
||||
return selectList(new LambdaQueryWrapperX<WorkHourDO>() |
||||
.eqIfPresent(WorkHourDO::getUserId, reqVO.getUserId()) |
||||
.eqIfPresent(WorkHourDO::getProjectId, reqVO.getProjectId()) |
||||
.eqIfPresent(WorkHourDO::getTaskId, reqVO.getTaskId()) |
||||
.eqIfPresent(WorkHourDO::getHour, reqVO.getHour()) |
||||
.betweenIfPresent(WorkHourDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) |
||||
.orderByDesc(WorkHourDO::getId)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,70 @@
|
||||
package cn.iocoder.yudao.module.farm.service.workHour; |
||||
|
||||
import java.util.*; |
||||
import javax.validation.*; |
||||
import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.*; |
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO; |
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
||||
/** |
||||
* Service 接口 |
||||
* |
||||
* @author 吴蓉 |
||||
*/ |
||||
public interface WorkHourService { |
||||
|
||||
/** |
||||
* 创建 |
||||
* |
||||
* @param createReqVO 创建信息 |
||||
* @return 编号 |
||||
*/ |
||||
Long createWorkHour(@Valid WorkHourCreateReqVO createReqVO); |
||||
|
||||
/** |
||||
* 更新 |
||||
* |
||||
* @param updateReqVO 更新信息 |
||||
*/ |
||||
void updateWorkHour(@Valid WorkHourUpdateReqVO updateReqVO); |
||||
|
||||
/** |
||||
* 删除 |
||||
* |
||||
* @param id 编号 |
||||
*/ |
||||
void deleteWorkHour(Long id); |
||||
|
||||
/** |
||||
* 获得 |
||||
* |
||||
* @param id 编号 |
||||
* @return |
||||
*/ |
||||
WorkHourDO getWorkHour(Long id); |
||||
|
||||
/** |
||||
* 获得列表 |
||||
* |
||||
* @param ids 编号 |
||||
* @return 列表 |
||||
*/ |
||||
List<WorkHourDO> getWorkHourList(Collection<Long> ids); |
||||
|
||||
/** |
||||
* 获得分页 |
||||
* |
||||
* @param pageReqVO 分页查询 |
||||
* @return 分页 |
||||
*/ |
||||
PageResult<WorkHourDO> getWorkHourPage(WorkHourPageReqVO pageReqVO); |
||||
|
||||
/** |
||||
* 获得列表, 用于 Excel 导出 |
||||
* |
||||
* @param exportReqVO 查询条件 |
||||
* @return 列表 |
||||
*/ |
||||
List<WorkHourDO> getWorkHourList(WorkHourExportReqVO exportReqVO); |
||||
|
||||
} |
@ -0,0 +1,82 @@
|
||||
package cn.iocoder.yudao.module.farm.service.workHour; |
||||
|
||||
import org.springframework.stereotype.Service; |
||||
import javax.annotation.Resource; |
||||
import org.springframework.validation.annotation.Validated; |
||||
|
||||
import java.util.*; |
||||
import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.*; |
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO; |
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
||||
import cn.iocoder.yudao.module.farm.convert.workHour.WorkHourConvert; |
||||
import cn.iocoder.yudao.module.farm.dal.mysql.workHour.WorkHourMapper; |
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
||||
import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.*; |
||||
|
||||
/** |
||||
* Service 实现类 |
||||
* |
||||
* @author 吴蓉 |
||||
*/ |
||||
@Service |
||||
@Validated |
||||
public class WorkHourServiceImpl implements WorkHourService { |
||||
|
||||
@Resource |
||||
private WorkHourMapper workHourMapper; |
||||
|
||||
@Override |
||||
public Long createWorkHour(WorkHourCreateReqVO createReqVO) { |
||||
// 插入
|
||||
WorkHourDO workHour = WorkHourConvert.INSTANCE.convert(createReqVO); |
||||
workHourMapper.insert(workHour); |
||||
// 返回
|
||||
return workHour.getId(); |
||||
} |
||||
|
||||
@Override |
||||
public void updateWorkHour(WorkHourUpdateReqVO updateReqVO) { |
||||
// 校验存在
|
||||
this.validateWorkHourExists(updateReqVO.getId()); |
||||
// 更新
|
||||
WorkHourDO updateObj = WorkHourConvert.INSTANCE.convert(updateReqVO); |
||||
workHourMapper.updateById(updateObj); |
||||
} |
||||
|
||||
@Override |
||||
public void deleteWorkHour(Long id) { |
||||
// 校验存在
|
||||
this.validateWorkHourExists(id); |
||||
// 删除
|
||||
workHourMapper.deleteById(id); |
||||
} |
||||
|
||||
private void validateWorkHourExists(Long id) { |
||||
if (workHourMapper.selectById(id) == null) { |
||||
throw exception(WORK_HOUR_NOT_EXISTS); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public WorkHourDO getWorkHour(Long id) { |
||||
return workHourMapper.selectById(id); |
||||
} |
||||
|
||||
@Override |
||||
public List<WorkHourDO> getWorkHourList(Collection<Long> ids) { |
||||
return workHourMapper.selectBatchIds(ids); |
||||
} |
||||
|
||||
@Override |
||||
public PageResult<WorkHourDO> getWorkHourPage(WorkHourPageReqVO pageReqVO) { |
||||
return workHourMapper.selectPage(pageReqVO); |
||||
} |
||||
|
||||
@Override |
||||
public List<WorkHourDO> getWorkHourList(WorkHourExportReqVO exportReqVO) { |
||||
return workHourMapper.selectList(exportReqVO); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
<?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="cn.iocoder.yudao.module.farm.dal.mysql.workHour.WorkHourMapper"> |
||||
|
||||
<!-- |
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 |
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 |
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 |
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ |
||||
--> |
||||
|
||||
</mapper> |
Loading…
Reference in new issue