奖惩流程
This commit is contained in:
parent
db23192652
commit
311de21aff
@ -31,6 +31,7 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode OA_SHIFTJOBS_NOT_EXISTS = new ErrorCode(1_009_001_107, "调岗申请不存在");
|
||||
ErrorCode OA_SECOND_NOT_EXISTS = new ErrorCode(1_009_001_108, "借调申请不存在");
|
||||
ErrorCode OA_IMPREST_NOT_EXISTS = new ErrorCode(1_009_001_109, "备用金申请不存在");
|
||||
ErrorCode OA_INCENTIVE_NOT_EXISTS = new ErrorCode(1_009_001_110, "奖惩申请不存在");
|
||||
|
||||
// ========== 流程模型 1-009-002-000 ==========
|
||||
ErrorCode MODEL_KEY_EXISTS = new ErrorCode(1_009_002_000, "已经存在流程标识为【{}】的流程");
|
||||
|
@ -0,0 +1,85 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.oa;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveCreateReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveRespVO;
|
||||
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOAIncentiveConvert;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAIncentiveDO;
|
||||
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAIncentiveService;
|
||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
/**
|
||||
* OA 奖惩申请 Controller
|
||||
*
|
||||
* @author 符溶馨
|
||||
|
||||
*/
|
||||
@Tag(name = "管理后台 - OA 奖惩申请")
|
||||
@RestController
|
||||
@RequestMapping("/bpm/oa/incentive")
|
||||
@Validated
|
||||
public class BpmOAIncentiveController {
|
||||
|
||||
@Resource
|
||||
private BpmOAIncentiveService incentiveService;
|
||||
|
||||
@Resource
|
||||
private AdminUserApi userApi;
|
||||
|
||||
@Resource
|
||||
private DeptApi deptApi;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建请求申请")
|
||||
public CommonResult<Long> createIncentive(@Valid @RequestBody BpmOAIncentiveCreateReqVO createReqVO) {
|
||||
|
||||
return success(incentiveService.createIncentive(getLoginUserId(), createReqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得奖惩申请")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
public CommonResult<BpmOAIncentiveRespVO> getIncentive(@RequestParam("id") Long id) {
|
||||
|
||||
BpmOAIncentiveDO incentive = incentiveService.getIncentive(id);
|
||||
|
||||
//获得 用户信息集合
|
||||
List<AdminUserRespDTO> userRespDTO = userApi.getUserListByDeptIds(incentive.getIncentiveDeptIds()).getCheckedData();
|
||||
|
||||
//获得 部门信息集合
|
||||
Map<Long, DeptRespDTO> deptRespDTOS = deptApi.getDeptMap(incentive.getIncentiveDeptIds());
|
||||
|
||||
Map<String, List<String>> userInfo = new HashMap<>();
|
||||
//遍历 部门map集合
|
||||
deptRespDTOS.forEach((key, value) -> {
|
||||
|
||||
List<String> userName = userRespDTO.stream().filter(user -> user.getDeptId().toString().contains(key.toString())
|
||||
&& incentive.getIncentiveUserIds().contains(user.getId()))
|
||||
.map(AdminUserRespDTO::getNickname).collect(Collectors.toList());
|
||||
|
||||
userInfo.put(value.getName(), userName);
|
||||
});
|
||||
|
||||
BpmOAIncentiveRespVO bpmOAIncentiveRespVO = BpmOAIncentiveConvert.INSTANCE.convert(incentive);
|
||||
bpmOAIncentiveRespVO.setUserInfo(userInfo);
|
||||
return success(bpmOAIncentiveRespVO);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.upload.UploadUserFile;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 奖惩申请创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode()
|
||||
@ToString(callSuper = true)
|
||||
public class BpmOAIncentiveCreateReqVO {
|
||||
|
||||
@Schema(description = "奖惩类型 字典值参考 bpm_oa_incentive_type", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩类型不能为空")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "奖惩人编号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩人编号不能为空")
|
||||
private Set<Long> incentiveUserIds;
|
||||
|
||||
@Schema(description = "奖惩人部门编号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩人部门编号不能为空")
|
||||
private Set<Long> incentiveDeptIds;
|
||||
|
||||
@Schema(description = "奖惩时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩时间不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime time;
|
||||
|
||||
@Schema(description = "奖惩金额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩金额不能为空")
|
||||
private BigDecimal amount;
|
||||
|
||||
@Schema(description = "奖惩事由", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "奖惩事由不能为空")
|
||||
private String reason;
|
||||
|
||||
@Schema(description = "上传文件", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<UploadUserFile> fileItems ;
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.BpmOABaseRespVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.upload.UploadUserFile;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 奖惩申请响应数据 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class BpmOAIncentiveRespVO extends BpmOABaseRespVO {
|
||||
|
||||
@Schema(description = "奖惩类型 字典值参考 bpm_oa_incentive_type")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "奖惩人信息列表 key:部门名称, value:用户名称集合")
|
||||
private Map<String, List<String>> userInfo;
|
||||
|
||||
@Schema(description = "奖惩时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime time;
|
||||
|
||||
@Schema(description = "奖惩金额")
|
||||
private BigDecimal amount;
|
||||
|
||||
@Schema(description = "奖惩事由")
|
||||
private String reason;
|
||||
|
||||
@Schema(description = "上传文件")
|
||||
private List<UploadUserFile> fileItems ;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.bpm.convert.oa;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveCreateReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveRespVO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAIncentiveDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 奖惩申请 Convert
|
||||
*
|
||||
* @author 符溶馨
|
||||
*/
|
||||
@Mapper
|
||||
public interface BpmOAIncentiveConvert {
|
||||
|
||||
BpmOAIncentiveConvert INSTANCE = Mappers.getMapper(BpmOAIncentiveConvert.class);
|
||||
|
||||
BpmOAIncentiveDO convert(BpmOAIncentiveCreateReqVO bean);
|
||||
|
||||
BpmOAIncentiveRespVO convert(BpmOAIncentiveDO bean);
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package cn.iocoder.yudao.module.bpm.dal.dataobject.oa;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.upload.UploadUserFile;
|
||||
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* OA 奖惩申请 DO
|
||||
*
|
||||
* @author 符溶馨
|
||||
*/
|
||||
@TableName(value ="bpm_oa_incentive", autoResultMap = true)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BpmOAIncentiveDO extends BaseDO {
|
||||
|
||||
|
||||
/**
|
||||
* 出差表单主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 申请人的用户编号
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 奖惩类型
|
||||
* 1:奖励 2:惩罚
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 奖惩人用户编号
|
||||
*/
|
||||
@TableField(typeHandler = JsonLongSetTypeHandler.class)
|
||||
private Set<Long> incentiveUserIds;
|
||||
|
||||
/**
|
||||
* 奖惩人部门编号
|
||||
*/
|
||||
@TableField(typeHandler = JsonLongSetTypeHandler.class)
|
||||
private Set<Long> incentiveDeptIds;
|
||||
|
||||
/**
|
||||
* 奖惩时间
|
||||
*/
|
||||
private LocalDateTime time;
|
||||
|
||||
/**
|
||||
* 奖惩金额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 奖惩事由
|
||||
*/
|
||||
private String reason;
|
||||
|
||||
/**
|
||||
* 用章的结果
|
||||
*
|
||||
* 枚举 {@link BpmProcessInstanceResultEnum}
|
||||
* 考虑到简单,所以直接复用了 BpmProcessInstanceResultEnum 枚举,也可以自己定义一个枚举哈
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 对应的流程编号
|
||||
*
|
||||
* 关联 ProcessInstance 的 id 属性
|
||||
*/
|
||||
private String processInstanceId;
|
||||
|
||||
/**
|
||||
* 附件基本信息
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<UploadUserFile> fileItems ;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package cn.iocoder.yudao.module.bpm.dal.mysql.oa;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAIncentiveDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 奖惩申请 Mapper
|
||||
*
|
||||
* @author 符溶馨
|
||||
|
||||
*/
|
||||
@Mapper
|
||||
public interface BpmOAIncentiveMapper extends BaseMapperX<BpmOAIncentiveDO> {
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.oa;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveCreateReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAIncentiveDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 奖惩申请 Service 接口
|
||||
*
|
||||
* @author 符溶馨
|
||||
|
||||
*/
|
||||
public interface BpmOAIncentiveService {
|
||||
|
||||
/**
|
||||
* 创建奖惩申请
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createIncentive(Long userId, @Valid BpmOAIncentiveCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新奖惩申请的状态
|
||||
*
|
||||
* @param id 编号
|
||||
* @param result 结果
|
||||
*/
|
||||
void updateIncentiveResult(Long id, Integer result);
|
||||
|
||||
/**
|
||||
* 获得奖惩申请
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 奖惩申请
|
||||
*/
|
||||
BpmOAIncentiveDO getIncentive(Long id);
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.oa;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
|
||||
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.incentive.BpmOAIncentiveCreateReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.upload.UploadUserFile;
|
||||
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOAIncentiveConvert;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAIncentiveDO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.mysql.oa.BpmOAIncentiveMapper;
|
||||
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.OA_INCENTIVE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* OA 奖惩申请 Service 实现类
|
||||
*
|
||||
* @author 符溶馨
|
||||
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class BpmOAIncentiveServiceImpl extends BpmOABaseService implements BpmOAIncentiveService{
|
||||
|
||||
/**
|
||||
* OA 奖惩对应的流程定义 KEY
|
||||
*/
|
||||
public static final String PROCESS_KEY = "oa_incentive";
|
||||
|
||||
@Resource
|
||||
private BpmOAIncentiveMapper incentiveMapper;
|
||||
|
||||
@Resource
|
||||
private BpmProcessInstanceApi processInstanceApi;
|
||||
|
||||
@Override
|
||||
public Long createIncentive(Long userId, BpmOAIncentiveCreateReqVO createReqVO) {
|
||||
|
||||
//插入OA 奖惩申请
|
||||
BpmOAIncentiveDO incentive = BpmOAIncentiveConvert.INSTANCE.convert(createReqVO).setUserId(userId)
|
||||
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
||||
incentiveMapper.insert(incentive) ;
|
||||
|
||||
// 发起 BPM 流程
|
||||
Map<String, Object> processInstanceVariables = new HashMap<>();
|
||||
String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
||||
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
||||
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(incentive.getId()))).getCheckedData();
|
||||
|
||||
// 将工作流的编号,更新到 OA 奖惩单中
|
||||
incentiveMapper.updateById(new BpmOAIncentiveDO().setId(incentive.getId()).setProcessInstanceId(processInstanceId));
|
||||
|
||||
List<UploadUserFile> fileItems = createReqVO.getFileItems() ;
|
||||
//这里的逻辑,如果fileItems不为空,且有数据,那么说明是上传了附件的,则需要更工作流文件表对应的实例Id
|
||||
if (fileItems != null && !fileItems.isEmpty()) {
|
||||
uploadBpmFileProcessInstanceId(processInstanceId,fileItems) ;
|
||||
}
|
||||
return incentive.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIncentiveResult(Long id, Integer result) {
|
||||
|
||||
validateLeaveExists(id);
|
||||
incentiveMapper.updateById(new BpmOAIncentiveDO().setId(id).setResult(result));
|
||||
}
|
||||
|
||||
private void validateLeaveExists(Long id) {
|
||||
if (incentiveMapper.selectById(id) == null) {
|
||||
throw exception(OA_INCENTIVE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BpmOAIncentiveDO getIncentive(Long id) {
|
||||
|
||||
return incentiveMapper.selectById(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.oa.listener;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEvent;
|
||||
import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEventListener;
|
||||
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAIncentiveService;
|
||||
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAIncentiveServiceImpl;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* OA 奖惩的结果的监听器实现类
|
||||
*
|
||||
* @author 符溶馨
|
||||
*/
|
||||
@Component
|
||||
public class BpmOAIncentiveResultListener extends BpmProcessInstanceResultEventListener {
|
||||
|
||||
@Resource
|
||||
private BpmOAIncentiveService incentiveService;
|
||||
|
||||
@Override
|
||||
protected String getProcessDefinitionKey() {
|
||||
return BpmOAIncentiveServiceImpl.PROCESS_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvent(BpmProcessInstanceResultEvent event) {
|
||||
incentiveService.updateIncentiveResult(Long.parseLong(event.getBusinessKey()), event.getResult());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user