Commit d138e6de by tangzhaoqian Committed by chenzg

审批撤回,审批详情头像,validation参数校验+AOP切面统一处理 校验报错返回

parent b536645a
......@@ -81,6 +81,11 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>provided</scope>
</dependency>
......@@ -231,7 +236,7 @@
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.2</version>
<version>4.6.1</version>
</dependency>
<!-- lombok -->
......
package cn.timer.api.aspect;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import com.alibaba.fastjson.JSONObject;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.timer.api.aspect.lang.annotation.BindingResultCtrol;
import cn.timer.api.aspect.lang.bean.ValidationError;
import cn.timer.api.utils.ResultUtil;
/**
* 校验信息返回
*
* @author TZQ
*/
@Aspect
@Component
public class BindingResultAspect {
// 配置织入点
@Pointcut("@annotation(cn.timer.api.aspect.lang.annotation.BindingResultCtrol)")
public void bindingResultPointCut()
{
}
@Before("bindingResultPointCut()")
public void doBefore(JoinPoint point) throws Throwable
{
// handleDataScope(point);
}
@Around("bindingResultPointCut() && args(..,bindingResult)")
public Object doAround(ProceedingJoinPoint joinPoint,BindingResult bindingResult) throws Throwable {
Long startTime = System.currentTimeMillis();
Object retVal;
if(bindingResult.hasErrors()){
List<ObjectError> ls = bindingResult.getAllErrors();
List<ValidationError> listVe = new ArrayList<ValidationError>();
ValidationError ve;
for (ObjectError one : ls) {
String fieldString = one.getCodes().length >= 1 ? one.getCodes()[0] : "";
if (fieldString != null) {
fieldString = fieldString.substring(fieldString.lastIndexOf(".") + 1);
}
for (String str : one.getCodes()) {
System.err.println(str);
}
ve = ValidationError.builder().field(fieldString).msg(one.getDefaultMessage()).build();
listVe.add(ve);
}
retVal = ResultUtil.error(listVe);
}else {
retVal = joinPoint.proceed(joinPoint.getArgs());
}
Console.log("返回内容 {}: " ,JSONObject.toJSONString(retVal));
Long endtime = System.currentTimeMillis();
Console.log("执行耗时为{}:" ,endtime-startTime + "ms");
return retVal;
}
protected void handleDataScope(final JoinPoint joinPoint)
{
// 获得注解
BindingResultCtrol controllerDataScope = getAnnotationLog(joinPoint);
if (controllerDataScope == null)
return;
Console.log("title" + controllerDataScope.title());
Console.log("paramType" + controllerDataScope.paramType());
Object[] objs = joinPoint.getArgs();
List<Object> listObj = CollectionUtil.toList(objs);
BeanPropertyBindingResult optional = (BeanPropertyBindingResult)listObj.stream()
.filter(p -> "BeanPropertyBindingResult".equals(ClassUtil.getClassName(p, true)))
.findFirst()
.orElse(null);
if (optional != null && optional.hasErrors()) {
System.err.println("Optional: "+ optional);
}
}
/**
* 是否存在注解,如果存在就获取
*/
private BindingResultCtrol getAnnotationLog(JoinPoint joinPoint)
{
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Method method = methodSignature.getMethod();
if (method != null)
{
return method.getAnnotation(BindingResultCtrol.class);
}
return null;
}
}
package cn.timer.api.aspect.lang.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface BindingResultCtrol {
/**
* 模块
*/
public String title() default "8小时";
/**
* 参数类型
*/
public String paramType() default "对象";
}
package cn.timer.api.aspect.lang.bean;
import cn.timer.api.bean.spmk.SpmkApprovalG;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ValidationError {
private String field;
private String msg;
}
......@@ -4,8 +4,11 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -26,6 +29,7 @@ import cn.hutool.core.lang.Console;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.timer.api.aspect.lang.annotation.BindingResultCtrol;
import cn.timer.api.bean.spmk.SpmkApprovalG;
import cn.timer.api.bean.spmk.SpmkApprovalTemplate;
import cn.timer.api.bean.spmk.SpmkApprovalTemplateG;
......@@ -48,6 +52,7 @@ import cn.timer.api.dao.spmk.SpmkApproveSummaryMapper;
import cn.timer.api.dao.spmk.SpmkCustomApprovalMapper;
import cn.timer.api.dao.spmk.SpmkExecutorMapper;
import cn.timer.api.dao.spmk.SpmkInitiatorConfigMapper;
import cn.timer.api.dao.yggl.YgglMainEmpMapper;
import cn.timer.api.dto.spmk.ApprovingDto;
import cn.timer.api.dto.spmk.FlowChildren;
import cn.timer.api.dto.spmk.FromData;
......@@ -375,13 +380,23 @@ public class SpmkServiceImpl {
@ApiOperation(value = "17.发起审批", httpMethod = "POST", notes = "发起审批")
@ApiOperationSupport(order = 17)
@Transactional(rollbackFor = Exception.class)
public Result<Object> saveCa(@CurrentUser UserBean userBean, @RequestBody SpmkApproveSummaryDto spmkApproveSummaryDto) throws Exception{
@BindingResultCtrol(title = "发起审批")
public Result<Object> saveCa(@CurrentUser UserBean userBean,@Valid @RequestBody SpmkApproveSummaryDto spmkApproveSummaryDto,BindingResult bindingResult) throws Exception{
YgglMainEmp ygglMainEmp = YgglMainEmp.builder().build().selectOne(new QueryWrapper<YgglMainEmp>()
.lambda()
.select(YgglMainEmp::getHeadUrl,YgglMainEmp::getName)
.eq(YgglMainEmp::getEmpNum, userBean.getEmpNum()));
if (ygglMainEmp == null)
return ResultUtil.error("发起人异常!");
List<Router> listRouter = new ArrayList<Router>();
listRouter.add(spmkApproveSummaryDto.getRouter());
JSONObject jSONObject = spmkApproveSummaryDto.getRequestData()
.put("orgCode", FromData.builder().value(String.valueOf(userBean.getOrgCode())).build())
.put("initiator", FromData.builder().value(spmkApproveSummaryDto.getInitiator()).build())
.put("headUrl", FromData.builder().value(ygglMainEmp.getHeadUrl()).build())
.put("id", FromData.builder().value(StrUtil.toString(userBean.getEmpNum())).build());
RouterUtils.NextNode(listRouter, jSONObject, ISFIRST);
List<FlowChildren> listFlowChildren = new ArrayList<FlowChildren>();
......@@ -479,6 +494,20 @@ public class SpmkServiceImpl {
return ResultUtil.data(adD, "操作成功!");
}
//TODO 撤销审批
/**
* 撤销审批
*/
@PutMapping(value = "/revoke_approval/{id}")
@ApiOperation(value = "22.撤销审批", httpMethod = "PUT", notes = "撤销审批")
@Transactional(rollbackFor = Exception.class)
@ApiOperationSupport(order = 22)
public Result<Object> revokeApproval(@PathVariable Integer id) throws Exception {
return SpmkApproveSummary.builder().id(id).endTime(new Date()).sts(1).build().updateById() ?
ResultUtil.success("操作成功!") : ResultUtil.error("操作失败!");
}
//TODO 审批人审批
/**
* 审批人审批
......@@ -487,7 +516,8 @@ public class SpmkServiceImpl {
@ApiOperation(value = "20.审批人审批", httpMethod = "POST", notes = "审批人审批")
@Transactional(rollbackFor = Exception.class)
@ApiOperationSupport(order = 20)
public Result<Object> approving(@RequestBody ApprovingDto approvingDto) throws Exception {
// @BindingResultCtrol(title = "审批人审批")
public Result<Object> approving(@Valid @RequestBody ApprovingDto approvingDto, BindingResult bindingResult) throws Exception {
SpmkApproveDetail ad = SpmkApproveDetail.builder().build()
.selectOne(new QueryWrapper<SpmkApproveDetail>()
.lambda()
......@@ -498,7 +528,7 @@ public class SpmkServiceImpl {
.select(SpmkApproveSummary::getSts)
.eq(SpmkApproveSummary::getId, approvingDto.getAsId()));
if (aSummary.getSts() == 2 || aSummary.getSts() == 3) {
if (aSummary.getSts() == 1 || aSummary.getSts() == 2 || aSummary.getSts() == 3) {
return ResultUtil.error("该审批已结束!");
}
......
package cn.timer.api.dto.spmk;
import javax.validation.constraints.NotNull;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
......@@ -12,19 +14,23 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class ApprovingDto {
@NotNull(message = "asId为空")
@ApiModelProperty(value = "审批汇总id", example = "2", required = true)
private Integer asId;
@NotNull(message = "executeRecordId为空")
@ApiModelProperty(value = "审批执行记录id", example = "10", required = true)
private Integer executeRecordId;
@NotNull(message = "executorId为空")
@ApiModelProperty(value = "执行人记录id", example = "10", required = true)
private Integer executorId;
@ApiModelProperty(value = "意见", example = "MMMMMMMM")
@ApiModelProperty(value = "意见", example = "同意、拒绝")
private String opinion;
@ApiModelProperty(value = "状态 2同意 3拒绝", example = "2", required = true)
@NotNull(message = "sts为空")
@ApiModelProperty(value = "状态 2同意 3拒绝 4转派", example = "2", required = true)
private Integer sts;
@ApiModelProperty(value = "被转派人 ", example = "对象")
......
package cn.timer.api.dto.spmk;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import cn.timer.api.utils.Page;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
......@@ -17,7 +22,7 @@ public class MySummaryQueryDto extends Page{
private Integer empNum;
@ApiModelProperty(value = "关键字", example = "请假")
@ApiModelProperty(value = "关键字 标题/审批人名称/审批总汇id", example = "请假")
private String query;
@ApiModelProperty(value = "状态 0审批中 1审批撤销 2审批通过/审批完成 3审批拒绝", example = "0")
......@@ -29,6 +34,9 @@ public class MySummaryQueryDto extends Page{
@ApiModelProperty(value = "结束时间 ", example = "2020-10-10 10:10:10")
private String endTime;
@NotNull(message = "type为空")
@DecimalMax(value = "2",message = "assoType 只能为 0我发起的 1抄送我的 2我审批的")
@DecimalMin(value = "0",message = "assoType 只能为 0我发起的 1抄送我的 2我审批的")
@ApiModelProperty(value = "0我发起的 1抄送我的 2我审批的", example = "0")
private Integer type;
......
......@@ -3,6 +3,8 @@ package cn.timer.api.dto.spmk;
import java.io.Serializable;
import java.util.List;
import javax.validation.constraints.Size;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONSupport;
import lombok.AllArgsConstructor;
......
package cn.timer.api.dto.spmk;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import javax.validation.Valid;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import cn.hutool.json.JSONObject;
import cn.timer.api.bean.spmk.SpmkApproveSummary;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 审批汇总
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SpmkApproveSummaryDto{
/*
* 审批汇总
*/
@NotBlank(message = "title为空")
@ApiModelProperty(value = "标题 ", example = "标题", required = true)
private String title;
@NotBlank(message = "approveName为空")
@ApiModelProperty(value = "审批名称 ", example = "审批名称", required = true)
private String approveName;
@NotBlank(message = "initiator为空")
@ApiModelProperty(value = "发起人名称 ", example = "发起人名称", required = true)
private String initiator;
@ApiModelProperty(value = "关联类型 1转正 2离职 3调薪 4调岗 5加班 6请假 7出差 8外出 9补卡 ", example = "5")
@NotNull(message = "assoType为空")
@DecimalMax(value = "9",message = "assoType 只能为 0无 1转正 2离职 3调薪 4调岗 5加班 6请假 7出差 8外出 9补卡")
@DecimalMin(value = "0",message = "assoType 只能为 0无 1转正 2离职 3调薪 4调岗 5加班 6请假 7出差 8外出 9补卡")
@ApiModelProperty(value = "关联类型 0无 1转正 2离职 3调薪 4调岗 5加班 6请假 7出差 8外出 9补卡 ", example = "5")
private Integer assoType;
@NotNull(message = "requestData为空")
@ApiModelProperty(value = "申请数据 ", example = "申请数据", required = true)
private JSONObject requestData;
@NotNull(message = "froms为空")
@ApiModelProperty(value = "审批表单 ", example = "数组", required = true)
private List<JSONObject> froms;
@ApiModelProperty(value = "审批流程 ", example = "审批流程", required = true)
@NotNull(message = "router为空")
@ApiModelProperty(value = "审批流程", example = "审批流程", required = true)
private Router router;
}
......@@ -18,7 +18,7 @@ public class SummaryQueryDto extends Page{
private Integer orgCode;
@ApiModelProperty(value = "关键字", example = "请假")
@ApiModelProperty(value = "关键字 标题/审批人名称/审批总汇id", example = "请假")
private String query;
@ApiModelProperty(value = "部门id", example = "10")
......
......@@ -24,4 +24,6 @@ public class User implements Serializable{
private String execute;
private String headUrl;
}
......@@ -27,7 +27,7 @@ public class ResultUtil<T> {
private static final String MESSAGE_UNLOGIN = "会话超时,请重新登录";
// private static final String MESSAGE_ERROR = "操作错误";
// private static final String MESSAGE_KICKOUT = "当前账户已在其他地方登录,请重新登录";
// private static final String MESSAGE_PARAMERROR = "参数错误";
private static final String MESSAGE_PARAMERROR = "参数错误";
// private static final String MESSAGE_UNAUTHORIZED = "授权错误";
// private static final String MESSAGE_UNAUTHENTICATED = "认证错误";
// private static final String MESSAGE_EXCEPTION = "服务器异常";
......@@ -37,7 +37,7 @@ public class ResultUtil<T> {
// private static final String STATUS_CODE_ERROR = "202";
private static final String STATUS_CODE_UNLOGIN = "301";
// private static final String STATUS_CODE_KICKOUT = "302";
// private static final String STATUS_CODE_UNPARAM = "400";
private static final String STATUS_CODE_UNPARAM = "400";
// private static final String STATUS_CODE_UNAUTHORIZED = "401";
// private static final String STATUS_CODE_UNAUTHENTICATED = "405";
private static final String STATUS_CODE_EXCEPTION = "500";
......@@ -114,6 +114,13 @@ public class ResultUtil<T> {
return this.result;
}
public Result<T> setErrorMsg(T t) {
this.result.setData(t);
this.result.setCode(STATUS_CODE_UNPARAM);
this.result.setMessage(MESSAGE_PARAMERROR);
return this.result;
}
public Result<T> setErrorMsg(String msg) {
this.result.setResult(false);
this.result.setMessage(msg);
......@@ -179,4 +186,8 @@ public class ResultUtil<T> {
return new ResultUtil<T>().setErrorMsg(code, msg);
}
public static <T> Result<T> error(T t) {
return new ResultUtil<T>().setErrorMsg(t);
}
}
......@@ -73,6 +73,7 @@ public class RouterUtils {
User userFirst = User.builder()
.name(obj.get("initiator",FromData.class).getValue())
.id(obj.get("id",FromData.class).getValue())
.headUrl(obj.get("headUrl",FromData.class).getValue())
.execute("0")
.build();
users.add(userFirst);
......@@ -342,6 +343,7 @@ public class RouterUtils {
SpmkExecutor.builder()
.approveExecuteRecordId(aer.getId())
.empNum(Integer.parseInt(user.getId()))
.operatorHeaderUrl(user.getHeadUrl())
.executorName(user.getName())
.sts(2)
.build()
......@@ -366,6 +368,7 @@ public class RouterUtils {
SpmkExecutor executor = SpmkExecutor.builder()
.approveExecuteRecordId(aer2.getId())
.empNum(Integer.parseInt(user2.getId()))
.operatorHeaderUrl(user2.getHeadUrl())
.executorName(user2.getName())
.build();
switch (user2.getExecute()) {
......@@ -404,6 +407,7 @@ public class RouterUtils {
.approveExecuteRecordId(aer3.getId())
.empNum(Integer.parseInt(user2.getId()))
.executorName(user2.getName())
.operatorHeaderUrl(user2.getHeadUrl())
.sts(2)
.build();
executor.insert();
......@@ -443,6 +447,7 @@ public class RouterUtils {
.opinion(opinion)
.empNum(Integer.parseInt(listUser.get(i_user).getId()))
.executorName(listUser.get(i_user).getName())
.operatorHeaderUrl(listUser.get(i_user).getHeadUrl())
.sts(sts)
.build()
.updateById();
......@@ -476,6 +481,7 @@ public class RouterUtils {
.approveExecuteRecordId(executeRecordId)
.empNum(Integer.parseInt(listUser.get(i_user).getId()))
.executorName(listUser.get(i_user).getName())
.operatorHeaderUrl(listUser.get(i_user).getHeadUrl())
.sts(1)
.build()
.insert();
......@@ -522,6 +528,7 @@ public class RouterUtils {
.approveExecuteRecordId(aer.getId())
.empNum(Integer.parseInt(user.getId()))
.executorName(user.getName())
.operatorHeaderUrl(user.getHeadUrl())
.sts(2)
.build()
.insert();
......@@ -545,6 +552,7 @@ public class RouterUtils {
.approveExecuteRecordId(aer2.getId())
.empNum(Integer.parseInt(listUser.get(i_user2).getId()))
.executorName(listUser.get(i_user2).getName())
.operatorHeaderUrl(listUser.get(i_user2).getHeadUrl())
.sts(1)
.build();
executor.insert();
......@@ -576,6 +584,7 @@ public class RouterUtils {
.approveExecuteRecordId(aer3.getId())
.empNum(Integer.parseInt(user2.getId()))
.executorName(user2.getName())
.operatorHeaderUrl(user2.getHeadUrl())
.sts(2)
.build();
executor.insert();
......
......@@ -98,7 +98,7 @@
and a.create_time <![CDATA[ >= ]]> #{param.startTime}
</if>
<if test="param.endTime != null and param.endTime != ''">
and qlb.create_time <![CDATA[ <= ]]> #{param.endTime}
and a.create_time <![CDATA[ <= ]]> #{param.endTime}
</if>
<if test="param.empNums != null and param.empNums.size() > 0">
and a.emp_num IN
......@@ -126,6 +126,7 @@
(SELECT approve_execute_record_id FROM spmk_executor WHERE emp_num = #{param.empNum})
and type = #{param.type}
)
and a.sts <![CDATA[ <> ]]> 1
</if>
<if test="param.type != null and param.type == 0">
......@@ -146,7 +147,7 @@
and a.create_time <![CDATA[ >= ]]> #{param.startTime}
</if>
<if test="param.endTime != null and param.endTime != ''">
and qlb.create_time <![CDATA[ <= ]]> #{param.endTime}
and a.create_time <![CDATA[ <= ]]> #{param.endTime}
</if>
ORDER BY a.id DESC
</select>
......
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