Commit afd0b960 authored by 耿迪迪's avatar 耿迪迪

自动划拨开关-结算

parent 177f7983
......@@ -122,4 +122,10 @@ public class TAccountController extends BaseController
{
return toAjax(tAccountService.deleteTAccountByIds(accountIds));
}
@PreAuthorize("@ss.hasPermi('system:account:turnTransferSwitch')")
@PostMapping("/turnTransferSwitch")
public AjaxResult turnTransferSwitch(@RequestBody TAccount tAccount){
return toAjax(tAccountService.turnTransferSwitch(tAccount));
}
}
......@@ -123,4 +123,14 @@ public class TTradeProjectController extends BaseController
List<TTradeProject> list = tTradeProjectService.getIncomeOrPayableList(tTradeProject);
return getDataTable(list);
}
/**
* 手动结算尾款
* @param tTradeProject
* @return
*/
@PostMapping("/settlePendingPayment")
public AjaxResult settlePendingPayment(@RequestBody TTradeProject tTradeProject) {
return toAjax(tTradeProjectService.settlePendingPayment(tTradeProject));
}
}
......@@ -94,7 +94,7 @@ zehong:
# 实例演示开关
demoEnabled: true
# 文件路径 示例( Windows配置D:/zehong/uploadPath,Linux配置 /home/zehong/uploadPath)
profile: /home/zehong/uploadPath
profile: D:/zehong/uploadPath
# 获取ip地址开关
addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证
......
......@@ -52,6 +52,10 @@ public class TCashOperate extends BaseEntity
private String endOperatorTime;
private Long operatePersonId;
private String operatePersonName;
public String getDocumentType() {
return documentType;
}
......@@ -150,6 +154,22 @@ public class TCashOperate extends BaseEntity
this.endOperatorTime = endOperatorTime;
}
public Long getOperatePersonId() {
return operatePersonId;
}
public void setOperatePersonId(Long operatePersonId) {
this.operatePersonId = operatePersonId;
}
public String getOperatePersonName() {
return operatePersonName;
}
public void setOperatePersonName(String operatePersonName) {
this.operatePersonName = operatePersonName;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
......
......@@ -61,4 +61,11 @@ public interface ITAccountService
public int deleteTAccountById(Long accountId);
public boolean checkAccountCanTrade(Long deptId, BigDecimal amount);
/**
* 设置开关
* @param tAccount
* @return
*/
int turnTransferSwitch(TAccount tAccount);
}
......@@ -73,4 +73,11 @@ public interface ITTradeProjectService
*/
int settlementTrade(TTradeProject tTradeProject);
public List<TTradeProject> getIncomeOrPayableList(TTradeProject tTradeProject);
/**
* 手动结算尾款
* @param project
* @return
*/
int settlePendingPayment(TTradeProject project);
}
package com.zehong.system.service.impl;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import com.zehong.common.utils.DateUtils;
import com.zehong.system.domain.TTradeProject;
import com.zehong.system.mapper.TTradeProjectMapper;
import com.zehong.system.service.impl.tradeSettlement.SettlementTrade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zehong.system.mapper.TAccountMapper;
import com.zehong.system.domain.TAccount;
import com.zehong.system.service.ITAccountService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
/**
* 账户Service业务层处理
......@@ -21,6 +29,12 @@ public class TAccountServiceImpl implements ITAccountService
@Autowired
private TAccountMapper tAccountMapper;
@Autowired
private TTradeProjectMapper tTradeProjectMapper;
@Resource
private SettlementTrade settlementTrade;
/**
* 查询账户
*
......@@ -110,4 +124,31 @@ public class TAccountServiceImpl implements ITAccountService
return false;
}
}
/**
* 设置开关
* @param tAccount
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int turnTransferSwitch(TAccount tAccount){
if("0".equals(tAccount.getTransferSwitch())){
//交易中心待手动支付更新结算
TTradeProject tTradeProject = new TTradeProject();
tTradeProject.setTradeDeptId(tAccount.getDeptId());
tTradeProject.setTradeStatus("5");
List<TTradeProject> tradeProjectList = tTradeProjectMapper.selectTTradeProjectList(tTradeProject);
if(!CollectionUtils.isEmpty(tradeProjectList)){
tradeProjectList.forEach(item ->{
settlementTrade.settleAbleAmount(item);
item.setTradeStatus("3");
item.setSettlementTime(new Date());
tTradeProjectMapper.updateTTradeProject(item);
});
}
}
tAccount.setUpdateTime(DateUtils.getNowDate());
return tAccountMapper.updateTAccount(tAccount);
}
}
......@@ -2,19 +2,25 @@ package com.zehong.system.service.impl;
import com.zehong.common.core.domain.entity.SysRole;
import com.zehong.common.core.domain.entity.SysUser;
import com.zehong.common.core.exception.BusinessException;
import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.SecurityUtils;
import com.zehong.system.domain.TAccount;
import com.zehong.system.domain.TTradeProject;
import com.zehong.system.mapper.TAccountMapper;
import com.zehong.system.mapper.TTradeProjectMapper;
import com.zehong.system.service.ITTradeProjectService;
import com.zehong.system.service.impl.tradeRoles.TradeRoles;
import com.zehong.system.service.impl.tradeRoles.roles.*;
import com.zehong.system.service.impl.tradeSettlement.SettlePendingPayment;
import com.zehong.system.service.impl.tradeSettlement.SettlementTrade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......@@ -34,6 +40,12 @@ public class TTradeProjectServiceImpl implements ITTradeProjectService
@Resource
private SettlementTrade settlementTrade;
@Resource
private TAccountMapper tAccountMapper;
@Resource
private SettlePendingPayment settlePendingPayment;
/**
* 查询交易项目
*
......@@ -69,10 +81,30 @@ public class TTradeProjectServiceImpl implements ITTradeProjectService
List<TTradeProject> tradeProjectList = tTradeProjectMapper.selectTTradeProjectList(tTradeProject);
for(TTradeProject project :tradeProjectList){
judgeRole(project).setOperators();
judgeTransferSwitch(project);
}
return tradeProjectList;
}
/**
* 根据部门支付开关设置结算
* @param project 交易信息
*/
private void judgeTransferSwitch(TTradeProject project){
Long deptId = SecurityUtils.getLoginUser().getUser().getDeptId();
if(deptId.equals(project.getTradeDeptId()) && "3".equals(project.getTradeStatus())){
TAccount account = new TAccount();
account.setDeptId(project.getTradeDeptId());
List<TAccount> accounts = tAccountMapper.selectTAccountList(account);
if (!CollectionUtils.isEmpty(accounts)){
String transferSwitch = accounts.get(0).getTransferSwitch();
if("1".equals(transferSwitch) && null != project.getPendingPayment() && project.getPendingPayment().compareTo(BigDecimal.ZERO) == 1){
project.getOperators().add("settlePendingPayment");
}
}
}
}
/**
* 判断角色
* @param tTradeProject
......@@ -165,7 +197,9 @@ public class TTradeProjectServiceImpl implements ITTradeProjectService
tradeInfo.setTradeStatus(tTradeProject.getTradeStatus());
//审核成功结算
settleByTradeStatus(tTradeProject,tradeInfo);
tradeInfo.setApplyDeptManagerId(tTradeProject.getApplyDeptManagerId());
if(!"5".equals(tTradeProject.getTradeStatus())){
tradeInfo.setApplyDeptManagerId(tTradeProject.getApplyDeptManagerId());
}
tradeInfo.setSettlementTime(new Date());
return tTradeProjectMapper.updateTTradeProject(tradeInfo);
}
......@@ -200,4 +234,11 @@ public class TTradeProjectServiceImpl implements ITTradeProjectService
public List<TTradeProject> getIncomeOrPayableList(TTradeProject tTradeProject) {
return tTradeProjectMapper.getIncomeOrPayableList(tTradeProject);
}
@Override
public int settlePendingPayment(TTradeProject project){
TTradeProject tradeInfo = tTradeProjectMapper.selectTTradeProjectById(project.getTradeId());
settlePendingPayment.settlePendingPayment(tradeInfo);
return tTradeProjectMapper.updateTTradeProject(tradeInfo);
}
}
......@@ -88,16 +88,17 @@ public class SettlementDebit {
private void debitDeptSettlement(Long deptId, BigDecimal amount,String operatorType){
TAccount account = getAccountInfo(deptId);
//结算本部尾款
List<TTradeProject> pendingPaymentInfo = tTradeProjectMapper.getTradePendingPaymentInfo(deptId);
for(TTradeProject project : pendingPaymentInfo){
if(amount.compareTo(BigDecimal.ZERO) == 0){
return;
if("0".equals(account.getTransferSwitch())){
List<TTradeProject> pendingPaymentInfo = tTradeProjectMapper.getTradePendingPaymentInfo(deptId);
for(TTradeProject project : pendingPaymentInfo){
if(amount.compareTo(BigDecimal.ZERO) == 0){
return;
}
BigDecimal changeAmount = updatePendingPayment(amount,project);
//重新计算进账金额
amount = amount.subtract(changeAmount);
}
BigDecimal changeAmount = updatePendingPayment(amount,project);
//重新计算进账金额
amount = amount.subtract(changeAmount);
}
//更新可用额度
updateAccount(account,amount,operatorType);
}
......
package com.zehong.system.service.impl.tradeSettlement;
import com.zehong.common.core.exception.BusinessException;
import com.zehong.common.utils.SecurityUtils;
import com.zehong.system.domain.TAccount;
import com.zehong.system.domain.TCashOperate;
import com.zehong.system.domain.TTradeProject;
import com.zehong.system.mapper.TAccountMapper;
import com.zehong.system.mapper.TCashOperateMapper;
import com.zehong.system.mapper.TTradeProjectMapper;
import io.jsonwebtoken.lang.Collections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* @author geng
* 交易结算
*/
@Component
public class SettlePendingPayment {
private static final Logger log = LoggerFactory.getLogger(SettlePendingPayment.class);
private TTradeProject tradeProject;
@Resource
private TAccountMapper tAccountMapper;
@Resource
private TTradeProjectMapper tTradeProjectMapper;
@Resource
private TCashOperateMapper cashOperateMapper;
/**
* 可用账户结算
*/
public void settlePendingPayment(TTradeProject tradeProject){
this.tradeProject = tradeProject;
//买方结算
BigDecimal payment = settleBuyerAbleAmount();
//卖方结算
settleSellerAbleAmount(payment.abs());
}
/**
* 买方结算
*/
private BigDecimal settleBuyerAbleAmount() {
TAccount account = getAccountInfo(this.tradeProject.getTradeDeptId());
//判断买方可用额度是否为0
if(account.getAbleAmount().compareTo(BigDecimal.ZERO) == 0){
throw new BusinessException("账户金额不足");
}
//买方可用额度为0,计算尾款
BigDecimal pendingPayment = account.getAbleAmount().compareTo(tradeProject.getPendingPayment()) == 1 ?
new BigDecimal("0") :
this.tradeProject.getPendingPayment().subtract(account.getAbleAmount());
//买方可用额度计算
BigDecimal payment = pendingPayment.compareTo(BigDecimal.ZERO) == 0 ?
this.tradeProject.getPendingPayment().negate() :
account.getAbleAmount().negate();
this.tradeProject.setPendingPayment(pendingPayment);
updateAccount(account,payment);
return payment;
}
/**
* 卖方结算
*/
private void settleSellerAbleAmount(BigDecimal incomeAmount) {
TAccount account = getAccountInfo(this.tradeProject.getApplyDeptId());
//判断是否有进账
if(incomeAmount.compareTo(BigDecimal.ZERO) == 1 && "0".equals(account.getTransferSwitch())){
//结算本部尾款
List<TTradeProject> pendingPaymentInfo = tTradeProjectMapper.getTradePendingPaymentInfo(this.tradeProject.getApplyDeptId());
for(TTradeProject project : pendingPaymentInfo){
if(incomeAmount.compareTo(BigDecimal.ZERO) == 0){
return;
}
BigDecimal amount = updatePendingPayment(incomeAmount,project);
//重新计算进账金额
incomeAmount = incomeAmount.subtract(amount);
}
}
//更新可用额度
updateAccount(account,incomeAmount);
}
/**
* 获取账户信息
* @param deptId
* @return
*/
private TAccount getAccountInfo(Long deptId){
TAccount tAccount = new TAccount();
tAccount.setDeptId(deptId);
List<TAccount> accounts = tAccountMapper.selectTAccountList(tAccount);
if(Collections.isEmpty(accounts)){
log.error("交易部门资金账户不能为空,部门id:" + tradeProject.getApplyDeptId());
throw new BusinessException("交易部门资金账户不能为空!");
}
return accounts.get(0);
}
/**
* 更新账户可用金额
* @param tAccount 账户信息
* @param amount 账户变动金额
*/
private void updateAccount(TAccount tAccount,BigDecimal amount){
if(amount.compareTo(BigDecimal.ZERO) == 0) return;
tAccount.setAbleAmount(tAccount.getAbleAmount().add(amount));
tAccountMapper.updateTAccount(tAccount);
//更新资金变动日志
TCashOperate operate = new TCashOperate();
operate.setOperateDeptId(tAccount.getDeptId());
operate.setOperateAmount(amount.compareTo(BigDecimal.ZERO) == 1?amount:amount.abs());
operate.setOperateTime(new Date());
operate.setRelationDoc(this.tradeProject.getTradeId().toString());
//1.交易单 2.借支单 3.外部采购单 4.借贷单
operate.setDocumentType("1");
operate.setOperateType(amount.compareTo(BigDecimal.ZERO) == 1 ? "1" : "2");
//TODO 操作人
operate.setOperatePersonId(SecurityUtils.getLoginUser().getUser().getUserId());
cashOperateMapper.insertTCashOperate(operate);
}
/**
* 更新尾款信息
* @param incomeAmount 进账金额
* @param project 交易项目
*/
private BigDecimal updatePendingPayment(BigDecimal incomeAmount,TTradeProject project){
//资金变动金额
BigDecimal amount = incomeAmount.compareTo(project.getPendingPayment()) == 1 ? project.getPendingPayment() : incomeAmount;
//尾款
BigDecimal pendingPayment = incomeAmount.compareTo(project.getPendingPayment()) == -1 ? project.getPendingPayment().subtract(incomeAmount) : new BigDecimal("0");
project.setPendingPayment(pendingPayment);
tTradeProjectMapper.updateTTradeProject(project);
//更新资金变动日志
TCashOperate operate = new TCashOperate();
operate.setOperateDeptId(project.getTradeDeptId());
operate.setOperateAmount(amount.compareTo(BigDecimal.ZERO) == 1?amount:amount.abs());
operate.setOperateTime(new Date());
operate.setRelationDoc(project.getTradeId().toString());
operate.setOperateType("3");
operate.setDocumentType("1");//1.交易单 2.借支单 3.外部采购单 4.借贷单
cashOperateMapper.insertTCashOperate(operate);
return amount;
}
}
package com.zehong.system.service.impl.tradeSettlement;
import com.zehong.common.core.exception.BusinessException;
import com.zehong.common.utils.SecurityUtils;
import com.zehong.system.domain.TAccount;
import com.zehong.system.domain.TCashOperate;
import com.zehong.system.domain.TTradeProject;
......@@ -87,7 +88,7 @@ public class SettlementTrade {
//进账
BigDecimal incomeAmount = this.tradeProject.getDealPrice().subtract(this.tradeProject.getPendingPayment());
//判断是否有进账
if(incomeAmount.compareTo(BigDecimal.ZERO) == 1 && account.getAbleAmount().compareTo(BigDecimal.ZERO) == 0){
if(incomeAmount.compareTo(BigDecimal.ZERO) == 1 && "0".equals(account.getTransferSwitch())){
//结算本部尾款
List<TTradeProject> pendingPaymentInfo = tTradeProjectMapper.getTradePendingPaymentInfo(this.tradeProject.getApplyDeptId());
for(TTradeProject project : pendingPaymentInfo){
......@@ -133,6 +134,9 @@ public class SettlementTrade {
TCashOperate operate = OperatorParam(tAccount.getDeptId(),amount,this.tradeProject.getTradeId().toString());
operate.setDocumentType("1");//1.交易单 2.借支单 3.外部采购单 4.借贷单
operate.setOperateType(amount.compareTo(BigDecimal.ZERO) == 1 ? "1" : "2");
if("5".equals(this.tradeProject.getTradeStatus())){
operate.setOperatePersonId(SecurityUtils.getLoginUser().getUser().getUserId());
}
cashOperateMapper.insertTCashOperate(operate);
}
......
......@@ -17,11 +17,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" />
<result property="operateDeptName" column="operate_dept_name"/>
<result property="documentType" column="document_type"/>
<result property="operatePersonId" column="operate_person_id"/>
<result property="operatePersonName" column="operate_person_name"/>
</resultMap>
<sql id="selectTCashOperateVo">
select operate_id, operate_dept_id, operate_type, operate_amount, relation_doc, operate_time, create_time, update_time, is_del, remark,document_type,(SELECT dept_name FROM sys_dept WHERE dept_id = operate_dept_id)AS operate_dept_name from t_cash_operate
SELECT
operate_id,
operate_dept_id,
operate_type,
operate_amount,
relation_doc,
operate_time,
create_time,
update_time,
is_del,
remark,
document_type,
operate_person_id,
(SELECT dept_name FROM sys_dept WHERE dept_id = operate_dept_id)AS operate_dept_name,
(SELECT nick_name FROM sys_user WHERE user_id = operate_person_id)AS operate_person_name
FROM
t_cash_operate
</sql>
<select id="selectTCashOperateList" parameterType="TCashOperate" resultMap="TCashOperateResult">
......@@ -56,6 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="isDel != null">is_del,</if>
<if test="remark != null">remark,</if>
<if test="documentType != null">document_type,</if>
<if test="operatePersonId != null">operate_person_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="operateDeptId != null">#{operateDeptId},</if>
......@@ -67,7 +86,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">#{updateTime},</if>
<if test="isDel != null">#{isDel},</if>
<if test="remark != null">#{remark},</if>
<if test="documentType != null">#{documentType}</if>
<if test="documentType != null">#{documentType},</if>
<if test="operatePersonId != null">#{operatePersonId},</if>
</trim>
</insert>
......@@ -83,6 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="isDel != null">is_del = #{isDel},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="operatePersonId != null">#{operatePersonId},</if>
</trim>
where operate_id = #{operateId}
</update>
......
......@@ -67,4 +67,12 @@ export function exportAccount(query) {
method: 'get',
params: query
})
}
\ No newline at end of file
}
export function turnTransferSwitch(data) {
return request({
url: '/system/account/turnTransferSwitch',
method: 'post',
data: data
})
}
......@@ -69,3 +69,12 @@ export function settlementTrade(data) {
data: data
})
}
//手动结算尾款
export function settlePendingPayment(data) {
return request({
url: '/trade/project/settlePendingPayment',
method: 'post',
data: data
})
}
......@@ -146,7 +146,7 @@
v-model="scope.row.transferSwitch"
active-value="0"
inactive-value="1"
v-hasPermi="['system:account:edit']"
v-hasPermi="['system:account:turnTransferSwitch']"
active-text="自动划拨开关"
@change="transferSwitchChange(scope.row)"
>
......@@ -286,6 +286,7 @@
<span v-if="scope.row.documentType == '4'">借贷申请</span>
</template>
</el-table-column>
<el-table-column label="操作人" align="center" prop="operatePersonName" />
<el-table-column
label="操作"
align="center"
......@@ -333,6 +334,7 @@ import {
addAccount,
updateAccount,
exportAccount,
turnTransferSwitch
} from "@/api/account/account";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
......@@ -612,8 +614,8 @@ export default {
transferSwitchChange(row){
getAccount(row.accountId).then(res =>{
if(res.code == 200){
let param = {accountId: res.data.accountId,transferSwitch:row.transferSwitch};
updateAccount(param).then(resp =>{
let param = {accountId: res.data.accountId,transferSwitch:row.transferSwitch,deptId:res.data.deptId};
turnTransferSwitch(param).then(resp =>{
if(resp.code == 200){
this.$message.success("开关设置成功!");
this.getList();
......
......@@ -12,7 +12,7 @@
</template>
<script>
import { getProject, updateProject, settlementTrade } from "@/api/transaction/tradeProject.js";
import { getProject, updateProject, settlementTrade, settlePendingPayment } from "@/api/transaction/tradeProject.js";
import tradeDetail from "./TradeDetail";
import evaluate from "./Evaluate";
import confirm from "./Confirm";
......@@ -57,6 +57,8 @@
return "卖方部门长审核";
case "toPay":
return "去支付";
case "settlePendingPayment":
return "尾款结算"
default:
return "";
}
......@@ -66,6 +68,10 @@
this.toPay();
return;
}
if(this.operatorName == "settlePendingPayment"){
this.settlePendingPayment();
return;
}
this.getProjectInfo();
},
//去支付
......@@ -90,6 +96,27 @@
.catch(() => {});
},
settlePendingPayment(){
this.$confirm(
'是否确认结算尾款',
"警告",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}
)
.then(() => {
console.log("7778444-------------------")
settlePendingPayment({tradeId:this.tradeInfo.tradeId}).then(res =>{
if(res.code == 200){
this.$emit("getList");
this.msgSuccess("结算成功");
}
})
})
.catch(() => {});
},
//获取项目信息
getProjectInfo(){
getProject(this.tradeInfo.tradeId).then(res =>{
......
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