修改code review

This commit is contained in:
jason 2021-10-31 22:13:51 +08:00
parent f26c17cff0
commit 0d2ae6be56
12 changed files with 78 additions and 85 deletions

View File

@ -1,9 +1,9 @@
package cn.iocoder.yudao.adminserver.modules.activiti.controller.oa;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.*;
import cn.iocoder.yudao.adminserver.modules.activiti.convert.oa.OaLeaveConvert;
import cn.iocoder.yudao.adminserver.modules.activiti.dal.dataobject.oa.OaLeaveDO;
import cn.iocoder.yudao.adminserver.modules.activiti.service.oa.OaLeaveService;
import cn.iocoder.yudao.adminserver.modules.activiti.convert.oa.OALeaveConvert;
import cn.iocoder.yudao.adminserver.modules.activiti.dal.dataobject.oa.OALeaveDO;
import cn.iocoder.yudao.adminserver.modules.activiti.service.oa.OALeaveService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
@ -26,20 +26,20 @@ import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
// TODO @jasonOa=OA 会不会好点名词缩写哈
@Api(tags = "请假申请")
@RestController
@RequestMapping("/oa/leave")
@Validated
public class OaLeaveController {
public class OALeaveController {
@Resource
private OaLeaveService leaveService;
private OALeaveService leaveService;
@PostMapping("/create")
@ApiOperation("创建请假申请")
@PreAuthorize("@ss.hasPermission('oa:leave:create')")
public CommonResult<Long> createLeave(@Valid @RequestBody OaLeaveCreateReqVO createReqVO) {
public CommonResult<Long> createLeave(@Valid @RequestBody OALeaveCreateReqVO createReqVO) {
// TODO @芋艿processKey 自己去理解下不过得把 leave 变成枚举
createReqVO.setProcessKey("leave");
return success(leaveService.createLeave(createReqVO));
@ -47,7 +47,7 @@ public class OaLeaveController {
@PostMapping("/form-key/create")
@ApiOperation("创建外置请假申请")
public CommonResult<Long> createFormKeyLeave(@Valid @RequestBody OaLeaveCreateReqVO createReqVO) {
public CommonResult<Long> createFormKeyLeave(@Valid @RequestBody OALeaveCreateReqVO createReqVO) {
// TODO @芋艿processKey 自己去理解下不过得把 formkey 变成枚举
createReqVO.setProcessKey("leave-formkey");
return success(leaveService.createLeave(createReqVO));
@ -56,7 +56,7 @@ public class OaLeaveController {
@PutMapping("/update")
@ApiOperation("更新请假申请")
@PreAuthorize("@ss.hasPermission('oa:leave:update')")
public CommonResult<Boolean> updateLeave(@Valid @RequestBody OaLeaveUpdateReqVO updateReqVO) {
public CommonResult<Boolean> updateLeave(@Valid @RequestBody OALeaveUpdateReqVO updateReqVO) {
leaveService.updateLeave(updateReqVO);
return success(true);
}
@ -74,41 +74,41 @@ public class OaLeaveController {
@ApiOperation("获得请假申请")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('oa:leave:query')")
public CommonResult<OaLeaveRespVO> getLeave(@RequestParam("id") Long id) {
OaLeaveDO leave = leaveService.getLeave(id);
return success(OaLeaveConvert.INSTANCE.convert(leave));
public CommonResult<OALeaveRespVO> getLeave(@RequestParam("id") Long id) {
OALeaveDO leave = leaveService.getLeave(id);
return success(OALeaveConvert.INSTANCE.convert(leave));
}
@GetMapping("/list")
@ApiOperation("获得请假申请列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('oa:leave:query')")
public CommonResult<List<OaLeaveRespVO>> getLeaveList(@RequestParam("ids") Collection<Long> ids) {
List<OaLeaveDO> list = leaveService.getLeaveList(ids);
return success(OaLeaveConvert.INSTANCE.convertList(list));
public CommonResult<List<OALeaveRespVO>> getLeaveList(@RequestParam("ids") Collection<Long> ids) {
List<OALeaveDO> list = leaveService.getLeaveList(ids);
return success(OALeaveConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得请假申请分页")
@PreAuthorize("@ss.hasPermission('oa:leave:query')")
public CommonResult<PageResult<OaLeaveRespVO>> getLeavePage(@Valid OaLeavePageReqVO pageVO) {
public CommonResult<PageResult<OALeaveRespVO>> getLeavePage(@Valid OALeavePageReqVO pageVO) {
//值查询自己申请请假
// TODO @芋艿这里的传值到底前端搞还是后端搞
pageVO.setUserId(SecurityFrameworkUtils.getLoginUser().getUsername());
PageResult<OaLeaveDO> pageResult = leaveService.getLeavePage(pageVO);
return success(OaLeaveConvert.INSTANCE.convertPage(pageResult));
PageResult<OALeaveDO> pageResult = leaveService.getLeavePage(pageVO);
return success(OALeaveConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/export-excel")
@ApiOperation("导出请假申请 Excel")
@PreAuthorize("@ss.hasPermission('oa:leave:export')")
@OperateLog(type = EXPORT)
public void exportLeaveExcel(@Valid OaLeaveExportReqVO exportReqVO,
public void exportLeaveExcel(@Valid OALeaveExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<OaLeaveDO> list = leaveService.getLeaveList(exportReqVO);
List<OALeaveDO> list = leaveService.getLeaveList(exportReqVO);
// 导出 Excel
List<OaLeaveExcelVO> datas = OaLeaveConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "请假申请.xls", "数据", OaLeaveExcelVO.class, datas);
List<OALeaveExcelVO> datas = OALeaveConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "请假申请.xls", "数据", OALeaveExcelVO.class, datas);
}
}

View File

@ -13,7 +13,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class OaLeaveBaseVO {
public class OALeaveBaseVO {
@ApiModelProperty(value = "流程id")
private String processInstanceId;

View File

@ -1,15 +1,13 @@
package cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.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 OaLeaveCreateReqVO extends OaLeaveBaseVO {
public class OALeaveCreateReqVO extends OALeaveBaseVO {
private String processKey;
}

View File

@ -12,7 +12,7 @@ import com.alibaba.excel.annotation.ExcelProperty;
* @author 芋艿
*/
@Data
public class OaLeaveExcelVO {
public class OALeaveExcelVO {
@ExcelProperty("请假表单主键")
private Long id;

View File

@ -10,7 +10,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@ApiModel(value = "请假申请 Excel 导出 Request VO", description = "参数和 OaLeavePageReqVO 是一致的")
@Data
public class OaLeaveExportReqVO {
public class OALeaveExportReqVO {
@ApiModelProperty(value = "流程id")
private String processInstanceId;

View File

@ -12,7 +12,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OaLeavePageReqVO extends PageParam {
public class OALeavePageReqVO extends PageParam {
@ApiModelProperty(value = "流程id")
private String processInstanceId;

View File

@ -1,14 +1,13 @@
package cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
@ApiModel("请假申请 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OaLeaveRespVO extends OaLeaveBaseVO {
public class OALeaveRespVO extends OALeaveBaseVO {
@ApiModelProperty(value = "请假表单主键", required = true)
private Long id;

View File

@ -13,7 +13,7 @@ import java.util.Map;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class OaLeaveUpdateReqVO extends OaLeaveBaseVO {
public class OALeaveUpdateReqVO extends OALeaveBaseVO {
@ApiModelProperty(value = "请假表单主键", required = true)
@NotNull(message = "请假表单主键不能为空")

View File

@ -2,12 +2,12 @@ package cn.iocoder.yudao.adminserver.modules.activiti.convert.oa;
import java.util.*;
import cn.iocoder.yudao.adminserver.modules.activiti.dal.dataobject.oa.OALeaveDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.*;
import cn.iocoder.yudao.adminserver.modules.activiti.dal.dataobject.oa.OaLeaveDO;
/**
* 请假申请 Convert
@ -15,20 +15,20 @@ import cn.iocoder.yudao.adminserver.modules.activiti.dal.dataobject.oa.OaLeaveDO
* @author 芋艿
*/
@Mapper
public interface OaLeaveConvert {
public interface OALeaveConvert {
OaLeaveConvert INSTANCE = Mappers.getMapper(OaLeaveConvert.class);
OALeaveConvert INSTANCE = Mappers.getMapper(OALeaveConvert.class);
OaLeaveDO convert(OaLeaveCreateReqVO bean);
OALeaveDO convert(OALeaveCreateReqVO bean);
OaLeaveDO convert(OaLeaveUpdateReqVO bean);
OALeaveDO convert(OALeaveUpdateReqVO bean);
OaLeaveRespVO convert(OaLeaveDO bean);
OALeaveRespVO convert(OALeaveDO bean);
List<OaLeaveRespVO> convertList(List<OaLeaveDO> list);
List<OALeaveRespVO> convertList(List<OALeaveDO> list);
PageResult<OaLeaveRespVO> convertPage(PageResult<OaLeaveDO> page);
PageResult<OALeaveRespVO> convertPage(PageResult<OALeaveDO> page);
List<OaLeaveExcelVO> convertList02(List<OaLeaveDO> list);
List<OALeaveExcelVO> convertList02(List<OALeaveDO> list);
}

View File

@ -17,7 +17,7 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OaLeaveDO extends BaseDO {
public class OALeaveDO extends BaseDO {
/**
* 请假表单主键

View File

@ -1,11 +1,11 @@
package cn.iocoder.yudao.adminserver.modules.activiti.service.oa;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OaLeaveCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OaLeaveExportReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OaLeavePageReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OaLeaveUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.dal.dataobject.oa.OaLeaveDO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OALeaveCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OALeaveUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OALeaveExportReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OALeavePageReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.dal.dataobject.oa.OALeaveDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.validation.Valid;
@ -17,7 +17,7 @@ import java.util.List;
*
* @author 芋艿
*/
public interface OaLeaveService {
public interface OALeaveService {
/**
* 创建请假申请
@ -25,14 +25,14 @@ public interface OaLeaveService {
* @param createReqVO 创建信息
* @return 编号
*/
Long createLeave(@Valid OaLeaveCreateReqVO createReqVO);
Long createLeave(@Valid OALeaveCreateReqVO createReqVO);
/**
* 更新请假申请
*
* @param updateReqVO 更新信息
*/
void updateLeave(@Valid OaLeaveUpdateReqVO updateReqVO);
void updateLeave(@Valid OALeaveUpdateReqVO updateReqVO);
/**
* 删除请假申请
@ -47,7 +47,7 @@ public interface OaLeaveService {
* @param id 编号
* @return 请假申请
*/
OaLeaveDO getLeave(Long id);
OALeaveDO getLeave(Long id);
/**
* 获得请假申请列表
@ -55,7 +55,7 @@ public interface OaLeaveService {
* @param ids 编号
* @return 请假申请列表
*/
List<OaLeaveDO> getLeaveList(Collection<Long> ids);
List<OALeaveDO> getLeaveList(Collection<Long> ids);
/**
* 获得请假申请分页
@ -63,7 +63,7 @@ public interface OaLeaveService {
* @param pageReqVO 分页查询
* @return 请假申请分页
*/
PageResult<OaLeaveDO> getLeavePage(OaLeavePageReqVO pageReqVO);
PageResult<OALeaveDO> getLeavePage(OALeavePageReqVO pageReqVO);
/**
* 获得请假申请列表, 用于 Excel 导出
@ -71,6 +71,6 @@ public interface OaLeaveService {
* @param exportReqVO 查询条件
* @return 请假申请列表
*/
List<OaLeaveDO> getLeaveList(OaLeaveExportReqVO exportReqVO);
List<OALeaveDO> getLeaveList(OALeaveExportReqVO exportReqVO);
}

View File

@ -1,16 +1,15 @@
package cn.iocoder.yudao.adminserver.modules.activiti.service.oa.impl;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OaLeaveCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OaLeaveExportReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OaLeavePageReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OaLeaveUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.convert.oa.OaLeaveConvert;
import cn.iocoder.yudao.adminserver.modules.activiti.dal.dataobject.oa.OaLeaveDO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OALeaveCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OALeaveUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OALeaveExportReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.controller.oa.vo.OALeavePageReqVO;
import cn.iocoder.yudao.adminserver.modules.activiti.convert.oa.OALeaveConvert;
import cn.iocoder.yudao.adminserver.modules.activiti.dal.dataobject.oa.OALeaveDO;
import cn.iocoder.yudao.adminserver.modules.activiti.dal.mysql.oa.OaLeaveMapper;
import cn.iocoder.yudao.adminserver.modules.activiti.service.oa.OaLeaveService;
import cn.iocoder.yudao.adminserver.modules.activiti.service.oa.OALeaveService;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.activiti.api.task.model.Task;
import org.activiti.api.task.model.builders.TaskPayloadBuilder;
import org.activiti.api.task.runtime.TaskRuntime;
@ -21,12 +20,9 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static cn.iocoder.yudao.adminserver.modules.activiti.enums.OaErrorCodeConstants.LEAVE_NOT_EXISTS;
import static cn.iocoder.yudao.adminserver.modules.activiti.enums.OAErrorCodeConstants.LEAVE_NOT_EXISTS;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
@ -36,7 +32,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
*/
@Service
@Validated
public class OaLeaveServiceImpl implements OaLeaveService {
public class OALeaveServiceImpl implements OALeaveService {
@Resource
private OaLeaveMapper leaveMapper;
@ -52,9 +48,9 @@ public class OaLeaveServiceImpl implements OaLeaveService {
@Override
@Transactional(rollbackFor = Exception.class)
public Long createLeave(OaLeaveCreateReqVO createReqVO) {
public Long createLeave(OALeaveCreateReqVO createReqVO) {
// 插入 OA 请假单
OaLeaveDO leave = OaLeaveConvert.INSTANCE.convert(createReqVO);
OALeaveDO leave = OALeaveConvert.INSTANCE.convert(createReqVO);
leave.setStatus(1);
leave.setUserId(SecurityFrameworkUtils.getLoginUser().getUsername());
leaveMapper.insert(leave);
@ -68,19 +64,17 @@ public class OaLeaveServiceImpl implements OaLeaveService {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(createReqVO.getProcessKey(), businessKey, variables);
String processInstanceId = processInstance.getProcessInstanceId();
// TODO @jsonservice 不要出现 dao 的元素例如说 UpdateWrapper这里我们可以调用 updateById 方法
// 将工作流的编号更新到 OA 请假单中
UpdateWrapper<OaLeaveDO> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", id);
OaLeaveDO updateDo = new OaLeaveDO();
OALeaveDO updateDo = new OALeaveDO();
updateDo.setProcessInstanceId(processInstanceId);
leaveMapper.update(updateDo, updateWrapper);
updateDo.setId(id);
leaveMapper.updateById(updateDo);
return id;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateLeave(OaLeaveUpdateReqVO updateReqVO) {
public void updateLeave(OALeaveUpdateReqVO updateReqVO) {
// 校验存在
this.validateLeaveExists(updateReqVO.getId());
@ -93,12 +87,12 @@ public class OaLeaveServiceImpl implements OaLeaveService {
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId())
.withVariables(variables)
.build());
// TODO @jason不需要加 final 虽然是不变但是代码比较少这么去写
final Object reApply = variables.get("reApply");
// TODO @jason直接使用 Objects.equals(reApply, true) 就可以
if((reApply instanceof Boolean) && (Boolean)reApply){
// TOTO @芋道源码 貌似 IDEA 会自动加上final不需要加 final 虽然是不变但是代码比较少这么去写)
Object reApply = variables.get("reApply");
if(Objects.equals(reApply, true)){
// 更新 表单
OaLeaveDO updateObj = OaLeaveConvert.INSTANCE.convert(updateReqVO);
OALeaveDO updateObj = OALeaveConvert.INSTANCE.convert(updateReqVO);
leaveMapper.updateById(updateObj);
}
}
@ -110,6 +104,8 @@ public class OaLeaveServiceImpl implements OaLeaveService {
// 删除
leaveMapper.deleteById(id);
// TODO @jason需要调用 runtimeService delete 方法删除
// TOTO @芋道源码 目前页面暂时没有实现基于业务表单的删除, 该代码自动生成的
// TODO @芋道源码 我理解提交流程后是不允许删除的 只能在流程处理中作废流程
}
private void validateLeaveExists(Long id) {
@ -119,22 +115,22 @@ public class OaLeaveServiceImpl implements OaLeaveService {
}
@Override
public OaLeaveDO getLeave(Long id) {
public OALeaveDO getLeave(Long id) {
return leaveMapper.selectById(id);
}
@Override
public List<OaLeaveDO> getLeaveList(Collection<Long> ids) {
public List<OALeaveDO> getLeaveList(Collection<Long> ids) {
return leaveMapper.selectBatchIds(ids);
}
@Override
public PageResult<OaLeaveDO> getLeavePage(OaLeavePageReqVO pageReqVO) {
public PageResult<OALeaveDO> getLeavePage(OALeavePageReqVO pageReqVO) {
return leaveMapper.selectPage(pageReqVO);
}
@Override
public List<OaLeaveDO> getLeaveList(OaLeaveExportReqVO exportReqVO) {
public List<OALeaveDO> getLeaveList(OALeaveExportReqVO exportReqVO) {
return leaveMapper.selectList(exportReqVO);
}