@ -28,21 +28,33 @@ package com.yxt.anrui.scm.biz.scmfinanceadjustapply;
import cn.hutool.core.bean.BeanUtil ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import org.apache.commons.lang3.StringUtils ;
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.portal.api.sysorganization.SysOrganizationFeign ;
import com.yxt.anrui.portal.api.sysorganization.SysOrganizationVo ;
import com.yxt.anrui.portal.api.sysuser.PrivilegeQuery ;
import com.yxt.anrui.portal.api.sysuser.PrivilegeVo ;
import com.yxt.anrui.portal.api.sysuser.SysUserFeign ;
import com.yxt.anrui.scm.api.scmfile.ScmFileDto ;
import com.yxt.anrui.scm.api.scmfile.ScmFileVo ;
import com.yxt.anrui.scm.api.scmfinanceadjustapply.* ;
import com.yxt.anrui.scm.api.scmfinanceadjustdetails.ScmFinanceAdjustDetails ;
import com.yxt.anrui.scm.biz.scmfile.ScmFileService ;
import com.yxt.anrui.scm.biz.scmfinanceadjustdetails.ScmFinanceAdjustDetailsService ;
import com.yxt.common.base.config.component.DocPdfComponent ;
import com.yxt.common.base.config.component.FileUploadComponent ;
import com.yxt.common.base.service.MybatisBaseService ;
import com.yxt.common.base.utils.PagerUtil ;
import com.yxt.common.core.query.PagerQuery ;
import com.yxt.common.core.result.ResultBean ;
import com.yxt.common.core.vo.PagerVo ;
import com.yxt.anrui.scm.api.scmfinanceadjustapply.ScmFinanceAdjustApply ;
import com.yxt.anrui.scm.api.scmfinanceadjustapply.ScmFinanceAdjustApplyQuery ;
import com.yxt.anrui.scm.api.scmfinanceadjustapply.ScmFinanceAdjustApplyVo ;
import com.yxt.anrui.scm.api.scmfinanceadjustapply.ScmFinanceAdjustApplyDetailsVo ;
import com.yxt.anrui.scm.api.scmfinanceadjustapply.ScmFinanceAdjustApplyDto ;
import com.yxt.anrui.scm.api.scmfinanceadjustapply.ScmFinanceAdjustApplyFeign ;
import org.apache.commons.lang3.StringUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import java.util.ArrayList ;
import java.util.List ;
/ * *
@ -60,6 +72,20 @@ import java.util.List;
* /
@Service
public class ScmFinanceAdjustApplyService extends MybatisBaseService < ScmFinanceAdjustApplyMapper , ScmFinanceAdjustApply > {
@Autowired
private ScmFileService scmFileService ;
@Autowired
private ScmFinanceAdjustDetailsService scmFinanceAdjustDetailsService ;
@Autowired
private FileUploadComponent fileUploadComponent ;
@Autowired
private DocPdfComponent docPdfComponent ;
@Autowired
private SysUserFeign sysUserFeign ;
@Autowired
private SysOrganizationFeign sysOrganizationFeign ;
private QueryWrapper < ScmFinanceAdjustApply > createQueryWrapper ( ScmFinanceAdjustApplyQuery query ) {
// todo: 这里根据具体业务调整查询条件
// 多字段Like示例:qw.and(wrapper -> wrapper.like("name", query.getName()).or().like("remark", query.getName()));
@ -69,13 +95,115 @@ public class ScmFinanceAdjustApplyService extends MybatisBaseService<ScmFinanceA
public PagerVo < ScmFinanceAdjustApplyVo > listPageVo ( PagerQuery < ScmFinanceAdjustApplyQuery > pq ) {
ScmFinanceAdjustApplyQuery query = pq . getParams ( ) ;
QueryWrapper < ScmFinanceAdjustApply > qw = createQueryWrapper ( query ) ;
QueryWrapper < ScmFinanceAdjustApply > qw = new QueryWrapper < > ( ) ;
if ( StringUtils . isNotBlank ( query . getMenuUrl ( ) ) ) {
PrivilegeQuery privilegeQuery = new PrivilegeQuery ( ) ;
privilegeQuery . setOrgPath ( query . getOrgPath ( ) ) ;
privilegeQuery . setMenuUrl ( query . getMenuUrl ( ) ) ;
privilegeQuery . setUserSid ( query . getUserSid ( ) ) ;
ResultBean < PrivilegeVo > defaultIdReltBean = sysUserFeign . selectPrivilegeLevelPath ( privilegeQuery ) ;
if ( null ! = defaultIdReltBean . getData ( ) ) {
//数据权限ID(1集团、2事业部、3分公司、4部门、5个人)
PrivilegeVo privilegeVo = defaultIdReltBean . getData ( ) ;
if ( "5" . equals ( privilegeVo . getOrgLevelKey ( ) ) ) {
qw . eq ( "a.createBySid" , privilegeVo . getLevelPath ( ) ) ;
} else {
qw . like ( "s.orgSidPath" , privilegeVo . getLevelPath ( ) ) ;
}
} else {
PagerVo < ScmFinanceAdjustApplyVo > p = new PagerVo < > ( ) ;
return p ;
}
}
if ( StringUtils . isNotBlank ( query . getUseOrgName ( ) ) ) {
qw . like ( "a.useOrgName" , query . getUseOrgName ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getDeptName ( ) ) ) {
qw . like ( "a.deptName" , query . getDeptName ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getCreateByName ( ) ) ) {
qw . like ( "a.createByName" , query . getCreateByName ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getBillNo ( ) ) ) {
qw . like ( "a.billNo" , query . getBillNo ( ) ) ;
}
String applyStartTime = query . getCreateStartDate ( ) ;
String applyEndTime = query . getCreateEndDate ( ) ;
qw . apply ( StringUtils . isNotEmpty ( applyStartTime ) , "date_format (a.createTime,'%Y-%m-%d') >= date_format('" + applyStartTime + "','%Y-%m-%d')" ) .
apply ( StringUtils . isNotEmpty ( applyEndTime ) , "date_format (a.createTime,'%Y-%m-%d') <= date_format('" + applyEndTime + "','%Y-%m-%d')"
) ;
String closingStartDate = query . getCloseStartDate ( ) ;
String closingEndDate = query . getCloseEndDate ( ) ;
qw . apply ( StringUtils . isNotEmpty ( closingStartDate ) , "date_format (a.closingDate,'%Y-%m-%d') >= date_format('" + closingStartDate + "','%Y-%m-%d')" ) .
apply ( StringUtils . isNotEmpty ( closingEndDate ) , "date_format (a.closingDate,'%Y-%m-%d') <= date_format('" + closingEndDate + "','%Y-%m-%d')"
) ;
IPage < ScmFinanceAdjustApply > page = PagerUtil . queryToPage ( pq ) ;
IPage < ScmFinanceAdjustApplyVo > pagging = baseMapper . selectPageVo ( page , qw ) ;
PagerVo < ScmFinanceAdjustApplyVo > p = PagerUtil . pageToVo ( pagging , null ) ;
return p ;
}
/ * *
* 生成申请单单据编号
*
* @param orgSid
* @return
* /
public String getApplyCode ( String orgSid ) {
//获取分公司sid
ResultBean < SysOrganizationVo > resultBean1 = sysOrganizationFeign . fetchBySid ( orgSid ) ;
String orgCode = resultBean1 . getData ( ) . getOrgCode ( ) ;
BillNo b = new BillNo ( ) ;
b . setOrgCode ( orgCode ) ;
b . setBillType ( BillTypeEnum . JRTXCY . getBillType ( ) ) ;
String bill = Rule . getBill ( b ) ;
int i = baseMapper . selectNum ( bill ) ;
String billNo = Rule . getBillNo ( bill , i ) ;
return billNo ;
}
public String saveBill ( ScmFinanceAdjustApplyDto dto ) {
String sid = "" ;
if ( StringUtils . isNotBlank ( dto . getSid ( ) ) ) {
sid = dto . getSid ( ) ;
ScmFinanceAdjustApply scmFinanceAdjustApply = fetchBySid ( sid ) ;
BeanUtil . copyProperties ( dto , scmFinanceAdjustApply , "id" , "sid" ) ;
baseMapper . updateById ( scmFinanceAdjustApply ) ;
} else {
ScmFinanceAdjustApply entity = new ScmFinanceAdjustApply ( ) ;
sid = entity . getSid ( ) ;
BeanUtil . copyProperties ( dto , entity , "id" , "sid" ) ;
entity . setNodeState ( "未提交" ) ;
String applyCode = getApplyCode ( dto . getUseOrgSid ( ) ) ;
entity . setBillNo ( applyCode ) ;
baseMapper . insert ( entity ) ;
}
scmFileService . delByMainSid ( sid ) ;
if ( ! dto . getFilePath ( ) . isEmpty ( ) & & dto . getFilePath ( ) . size ( ) > 0 ) {
for ( QueryUrl scmFile : dto . getFilePath ( ) ) {
ScmFileDto scmFileDto = new ScmFileDto ( ) ;
scmFileDto . setAttachType ( CommonAttachTypeEnum . JRTXCYTZ . getAttachType ( ) ) ;
scmFileDto . setLinkSid ( sid ) ;
String filePath = scmFile . getUrl ( ) ;
if ( filePath . indexOf ( fileUploadComponent . getUrlPrefix ( ) ) > - 1 ) {
filePath = filePath . replace ( fileUploadComponent . getUrlPrefix ( ) , "" ) ;
}
scmFileDto . setFilePath ( filePath ) ;
scmFileService . insertByDto ( scmFileDto ) ;
}
}
scmFinanceAdjustDetailsService . delByMainSid ( sid ) ;
if ( ! dto . getList ( ) . isEmpty ( ) & & dto . getList ( ) . size ( ) > 0 ) {
for ( AdjustDetailsListVo detailsListVo : dto . getList ( ) ) {
ScmFinanceAdjustDetails details = new ScmFinanceAdjustDetails ( ) ;
BeanUtil . copyProperties ( detailsListVo , details , "id" , "sid" ) ;
details . setMainSid ( sid ) ;
scmFinanceAdjustDetailsService . insert ( details ) ;
}
}
return sid ;
}
public void saveOrUpdateDto ( ScmFinanceAdjustApplyDto dto ) {
String dtoSid = dto . getSid ( ) ;
if ( StringUtils . isBlank ( dtoSid ) ) {
@ -104,7 +232,129 @@ public class ScmFinanceAdjustApplyService extends MybatisBaseService<ScmFinanceA
public ScmFinanceAdjustApplyDetailsVo fetchDetailsVoBySid ( String sid ) {
ScmFinanceAdjustApply entity = fetchBySid ( sid ) ;
ScmFinanceAdjustApplyDetailsVo vo = new ScmFinanceAdjustApplyDetailsVo ( ) ;
BeanUtil . copyProperties ( entity , vo ) ;
List < QueryUrl > filePaths = new ArrayList < > ( ) ;
List < AdjustDetailsListVo > listVos = new ArrayList < > ( ) ;
if ( null ! = entity ) {
BeanUtil . copyProperties ( entity , vo ) ;
if ( StringUtils . isNotBlank ( entity . getProcInstId ( ) ) ) {
vo . setInstanceId ( entity . getProcInstId ( ) ) ;
}
List < ScmFileVo > scmFileVos = scmFileService . fetchByMainSid ( sid ) ;
if ( ! scmFileVos . isEmpty ( ) & & scmFileVos . size ( ) > 0 ) {
for ( ScmFileVo scmFileVo : scmFileVos ) {
QueryUrl url = new QueryUrl ( ) ;
String filePath = scmFileVo . getFilePath ( ) ;
String urlPrefix = fileUploadComponent . getUrlPrefix ( ) ;
filePath = urlPrefix + filePath ;
url . setUrl ( filePath ) ;
filePaths . add ( url ) ;
}
vo . setFilePath ( filePaths ) ;
}
List < ScmFinanceAdjustDetails > details = scmFinanceAdjustDetailsService . selByMainSid ( sid ) ;
if ( ! details . isEmpty ( ) & & details . size ( ) > 0 ) {
for ( ScmFinanceAdjustDetails detail : details ) {
AdjustDetailsListVo detailsListVo = new AdjustDetailsListVo ( ) ;
BeanUtil . copyProperties ( detail , detailsListVo ) ;
listVos . add ( detailsListVo ) ;
}
vo . setList ( listVos ) ;
}
}
return vo ;
}
public PagerVo < AdjustVehListVo > getAdjustVehList ( PagerQuery < AdjustVehListQuery > pq ) {
AdjustVehListQuery query = pq . getParams ( ) ;
QueryWrapper < ScmFinanceAdjustApply > qw = new QueryWrapper < > ( ) ;
if ( StringUtils . isNotBlank ( query . getPurchaseSystemName ( ) ) ) {
qw . like ( "n.purchaseSystemName" , query . getPurchaseSystemName ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getBrandName ( ) ) ) {
qw . like ( "n.brandName" , query . getBrandName ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getVehModel ( ) ) ) {
qw . like ( "n.vehModelName" , query . getVehModel ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getVinNo ( ) ) ) {
qw . like ( "n.vinNo" , query . getVinNo ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getCustomerName ( ) ) ) {
qw . like ( "bo.customerName" , query . getCustomerName ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getContractNo ( ) ) ) {
qw . like ( "bo.contractNo" , query . getContractNo ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getStaffSid ( ) ) ) {
qw . eq ( "bo.createBySid" , query . getStaffSid ( ) ) ;
}
qw . apply ( "n.nowDiffAmount != 0" ) ;
qw . eq ( "n.useOrgSid" , query . getUseOrgSid ( ) ) ;
IPage < ScmFinanceAdjustApply > page = PagerUtil . queryToPage ( pq ) ;
IPage < AdjustVehListVo > pagging = baseMapper . getAdjustVehList ( page , qw ) ;
PagerVo < AdjustVehListVo > p = PagerUtil . pageToVo ( pagging , null ) ;
return p ;
}
public PagerVo < AdjustVehListVo > finAdjustList ( PagerQuery < AdjustVehListQuery > pq ) {
AdjustVehListQuery query = pq . getParams ( ) ;
QueryWrapper < ScmFinanceAdjustDetails > qw = new QueryWrapper < > ( ) ;
if ( StringUtils . isNotBlank ( query . getMenuUrl ( ) ) ) {
PrivilegeQuery privilegeQuery = new PrivilegeQuery ( ) ;
privilegeQuery . setOrgPath ( query . getOrgPath ( ) ) ;
privilegeQuery . setMenuUrl ( query . getMenuUrl ( ) ) ;
privilegeQuery . setUserSid ( query . getUserSid ( ) ) ;
ResultBean < PrivilegeVo > defaultIdReltBean = sysUserFeign . selectPrivilegeLevelPath ( privilegeQuery ) ;
if ( null ! = defaultIdReltBean . getData ( ) ) {
//数据权限ID(1集团、2事业部、3分公司、4部门、5个人)
PrivilegeVo privilegeVo = defaultIdReltBean . getData ( ) ;
if ( "5" . equals ( privilegeVo . getOrgLevelKey ( ) ) ) {
qw . eq ( "n.createBySid" , privilegeVo . getLevelPath ( ) ) ;
} else {
qw . like ( "n.orgPath" , privilegeVo . getLevelPath ( ) ) ;
}
} else {
PagerVo < AdjustVehListVo > p = new PagerVo < > ( ) ;
return p ;
}
}
if ( StringUtils . isNotBlank ( query . getPurchaseSystemName ( ) ) ) {
qw . like ( "n.purchaseSystemName" , query . getPurchaseSystemName ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getBrandName ( ) ) ) {
qw . like ( "n.brandName" , query . getBrandName ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getVehModel ( ) ) ) {
qw . like ( "n.vehModelName" , query . getVehModel ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getVinNo ( ) ) ) {
qw . like ( "n.vinNo" , query . getVinNo ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getCustomerName ( ) ) ) {
qw . like ( "bo.customerName" , query . getCustomerName ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getContractNo ( ) ) ) {
qw . like ( "bo.contractNo" , query . getContractNo ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getStaffSid ( ) ) ) {
qw . eq ( "bo.createBySid" , query . getStaffSid ( ) ) ;
}
if ( StringUtils . isNotBlank ( query . getState ( ) ) ) {
if ( query . getState ( ) . equals ( "未调整" ) ) {
qw . apply ( "n.alreadyMoney = 0" ) ;
} else if ( query . getState ( ) . equals ( "已调整" ) ) {
qw . apply ( "n.nowDiffAmount = 0" ) ;
} else {
qw . apply ( "n.nowDiffAmount != 0 and n.alreadyMoney != 0" ) ;
}
}
IPage < ScmFinanceAdjustDetails > page = PagerUtil . queryToPage ( pq ) ;
IPage < AdjustVehListVo > pagging = baseMapper . finAdjustList ( page , qw ) ;
PagerVo < AdjustVehListVo > p = PagerUtil . pageToVo ( pagging , null ) ;
return p ;
}
public int selectBySid ( String join ) {
return baseMapper . selectBySid ( join ) ;
}
}