demand: TMS系统财务销账优化
committer: heyu
This commit is contained in:
parent
3a24888794
commit
c5d361c154
@ -16,8 +16,10 @@ import com.xdadan.erp.common.core.page.TableDataInfo;
|
||||
import com.xdadan.erp.common.enums.BusinessType;
|
||||
import com.xdadan.erp.emis.domain.EmisWriteoffApply;
|
||||
import com.xdadan.erp.emis.domain.EmisWriteoffApplyDetail;
|
||||
import com.xdadan.erp.emis.domain.EmisSalesmenRel;
|
||||
import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
||||
import com.xdadan.erp.emis.service.IEmisWriteoffApplyService;
|
||||
import com.xdadan.erp.emis.service.IEmisSalesmenRelService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@ -28,6 +30,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 销账申请Controller
|
||||
@ -42,6 +45,9 @@ public class EmisWriteoffApplyController extends EmisBaseController {
|
||||
@Autowired
|
||||
private IEmisWriteoffApplyService emisWriteoffApplyService;
|
||||
|
||||
@Autowired
|
||||
private IEmisSalesmenRelService emisSalesmenRelService;
|
||||
|
||||
/**
|
||||
* 查询销账申请列表
|
||||
*/
|
||||
@ -433,10 +439,96 @@ public class EmisWriteoffApplyController extends EmisBaseController {
|
||||
|
||||
List<EmisWriteoffApplyDetail> list = emisWriteoffApplyService
|
||||
.selectEmisWriteoffApplyDetailListByBillCodes(billCodeList);
|
||||
return AjaxResult.success(list != null ? list : new java.util.ArrayList<>());
|
||||
|
||||
if (list == null || list.isEmpty()) {
|
||||
return AjaxResult.success(new java.util.ArrayList<>());
|
||||
}
|
||||
|
||||
// 获取当前登录用户信息
|
||||
String currentEmpName = getLoginUser().getUser().getEmpName();
|
||||
|
||||
// 验证权限和账单状态
|
||||
for (EmisWriteoffApplyDetail detail : list) {
|
||||
// 1. 验证用户权限:检查是否是运单的销售联系人/回款联系人/销售联系人关联的助理
|
||||
if (!hasPermissionToViewBill(detail, currentEmpName)) {
|
||||
return error("您没有权限查看运单 " + detail.getBillCode() + " 的信息");
|
||||
}
|
||||
|
||||
// 2. 验证账单确认状态:检查账单是否已确认
|
||||
if (!isBillConfirmed(detail)) {
|
||||
return error("运单 " + detail.getBillCode() + " 的账单未确认,不允许进行销账申请");
|
||||
}
|
||||
}
|
||||
|
||||
return AjaxResult.success(list);
|
||||
} catch (Exception e) {
|
||||
log.error("根据运单号查询运单、结算账单、结算子账单信息失败", e);
|
||||
return error("查询失败:" + (e.getMessage() != null ? e.getMessage() : "未知错误"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证用户是否有权限查看运单信息
|
||||
* 检查是否是运单的销售联系人/回款联系人/销售联系人关联的助理
|
||||
*
|
||||
* @param detail 销账申请明细
|
||||
* @param currentEmpName 当前登录用户姓名
|
||||
* @return 是否有权限
|
||||
*/
|
||||
private boolean hasPermissionToViewBill(EmisWriteoffApplyDetail detail, String currentEmpName) {
|
||||
if (detail == null || detail.getEmisWaybill() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String salesmen = detail.getEmisWaybill().getSalesmen();
|
||||
String payee = detail.getEmisWaybill().getPayee();
|
||||
|
||||
// 1. 检查是否是销售联系人
|
||||
if (currentEmpName.equals(salesmen)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 2. 检查是否是回款联系人
|
||||
if (currentEmpName.equals(payee)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. 检查是否是销售联系人关联的助理
|
||||
if (salesmen != null && !salesmen.trim().isEmpty()) {
|
||||
EmisSalesmenRel queryRel = new EmisSalesmenRel();
|
||||
queryRel.setSalesAss(currentEmpName);
|
||||
queryRel.setSalesmen(salesmen);
|
||||
queryRel.setBlOpen("1"); // 只查询启用的关联关系
|
||||
|
||||
int count = emisSalesmenRelService.checkRelIsValid(queryRel);
|
||||
if (count > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证账单是否已确认
|
||||
*
|
||||
* @param detail 销账申请明细
|
||||
* @return 账单是否已确认
|
||||
*/
|
||||
private boolean isBillConfirmed(EmisWriteoffApplyDetail detail) {
|
||||
if (detail == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查结算账单确认状态
|
||||
if (detail.getEmisSettleBill() != null) {
|
||||
String billConfirmSite = detail.getEmisSettleBill().getBlConfirmSite();
|
||||
|
||||
if (!"1".equals(billConfirmSite)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -340,7 +340,16 @@ public class EmisWriteoffApplyServiceImpl extends EmisBaseService implements IEm
|
||||
throw new EmisBizError("已审核/已撤销");
|
||||
}
|
||||
|
||||
// 设置审核信息
|
||||
// 先更新相关业务数据(在更新审核状态之前进行验证和更新)
|
||||
List<EmisWriteoffApplyDetail> detailList = updateRelatedBusinessData(existingApply, true);
|
||||
|
||||
// 更新运单的付款状态
|
||||
updateWaybillPaymentStatus(existingApply, detailList, true);
|
||||
|
||||
// 重算并更新月结客户额度和现金客户额度
|
||||
updateCreditLimits(existingApply, detailList);
|
||||
|
||||
// 所有业务数据更新成功后,再更新审核状态
|
||||
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
|
||||
emisWriteoffApply.setBlCenterConfirmed(WriteoffApplyStatus.CENTER_APPROVED.statusCode);
|
||||
emisWriteoffApply.setCenterConfirmManCode(currentUser.getEmpCode());
|
||||
@ -350,15 +359,6 @@ public class EmisWriteoffApplyServiceImpl extends EmisBaseService implements IEm
|
||||
// 更新申请状态
|
||||
int result = emisWriteoffApplyMapper.auditCenterPass(emisWriteoffApply);
|
||||
|
||||
// 更新相关业务数据
|
||||
List<EmisWriteoffApplyDetail> detailList = updateRelatedBusinessData(existingApply, true);
|
||||
|
||||
// 更新运单的付款状态
|
||||
updateWaybillPaymentStatus(existingApply, detailList, true);
|
||||
|
||||
// 重算并更新月结客户额度和现金客户额度
|
||||
updateCreditLimits(existingApply, detailList);
|
||||
|
||||
// 发送通知给申请人
|
||||
sendWriteoffApplyNotification(existingApply, "centerPass", null);
|
||||
|
||||
@ -482,7 +482,16 @@ public class EmisWriteoffApplyServiceImpl extends EmisBaseService implements IEm
|
||||
throw new EmisBizError("已驳回");
|
||||
}
|
||||
|
||||
// 设置驳回信息
|
||||
// 先回退相关业务数据(在更新审核状态之前进行回退)
|
||||
List<EmisWriteoffApplyDetail> detailList = rollbackRelatedBusinessData(existingApply);
|
||||
|
||||
// 更新运单的付款状态
|
||||
updateWaybillPaymentStatus(existingApply, detailList, false);
|
||||
|
||||
// 重算并更新月结客户额度和现金客户额度
|
||||
updateCreditLimits(existingApply, detailList);
|
||||
|
||||
// 所有业务数据回退成功后,再更新审核状态
|
||||
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
|
||||
emisWriteoffApply.setBlHeadquartersConfirmed(WriteoffApplyStatus.HEADQUARTERS_REJECTED.statusCode);
|
||||
emisWriteoffApply.setHeadquartersConfirmManCode(currentUser.getEmpCode());
|
||||
@ -492,15 +501,6 @@ public class EmisWriteoffApplyServiceImpl extends EmisBaseService implements IEm
|
||||
// 更新申请状态
|
||||
int result = emisWriteoffApplyMapper.auditHeadquartersReject(emisWriteoffApply);
|
||||
|
||||
// 回退相关业务数据
|
||||
List<EmisWriteoffApplyDetail> detailList = rollbackRelatedBusinessData(existingApply);
|
||||
|
||||
// 更新运单的付款状态
|
||||
updateWaybillPaymentStatus(existingApply, detailList, false);
|
||||
|
||||
// 重算并更新月结客户额度和现金客户额度
|
||||
updateCreditLimits(existingApply, detailList);
|
||||
|
||||
// 发送通知给申请人和财务中心审批人员
|
||||
sendWriteoffApplyNotification(existingApply, "headquartersReject",
|
||||
emisWriteoffApply.getHeadquartersRejectReason());
|
||||
|
||||
@ -419,6 +419,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="payee" column="sb_payee"/>
|
||||
<result property="salesmen" column="sb_salesmen"/>
|
||||
<result property="creditPeriod" column="sb_credit_period"/>
|
||||
<result property="blConfirmCenter" column="sb_bl_confirm_center"/>
|
||||
<result property="blConfirmSite" column="sb_bl_confirm_site"/>
|
||||
<result property="createBy" column="sb_create_by"/>
|
||||
<result property="createTime" column="sb_create_time"/>
|
||||
<result property="updateBy" column="sb_update_by"/>
|
||||
@ -454,6 +456,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="allowanceReason" column="ssb_allowance_reason"/>
|
||||
<result property="deductionReason" column="ssb_deduction_reason"/>
|
||||
<result property="otherReason" column="ssb_other_reason"/>
|
||||
<result property="blConfirmCenter" column="ssb_bl_confirm_center"/>
|
||||
<result property="blConfirmSite" column="ssb_bl_confirm_site"/>
|
||||
<result property="createBy" column="ssb_create_by"/>
|
||||
<result property="createTime" column="ssb_create_time"/>
|
||||
<result property="updateBy" column="ssb_update_by"/>
|
||||
@ -499,7 +503,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
sb.open_bill_status as sb_open_bill_status, sb.payment_status as sb_payment_status, sb.charge_status as sb_charge_status,
|
||||
sb.send_piece_sum as sb_send_piece_sum, sb.piece_number as sb_piece_number, sb.fee_weight as sb_fee_weight,
|
||||
sb.uncollected_amount as sb_uncollected_amount, sb.send_money_sum as sb_send_money_sum, sb.refund_amount as sb_refund_amount,
|
||||
sb.refund_money as sb_refund_money, sb.payee as sb_payee, sb.salesmen as sb_salesmen, sb.credit_period as sb_credit_period,
|
||||
sb.refund_money as sb_refund_money, sb.payee as sb_payee, sb.salesmen as sb_salesmen, sb.credit_period as sb_credit_period,
|
||||
sb.bl_confirm_center as sb_bl_confirm_center, sb.bl_confirm_site as sb_bl_confirm_site,
|
||||
sb.create_by as sb_create_by, sb.create_time as sb_create_time, sb.update_by as sb_update_by,
|
||||
sb.update_time as sb_update_time, sb.remark as sb_remark,
|
||||
|
||||
@ -511,9 +516,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
ssb.cust_no as ssb_cust_no, ssb.cust_name as ssb_cust_name, ssb.customer_code as ssb_customer_code,
|
||||
ssb.customer_name as ssb_customer_name, ssb.invoiced_money as ssb_invoiced_money, ssb.reced_money as ssb_reced_money,
|
||||
ssb.satisfy_money as ssb_satisfy_money, ssb.allowance_money as ssb_allowance_money, ssb.deduction_money as ssb_deduction_money,
|
||||
ssb.other_money as ssb_other_money, ssb.satisfy_reason as ssb_satisfy_reason, ssb.allowance_reason as ssb_allowance_reason,
|
||||
ssb.deduction_reason as ssb_deduction_reason, ssb.other_reason as ssb_other_reason, ssb.create_by as ssb_create_by,
|
||||
ssb.create_time as ssb_create_time, ssb.update_by as ssb_update_by, ssb.update_time as ssb_update_time
|
||||
ssb.other_money as ssb_other_money, ssb.satisfy_reason as ssb_satisfy_reason, ssb.allowance_reason as ssb_allowance_reason,
|
||||
ssb.deduction_reason as ssb_deduction_reason, ssb.other_reason as ssb_other_reason,
|
||||
ssb.bl_confirm_center as ssb_bl_confirm_center, ssb.bl_confirm_site as ssb_bl_confirm_site,
|
||||
ssb.create_by as ssb_create_by, ssb.create_time as ssb_create_time, ssb.update_by as ssb_update_by,
|
||||
ssb.update_time as ssb_update_time
|
||||
from emis_waybill w
|
||||
left join emis_settle_sub_bill ssb on w.bill_code = ssb.bill_code and ssb.del_flag = '0'
|
||||
left join emis_settle_bill sb on ssb.settle_bill_no = sb.settle_bill_no and sb.del_flag = '0'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user