|
|
@ -31,10 +31,23 @@ import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.google.common.util.concurrent.ThreadFactoryBuilder; |
|
|
|
import com.yxt.anrui.base.api.basevehicle.BaseVehicle; |
|
|
|
import com.yxt.anrui.base.api.basevehicle.BaseVehicleFeign; |
|
|
|
import com.yxt.anrui.base.api.commonappendix.CommonAttachTypeEnum; |
|
|
|
import com.yxt.anrui.base.common.enums.BillTypeEnum; |
|
|
|
import com.yxt.anrui.base.common.utils.Rule; |
|
|
|
import com.yxt.anrui.base.common.utils.domain.BillNo; |
|
|
|
import com.yxt.anrui.buscenter.api.bussalesorder.BusSalesOrder; |
|
|
|
import com.yxt.anrui.buscenter.api.bussalesorder.BusSalesOrderFeign; |
|
|
|
import com.yxt.anrui.buscenter.api.bussalesordervehicle.BusSalesOrderVehicle; |
|
|
|
import com.yxt.anrui.buscenter.api.bussalesordervehicle.BusSalesOrderVehicleFeign; |
|
|
|
import com.yxt.anrui.crm.api.crmcustomertemp.CrmCustomerTemp; |
|
|
|
import com.yxt.anrui.crm.api.crmcustomertemp.CrmCustomerTempFeign; |
|
|
|
import com.yxt.anrui.fin.api.finuncollectedreceivablesdetailed.FinUncollectedReceivablesDetailedDto; |
|
|
|
import com.yxt.anrui.fin.api.finuncollectedreceivablesdetailed.FinUncollectedReceivablesDetailedFeign; |
|
|
|
import com.yxt.anrui.fin.api.kingdee.FinKingDeeFeign; |
|
|
|
import com.yxt.anrui.fin.api.kingdee.costadjustmentsbill.CostAdjustmentsBill; |
|
|
|
import com.yxt.anrui.fin.api.kingdee.voucher.GeneralVoucher; |
|
|
|
import com.yxt.anrui.flowable.api.flow.FlowableFeign; |
|
|
|
import com.yxt.anrui.flowable.api.flow.UpdateFlowFieldVo; |
|
|
|
import com.yxt.anrui.flowable.api.flow2.FlowDelegateQuery; |
|
|
@ -57,8 +70,13 @@ import com.yxt.anrui.scm.api.scmfile.ScmFileVo; |
|
|
|
import com.yxt.anrui.scm.api.scmfinanceadjustapply.*; |
|
|
|
import com.yxt.anrui.scm.api.scmfinanceadjustapply.flow.*; |
|
|
|
import com.yxt.anrui.scm.api.scmfinanceadjustdetails.ScmFinanceAdjustDetails; |
|
|
|
import com.yxt.anrui.scm.api.scmvehrebate.ScmVehRebate; |
|
|
|
import com.yxt.anrui.scm.api.scmvehrebatecheckapply.ScmVehrebateCheckapply; |
|
|
|
import com.yxt.anrui.scm.biz.scmfile.ScmFileService; |
|
|
|
import com.yxt.anrui.scm.biz.scmfinanceadjustdetails.ScmFinanceAdjustDetailsService; |
|
|
|
import com.yxt.anrui.scm.biz.scmvehrebate.ScmVehRebateService; |
|
|
|
import com.yxt.anrui.scm.biz.scmvehrebatecheckapply.ScmVehrebateCheckapplyService; |
|
|
|
import com.yxt.anrui.scm.biz.scmvehrebatewithapply.ScmVehRebateWithApplyService; |
|
|
|
import com.yxt.common.base.config.component.DocPdfComponent; |
|
|
|
import com.yxt.common.base.config.component.FileUploadComponent; |
|
|
|
import com.yxt.common.base.service.MybatisBaseService; |
|
|
@ -93,7 +111,16 @@ import java.util.stream.Collectors; |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
public class ScmFinanceAdjustApplyService extends MybatisBaseService<ScmFinanceAdjustApplyMapper, ScmFinanceAdjustApply> { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private BusSalesOrderVehicleFeign busSalesOrderVehicleFeign; |
|
|
|
@Autowired |
|
|
|
private FinUncollectedReceivablesDetailedFeign finUncollectedReceivablesDetailedFeign; |
|
|
|
@Autowired |
|
|
|
private BaseVehicleFeign baseVehicleFeign; |
|
|
|
@Autowired |
|
|
|
private BusSalesOrderFeign busSalesOrderFeign; |
|
|
|
@Autowired |
|
|
|
private ScmVehrebateCheckapplyService scmVehrebateCheckapplyService; |
|
|
|
@Autowired |
|
|
|
private MessageFeign messageFeign; |
|
|
|
@Autowired |
|
|
@ -116,6 +143,14 @@ public class ScmFinanceAdjustApplyService extends MybatisBaseService<ScmFinanceA |
|
|
|
private SysUserFeign sysUserFeign; |
|
|
|
@Autowired |
|
|
|
private SysOrganizationFeign sysOrganizationFeign; |
|
|
|
@Autowired |
|
|
|
private CrmCustomerTempFeign crmCustomerTempFeign; |
|
|
|
@Autowired |
|
|
|
private ScmVehRebateWithApplyService scmVehRebateWithApplyService; |
|
|
|
@Autowired |
|
|
|
private ScmVehRebateService scmVehRebateService; |
|
|
|
@Autowired |
|
|
|
private FinKingDeeFeign finKingDeeFeign; |
|
|
|
|
|
|
|
private QueryWrapper<ScmFinanceAdjustApply> createQueryWrapper(ScmFinanceAdjustApplyQuery query) { |
|
|
|
// todo: 这里根据具体业务调整查询条件
|
|
|
@ -672,26 +707,172 @@ public class ScmFinanceAdjustApplyService extends MybatisBaseService<ScmFinanceA |
|
|
|
ScmFinanceAdjustApply adjustApply = fetchBySid(sid); |
|
|
|
String adjustWay = adjustApply.getAdjustWay(); |
|
|
|
List<ScmFinanceAdjustDetails> details = scmFinanceAdjustDetailsService.selByMainSid(sid); |
|
|
|
String format = scmVehRebateWithApplyService.returnBusDate(new Date()); |
|
|
|
if (!details.isEmpty() && details.size() > 0) { |
|
|
|
for (ScmFinanceAdjustDetails detail : details) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (adjustWay.equals("客户交纳")) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (adjustWay.equals("公司认损")) { |
|
|
|
|
|
|
|
|
|
|
|
if (adjustWay.equals("客户交纳")) { |
|
|
|
//按照采购系统分组
|
|
|
|
if (!details.isEmpty()) { |
|
|
|
Map<String, List<ScmFinanceAdjustDetails>> map = details.stream().collect(Collectors.groupingBy(ScmFinanceAdjustDetails::getPurchaseSystemSid)); |
|
|
|
map.forEach((k, v) -> { |
|
|
|
List<ScmFinanceAdjustDetails> rebates = v; |
|
|
|
GeneralVoucher generalVoucher = new GeneralVoucher(); |
|
|
|
generalVoucher.setBussDate(format); |
|
|
|
List<GeneralVoucher.GeneralVoucherDetail> voucherDetails = new ArrayList<>(); |
|
|
|
if (!v.isEmpty()) { |
|
|
|
for (ScmFinanceAdjustDetails rebate : v) { |
|
|
|
String useOrgCode = ""; |
|
|
|
String vinCode = ""; |
|
|
|
String deptCode = ""; |
|
|
|
if (StringUtils.isNotBlank(adjustApply.getUseOrgSid())) { |
|
|
|
String useOrgSid = adjustApply.getUseOrgSid(); |
|
|
|
SysOrganizationVo organizationVo = sysOrganizationFeign.fetchBySid(useOrgSid).getData(); |
|
|
|
if (null != organizationVo) { |
|
|
|
generalVoucher.setUseOrgCode(organizationVo.getOrgCode()); |
|
|
|
useOrgCode = organizationVo.getOrgCode(); |
|
|
|
} |
|
|
|
} |
|
|
|
GeneralVoucher.GeneralVoucherDetail voucherDetail = new GeneralVoucher.GeneralVoucherDetail(); |
|
|
|
String summaryTag = "";//摘要前缀
|
|
|
|
ScmVehrebateCheckapply checkapply = scmVehrebateCheckapplyService.fetchBySid(rebate.getCheckApplySid()); |
|
|
|
if (null != checkapply) { |
|
|
|
if (StringUtils.isNotBlank(checkapply.getCheckApply())) { |
|
|
|
summaryTag = checkapply.getCheckApply(); |
|
|
|
} |
|
|
|
} |
|
|
|
String finalSummaryTag = summaryTag; |
|
|
|
String[] split = finalSummaryTag.split("年"); |
|
|
|
String y1 = split[0]; //核对申请标题年份
|
|
|
|
ScmVehRebate scmVehRebate = scmVehRebateService.fetchBySid(rebate.getRebateSid()); |
|
|
|
String palceGenDate = scmVehRebate.getPalceGenDate(); |
|
|
|
String[] palceGenDateSplit = palceGenDate.split("-"); |
|
|
|
String y2 = palceGenDateSplit[0];//所属年份
|
|
|
|
if (y1.equals(y2)) { |
|
|
|
voucherDetail.setType("本年"); |
|
|
|
} else { |
|
|
|
voucherDetail.setType("上年"); |
|
|
|
} |
|
|
|
BusSalesOrder salesOrder = busSalesOrderFeign.fetchBySid(rebate.getSalesOrderSid()).getData(); |
|
|
|
if (null != salesOrder) { |
|
|
|
SysOrganizationVo data = sysOrganizationFeign.fetchBySid(salesOrder.getOrgSid()).getData(); |
|
|
|
if (null != data) { |
|
|
|
voucherDetail.setDeptCode(data.getOrgCode()); //部门编码赋值
|
|
|
|
deptCode = data.getOrgCode(); |
|
|
|
} |
|
|
|
} |
|
|
|
BaseVehicle vehicle = baseVehicleFeign.fetchBySid(rebate.getVehSid()).getData(); |
|
|
|
if (null != vehicle) { |
|
|
|
if (StringUtils.isNotBlank(vehicle.getManufacturerCode())) { |
|
|
|
voucherDetail.setManufacturer(vehicle.getManufacturerCode()); |
|
|
|
} |
|
|
|
vinCode = vehicle.getVinNo().substring(vehicle.getVinNo().length() - 8); |
|
|
|
voucherDetail.setMaterial(vinCode); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(rebate.getCustomerSid())) { |
|
|
|
CrmCustomerTemp customerTemp = crmCustomerTempFeign.fetchEntity(rebate.getCustomerSid()).getData(); |
|
|
|
if (null != customerTemp) { |
|
|
|
voucherDetail.setCustomerCode(customerTemp.getCustomerNo()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (null != rebate.getNowAdjustmentMoney()) { |
|
|
|
if (rebate.getNowAdjustmentMoney().compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
voucherDetail.setAmount(rebate.getNowAdjustmentMoney()); |
|
|
|
voucherDetails.add(voucherDetail); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//生成应收
|
|
|
|
if (null != salesOrder) { |
|
|
|
FinUncollectedReceivablesDetailedDto finUncollectedReceivablesDetailedDto = new FinUncollectedReceivablesDetailedDto(); |
|
|
|
finUncollectedReceivablesDetailedDto.setCreateByName(adjustApply.getCreateByName()); |
|
|
|
finUncollectedReceivablesDetailedDto.setCreateBySid(adjustApply.getCreateBySid()); |
|
|
|
finUncollectedReceivablesDetailedDto.setContractNo(rebate.getContractNo()); |
|
|
|
finUncollectedReceivablesDetailedDto.setCustomerSid(rebate.getCustomerSid()); |
|
|
|
finUncollectedReceivablesDetailedDto.setCustomerName(rebate.getCustomerName()); |
|
|
|
finUncollectedReceivablesDetailedDto.setVIN(rebate.getVinNo()); |
|
|
|
if (StringUtils.isNotBlank(salesOrder.getMobile())) { |
|
|
|
finUncollectedReceivablesDetailedDto.setCustomerPhone(salesOrder.getMobile()); |
|
|
|
} |
|
|
|
finUncollectedReceivablesDetailedDto.setUseOrgSid(adjustApply.getUseOrgSid()); |
|
|
|
finUncollectedReceivablesDetailedDto.setReceivablesName("车款"); |
|
|
|
finUncollectedReceivablesDetailedDto.setCurrentReceivableMoney(rebate.getNowAdjustmentMoney().toString()); |
|
|
|
finUncollectedReceivablesDetailedDto.setReveivableMoney(rebate.getNowAdjustmentMoney().toString()); |
|
|
|
BusSalesOrderVehicle busSalesOrderVehicle = busSalesOrderVehicleFeign.selectByNoAndVinSid(rebate.getContractNo(), rebate.getVehSid()).getData(); |
|
|
|
finUncollectedReceivablesDetailedDto.setOrgSidPath(salesOrder.getOrgSidPath()); |
|
|
|
finUncollectedReceivablesDetailedDto.setBusVinSid(busSalesOrderVehicle.getSid()); |
|
|
|
finUncollectedReceivablesDetailedDto.setPayTypeKey(salesOrder.getPayTypeKey()); |
|
|
|
finUncollectedReceivablesDetailedDto.setPayType(salesOrder.getPayType()); |
|
|
|
finUncollectedReceivablesDetailedDto.setUseOrgName(adjustApply.getUseOrgName()); |
|
|
|
finUncollectedReceivablesDetailedDto.setKxState("01"); |
|
|
|
finUncollectedReceivablesDetailedDto.setPurchaseSystemSid(rebate.getPurchaseSystemSid()); |
|
|
|
finUncollectedReceivablesDetailedDto.setPurchaseSystemName(rebate.getPurchaseSystemName()); |
|
|
|
finUncollectedReceivablesDetailedDto.setStaffName(salesOrder.getStaffName()); |
|
|
|
SysUserVo sysUserVo = sysUserFeign.selectByStaffsid(salesOrder.getStaffSid()).getData(); |
|
|
|
finUncollectedReceivablesDetailedDto.setStaffUserSid(sysUserVo.getSid()); |
|
|
|
finUncollectedReceivablesDetailedDto.setStaffDeptSid(salesOrder.getOrgSid()); |
|
|
|
finUncollectedReceivablesDetailedDto.setStaffDeptName(salesOrder.getOrgName()); |
|
|
|
finUncollectedReceivablesDetailedFeign.saveOrUpdate(finUncollectedReceivablesDetailedDto); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!voucherDetails.isEmpty()) { |
|
|
|
generalVoucher.setVoucherDetails(voucherDetails); |
|
|
|
finKingDeeFeign.saveJRAdjustVoucher(generalVoucher); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} else if (adjustWay.equals("公司认损")) { |
|
|
|
if (!details.isEmpty()) { |
|
|
|
Map<String, List<ScmFinanceAdjustDetails>> map = details.stream().collect(Collectors.groupingBy(ScmFinanceAdjustDetails::getPurchaseSystemSid)); |
|
|
|
map.forEach((k, v) -> { |
|
|
|
List<ScmFinanceAdjustDetails> rebates = v; |
|
|
|
CostAdjustmentsBill costAdjustmentsBill = new CostAdjustmentsBill(); |
|
|
|
costAdjustmentsBill.setBussDate(format); |
|
|
|
List<CostAdjustmentsBill.CostAdjustmentsBillDetailDto> resultDetails = new ArrayList<>(); |
|
|
|
if (!v.isEmpty()) { |
|
|
|
for (ScmFinanceAdjustDetails rebate : v) { |
|
|
|
String useOrgCode = ""; |
|
|
|
String vinCode = ""; |
|
|
|
String deptCode = ""; |
|
|
|
SysOrganizationVo data = sysOrganizationFeign.fetchBySid(rebate.getPurchaseSystemSid()).getData(); |
|
|
|
if (null != data) { |
|
|
|
deptCode = data.getOrgCode(); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(adjustApply.getUseOrgSid())) { |
|
|
|
String useOrgSid = adjustApply.getUseOrgSid(); |
|
|
|
SysOrganizationVo organizationVo = sysOrganizationFeign.fetchBySid(useOrgSid).getData(); |
|
|
|
if (null != organizationVo) { |
|
|
|
costAdjustmentsBill.setUseOrgCode(organizationVo.getOrgCode()); |
|
|
|
useOrgCode = organizationVo.getOrgCode(); |
|
|
|
} |
|
|
|
} |
|
|
|
BaseVehicle vehicle = baseVehicleFeign.fetchBySid(rebate.getVehSid()).getData(); |
|
|
|
if (null != vehicle) { |
|
|
|
if (StringUtils.isNotBlank(vehicle.getManufacturerCode())) { |
|
|
|
costAdjustmentsBill.setCommUnit(vehicle.getManufacturerCode()); |
|
|
|
} |
|
|
|
vinCode = vehicle.getVinNo().substring(vehicle.getVinNo().length() - 8); |
|
|
|
} |
|
|
|
if (null != rebate.getNowAdjustmentMoney()) { |
|
|
|
if (rebate.getNowAdjustmentMoney().compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
//添加成本调整单
|
|
|
|
CostAdjustmentsBill.CostAdjustmentsBillDetailDto dto = new CostAdjustmentsBill.CostAdjustmentsBillDetailDto(); |
|
|
|
dto.setCompanyCode(useOrgCode); |
|
|
|
dto.setMaterialID(vinCode); |
|
|
|
dto.setDeptCode(deptCode); |
|
|
|
dto.setAmount(rebate.getNowAdjustmentMoney().toString()); |
|
|
|
resultDetails.add(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!resultDetails.isEmpty()) { |
|
|
|
costAdjustmentsBill.setResultDetails(resultDetails); |
|
|
|
finKingDeeFeign.pushCostAdjustmentsBill(costAdjustmentsBill); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|