@@ -4,14 +4,8 @@ import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.IdWorker ;
import com.ruoyi.common.core.utils.StringUtils ;
import com.ruoyi.common.security.utils.SecurityUtils ;
import com.ruoyi.invest.domain.AccountsDealRecord ;
import com.ruoyi.invest.domain.CreditCardBill ;
import com.ruoyi.invest.domain.InstallmentHistory ;
import com.ruoyi.invest.domain.InstallmentHistoryDetail ;
import com.ruoyi.invest.domain.dto.AccountsDealRecordDto ;
import com.ruoyi.invest.domain.dto.BankCardLendDto ;
import com.ruoyi.invest.domain.dto.CreditCardBillDto ;
import com.ruoyi.invest.domain.dto.InstallmentHistoryDetailDto ;
import com.ruoyi.invest.domain.* ;
import com.ruoyi.invest.domain.dto.* ;
import com.ruoyi.invest.domain.vo.* ;
import com.ruoyi.invest.mapper.* ;
import com.ruoyi.job.service.IInvestJobService ;
@@ -49,6 +43,12 @@ public class InvestJobImpl implements IInvestJobService
@Resource
private InstallmentHistoryMapper installmentHistoryMapper ;
@Resource
private FutureStocksBillMapper futureStocksBillMapper ;
@Resource
private FutureStocksMapper futureStocksMapper ;
/**
* 生成数据
*
@@ -305,4 +305,107 @@ public class InvestJobImpl implements IInvestJobService
return accountsDealRecordMapper . insertAccountsDealRecord ( accountsDealRecord ) ;
}
/**
* 生成数据
*
* @author tianyongbao
* @date 2023-12-11
*/
@Override
public void generateFutureStocksBill ( ) {
//未出账单生成, 定时任务, 每1个小时同步计算一次, 作为未出账单, 根据投资账户基础信息, 遍历投资账户记录信息表和交易记录表即可
FutureStocksDto futureStocksDto = new FutureStocksDto ( ) ;
// futureStocksDto.setStatus("1");
List < FutureStocksVo > list = futureStocksMapper . selectFutureStocksList ( futureStocksDto ) ;
// 获取当前日期
LocalDate currentDate = LocalDate . now ( ) ;
int month = currentDate . getMonthValue ( ) ;
int year = currentDate . getYear ( ) ;
int dayOfMonth = currentDate . getDayOfMonth ( ) ;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat ( " yyyy年MM月账单 " ) ;
SimpleDateFormat formatter = new SimpleDateFormat ( " yyyy-MM-dd " ) ;
SimpleDateFormat formatterTime = new SimpleDateFormat ( " yyyy-MM-dd HH:mm:ss " ) ;
SimpleDateFormat yearFormatter = new SimpleDateFormat ( " yyyy " ) ;
SimpleDateFormat monthFormatter = new SimpleDateFormat ( " yyyy-MM " ) ;
Date billDate = new Date ( ) ;
//遍历数据,获取信用卡账单日及数据
for ( FutureStocksVo futureStocksVo : list ) {
//如果不是正常使用的账户,不需要生成账单信息
if ( ! futureStocksVo . getStatus ( ) . equals ( " 1 " ) ) {
continue ;
}
Calendar calendarStart = Calendar . getInstance ( ) ;
calendarStart . setTime ( billDate ) ;
calendarStart . set ( Calendar . DAY_OF_MONTH , 1 ) ; // 设置为当月的第一天
Date startDate = calendarStart . getTime ( ) ;
String periodStart = formatter . format ( startDate ) ;
Calendar calendarEnd = Calendar . getInstance ( ) ;
calendarEnd . setTime ( billDate ) ;
int lastDay = calendarEnd . getActualMaximum ( Calendar . DAY_OF_MONTH ) ; // 当月的最后一天
calendarEnd . set ( Calendar . DAY_OF_MONTH , lastDay ) ;
Date endDate = calendarEnd . getTime ( ) ;
String periodEnd = formatter . format ( endDate ) ;
double billAmount = 0 ;
AccountsDealRecordDto accountsDealRecordDto = new AccountsDealRecordDto ( ) ;
accountsDealRecordDto . setAccountId ( futureStocksVo . getId ( ) ) ;
try {
accountsDealRecordDto . setStartDateTime ( formatterTime . parse ( periodStart + " 00:00:00 " ) ) ;
accountsDealRecordDto . setEndDateTime ( formatterTime . parse ( periodEnd + " 23:59:59 " ) ) ;
} catch ( ParseException e ) {
throw new RuntimeException ( e ) ;
}
accountsDealRecordDto . setDealCategory ( " 2 " ) ;
//获取所有交易记录
List < AccountsDealRecordVo > accountsDealRecordVoList = accountsDealRecordMapper . selectAccountsDealRecordList ( accountsDealRecordDto ) ;
//收入转为负数
for ( AccountsDealRecordVo vo : accountsDealRecordVoList
) {
if ( vo . getDealType ( ) . equals ( " 1 " ) ) {
vo . setAmount ( vo . getAmount ( ) * ( - 1 ) ) ;
}
}
//如果存在交易记录,进行账单汇总,否则不进行
if ( accountsDealRecordVoList . size ( ) > 0 ) {
billAmount = accountsDealRecordVoList . stream ( ) . mapToDouble ( AccountsDealRecordVo : : getAmount ) . sum ( ) ;
FutureStocksBillDto futureStocksBillDto = new FutureStocksBillDto ( ) ;
futureStocksBillDto . setFutureStocksId ( futureStocksVo . getId ( ) ) ;
String billMonth = year + " - " + String . format ( " %02d " , month ) ;
futureStocksBillDto . setBillMonth ( billMonth ) ;
List < FutureStocksBillVo > futureStocksBillVoList = futureStocksBillMapper . selectFutureStocksBillList ( futureStocksBillDto ) ;
if ( futureStocksBillVoList . size ( ) > 0 ) {
FutureStocksBillVo futureStocksBillVo = futureStocksBillVoList . get ( 0 ) ;
FutureStocksBill futureStocksBill = new FutureStocksBill ( ) ;
futureStocksBill . setUpdateBy ( SecurityUtils . getUsername ( ) ) ;
futureStocksBill . setUpdateTime ( DateUtils . getNowDate ( ) ) ;
futureStocksBill . setId ( futureStocksVo . getId ( ) ) ;
futureStocksBill . setBillAmount ( billAmount ) ;
//更新账单
futureStocksBillMapper . updateFutureStocksBill ( futureStocksBill ) ;
} else {
//进行插入操作
FutureStocksBill futureStocksBill = new FutureStocksBill ( ) ;
futureStocksBill . setBillDate ( endDate ) ;
futureStocksBill . setName ( simpleDateFormat . format ( endDate ) ) ;
futureStocksBill . setBillDatePeriod ( periodStart + " ~ " + periodEnd ) ;
futureStocksBill . setCreateBy ( futureStocksVo . getCreateBy ( ) ) ;
futureStocksBill . setCreateTime ( DateUtils . getNowDate ( ) ) ;
futureStocksBill . setId ( IdWorker . getId ( ) ) ;
futureStocksBill . setFutureStocksId ( futureStocksVo . getId ( ) ) ;
futureStocksBill . setBillAmount ( billAmount ) ;
futureStocksBill . setBillDatePeriod ( periodStart + " ~ " + periodEnd ) ;
futureStocksBill . setBillYear ( yearFormatter . format ( futureStocksBill . getBillDate ( ) ) ) ;
futureStocksBill . setBillMonth ( monthFormatter . format ( futureStocksBill . getBillDate ( ) ) ) ;
//插入未出账单
futureStocksBillMapper . insertFutureStocksBill ( futureStocksBill ) ;
}
}
}
}
}