Commit fe73d4f2 authored by hongguangwu's avatar hongguangwu

定时器

parent 256173ba
package com.yifu.cloud.plus.v1.yifu.common.dapr.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
/**
* @Author hgw
* @Date 2022-7-27 19:38:08
* @Description
* @Version 1.0
*/
@Data
@Component
@PropertySource("classpath:daprConfig.properties")
@ConfigurationProperties(value = "dapr.social", ignoreInvalidFields = false)
public class DaprSocialProperties {
/*
* @author fxj
* @date 14:34
* @Description dapr sidercar url 如:http://localhost:3005/v1.0/invoke/
**/
String appUrl;
/*
* @author fxj
* @date 14:35
* @decription app_id 如:"yifu_upms_sider"
**/
String appId;
String appPort;
String httpPort;
String grpcPort;
String metricsPort;
}
package com.yifu.cloud.plus.v1.job.compont;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants;
import com.yifu.cloud.plus.v1.yifu.common.dapr.config.DaprArchivesProperties;
import com.yifu.cloud.plus.v1.yifu.common.dapr.config.DaprSocialProperties;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.HttpDaprUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @Author hgw
* @Date 2022-7-27 19:37:14
* @Description 社保定时任务
* @Version 1.0
*/
@Component(value = "socialTask")
@Slf4j
@EnableConfigurationProperties(DaprSocialProperties.class)
public class SocialTask {
@Autowired
private DaprSocialProperties daprProperties;
/**
* @Description: 定时生成基数配置新增的数据
* @Author: hgw
* @Date: 2022/7/27 19:39
* @return: void
**/
public void updateForecastLibaryBySysBase() {
log.info("------------定时生成基数配置新增的数据-定时任务开始------------");
HttpDaprUtil.invokeMethodPost(daprProperties.getAppUrl(),daprProperties.getAppId(),"/tforecastlibrary/inner/updateForecastLibaryBySysBase","", Object.class, SecurityConstants.FROM_IN);
log.info("------------定时生成基数配置新增的数据-定时任务结束------------");
}
/**
* @Description: 每月定时生成下月预估库数据
*
* 必须在【定时生成基数配置新增的数据】之后执行
*
* @Author: hgw
* @Date: 2022/7/27 19:39
* @return: void
**/
public void everyMonthCreateForecastLibary() {
log.info("------------每月定时生成下月预估库数据-定时任务开始------------");
HttpDaprUtil.invokeMethodPost(daprProperties.getAppUrl(),daprProperties.getAppId(),"/tforecastlibrary/inner/everyMonthCreateForecastLibary","", Object.class, SecurityConstants.FROM_IN);
log.info("------------每月定时生成下月预估库数据-定时任务结束------------");
}
}
......@@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner;
import com.yifu.cloud.plus.v1.yifu.social.entity.TForecastLibrary;
import com.yifu.cloud.plus.v1.yifu.social.service.TForecastLibraryService;
import io.swagger.v3.oas.annotations.Operation;
......@@ -168,4 +169,31 @@ public class TForecastLibraryController {
return tForecastLibraryService.createForecastlibary(payMonths, empIdCard, settleDomainIds);
}
/**
* @Description: 每日定时刷新社保公积金信息、预估数据,根据新增的户数据
* @Author: hgw
* @Date: 2022/7/27 19:34
* @return: void
**/
@SysLog("每日定时刷新社保公积金信息、预估数据,根据新增的户数据")
@Inner
@GetMapping("/inner/updateForecastLibaryBySysBase")
public void updateForecastLibaryBySysBase() {
tForecastLibraryService.updateForecastLibaryBySysBase(null);
}
/**
* @Description: 每月定时生成下月预估库数据
* @Author: hgw
* @Date: 2022/7/27 19:34
* @return: void
**/
@SysLog("每月定时生成下月预估库数据")
@Inner
@GetMapping("/inner/everyMonthCreateForecastLibary")
public void everyMonthCreateForecastLibary() {
tForecastLibraryService.everyMonthCreateForecastLibary();
}
}
......@@ -1656,15 +1656,115 @@ public class TForecastLibraryServiceImpl extends ServiceImpl<TForecastLibraryMap
return null;
}
/**
* @Description: 每月1号定时生成下月预估库数据
* @Author: hgw
* @Date: 2022/7/27 19:30
* @return: void
**/
@Override
public void everyMonthCreateForecastLibary() {
List<TSocialFundInfo> socialFundInfoList = socialFundInfoMapper.selectList(Wrappers.<TSocialFundInfo>query().lambda());
if (socialFundInfoList != null && !socialFundInfoList.isEmpty()) {
String payMonth = DateUtil.addMonth(1);
for (TSocialFundInfo socialFundInfo : socialFundInfoList) {
// TODO-生成新的社保公积金数据
everyMonthCreateForecastLibaryCore(payMonth, socialFundInfo);
}
}
}
private R<String> everyMonthCreateForecastLibaryCore(String payMonth, TSocialFundInfo socialFundInfo) {
String empIdCard = socialFundInfo.getEmpIdcard();
//定义未推送的按条件查询得到的预估数据
List<TForecastLibrary> librarySocialList = null;
//定义已推送的按条件查询得到的预估数据
List<TForecastLibrary> librarySocialListTemp = null;
//定义未推送的按条件查询得到的预估数据
List<TForecastLibrary> libraryFundList = null;
//定义已推送的按条件查询得到的预估数据
List<TForecastLibrary> libraryFundListTemp = null;
List<String> payMonthList = new ArrayList<>();
payMonthList.add(payMonth);
//查询出所有符合条件的社保数据
List<TSocialFundInfo> socialInfoList = null;
List<TSocialFundInfo> fundList = null;
// 查询当年所有的社保临时政策用于生成预估数据
List<TAgentConfig> configList = agentConfigMapper.selectList(Wrappers.<TAgentConfig>query().lambda()
.eq(TAgentConfig::getOpenFlag, CommonConstants.ZERO_INT));
HashMap<String, TAgentConfig> agentConfigHashMap = new HashMap<>();
if (Common.isNotNull(configList) && Common.isNotNull(payMonthList)) {
initConfigByPayMonths(configList, payMonthList, agentConfigHashMap);
}
//查询出所有对应条件的预估数、社保数据、公积金数据据用于重新生成
if (Common.isNotNull(empIdCard)) {
librarySocialList = baseMapper.selectList(Wrappers.<TForecastLibrary>query().lambda()
.eq(TForecastLibrary::getEmpIdcard, empIdCard)
.eq(TForecastLibrary::getDataType, CommonConstants.ZERO_INT)
.eq(TForecastLibrary::getSocialPayMonth, payMonth)
.eq(TForecastLibrary::getDataPush, CommonConstants.ZERO_INT));
librarySocialListTemp = baseMapper.selectList(Wrappers.<TForecastLibrary>query().lambda()
.eq(TForecastLibrary::getEmpIdcard, empIdCard)
.eq(TForecastLibrary::getDataType, CommonConstants.ZERO_INT)
.eq(TForecastLibrary::getSocialPayMonth, payMonth)
.eq(TForecastLibrary::getDataPush, CommonConstants.ONE_INT));
libraryFundList = baseMapper.selectList(Wrappers.<TForecastLibrary>query().lambda()
.eq(TForecastLibrary::getEmpIdcard, empIdCard)
.eq(TForecastLibrary::getDataType, CommonConstants.ONE_INT)
.eq(TForecastLibrary::getProvidentPayMonth, payMonth)
.eq(TForecastLibrary::getDataPush, CommonConstants.ZERO_INT));
libraryFundListTemp = baseMapper.selectList(Wrappers.<TForecastLibrary>query().lambda()
.eq(TForecastLibrary::getEmpIdcard, empIdCard)
.eq(TForecastLibrary::getDataType, CommonConstants.ONE_INT)
.eq(TForecastLibrary::getProvidentPayMonth, payMonth)
.eq(TForecastLibrary::getDataPush, CommonConstants.ONE_INT));
socialInfoList = socialFundInfoMapper.getSocialList(empIdCard, null);
fundList = socialFundInfoMapper.getFundList(empIdCard, null);
}
if (Common.isEmpty(socialInfoList)
&& Common.isEmpty(fundList)) {
return R.failed("无需要重新生成的数据(无数据或数据已结算不可重新生成!)");
}
//先删除然后重新生成
if (Common.isNotNull(librarySocialList)) {
baseMapper.deleteBatchIds(librarySocialList);
}
if (Common.isNotNull(libraryFundList)) {
baseMapper.deleteBatchIds(libraryFundList);
}
// 已存在的预估数据,采用比例
HashMap<String, TForecastLibrary> socialHistoryMap = new HashMap<>();
HashMap<String, TForecastLibrary> fundHistoryMap = new HashMap<>();
// 已推送的预估明细Map
HashMap<String, TForecastLibrary> socialPushMap = new HashMap<>();
HashMap<String, TForecastLibrary> fundPushMap = new HashMap<>();
// 组建基础Map
this.getBaseMap(librarySocialList, librarySocialListTemp, libraryFundList, libraryFundListTemp
, socialHistoryMap, fundHistoryMap, socialPushMap, fundPushMap);
Map<String, TForecastLibrary> saveLibraryMap = new HashMap<>();
boolean isReduceSocial = false;
boolean isReduceFund = false;
// 核心刷新
R<String> coreR = this.doCore(payMonthList, socialInfoList, fundList, agentConfigHashMap, socialHistoryMap
, fundHistoryMap, socialPushMap, fundPushMap, saveLibraryMap, isReduceSocial, isReduceFund);
if (coreR != null) return coreR;
boolean isSaveAndUpdate = false;
for (TForecastLibrary library : saveLibraryMap.values()) {
if (Common.isEmpty(library.getSocialId()) && Common.isEmpty(library.getProvidentId())) {
continue;
}
if (Common.isNotNull(library.getId())) {
baseMapper.updateById(library);
} else {
library.setCreateTime(LocalDateTime.now());
baseMapper.insert(library);
}
isSaveAndUpdate = true;
}
if (isSaveAndUpdate) {
return R.ok(null, "执行成功!");
} else {
return R.failed("执行失败!无需更新的数据!");
}
}
}
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