Commit 38ea3157 by huluobin

update

parent 4729fa00
package com.blt.other.module.auth.controller;
import com.bailuntec.cost.api.response.CostResult;
import com.blt.other.common.util.AxiosUtil;
import com.blt.other.module.auth.service.UserService;
import com.blt.other.module.auth.service.UserSyncService;
import com.blt.other.module.auth.vo.GetByBLUserAcct;
import com.blt.other.module.auth.vo.UserGetByBLUserAcct;
import com.blt.other.common.util.AxiosUtil;
import com.blt.other.module.database.model.BuyUserDomain;
import com.blt.other.module.database.model.UserDomain;
import com.blt.other.module.supplier.service.BuyUserService;
......
package com.blt.other.module.auth.dao;
import com.blt.other.module.auth.model.CostReviewer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blt.other.module.auth.model.CostReviewer;
import org.apache.ibatis.annotations.Param;
/**
* <p>
......@@ -13,4 +14,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface CostReviewerMapper extends BaseMapper<CostReviewer> {
CostReviewer queryOne(@Param("referId") Integer referId, @Param("type") Integer type, @Param("reviewerUserId") Integer reviewerUserId);
}
package com.blt.other.module.auth.dao;
import com.blt.other.module.auth.model.OaUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blt.other.module.auth.model.OaUser;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
......@@ -11,6 +12,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @author robbendev
* @since 2020-10-12
*/
@Mapper
public interface OaUserMapper extends BaseMapper<OaUser> {
OaUser selectByOaUserId(Integer oaUserId);
......
......@@ -31,12 +31,12 @@ public class CostDomain {
//借支/借还
public final static Integer COST_FROM_3 = 2;
// @ApiModelProperty("费用单状态 0 未提交 1待审核 2待出纳付款 3已支付 4-待部门审核 5-待财务审核 6-待最终审核人审核")
// 0 待提交 1- 待财务审核 2待出纳付款 3被驳回 4已支付 5已作废 6-待部门审核 7-待财务审核 8-待最终审核人审核
public final static int STATUS_UN_SUBMIT = 0;
public final static int STATUS_DEPARTMENT_CHECK = 4;
public final static int STATUS_FINANCIAL_CHECK = 5;
public final static int STATUS_FINAL_CHECK = 6;
public final static int STATUS_DEPARTMENT_CHECK = 6;
public final static int STATUS_FINANCIAL_CHECK = 7;
public final static int STATUS_FINAL_CHECK = 8;
public final static int STATUS_UN_PAY = 2;
public final static int STATUS_PAYED = 3;
......@@ -95,7 +95,7 @@ public class CostDomain {
@ApiModelProperty("关联父单")
private String supCostNo;
@ApiModelProperty("费用单状态 0 未提交 1待审核 2待出纳付款 3已支付 4-待部门审核 5-待财务审核 6-待最终审核人审核")
@ApiModelProperty("费用单状态 0 待提交 1- 待财务审核 2待出纳付款 3被驳回 4已支付 5已作废 6-待部门审核 7-待财务审核 8-待最终审核人审核")
private Integer costStatus;
@ApiModelProperty("文件地址")
......
......@@ -52,7 +52,7 @@ public class CostTemplate implements Serializable {
@ApiModelProperty("自动审核金额 冗余从表金额字段")
private BigDecimal autoCheckAmount;
// @TableField(exist = false)
// @TableField(exist = false)
@ApiModelProperty("是否设置了自动审核规则")
private Boolean setAutoCheck;
......@@ -79,4 +79,20 @@ public class CostTemplate implements Serializable {
private List<CostTemplateCol> costTemplateColList;
public boolean shouldDepartmentAutoCheck() {
return enableAutoReview && enableDepartmentReview;
}
public boolean shouldFinanciaAutoCheck() {
return enableAutoReview && enableFinancialAutoReview;
}
public boolean shouldFinalAutoCheck() {
return enableAutoReview && enableFinalReview;
}
public boolean shouldFinalCheck(BigDecimal amount) {
return amount.compareTo(finalMinimumReviewAmount) > 0;
}
}
......@@ -2,6 +2,7 @@ package com.blt.other.module.cost.service;
import com.bailuntec.cost.api.dto.CostDto;
import com.bailuntec.cost.api.dto.CostListPrintDto;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blt.other.module.cost.dto.CostApiDto;
import com.blt.other.module.cost.dto.CostPageResult;
import com.blt.other.module.cost.model.CostDomain;
......@@ -16,7 +17,7 @@ public interface CostService {
* @param costDomain cost
* @return res
*/
@Deprecated
// @Deprecated
Integer saveNewCost(CostDomain costDomain);
/**
......@@ -104,6 +105,7 @@ public interface CostService {
*/
void departmentCheck(String costNo, Integer currentUserId);
/**
* 财务审核
*
......@@ -112,6 +114,7 @@ public interface CostService {
*/
void financialCheck(String costNo, Integer currentUserId);
/**
* 最终审核
*
......@@ -119,4 +122,17 @@ public interface CostService {
* @param currentUserId 当前用户id
*/
void finalCheck(String costNo, Integer currentUserId);
/**
* 审核费用单列表
*
* @param pageSize page
* @param pageNum page
* @param userid 当前用户id
* @param type 1-财务+最终审核 2-部门审核
* @return 费用单列表
*/
IPage<CostDto> checkCostList(Integer userid, Integer pageNum, Integer pageSize, Integer type);
}
......@@ -3,6 +3,8 @@ package com.blt.other.module.cost.service.impl.cost;
import com.bailuntec.cost.api.dto.CostDto;
import com.bailuntec.cost.api.dto.CostListPrintDto;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blt.other.common.exception.BizRuntimeException;
import com.blt.other.common.util.MoneyUtil;
import com.blt.other.module.auth.dao.CostReviewerMapper;
......@@ -18,9 +20,11 @@ import com.blt.other.module.cost.dto.CostApiDto;
import com.blt.other.module.cost.dto.CostPageResult;
import com.blt.other.module.cost.model.CostDetailDomain;
import com.blt.other.module.cost.model.CostDomain;
import com.blt.other.module.cost.model.CostTemplate;
import com.blt.other.module.cost.service.CostLogService;
import com.blt.other.module.cost.service.CostService;
import com.blt.other.module.cost.service.ICostTemplateService;
import com.blt.other.module.database.model.CostCompanyDomain;
import com.blt.other.module.database.model.CostLogDomain;
import com.blt.other.module.database.model.CostTypeKindDomain;
import com.blt.other.module.database.model.UserDomain;
......@@ -107,7 +111,6 @@ public abstract class AbstractCostService implements CostService {
setCostDomain(costDomain);
Integer update = costDao.update(costDomain);
String costNo = costDomain.getCostNo();
resp.setMsg("success");
......@@ -180,52 +183,112 @@ public abstract class AbstractCostService implements CostService {
return printNos.stream().map(this::printDto).collect(Collectors.toList());
}
@Override
public void departmentCheck(String costNo, Integer currentUserId) {
CostDomain costDomain = costDao.selectByCostNo(costNo);
OaUser costUser = oaUserMapper.selectByOaUserId(costDomain.getCreateUserid());
//人工审核流程
CostReviewer costReviewer = costReviewerMapper.selectOne(new LambdaQueryWrapper<CostReviewer>()
.eq(CostReviewer::getReferId, costUser.getPrimaryDepartmentId())
.eq(CostReviewer::getReviewerUserId, currentUserId)
.eq(CostReviewer::getType, CostReviewer.departmentReviewer));
if (costReviewer == null) {
throw new BizRuntimeException("on authority");
}
@Transactional
@Override
public void departmentCheck(String costNo, Integer currentUserId) {
CostDomain costDomain = costDao.selectByCostNo(costNo);
CostTemplate costTemplate = costTemplateService.queryDetail(costDomain.getCostTemplateId());
//需要自动审核
if (costTemplate.shouldDepartmentAutoCheck()) {
//自动审核通过
if (this.autoCheck(costDomain)) {
costDomain.setCostStatus(CostDomain.STATUS_FINANCIAL_CHECK);
costDao.updateById(costDomain);
//流转状态
costSubscribe.subscribe(costDomain);
costLogService.save(costNo, currentUserId, "审核费用单", CostLogDomain.MANUAL_CHECK);
costLogService.save(costNo, currentUserId, "部门自动审核通过", CostLogDomain.AUTO_CHECK);
}
//自动审核失败
else {
//人工审核
this.departmentManualCheck(costNo, currentUserId);
}
}
//人工审核
else {
//人工审核
this.departmentManualCheck(costNo, currentUserId);
}
}
}
@Transactional
@Override
public void financialCheck(String costNo, Integer currentUserId) {
CostDomain costDomain = costDao.selectByCostNo(costNo);
OaUser costUser = oaUserMapper.selectByOaUserId(costDomain.getCreateUserid());
CostTemplate costTemplate = costTemplateService.queryDetail(costDomain.getCostTemplateId());
//需要自动审核
if (costTemplate.shouldFinalAutoCheck()) {
//自动审核通过
if (this.autoCheck(costDomain)) {
costDomain.setCostStatus(CostDomain.STATUS_FINAL_CHECK);
costDao.updateById(costDomain);
//流转状态
costSubscribe.subscribe(costDomain);
costLogService.save(costNo, currentUserId, "财务自动审核通过", CostLogDomain.AUTO_CHECK);
}
//自动审核失败
else {
//人工审核
this.financialManualCheck(costNo, currentUserId);
}
}
//人工审核
else {
//人工审核
this.financialManualCheck(costNo, currentUserId);
}
}
//人工审核流程
CostReviewer costReviewer = costReviewerMapper.selectOne(new LambdaQueryWrapper<CostReviewer>()
.eq(CostReviewer::getReferId, costUser.getPrimaryDepartmentId())
.eq(CostReviewer::getReviewerUserId, currentUserId)
.eq(CostReviewer::getType, CostReviewer.financialReviewer));
protected void financialManualCheck(String costNo, Integer currentUserId) {
if (costReviewer == null) {
throw new BizRuntimeException("on authority");
}
CostDomain costDomain = costDao.selectByCostNo(costNo);
CostCompanyDomain costCompany = costCompanyDao.selectByNo(costDomain.getCompanyNo());
//人工审核通过
if (costReviewerMapper.queryOne(costCompany.getId(), CostReviewer.financialReviewer, currentUserId) != null) {
costDomain.setCostStatus(CostDomain.STATUS_FINAL_CHECK);
costDao.updateById(costDomain);
//流转状态
costSubscribe.subscribe(costDomain);
costLogService.save(costNo, currentUserId, "审核费用单", CostLogDomain.MANUAL_CHECK);
costLogService.save(costNo, currentUserId, "财务审核通过", CostLogDomain.MANUAL_CHECK);
}
//人工审核没权限
else {
throw new BizRuntimeException("current user no authority");
}
}
@Transactional
@Override
public IPage<CostDto> checkCostList(Integer userid, Integer pageNum, Integer pageSize, Integer type) {
IPage<CostDomain> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<CostDomain> wrapper = new LambdaQueryWrapper<>();
UserDomain userDomain = userService.findByUserid(userid);
//财务或者管理员
if (userDomain.getIsadmin() != 0 || userDomain.getIsfinansys() != 0) {
wrapper.in(CostDomain::getCompanyValue, Lists.newArrayList(userDomain.getAuthority().split(",")));
} else {
wrapper.eq(CostDomain::getCreateUserid, userid);
}
//财务 最终审核
if (type == 1) {
wrapper.in(CostDomain::getCostStatus, CostDomain.STATUS_FINAL_CHECK, CostDomain.STATUS_DEPARTMENT_CHECK);
}
//部门审核
else if (type == 2) {
wrapper.in(CostDomain::getCostStatus, CostDomain.STATUS_DEPARTMENT_CHECK);
} else {
log.warn("invalid type");
}
return costDao.selectPage(page, wrapper).convert(CostDomain::castToDto);
}
......
package com.blt.other.module.cost.service.impl.cost;
import com.blt.other.module.cost.model.CostDomain;
import com.blt.other.module.cost.service.CostService;
import com.blt.other.module.cost.service.impl.costcheck.CostContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
......@@ -24,24 +22,7 @@ public class CostSubscribe {
@Async
public void subscribe(CostDomain costDomain) {
CostService costService = CostServiceFactory.getCostService(costDomain);
switch (costDomain.getCostStatus()) {
//如果是待部门审核 就提交部门审核
case CostDomain.STATUS_DEPARTMENT_CHECK:
costService.departmentCheck(costDomain.getCostNo(), -1);
break;
//如果是待财务审核 就提交部门审核
case CostDomain.STATUS_FINANCIAL_CHECK:
costService.financialCheck(costDomain.getCostNo(), -1);
break;
//如果是待最终审核 就提交部门审核
case CostDomain.STATUS_FINAL_CHECK:
costService.finalCheck(costDomain.getCostNo(), -1);
break;
default:
log.error("invalid cost status");
}
public void subscribe(CostContext costContext) {
costContext.nexState();
}
}
package com.blt.other.module.cost.service.impl.costcheck;
import com.bailuntec.common.SpringContextUtil;
import com.blt.other.module.cost.dao.CostDao;
import com.blt.other.module.cost.model.CostDomain;
import com.blt.other.module.cost.service.CostService;
import com.blt.other.module.cost.service.impl.cost.CostServiceFactory;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/10/30 2:52 下午
*/
public class CostContext {
public void setCostState(CostState costState) {
this.costState = costState;
this.costState.setCostContext(this);
}
protected CostState costState;
protected CostService costService;
protected CostDomain costDomain;
protected Integer currentUserId;
public CostContext(String costNo, Integer currentUserId) {
this.costService = CostServiceFactory.getCostService(costNo);
this.currentUserId = currentUserId;
this.costDomain = SpringContextUtil.getBean(CostDao.class).selectByCostNo(costNo);
}
public void nexState() {
costState.handle();
}
public void refuse() {
costState.refuse();
}
}
package com.blt.other.module.cost.service.impl.costcheck;
import com.blt.other.module.auth.dao.CostReviewerMapper;
import com.blt.other.module.auth.dao.OaUserMapper;
import com.blt.other.module.cost.dao.CostDao;
import com.blt.other.module.cost.model.CostDomain;
import com.blt.other.module.cost.model.CostTemplate;
import com.blt.other.module.cost.service.CostLogService;
import com.blt.other.module.cost.service.ICostTemplateService;
import com.blt.other.module.cost.service.impl.cost.CostSubscribe;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/10/30 2:18 下午
*/
public abstract class CostState {
@Autowired
CostDao costDao;
@Autowired
CostLogService costLogService;
@Autowired
ICostTemplateService costTemplateService;
@Autowired
OaUserMapper oaUserMapper;
@Autowired
CostReviewerMapper costReviewerMapper;
@Autowired
CostSubscribe costSubscribe;
//0 待提交 1- 待财务审核 2待出纳付款 3被驳回 4已支付 5已作废 6-待部门审核 7-待财务审核 8-待最终审核人审核
protected CostContext costContext;
/**
* 是否通过所有模版自动校验
*
* @param costDomain ost
* @return res
*/
boolean autoCheck(CostDomain costDomain) {
CostTemplate costTemplate = costTemplateService.queryDetail(costDomain.getCostTemplateId());
//是否通过所有模版自动校验
List<Boolean> ruleChecks = costTemplate.getCostTemplateColList()
.stream()
.map(costTemplateCol -> costTemplateCol.ruleCheck(costDomain))
.collect(Collectors.toList());
return !ruleChecks.contains(false);
}
public CostContext getCostContext() {
return costContext;
}
public void setCostContext(CostContext costContext) {
this.costContext = costContext;
}
void nextState(CostState costState) {
//清空审核上下文的审核人
costContext.currentUserId = null;
//并且流转到下一个状态
costContext.setCostState(costState);
}
public abstract void handle();
public abstract void refuse();
}
package com.blt.other.module.cost.service.impl.costcheck;
import com.blt.other.common.exception.BizRuntimeException;
import com.blt.other.module.auth.model.CostReviewer;
import com.blt.other.module.auth.model.OaUser;
import com.blt.other.module.cost.model.CostDomain;
import com.blt.other.module.cost.model.CostTemplate;
import com.blt.other.module.database.model.CostLogDomain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/10/30 2:57 下午
*/
@Component
public class DepartmentCheckState extends CostState {
@Autowired
FinancialCheckState financialCheckState;
@Override
public void handle() {
CostDomain costDomain = costContext.costDomain;
Integer currentUserId = costContext.currentUserId;
CostTemplate costTemplate = costTemplateService.queryDetail(costDomain.getCostTemplateId());
//需要自动审核
if (costTemplate.shouldDepartmentAutoCheck()) {
//自动审核通过
if (autoCheck(costDomain)) {
costDomain.setCostStatus(CostDomain.STATUS_FINANCIAL_CHECK);
costDao.updateById(costDomain);
costLogService.save(costDomain.getCostNo(), currentUserId, "部门自动审核通过", CostLogDomain.AUTO_CHECK);
//流转状态
nextState(financialCheckState);
costSubscribe.subscribe(costContext);
return;
}
}
//人工审核
OaUser costUser = oaUserMapper.selectByOaUserId(costDomain.getCreateUserid());
//人工审核通过
if (costReviewerMapper.queryOne(costUser.getPrimaryDepartmentId(), CostReviewer.departmentReviewer, currentUserId) != null) {
costDomain.setCostStatus(CostDomain.STATUS_FINANCIAL_CHECK);
costDao.updateById(costDomain);
costLogService.save(costDomain.getCostNo(), currentUserId, "部门审核通过", CostLogDomain.MANUAL_CHECK);
nextState(financialCheckState);
//发布到总线尝试审核
costSubscribe.subscribe(costContext);
}
//人工审核没权限
else {
throw new BizRuntimeException("current user no authority");
}
}
@Override
public void refuse() {
}
}
package com.blt.other.module.cost.service.impl.costcheck;
import org.springframework.stereotype.Component;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/10/30 2:57 下午
*/
public class FinalCheckState extends CostState {
@Override
public void handle() {
}
@Override
public void refuse() {
}
}
package com.blt.other.module.cost.service.impl.costcheck;
import org.springframework.stereotype.Component;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/10/30 2:57 下午
*/
@Component
public class FinancialCheckState extends CostState {
@Override
public void handle() {
}
@Override
public void refuse() {
}
}
package com.blt.other.module.cost.service.impl.costcheck;
import org.springframework.stereotype.Component;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/10/30 2:57 下午
*/
public class PayedState extends CostState {
@Override
public void handle() {
}
@Override
public void refuse() {
}
}
package com.blt.other.module.cost.service.impl.costcheck;
import org.springframework.stereotype.Component;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/10/30 2:57 下午
*/
public class RefuseState extends CostState {
@Override
public void handle() {
}
@Override
public void refuse() {
}
}
package com.blt.other.module.cost.service.impl.costcheck;
import org.springframework.stereotype.Component;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/10/30 2:57 下午
*/
public class UnPayState extends CostState {
@Override
public void handle() {
}
@Override
public void refuse() {
}
}
package com.blt.other.module.cost.service.impl.costcheck;
import com.blt.other.common.exception.BizRuntimeException;
import com.blt.other.module.cost.model.CostDomain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/10/30 2:57 下午
*/
@Component
public class UnSubmitState extends CostState {
@Autowired
DepartmentCheckState departmentCheckState;
@Transactional(rollbackFor = Exception.class)
@Override
public void handle() {
CostDomain costDomain = costContext.costDomain;
//校验费用单状态 和 当前处理用户
if (costDomain.getCostStatus() != CostDomain.STATUS_UN_SUBMIT ||
!costDomain.getCreateUserid().equals(costContext.currentUserId)) {
throw new BizRuntimeException("invalid status");
}
//更新费用单
costDomain.setCostStatus(1);
costDao.updateById(costDomain);
costLogService.save(costDomain.getCostNo(), costContext.currentUserId, "提交费用单");
//清空审核上下文的审核人
costContext.currentUserId = null;
//并且流转到下一个状态
costContext.setCostState(departmentCheckState);
//尝试审核(由于清空了审核人,这里只会走自动审核)
costContext.nexState();
}
@Override
public void refuse() {
}
}
package com.blt.other.module.cost.vo;
import lombok.Data;
@Data
public class ApplyCallbackUrlVo {
private ApplyCallbackUrlDataVo data;
private String id;
public ApplyCallbackUrlDataVo getData() {
return data;
}
public void setData(ApplyCallbackUrlDataVo data) {
this.data = data;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public String toString() {
return "ApplyCallbackUrlVo{" +
"data=" + data +
", id='" + id + '\'' +
'}';
}
}
package com.blt.other.module.cost.vo;
import lombok.Data;
@Data
public class ApplyCallbackVo {
private boolean success;
......
......@@ -2,4 +2,13 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.blt.other.module.auth.dao.CostReviewerMapper">
<select id="queryOne" resultType="com.blt.other.module.auth.model.CostReviewer">
select *
from cost_reviewer
where refer_id = #{referId}
and type = #{type}
and reviewer_user_id = #{reviewerUserId}
limit 1
</select>
</mapper>
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