Commit 85892527 authored by 位宇华's avatar 位宇华

现金流量--代码提交

parent 7776e3e4
package com.tianyi.sync.controller;
import com.tianyi.sync.service.CashFlowService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CashFlowController {
private final CashFlowService cashFlowService;
public CashFlowController(CashFlowService cashFlowService) {
this.cashFlowService = cashFlowService;
}
/**
* 现金流量
* @return
*/
@PostMapping("/cash/flow")
public Object cashFlow(){
return cashFlowService.cashFlow();
}
}
package com.tianyi.sync.mapper.master;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.tianyi.sync.model.CashFlowModel;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@DS("master")
public interface CashFlowMapper {
List<CashFlowModel> getCashFlowInfo(@Param("period") String period,@Param("codeStr") String codeStr);
}
package com.tianyi.sync.mapper.slave;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.tianyi.sync.model.CashFlowModel;
import com.tianyi.sync.model.FallDataModel;
import com.tianyi.sync.model.ParmDataModel;
import org.apache.ibatis.annotations.Param;
......@@ -15,4 +16,8 @@ public interface FallSlaveMapper {
void delete(ParmDataModel parmDataModel);
List<String> getCodeList();
void save(@Param("cashFlowModels") List<CashFlowModel> cashFlowModels);
void deleteCashFlow(@Param("period") String period);
}
package com.tianyi.sync.model;
import java.io.Serializable;
import java.math.BigDecimal;
public class CashFlowModel implements Serializable {
private String period;
private String voucher;
private String cashflowitem;
private String direction;
private BigDecimal money;
private String itemcode;
private String itemname;
private String entityname;
private String entitycode;
private String icpcode;
private String icpname;
public String getPeriod() {
return period;
}
public void setPeriod(String period) {
this.period = period;
}
public String getVoucher() {
return voucher;
}
public void setVoucher(String voucher) {
this.voucher = voucher;
}
public String getCashflowitem() {
return cashflowitem;
}
public void setCashflowitem(String cashflowitem) {
this.cashflowitem = cashflowitem;
}
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
public BigDecimal getMoney() {
return money;
}
public void setMoney(BigDecimal money) {
this.money = money;
}
public String getItemcode() {
return itemcode;
}
public void setItemcode(String itemcode) {
this.itemcode = itemcode;
}
public String getItemname() {
return itemname;
}
public void setItemname(String itemname) {
this.itemname = itemname;
}
public String getEntityname() {
return entityname;
}
public void setEntityname(String entityname) {
this.entityname = entityname;
}
public String getEntitycode() {
return entitycode;
}
public void setEntitycode(String entitycode) {
this.entitycode = entitycode;
}
public String getIcpcode() {
return icpcode;
}
public void setIcpcode(String icpcode) {
this.icpcode = icpcode;
}
public String getIcpname() {
return icpname;
}
public void setIcpname(String icpname) {
this.icpname = icpname;
}
}
package com.tianyi.sync.service;
public interface CashFlowService {
Object cashFlow();
}
package com.tianyi.sync.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tianyi.sync.mapper.master.CashFlowMapper;
import com.tianyi.sync.mapper.slave.FallSlaveMapper;
import com.tianyi.sync.model.CashFlowModel;
import com.tianyi.sync.service.CashFlowService;
import com.tianyi.sync.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StopWatch;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class CashFlowServiceImpl implements CashFlowService {
private final static Logger logger= LoggerFactory.getLogger(CashFlowServiceImpl.class);
private final CashFlowMapper cashFlowMapper;
private final FallSlaveMapper fallSlaveMapper;
public CashFlowServiceImpl(CashFlowMapper cashFlowMapper, FallSlaveMapper fallSlaveMapper) {
this.cashFlowMapper = cashFlowMapper;
this.fallSlaveMapper = fallSlaveMapper;
}
@Override
public Object cashFlow() {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
String period= DateUtils.getYearAndMonthLast();
List<String> stringList=fallSlaveMapper.getCodeList().stream().map(v->v.replaceAll("[a-zA-Z]", StringUtils.EMPTY)).collect(Collectors.toList());
List<CashFlowModel> cashFlowModels=new ArrayList<>();
stringList.forEach(v->{
List<CashFlowModel> cashFlowModelList=cashFlowMapper.getCashFlowInfo(period, v);
cashFlowModels.addAll(cashFlowModelList);
});
if (!CollectionUtils.isEmpty(cashFlowModels)){
fallSlaveMapper.deleteCashFlow(period);
fallSlaveMapper.save(cashFlowModels);
}
stopWatch.stop();
logger.info("执行耗时:{}",stopWatch.getTotalTimeMillis());
JSONObject jsonObject = new JSONObject();
jsonObject.put("msg","保存成功!");
return jsonObject;
}
}
package com.tianyi.sync.task;
import com.tianyi.sync.service.CashFlowService;
import com.tianyi.sync.service.DataSyncService;
import com.tianyi.sync.service.LiabilitiesDataSyncService;
import com.tianyi.sync.service.ProfitDataSyncService;
......@@ -18,11 +19,15 @@ public class ScheduleTask {
private final DataSyncService dataSyncService;
private final CashFlowService cashFlowService;
private final ProfitDataSyncService profitDataSyncService;
private final LiabilitiesDataSyncService liabilitiesDataSyncService;
public ScheduleTask(DataSyncService dataSyncService, ProfitDataSyncService profitDataSyncService, LiabilitiesDataSyncService liabilitiesDataSyncService) {
public ScheduleTask(DataSyncService dataSyncService, CashFlowService cashFlowService, ProfitDataSyncService profitDataSyncService, LiabilitiesDataSyncService liabilitiesDataSyncService) {
this.dataSyncService = dataSyncService;
this.cashFlowService = cashFlowService;
this.profitDataSyncService = profitDataSyncService;
this.liabilitiesDataSyncService = liabilitiesDataSyncService;
}
......@@ -36,6 +41,7 @@ public class ScheduleTask {
dataSyncService.sync();
logger.info("定时任务执行成功!!!!!!");
}
/**
* 每月3号10.30执行一次
*/
......@@ -45,6 +51,7 @@ public class ScheduleTask {
profitDataSyncService.profitSync();
logger.info("定时任务执行成功!!!!!!");
}
/**
* 每月3号10.30执行一次
*/
......@@ -54,4 +61,11 @@ public class ScheduleTask {
liabilitiesDataSyncService.liabilitiesSync();
logger.info("资产负债定时任务执行成功!!!!!!");
}
@Async
@Scheduled
public void cashFlow() {
cashFlowService.cashFlow();
logger.info("现金流量定时任务成功!");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tianyi.sync.mapper.master.CashFlowMapper">
<select id="getCashFlowInfo" resultType="com.tianyi.sync.model.CashFlowModel">
select
cashflow.period ,
cashflow.voucher,
cashflow.cashflowitem ,
cashflow.direction,
cashflow.amountoriginal as money,
item.code as itemcode ,
item.name as itemname,
acc.name as entityname,
acc.code as entitycode,
accentity.code as icpcode,
accentity.name as icpname
from
figl.cf_cashflow cashflow
inner join fiepub.epub_cashflowitem item on
cashflow.cashflowitem = item.id
left join figl.fi_voucher_b b on
b.id = cashflow.voucherrecord
left join fiepub.epub_accountbook acc on
cashflow.accbook = acc.id
left join fiepub.epub_accountbook accentity on
cashflow.innerorg = accentity.accentity
where
cashflow.innerorg is not null
and cashflow.period = #{period}
and acc.code =#{codeStr}
</select>
</mapper>
\ No newline at end of file
......@@ -11,15 +11,28 @@
#{item.c1},#{item.c2},#{item.c3},#{item.c4})
</foreach>
</insert>
<delete id="delete">
delete
from elim
where `year` = #{year}
and `month`=#{month}
and `source` = 1
and `month` = #{month}
and `source` = 1
</delete>
<delete id="deleteCashFlow">
delete from elimtable.free_query_cashflow where yearm=#{period}
</delete>
<select id="getCodeList" resultType="java.lang.String">
select code
from icp
</select>
<insert id="save">
INSERT INTO
elimtable.free_query_cashflow(yearm,accbook,voucher,direction,money,itemcode,itemname,entityname,entitycode,icpcode,icpname)
values
<foreach collection="cashFlowModels" index="index" item="item" separator=",">
(#{item.period},#{item.entitycode},#{item.voucher},#{item.direction},#{item.money},#{item.itemcode},#{item.itemname},#{item.entityname},#{item.entitycode},#{item.icpcode},#{item.icpname})
</foreach>
</insert>
</mapper>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment