|
|
|
@@ -6,6 +6,8 @@ import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.dto.FinanceSetOffDTO; |
|
|
|
import com.iformall.domain.dto.WxBillPayDTO; |
|
|
|
import com.iformall.domain.po.MallUserInfo; |
|
|
|
@@ -19,6 +21,7 @@ import com.iformall.domain.po.WxMerchant; |
|
|
|
import com.iformall.domain.po.WxShop; |
|
|
|
import com.iformall.domain.po.base.TenantEntity; |
|
|
|
import com.iformall.domain.po.base.WxBillBaseEntity; |
|
|
|
import com.iformall.domain.vo.FinanceBillSetoffSum; |
|
|
|
import com.iformall.enums.EnumBillAllType; |
|
|
|
import com.iformall.enums.EnumBillStatus; |
|
|
|
import com.iformall.enums.EnumFinanceReceiveStatus; |
|
|
|
@@ -172,11 +175,34 @@ public class WxFinanceServiceImpl implements WxFinanceService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<WxFinanceReceive> getMerchantAdvanceGroupSumList(WxFinanceReceive record){ |
|
|
|
return wxFinanceReceiveMapper.getMerchantAdvanceGroupSumList(record); |
|
|
|
public FinanceBillSetoffSum getBillSetoffSum(WxFinanceReceive record) { |
|
|
|
record.setType(EnumFinanceReceiveType.ADVANCE.getCode()); |
|
|
|
record.setStatus(EnumFinanceReceiveStatus.NORMAL.getCode()); |
|
|
|
List<WxFinanceReceive> advanceList = wxFinanceReceiveMapper.getMerchantAdvanceGroupSumList(record); |
|
|
|
BigDecimal total = new BigDecimal(0); |
|
|
|
FinanceBillSetoffSum retMap = new FinanceBillSetoffSum(); |
|
|
|
if (null != advanceList && advanceList.size() > 0 ) { |
|
|
|
WxEnergyFees fat = new WxEnergyFees(); |
|
|
|
fat.updateTenantInfo(record); |
|
|
|
Map<Long, WxEnergyFees> advanceTypMap = wxEnergyService.getFeesMap(fat); |
|
|
|
for (int i = 0 ; i < advanceList.size() ; i++) { |
|
|
|
WxFinanceReceive at = advanceList.get(i); |
|
|
|
if (null != at.getFeesId() && null != advanceTypMap) { |
|
|
|
WxEnergyFees wfat = advanceTypMap.get(at.getFeesId()); |
|
|
|
if (null != wfat) { |
|
|
|
at.setFeesName(wfat.getName()); |
|
|
|
at.setRate(wfat.getRate()); |
|
|
|
} |
|
|
|
total.add(new BigDecimal(at.getRemain())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
retMap.setTotal(total); |
|
|
|
retMap.setAdvanceList(advanceList); |
|
|
|
return retMap; |
|
|
|
} |
|
|
|
|
|
|
|
private List<WxFinanceReceive> getAdvanceListByFeesId(TenantEntity tenantEntity,Long feesId) { |
|
|
|
private FinanceBillSetoffSum getAdvanceListByFeesId(TenantEntity tenantEntity,Long feesId) { |
|
|
|
WxEnergyFeesSetoff tf = new WxEnergyFeesSetoff(); |
|
|
|
tf.updateTenantInfo(tenantEntity); |
|
|
|
tf.setFeesId(feesId); |
|
|
|
@@ -185,48 +211,36 @@ public class WxFinanceServiceImpl implements WxFinanceService { |
|
|
|
WxFinanceReceive faq = new WxFinanceReceive(); |
|
|
|
faq.updateTenantInfo(tenantEntity); |
|
|
|
faq.setFeesIdList(feesIdList); |
|
|
|
return wxFinanceReceiveMapper.findList(faq); |
|
|
|
return getBillSetoffSum(faq); |
|
|
|
}else { |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Map> getSetOffList(FinanceSetOffDTO dto) { |
|
|
|
//根据账单的科目查询可抵扣的预充值 |
|
|
|
WxMerchant merchant = new WxMerchant(); |
|
|
|
merchant.updateTenantInfo(dto); |
|
|
|
WxBillBaseEntity be = wxBillAllHelper.getBillDetail(EnumBillAllType.getEnum(dto.getBillType()), merchant, dto.getBillId()); |
|
|
|
if (null == be) { |
|
|
|
return null; |
|
|
|
public List<WxFinanceReceive> getSetOffList(FinanceSetOffDTO dto) { |
|
|
|
if (null == dto.getBills() || dto.getBills().size() <= 0 ) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"请选择账单"); |
|
|
|
} |
|
|
|
//通过科目去查询可以抵扣的预充费用 |
|
|
|
List<WxFinanceReceive> advanceList = getAdvanceListByFeesId(dto, be.getEnergyFeesId()); |
|
|
|
|
|
|
|
if (null != advanceList && advanceList.size() > 0 ) { |
|
|
|
WxEnergyFees atq = new WxEnergyFees(); |
|
|
|
atq.updateTenantInfo(dto); |
|
|
|
Map<Long, WxEnergyFees> typeMap = wxEnergyService.getFeesMap(atq); |
|
|
|
List retList = new ArrayList(); |
|
|
|
for (int i = 0 ; i < advanceList.size() ; i ++) { |
|
|
|
WxFinanceReceive a = advanceList.get(i); |
|
|
|
Map m = new HashMap(); |
|
|
|
m.put("id", a.getId()); |
|
|
|
if (null != typeMap && null != a.getFeesId()) { |
|
|
|
WxEnergyFees fat = typeMap.get(a.getFeesId()); |
|
|
|
if (null != fat) { |
|
|
|
m.put("name", fat.getName()); |
|
|
|
m.put("rate", fat.getRate()); |
|
|
|
m.put("money", calcuteSetOffMoney(fat.getRate(),be.getOwe())); |
|
|
|
} |
|
|
|
} |
|
|
|
retList.add(m); |
|
|
|
Long billFeesId = null; |
|
|
|
for (int i = 0 ; i < dto.getBills().size(); i++) { |
|
|
|
WxBillBaseEntity b = dto.getBills().get(i); |
|
|
|
if (null == billFeesId) { |
|
|
|
billFeesId = b.getEnergyFeesId(); |
|
|
|
}else if (billFeesId.equals(b.getEnergyFeesId())) { |
|
|
|
}else if (!billFeesId.equals(b.getEnergyFeesId())) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"请选择相同科目"); |
|
|
|
} |
|
|
|
return retList; |
|
|
|
} |
|
|
|
return null; |
|
|
|
//通过账单科目去查询可以抵扣的预充费用 |
|
|
|
FinanceBillSetoffSum sum = getAdvanceListByFeesId(dto, billFeesId); |
|
|
|
if (null == sum) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
return sum.getAdvanceList(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String calcuteSetOffMoney(String rate,String money) { |
|
|
|
if (new BigDecimal(money).compareTo(new BigDecimal(0)) <= 0) { |
|
|
|
return "0"; |
|
|
|
@@ -235,10 +249,22 @@ public class WxFinanceServiceImpl implements WxFinanceService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public WxBillBaseEntity setOff(FinanceSetOffDTO dto,MallUserInfo user) { |
|
|
|
public WxBillBaseEntity calcuetSetOff(FinanceSetOffDTO dto,MallUserInfo user) { |
|
|
|
//多个账单类型和科目必须一致 |
|
|
|
//优先冲抵时间早的账单,优先用时间早的预充费用来冲抵 |
|
|
|
if (null == dto.getBills() || dto.getBills().size() <= 0 || null == dto.getFeesIdList() || dto.getFeesIdList().size() <= 0 ) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"请选择账单和抵扣科目"); |
|
|
|
} |
|
|
|
//查询出账单可以抵扣的科目预收项 |
|
|
|
List<WxFinanceReceive> advanceList = getSetOffList(dto); |
|
|
|
WxBillBaseEntity bill = wxBillAllHelper.getBillDetail(EnumBillAllType.getEnum(be.getBillType()), merchant, be.getId()); |
|
|
|
if (new BigDecimal(bill.getOwe()).compareTo(b0) <= 0 ) { |
|
|
|
}else { |
|
|
|
billList.add(bill); |
|
|
|
} |
|
|
|
|
|
|
|
//根据预充规则计算冲抵费用 |
|
|
|
WxMerchant merchant = new WxMerchant(); |
|
|
|
merchant.updateTenantInfo(dto); |
|
|
|
|
|
|
|
WxBillBaseEntity bill = wxBillAllHelper.getBillDetail(EnumBillAllType.getEnum(dto.getBillType()), merchant, dto.getBillId()); |
|
|
|
if (new BigDecimal(bill.getOwe()).compareTo(new BigDecimal(0)) <= 0) { |
|
|
|
return null; |
|
|
|
@@ -370,7 +396,7 @@ public class WxFinanceServiceImpl implements WxFinanceService { |
|
|
|
return page; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public void saveOrUpdateReceive(WxFinanceReceive record, MallUserInfo user) { |
|
|
|
Date date = new Date(); |
|
|
|
@@ -432,6 +458,27 @@ public class WxFinanceServiceImpl implements WxFinanceService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void sortBills(List<WxBillBaseEntity> billList) { |
|
|
|
Collections.sort(billList, new Comparator<WxBillBaseEntity>() { |
|
|
|
@Override |
|
|
|
public int compare(WxBillBaseEntity o1, WxBillBaseEntity o2) { |
|
|
|
if (o1.getStarttime().before(o2.getStarttime())) { |
|
|
|
return -1; |
|
|
|
}else if (o1.getStarttime().equals(o2.getStarttime())) { |
|
|
|
if (o1.getEndtime().before(o2.getEndtime())) { |
|
|
|
return -1; |
|
|
|
}else if (o1.getEndtime().equals(o2.getEndtime())) { |
|
|
|
return 0; |
|
|
|
}else { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
}else { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public List<WxBillBaseEntity> createReceive(WxFinanceReceive record,MallUserInfo user) { |
|
|
|
@@ -451,24 +498,7 @@ public class WxFinanceServiceImpl implements WxFinanceService { |
|
|
|
if (billList.size() <= 0 ) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
Collections.sort(billList, new Comparator<WxBillBaseEntity>() { |
|
|
|
@Override |
|
|
|
public int compare(WxBillBaseEntity o1, WxBillBaseEntity o2) { |
|
|
|
if (o1.getStarttime().before(o2.getStarttime())) { |
|
|
|
return -1; |
|
|
|
}else if (o1.getStarttime().equals(o2.getStarttime())) { |
|
|
|
if (o1.getEndtime().before(o2.getEndtime())) { |
|
|
|
return -1; |
|
|
|
}else if (o1.getEndtime().equals(o2.getEndtime())) { |
|
|
|
return 0; |
|
|
|
}else { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
}else { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
sortBills(billList); |
|
|
|
//增加一条收款记录。关联账单,账单更新收款信息 |
|
|
|
BigDecimal total = new BigDecimal(0); |
|
|
|
for (int i = 0 ; i < record.getPayWays().size() ; i ++) { |
|
|
|
|