提交 a425d062 作者: guofeng

BSAD、BSID更新

上级 7762d5fe
......@@ -15,6 +15,8 @@ import com.huazheng.project.hana.model.Afpo;
import com.huazheng.project.hana.model.Aufk;
import com.huazheng.project.hana.model.Ausp;
import com.huazheng.project.hana.model.Bkpf;
import com.huazheng.project.hana.model.Bsad;
import com.huazheng.project.hana.model.Bsid;
import com.huazheng.project.hana.model.Kna1;
import com.huazheng.project.hana.model.Knvv;
import com.huazheng.project.hana.model.Konv;
......@@ -655,5 +657,64 @@ public class CheckDeleteServiceImpl {
redis1Template.opsForValue().set("huazheng:checkDeleteError:Zpoedit:rowNum", SomeUtils.getErrorInfoFromException(e));
}
}
public void selectBsadCheckByDelete() {
try {
ValueOperations<String, String> opsForValue = redis1Template.opsForValue();
opsForValue.setIfAbsent("huazheng:checkDelete:Bsad:rowNum", "0");
String rowNum = opsForValue.get("huazheng:checkDelete:Bsad:rowNum");
Bsad build = Bsad.builder().rowNum(rowNum).build();
List<Bsad> list = gpMapper.selectBsadCheck(build); // 从数仓中查询一组数据
if (list.size() == 0) {
redis1Template.opsForValue().set("huazheng:checkDelete:Bsad:rowNum", "0"); // 计数器复位
ThreadUtil.sleep(1000); // 没有数据了,休眠一下
}
list.forEach(target -> { // 遍历要检查的数据
Bsad source = sapMapper.selectBsadById(target); // 根据主键查询源库中的数据
String operator = "none";
if (source == null) { // 如果源库中没有数据
gpMapper.deleteBsad(target); // 删除数仓中的数据
operator = "delete";
}
redis1Template.opsForValue().set("huazheng:checkDelete:Bsad:rowNum", target.getRowNum());
if (!operator.equals("none")) {
log.info(String.format("selectBsadcheckDelete --> rowNum:%s, operator:%s", target.getRowNum(), operator));
}
});
} catch (Exception e) {
redis1Template.opsForValue().set("huazheng:checkDeleteError:Bsad:rowNum", SomeUtils.getErrorInfoFromException(e));
}
}
public void selectBsidCheckByDelete() {
try {
ValueOperations<String, String> opsForValue = redis1Template.opsForValue();
opsForValue.setIfAbsent("huazheng:checkDelete:Bsid:rowNum", "0");
String rowNum = opsForValue.get("huazheng:checkDelete:Bsid:rowNum");
Bsid build = Bsid.builder().rowNum(rowNum).build();
List<Bsid> list = gpMapper.selectBsidCheck(build); // 从数仓中查询一组数据
if (list.size() == 0) {
redis1Template.opsForValue().set("huazheng:checkDelete:Bsid:rowNum", "0"); // 计数器复位
ThreadUtil.sleep(1000); // 没有数据了,休眠一下
}
list.forEach(target -> { // 遍历要检查的数据
Bsid source = sapMapper.selectBsidById(target); // 根据主键查询源库中的数据
String operator = "none";
if (source == null) { // 如果源库中没有数据
gpMapper.deleteBsid(target); // 删除数仓中的数据
operator = "delete";
}
redis1Template.opsForValue().set("huazheng:checkDelete:Bsid:rowNum", target.getRowNum());
if (!operator.equals("none")) {
log.info(String.format("selectBsidcheckDelete --> rowNum:%s, operator:%s", target.getRowNum(), operator));
}
});
} catch (Exception e) {
redis1Template.opsForValue().set("huazheng:checkDeleteError:Bsid:rowNum", SomeUtils.getErrorInfoFromException(e));
}
}
}
......@@ -16,6 +16,8 @@ import com.huazheng.project.hana.model.Afpo;
import com.huazheng.project.hana.model.Aufk;
import com.huazheng.project.hana.model.Ausp;
import com.huazheng.project.hana.model.Bkpf;
import com.huazheng.project.hana.model.Bsad;
import com.huazheng.project.hana.model.Bsid;
import com.huazheng.project.hana.model.Kna1;
import com.huazheng.project.hana.model.Knvv;
import com.huazheng.project.hana.model.Konv;
......@@ -32,8 +34,10 @@ import com.huazheng.project.hana.model.Zpoedit;
import com.huazheng.project.hana.model.Zsd06;
import com.huazheng.project.hana.model.Zsdfhzl;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONUtil;
import lombok.extern.log4j.Log4j2;
......@@ -182,6 +186,21 @@ public class CheckUpdateServiceImpl {
ThreadUtil.safeSleep(500);
}
}
// 级联更新业务
List<Bsad> sBsadList = sapMapper.cascadeBsadByBkpf(source); // 级联查询源库afko表
for (Bsad sBsad : sBsadList) {
Bsad tBsad = gpMapper.selectBsad(sBsad); // 查询目标库中afko表
cascadeBsadCheckByUpdate(sBsad, tBsad); // 级联更新afko表
}
// 级联更新业务
List<Bsid> sBsidList = sapMapper.cascadeBsidByBkpf(source); // 级联查询源库afko表
for (Bsid sBsid : sBsidList) {
Bsid tBsid = gpMapper.selectBsid(sBsid); // 查询目标库中afko表
cascadeBsidCheckByUpdate(sBsid, tBsid); // 级联更新afko表
}
ThreadUtil.safeSleep(500);
}
}
......@@ -738,6 +757,148 @@ public class CheckUpdateServiceImpl {
}
}
// 所属selectBkpfCheckByUpdate的级联
private void cascadeBsadCheckByUpdate(Bsad source, Bsad target) {
if (target != null) { // 目标库有数据
String shash = SecureUtil.md5(JSONUtil.toJsonStr(source)); // 源库中数据的hash结果
String thash = target.getHashResult(); // 数仓中数据的hash结果
if (!shash.equals(thash)) { // 如果hash结果不一致
source.setHashResult(shash);
// ===============================
if (StrUtil.isBlank(source.getUmsks())) {
source.setUmskz(""); // 属于主键组,不能为空
}
String augdts = source.getAugdts(); // 日期转义
if (augdts == null || augdts.equals("00000000") || StrUtil.isBlank(augdts)) {
Date date = DateUtil.parse("1970-01-01 00:00:00");
source.setAugdt(date);
} else {
String erdat2 = new StringBuffer(augdts).insert(4, "-").insert(7, "-").toString();
Date date = DateUtil.parse(erdat2);
source.setAugdt(date);
}
String zfbdts = source.getZfbdts(); // 转义日期
if (zfbdts == null || zfbdts.equals("00000000") || StrUtil.isBlank(zfbdts)) {
Date date = DateUtil.parse("1970-01-01 00:00:00");
source.setZfbdt(date);
} else {
String erdat2 = new StringBuffer(zfbdts).insert(4, "-").insert(7, "-").toString();
Date date = DateUtil.parse(erdat2);
source.setZfbdt(date);
}
String budats = source.getBudats(); // 转义日期
if (budats == null || budats.equals("00000000") || StrUtil.isBlank(budats)) {
Date date = DateUtil.parse("1970-01-01 00:00:00");
source.setBudat(date);
source.setBudatc("1970-01");
source.setDqsjc(null); // 到期时间不用计算
} else {
String erdat2 = new StringBuffer(budats).insert(4, "-").insert(7, "-").toString();
Date date = DateUtil.parse(erdat2);
source.setBudat(date);
source.setBudatc(DateUtil.format(date, "yyyy-MM"));
int budatDay = Integer.parseInt(DateUtil.format(source.getBudat(), "dd")); // 过账日期
if (budatDay > 26) { // budat(过账日期) > 26号 :zfbdt(基准日期)+2个月
source.setDqsjc(DateUtil.offset(source.getZfbdt(), DateField.MONTH, 2)); // 到期时间
// 根据过账日期判断日是否>26,大于的话,就在过账日期的基础上加一个月,小于等于的话就是不变
source.setBudatd(DateUtil.format(DateUtil.offset(source.getBudat(), DateField.MONTH, 1), "yyyy-MM"));
} else if (budatDay <= 26) { // budat(过账日期) <= 26号 :zfbdt(基准日期)+1个月
source.setDqsjc(DateUtil.offset(source.getZfbdt(), DateField.MONTH, 1)); // 到期时间
// 根据过账日期判断日是否>26,大于的话,就在过账日期的基础上加一个月,小于等于的话就是不变
source.setBudatd(DateUtil.format(source.getBudat(), "yyyy-MM"));
}
if ("Z001".equals(source.getZterm())) {
source.setDqsjc(source.getZfbdt()); // 现款,到期时间=基准日期
}
}
// ===============================
while (true) {
try {
gpMapper.updateBsad(source); // 更新数据到数仓中
break;
} catch (RuntimeException e) {
log.error(e.getMessage());
ThreadUtil.safeSleep(500);
}
}
ThreadUtil.safeSleep(500);
}
}
}
// 所属selectBkpfCheckByUpdate的级联
private void cascadeBsidCheckByUpdate(Bsid source, Bsid target) {
if (target != null) { // 目标库有数据
String shash = SecureUtil.md5(JSONUtil.toJsonStr(source)); // 源库中数据的hash结果
String thash = target.getHashResult(); // 数仓中数据的hash结果
if (!shash.equals(thash)) { // 如果hash结果不一致
source.setHashResult(shash);
// ===============================
if (StrUtil.isBlank(source.getUmsks())) {
source.setUmskz(""); // 属于主键组,不能为空
}
String augdts = source.getAugdts(); // 日期转义
if (augdts == null || augdts.equals("00000000") || StrUtil.isBlank(augdts)) {
Date date = DateUtil.parse("1970-01-01 00:00:00");
source.setAugdt(date);
} else {
String erdat2 = new StringBuffer(augdts).insert(4, "-").insert(7, "-").toString();
Date date = DateUtil.parse(erdat2);
source.setAugdt(date);
}
String zfbdts = source.getZfbdts(); // 转义日期
if (zfbdts == null || zfbdts.equals("00000000") || StrUtil.isBlank(zfbdts)) {
Date date = DateUtil.parse("1970-01-01 00:00:00");
source.setZfbdt(date);
} else {
String erdat2 = new StringBuffer(zfbdts).insert(4, "-").insert(7, "-").toString();
Date date = DateUtil.parse(erdat2);
source.setZfbdt(date);
}
String budats = source.getBudats(); // 转义日期
if (budats == null || budats.equals("00000000") || StrUtil.isBlank(budats)) {
Date date = DateUtil.parse("1970-01-01 00:00:00");
source.setBudat(date);
source.setBudatc("1970-01");
source.setDqsjc(null); // 到期时间不用计算
} else {
String erdat2 = new StringBuffer(budats).insert(4, "-").insert(7, "-").toString();
Date date = DateUtil.parse(erdat2);
source.setBudat(date);
source.setBudatc(DateUtil.format(date, "yyyy-MM"));
int budatDay = Integer.parseInt(DateUtil.format(source.getBudat(), "dd")); // 过账日期
if (budatDay > 26) { // budat(过账日期) > 26号 :zfbdt(基准日期)+2个月
source.setDqsjc(DateUtil.offset(source.getZfbdt(), DateField.MONTH, 2)); // 到期时间
// 根据过账日期判断日是否>26,大于的话,就在过账日期的基础上加一个月,小于等于的话就是不变
source.setBudatd(DateUtil.format(DateUtil.offset(source.getBudat(), DateField.MONTH, 1), "yyyy-MM"));
} else if (budatDay <= 26) { // budat(过账日期) <= 26号 :zfbdt(基准日期)+1个月
source.setDqsjc(DateUtil.offset(source.getZfbdt(), DateField.MONTH, 1)); // 到期时间
// 根据过账日期判断日是否>26,大于的话,就在过账日期的基础上加一个月,小于等于的话就是不变
source.setBudatd(DateUtil.format(source.getBudat(), "yyyy-MM"));
}
if ("Z001".equals(source.getZterm())) {
source.setDqsjc(source.getZfbdt()); // 现款,到期时间=基准日期
}
}
// ===============================
while (true) {
try {
gpMapper.updateBsid(source); // 更新数据到数仓中
break;
} catch (RuntimeException e) {
log.error(e.getMessage());
ThreadUtil.safeSleep(500);
}
}
ThreadUtil.safeSleep(500);
}
}
}
// 所属selectAufkCheckByUpdate的级联
private void cascadeZpoeditCheckByUpdate(Zpoedit source, Zpoedit target) {
if (target != null) { // 目标库有数据
......
......@@ -111,6 +111,12 @@ public interface SapMapper {
public List<Makt> cascadeMaktByMara(Mara mara);
public List<Vbuk> cascadeVbukByLips(Lips lips);
public List<Zpoedit> cascadeZpoeditByAufk(Aufk aufk);
public List<Bsad> cascadeBsadByBkpf(Bkpf bkpf);
public List<Bsid> cascadeBsidByBkpf(Bkpf bkpf);
// ......
public Bkpf selectBkpfById(Bkpf target);
......@@ -149,5 +155,6 @@ public interface SapMapper {
public Bsid selectBsidById(Bsid target);
public Vbap selectVbapById(Vbap target);
public Tvkbt selectTvkbtById(Tvkbt target);
}
......@@ -483,8 +483,20 @@
from ${hana_user}.Zpo_edit
where aufnr = #{aufnr} ${hana_mandt}
</select>
<select id="cascadeBsadByBkpf" parameterType="Bkpf" resultType="Bsad">
select
a.vbeln,a.mandt,a.bukrs,a.kunnr,a.umsks,a.umskz,a.augdt as augdts,a.augbl,a.zuonr,a.gjahr,a.belnr,a.buzei,a.buzei as buzeis,
a.blart,a.waers,a.wrbtr,a.shkzg,a.budat as budats,a.zfbdt as zfbdts,a.zterm
from ${hana_user}.bsad a
where a.bukrs = #{bukrs} and a.belnr = #{belnr} and a.gjahr = #{gjahr} and a.mandt = '800'
</select>
<select id="cascadeBsidByBkpf" parameterType="Bkpf" resultType="Bsid">
select
a.vbeln,a.mandt,a.bukrs,a.kunnr,a.umsks,a.umskz,a.augdt as augdts,a.augbl,a.zuonr,a.gjahr,a.belnr,a.buzei,a.buzei as buzeis,
a.blart,a.waers,a.wrbtr,a.shkzg,a.budat as budats,a.zfbdt as zfbdts,a.zterm
from ${hana_user}.bsid a
where a.bukrs = #{bukrs} and a.belnr = #{belnr} and a.gjahr = #{gjahr} and a.mandt = '800'
</select>
<select id="selectAfkoById" parameterType="Afko" resultType="Afko">
......
......@@ -668,15 +668,6 @@
<property name="jobDetail">
<bean parent="methodJobDetail">
<property name="targetObject" ref="deleteUpdateJobServiceImpl" />
<property name="targetMethod" value="checkJob7" />
</bean>
</property>
<property name="cronExpression" value="* * * * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail">
<bean parent="methodJobDetail">
<property name="targetObject" ref="deleteUpdateJobServiceImpl" />
<property name="targetMethod" value="checkJob8" />
</bean>
</property>
......@@ -987,7 +978,24 @@
</property>
<property name="cronExpression" value="* * * * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail">
<bean parent="methodJobDetail">
<property name="targetObject" ref="checkDeleteServiceImpl" />
<property name="targetMethod" value="selectBsadCheckByDelete" />
</bean>
</property>
<property name="cronExpression" value="* * * * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail">
<bean parent="methodJobDetail">
<property name="targetObject" ref="checkDeleteServiceImpl" />
<property name="targetMethod" value="selectBsidCheckByDelete" />
</bean>
</property>
<property name="cronExpression" value="* * * * * ?" />
</bean>
</list>
</constructor-arg>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论