|
@@ -9,12 +9,13 @@ import com.jeeplus.test.reimbursementAccountant.mapper.AccountantReimbursementSy
|
|
|
import com.jeeplus.test.reimbursementAccountant.service.AccountantReimbursementBusinessService;
|
|
|
import com.jeeplus.test.reimbursementAccountant.service.AccountantReimbursementSysService;
|
|
|
import com.jeeplus.test.reimbursementAccountant.utils.MyBeanUtils;
|
|
|
+import com.jeeplus.test.reimbursementsys.domain.dto.ReimbursementDTO;
|
|
|
+import com.jeeplus.test.reimbursementsys.utils.PublicUtil;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -37,13 +38,23 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
|
|
|
@Override
|
|
|
public AccountantReimbursementDTO queryBusinessById(String id) {
|
|
|
//根据发票id查询业务具体信息
|
|
|
- return mapper.queryBusinessById(id);
|
|
|
+ AccountantReimbursementDTO reimbursementDTO = mapper.queryBusinessById(id);
|
|
|
+ //如果没有随即类型,则将随即类型默认为非随机(即指定业务编码)
|
|
|
+ if(StringUtils.isBlank(reimbursementDTO.getRandomType())){
|
|
|
+ reimbursementDTO.setRandomType("0");
|
|
|
+ }
|
|
|
+ return reimbursementDTO;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public AccountantReimbursementDTO queryBusinessByInvoiceId(String id) {
|
|
|
//根据发票id查询业务具体信息
|
|
|
- return mapper.queryBusinessByInvoiceId(id);
|
|
|
+ AccountantReimbursementDTO accountantReimbursementDTO = mapper.queryBusinessByInvoiceId(id);
|
|
|
+ //如果没有随即类型,则将随即类型默认为非随机(即指定业务编码)
|
|
|
+ if(StringUtils.isBlank(accountantReimbursementDTO.getRandomType())){
|
|
|
+ accountantReimbursementDTO.setRandomType("0");
|
|
|
+ }
|
|
|
+ return accountantReimbursementDTO;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -62,7 +73,14 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
|
|
|
public IPage<AccountantReimbursementDTO> treeData(Page<AccountantReimbursementDTO> page, AccountantReimbursementDTO reimbursement) {
|
|
|
IPage<AccountantReimbursementDTO> pageList = new Page();
|
|
|
//如果筛选项含有发票号码,则需先查询对应的发票信息
|
|
|
- if(StringUtils.isNotBlank(reimbursement.getInvoiceNumber()) || StringUtils.isNotBlank(reimbursement.getProposer()) || StringUtils.isNotBlank(reimbursement.getPartner())){
|
|
|
+ if(StringUtils.isNotBlank(reimbursement.getInvoiceNumber()) ||
|
|
|
+ StringUtils.isNotBlank(reimbursement.getProposer()) ||
|
|
|
+ StringUtils.isNotBlank(reimbursement.getPartner()) ||
|
|
|
+ null != reimbursement.getBeginDate() ||
|
|
|
+ null != reimbursement.getEndDate() ||
|
|
|
+ StringUtils.isNotBlank(reimbursement.getBeginIncome()) ||
|
|
|
+ StringUtils.isNotBlank(reimbursement.getEndIncome()) ||
|
|
|
+ StringUtils.isNotBlank(reimbursement.getFirmName())){
|
|
|
List<AccountantReimbursementDTO> invoiceList = mapper.getInvoiceList(reimbursement);
|
|
|
//如果存在发票信息,则根据发票的父节点查询对应的业务信息
|
|
|
if(invoiceList.size()>0){
|
|
@@ -227,16 +245,20 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //获取当前年份
|
|
|
+ Calendar date = Calendar.getInstance();
|
|
|
+ String year = String.valueOf(date.get(Calendar.YEAR));
|
|
|
+
|
|
|
//查询非空的业务编号数据在数据库中是否存在,若存在,返回已存在的业务编号集合
|
|
|
- List<String> oldBusinessCodeList = mapper.selectOldBusinessCode(businessCodeList);
|
|
|
+ List<AccountantReimbursementDTO> oldBusinessCodeList = mapper.selectOldBusinessCodeByInfo(businessCodeList,year);
|
|
|
if (oldBusinessCodeList.size()>0){
|
|
|
//如果数据库已存在部分业务编号信息,则去除该部分的业务编号信息
|
|
|
- for (String oldBusinessCode: oldBusinessCodeList) {
|
|
|
+ for (AccountantReimbursementDTO oldBusinessCode: oldBusinessCodeList) {
|
|
|
Iterator iterator = businessCodeInfoList.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
AccountantReimbursementDTO data = (AccountantReimbursementDTO) iterator.next();
|
|
|
- if (oldBusinessCode.equals(data.getBusinessCode())){
|
|
|
- iterator.remove();
|
|
|
+ if (oldBusinessCode.getBusinessCode().equals(data.getBusinessCode())){
|
|
|
+ data.setId(oldBusinessCode.getId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -245,28 +267,38 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
|
|
|
|
|
|
//将空的业务编号 的信息添加到集合中
|
|
|
businessCodeInfoList.addAll(businessCodeNullList);
|
|
|
+ List<AccountantReimbursementDTO> newBusinessCodeInfoList = Lists.newArrayList();
|
|
|
+ newBusinessCodeInfoList.addAll(businessCodeInfoList);
|
|
|
+
|
|
|
//对业务编号的数据进行新增保存
|
|
|
- for (AccountantReimbursementDTO newBusinessCodeInfo : businessCodeInfoList) {
|
|
|
- newBusinessCodeInfo.preInsert();
|
|
|
- newBusinessCodeInfo.setParentId("0");
|
|
|
- newBusinessCodeInfo.setParentIds("0,");
|
|
|
+ Iterator iterator = businessCodeInfoList.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ AccountantReimbursementDTO data = (AccountantReimbursementDTO) iterator.next();
|
|
|
+ if (StringUtils.isBlank(data.getId())){
|
|
|
+ data.preInsert();
|
|
|
+ data.setParentId("0");
|
|
|
+ data.setParentIds("0,");
|
|
|
+ data.setYear(year);
|
|
|
+ data.setRandomType("0");
|
|
|
+ }else{
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(businessCodeInfoList.size()>0){
|
|
|
+ mapper.insertBusinessCodeList(businessCodeInfoList);
|
|
|
}
|
|
|
- mapper.insertBusinessCodeList(businessCodeInfoList);
|
|
|
|
|
|
|
|
|
//业务编号对应的数据集合
|
|
|
List<AccountantReimbursementDTO> invoiceInfoList = Lists.newArrayList();
|
|
|
|
|
|
- for (AccountantReimbursementDTO info : businessCodeInfoList) {
|
|
|
+ for (AccountantReimbursementDTO info : newBusinessCodeInfoList) {
|
|
|
if(StringUtils.isNotBlank(info.getBusinessCode())){
|
|
|
//处理业务编号不为空的数据
|
|
|
for (String key : businessCodeListMap.keySet()) {
|
|
|
if(info.getBusinessCode().equals(key)){
|
|
|
List<AccountantReimbursementDTO> infoList = businessCodeListMap.get(key);
|
|
|
for (AccountantReimbursementDTO childrenInfo : infoList) {
|
|
|
- if(info.getBusinessCode().equals("2021-01768")){
|
|
|
- System.out.println("");
|
|
|
- }
|
|
|
childrenInfo.setParentId(info.getId());
|
|
|
String parentIds = "0," + info.getId() + ",";
|
|
|
childrenInfo.setParentIds(parentIds);
|
|
@@ -299,28 +331,19 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
|
|
|
@Override
|
|
|
@Transactional(readOnly = false)
|
|
|
public void saveBusiness(AccountantReimbursementDTO reimbursement) {
|
|
|
- //查询该业务编码在数据库中是否存在
|
|
|
- AccountantReimbursementDTO infoByBusinessCode = mapper.getInfoByBusinessCode(reimbursement.getBusinessCode());
|
|
|
- if(null != infoByBusinessCode){
|
|
|
- //如果存在该业务编码 则将该业务编码对应的发票数据的父节点变更为已存在的业务编码的id信息
|
|
|
- //根据id 查询对应的发票信息
|
|
|
- List<String> parentIdList = Lists.newArrayList();
|
|
|
- parentIdList.add(reimbursement.getId());
|
|
|
- List<AccountantReimbursementDTO> invoiceByParentIdList = mapper.getInvoiceByParentIdList(parentIdList);
|
|
|
- if(invoiceByParentIdList.size()>0){
|
|
|
- List<AccountantReimbursementDTO> updateInvoiceData = Lists.newArrayList();
|
|
|
- for (AccountantReimbursementDTO invoiceInfo: invoiceByParentIdList) {
|
|
|
- invoiceInfo.setBusinessCode(infoByBusinessCode.getBusinessCode());
|
|
|
- invoiceInfo.setParentId(infoByBusinessCode.getId());
|
|
|
- invoiceInfo.setParentIds("0," + infoByBusinessCode.getId() + ",");
|
|
|
- invoiceInfo.preUpdate();
|
|
|
- updateInvoiceData.add(invoiceInfo);
|
|
|
- }
|
|
|
- mapper.updateInvoiceList(updateInvoiceData);
|
|
|
+ //获取当前年份
|
|
|
+ Calendar date = Calendar.getInstance();
|
|
|
+ String year = String.valueOf(date.get(Calendar.YEAR));
|
|
|
+ reimbursement.setYear(year);
|
|
|
+
|
|
|
+ if("1".equals(reimbursement.getRandomType())){
|
|
|
+
|
|
|
+ //根据id查询业务信息是否已经是随机生成的业务编码
|
|
|
+ AccountantReimbursementDTO reimbursementInfo = mapper.queryBusinessById(reimbursement.getId());
|
|
|
+ if("1".equals(reimbursementInfo.getRandomType()) || StringUtils.isNotBlank(reimbursementInfo.getBusinessCode())){
|
|
|
+ return;
|
|
|
}
|
|
|
- //删除该业务编码信息
|
|
|
- mapper.deleteBusinessById(reimbursement.getId());
|
|
|
- }else{
|
|
|
+
|
|
|
//根据id查询对应发票信息
|
|
|
List<String> parentIdList = Lists.newArrayList();
|
|
|
parentIdList.add(reimbursement.getId());
|
|
@@ -328,6 +351,22 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
|
|
|
if(invoiceByParentIdList.size()>0){
|
|
|
List<AccountantReimbursementDTO> updateInvoiceData = Lists.newArrayList();
|
|
|
for (AccountantReimbursementDTO invoiceInfo: invoiceByParentIdList) {
|
|
|
+ synchronized (this){
|
|
|
+ //生成随机业务编号
|
|
|
+ //查询最后一个业务编号信息
|
|
|
+ String lastRandomBusinessCodeIndex = mapper.getLastRandomBusinessCodeIndex(year);
|
|
|
+ if(StringUtils.isBlank(lastRandomBusinessCodeIndex)){
|
|
|
+ lastRandomBusinessCodeIndex = "0";
|
|
|
+ }
|
|
|
+ Integer randomBusinessCodeIndex = Integer.parseInt(lastRandomBusinessCodeIndex) + 1;
|
|
|
+ reimbursement.setRandomBusinessCodeIndex(randomBusinessCodeIndex.toString());
|
|
|
+ //将新的序列号进行向左补齐4位
|
|
|
+ String padLeft = PublicUtil.padLeft(randomBusinessCodeIndex.toString(), 4, '0');
|
|
|
+ //生成新的随机业务编号
|
|
|
+ StringBuilder sbCode = new StringBuilder().append(year).append("-kjsj-").append(padLeft);
|
|
|
+ reimbursement.setBusinessCode(sbCode.toString());
|
|
|
+ }
|
|
|
+
|
|
|
invoiceInfo.setBusinessCode(reimbursement.getBusinessCode());
|
|
|
invoiceInfo.preUpdate();
|
|
|
updateInvoiceData.add(invoiceInfo);
|
|
@@ -336,7 +375,47 @@ public class AccountantReimbursementSysServiceImpl implements AccountantReimburs
|
|
|
}
|
|
|
reimbursement.preUpdate();
|
|
|
mapper.saveBusiness(reimbursement);
|
|
|
+ }else{
|
|
|
+ //查询该业务编码在数据库中是否存在(当年)
|
|
|
+ AccountantReimbursementDTO infoByBusinessCode = mapper.getInfoByBusinessCode(reimbursement);
|
|
|
+ if(null != infoByBusinessCode){
|
|
|
+ //如果存在该业务编码 则将该业务编码对应的发票数据的父节点变更为已存在的业务编码的id信息
|
|
|
+ //根据id 查询对应的发票信息
|
|
|
+ List<String> parentIdList = Lists.newArrayList();
|
|
|
+ parentIdList.add(reimbursement.getId());
|
|
|
+ List<AccountantReimbursementDTO> invoiceByParentIdList = mapper.getInvoiceByParentIdList(parentIdList);
|
|
|
+ if(invoiceByParentIdList.size()>0){
|
|
|
+ List<AccountantReimbursementDTO> updateInvoiceData = Lists.newArrayList();
|
|
|
+ for (AccountantReimbursementDTO invoiceInfo: invoiceByParentIdList) {
|
|
|
+ invoiceInfo.setBusinessCode(infoByBusinessCode.getBusinessCode());
|
|
|
+ invoiceInfo.setParentId(infoByBusinessCode.getId());
|
|
|
+ invoiceInfo.setParentIds("0," + infoByBusinessCode.getId() + ",");
|
|
|
+ invoiceInfo.preUpdate();
|
|
|
+ updateInvoiceData.add(invoiceInfo);
|
|
|
+ }
|
|
|
+ mapper.updateInvoiceList(updateInvoiceData);
|
|
|
+ }
|
|
|
+ //删除该业务编码信息
|
|
|
+ mapper.deleteBusinessById(reimbursement.getId());
|
|
|
+ }else{
|
|
|
+ //根据id查询对应发票信息
|
|
|
+ List<String> parentIdList = Lists.newArrayList();
|
|
|
+ parentIdList.add(reimbursement.getId());
|
|
|
+ List<AccountantReimbursementDTO> invoiceByParentIdList = mapper.getInvoiceByParentIdList(parentIdList);
|
|
|
+ if(invoiceByParentIdList.size()>0){
|
|
|
+ List<AccountantReimbursementDTO> updateInvoiceData = Lists.newArrayList();
|
|
|
+ for (AccountantReimbursementDTO invoiceInfo: invoiceByParentIdList) {
|
|
|
+ invoiceInfo.setBusinessCode(reimbursement.getBusinessCode());
|
|
|
+ invoiceInfo.preUpdate();
|
|
|
+ updateInvoiceData.add(invoiceInfo);
|
|
|
+ }
|
|
|
+ mapper.updateInvoiceList(updateInvoiceData);
|
|
|
+ }
|
|
|
+ reimbursement.preUpdate();
|
|
|
+ mapper.saveBusiness(reimbursement);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|