Commit d084ea9e authored by 董建华's avatar 董建华

数据上报完结

parent 0444d51a
......@@ -178,11 +178,16 @@ public class ReportController {
}
@RequestMapping("/runData")
public String runData(String date) {
public String runData(String date, String type) {
if (isrun) {
return "程序正在奔跑";
}
reportService.runData(date);
if (type.equals("1")) {
reportService.runData(date);
} else {
reportService.runMonthData(date);
}
return "已经开始跑数据";
}
......
......@@ -13,5 +13,7 @@ public interface ReportRecordMapper {
int insert(ReportRecord record);
int updateByPrimaryKeySelectiveByFileName(ReportRecord record);
int banchInsert(@Param("records") List<Map<String,Object>> params);
List<Map<String,Object>> getDataByTYpe(String type);
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ public interface ReportService {
FileEntry creatZipFile(String date,List<Map<String,Object>> dataList, InfoType infoType, BusinessType businessType) throws QgException;
void creatTxtFile(String filePath,List<Map<String,Object>> dataList, InfoType infoType, BusinessType businessType) throws QgException;
void creatTxtFile(String filePath,List<Map<String,Object>> dataList, InfoType infoType, BusinessType businessType,boolean isDesensitization) throws QgException;
List<Map<String,Object>> getDataAsync(Map<String,String> param);
......@@ -37,4 +37,6 @@ public interface ReportService {
void reportOverMonthData();
void runData(String date);
void runMonthData(String date);
}
......@@ -157,11 +157,11 @@ public class IReportServiceImpl implements ReportService {
}
@Override
public void creatTxtFile(String filePath, List<Map<String, Object>> dataList, InfoType infoType, BusinessType businessType) throws QgException {
public void creatTxtFile(String filePath, List<Map<String, Object>> dataList, InfoType infoType, BusinessType businessType,boolean isDesensitization) throws QgException {
if (dataList == null || dataList.size() == 0) {
return;
}
String str = formatData(dataList, reportConfig.isDesensitization());
String str = formatData(dataList, isDesensitization);
// String savepath = reportConfig.getFilePathPre() + File.separator + DateUtil.getCurrentServerDate(DateUtil.YYYYMMDD) + File.separator + PathType.REPORT.getPath();
......@@ -550,8 +550,8 @@ public class IReportServiceImpl implements ReportService {
public void reportOverMonthData() {
try {
Map<String, String> param = new HashMap<>();
param.put("startDate", DateUtil.getCurrentDay(-1));
param.put("endDate", DateUtil.getCurrentDay(0));
param.put("startDate", DateUtil.getCurrentDay(-1,DateUtil.YYYY_MM_DD));
param.put("endDate", DateUtil.getCurrentDay(0,DateUtil.YYYY_MM_DD));
log.info("开始上报月逾期数据");
List<Map<String, Object>> overMonthData = dataMapper.getOverMonthData(param);
if (overMonthData == null || overMonthData.size() == 0) {
......@@ -579,7 +579,7 @@ public class IReportServiceImpl implements ReportService {
ReportController.isrun = true;
try {
// String date = "2017-10-01 00:00:00";
while (!date.equals("2019-11-02 00:00:00")) {
while (!date.equals("2019-11-14 00:00:00")) {
Map<String, String> param = new HashMap<>();
param.put("startDate", DateUtil.getCurrentDay(date, -1));
param.put("endDate", date);
......@@ -596,7 +596,29 @@ public class IReportServiceImpl implements ReportService {
} finally {
ReportController.isrun = false;
}
//
}
@Async
@Override
public void runMonthData(String date) {
ReportController.isrun = true;
try {
while (!date.equals("2019-12-01")) {
log.info("开始跑取"+date+"的数据");
Map<String, String> param = new HashMap<>();
param.put("startDate", DateUtil.getCurrentDay(date, -1,DateUtil.YYYY_MM_DD, DateUtil.YYYY_MM_DD));
param.put("endDate", date);
List<Map<String, Object>> monthData = getMonthData(param);
List<List<Map<String, Object>>> lists = utils.subList(monthData, 1000, "4");
for (List<Map<String, Object>> list : lists) {
reportRecordMapper.banchInsert(list);
}
log.info("跑取"+date+"的数据结束");
date = DateUtil.getCurrentMonth(date, 1, DateUtil.YYYY_MM_DD, DateUtil.YYYY_MM_DD);
}
} finally {
ReportController.isrun = false;
}
}
......@@ -656,6 +678,10 @@ public class IReportServiceImpl implements ReportService {
return result;
}
List<Map<String, Object>> getMonthData(Map<String, String> param) {
return dataMapper.getOverMonthData(param);
}
/**
* 格式化数据
*
......
......@@ -38,7 +38,7 @@ public class ReportTimer {
}
//每天凌晨2点
// @Scheduled(cron = "0 0 2 * * ?")
@Scheduled(cron = "0 0 2 * * ?")
void reportDayData() {
if (!isRun) {
return;
......@@ -59,7 +59,7 @@ public class ReportTimer {
}
//每月1次
// @Scheduled(cron = "0 0 3 1 1/1 ?")
@Scheduled(cron = "0 0 3 1 1/1 ?")
void reportMonthData() {
if (!isRun) {
return;
......@@ -75,12 +75,12 @@ public class ReportTimer {
}
//一小时一次 延迟10秒
// @Scheduled(fixedDelay = 1000 * 60 * 60, initialDelay = 10000)
@Scheduled(fixedDelay = 1000 * 60 * 60, initialDelay = 10000)
public void quaryReportedStatus() {
//测试先去掉这个限制
// if (!isRun) {
// return;
// }
if (!isRun) {
return;
}
if (monReportIsRunning || dayReportIsRunning) {
return;
}
......
......@@ -25,6 +25,7 @@ public class DateUtil {
public final static String YYYYMMDDHHMM = "yyyyMMddHHmm";
public static final String YYYYMMDD = "yyyyMMdd";
public static final String YYYYMM = "yyyyMM";
public static String getCurrentDay(int day) {
Calendar calendar = Calendar.getInstance();
......@@ -34,7 +35,14 @@ public class DateUtil {
calendar.set(Calendar.SECOND, 0);
return new SimpleDateFormat(YYYY_MM_DD_MM_HH_SS).format(calendar.getTime());
}
public static String getCurrentDay(int day,String pattner) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
return new SimpleDateFormat(pattner).format(calendar.getTime());
}
public static String getCurrentDay(String date, int day) {
Date time = null;
try {
......@@ -50,6 +58,36 @@ public class DateUtil {
calendar.set(Calendar.SECOND, 0);
return new SimpleDateFormat(YYYY_MM_DD_MM_HH_SS).format(calendar.getTime());
}
public static String getCurrentDay(String date, int day,String inPartner,String outPartner) {
Date time = null;
try {
time = new SimpleDateFormat(inPartner).parse(date);
}catch (Exception e){
e.printStackTrace();
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
calendar.add(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
return new SimpleDateFormat(outPartner).format(calendar.getTime());
}
public static String getCurrentMonth(String date, int month,String inPartner,String outPartner) {
Date time = null;
try {
time = new SimpleDateFormat(inPartner).parse(date);
}catch (Exception e){
e.printStackTrace();
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
calendar.add(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH,1);
return new SimpleDateFormat(outPartner).format(calendar.getTime());
}
/**
* 获取当月月初日期
*
......
<?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.mapper.report.ReportRecordMapper">
<resultMap id="BaseResultMap" type="com.entity.report.ReportRecord">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="filename" jdbcType="VARCHAR" property="filename" />
<result column="filepath" jdbcType="VARCHAR" property="filepath" />
<result column="reportmsg" jdbcType="VARCHAR" property="reportmsg" />
<result column="issearch" jdbcType="INTEGER" property="issearch" />
<result column="feedback" jdbcType="VARCHAR" property="feedback" />
<result column="loadcount" jdbcType="INTEGER" property="loadcount" />
<result column="errorcount" jdbcType="INTEGER" property="errorcount" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="createtime" jdbcType="TIMESTAMP" property="createtime" />
<result column="updatetime" jdbcType="TIMESTAMP" property="updatetime" />
</resultMap>
<sql id="Base_Column_List">
<resultMap id="BaseResultMap" type="com.entity.report.ReportRecord">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="filename" jdbcType="VARCHAR" property="filename"/>
<result column="filepath" jdbcType="VARCHAR" property="filepath"/>
<result column="reportmsg" jdbcType="VARCHAR" property="reportmsg"/>
<result column="issearch" jdbcType="INTEGER" property="issearch"/>
<result column="feedback" jdbcType="VARCHAR" property="feedback"/>
<result column="loadcount" jdbcType="INTEGER" property="loadcount"/>
<result column="errorcount" jdbcType="INTEGER" property="errorcount"/>
<result column="status" jdbcType="INTEGER" property="status"/>
<result column="createtime" jdbcType="TIMESTAMP" property="createtime"/>
<result column="updatetime" jdbcType="TIMESTAMP" property="updatetime"/>
</resultMap>
<sql id="Base_Column_List">
id, filename, filepath, reportmsg, issearch, feedback, loadcount, errorcount, status,
createtime, updatetime
</sql>
<insert id="insert" parameterType="com.entity.report.ReportRecord">
<insert id="insert" parameterType="com.entity.report.ReportRecord">
insert into reportrecord (id, filename, filepath,
reportmsg, issearch, feedback,
loadcount, errorcount, status,
......@@ -30,74 +30,80 @@
#{createtime,jdbcType=TIMESTAMP}, #{updatetime,jdbcType=TIMESTAMP})
</insert>
<update id="updateByPrimaryKeySelectiveByFileName" parameterType="com.entity.report.ReportRecord">
update reportrecord
<set>
<if test="filename != null">
filename = #{filename,jdbcType=VARCHAR},
</if>
<if test="filepath != null">
filepath = #{filepath,jdbcType=VARCHAR},
</if>
<if test="reportmsg != null">
reportmsg = #{reportmsg,jdbcType=VARCHAR},
</if>
<if test="issearch != null">
issearch = #{issearch,jdbcType=INTEGER},
</if>
<if test="feedback != null">
feedback = #{feedback,jdbcType=VARCHAR},
</if>
<if test="loadcount != null">
loadcount = #{loadcount,jdbcType=INTEGER},
</if>
<if test="errorcount != null">
errorcount = #{errorcount,jdbcType=INTEGER},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
<if test="createtime != null">
createtime = #{createtime,jdbcType=TIMESTAMP},
</if>
<if test="updatetime != null">
updatetime = #{updatetime,jdbcType=TIMESTAMP},
</if>
</set>
where filename = #{filename,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKeySelectiveByFileName" parameterType="com.entity.report.ReportRecord">
update reportrecord
<set>
<if test="filename != null">
filename = #{filename,jdbcType=VARCHAR},
</if>
<if test="filepath != null">
filepath = #{filepath,jdbcType=VARCHAR},
</if>
<if test="reportmsg != null">
reportmsg = #{reportmsg,jdbcType=VARCHAR},
</if>
<if test="issearch != null">
issearch = #{issearch,jdbcType=INTEGER},
</if>
<if test="feedback != null">
feedback = #{feedback,jdbcType=VARCHAR},
</if>
<if test="loadcount != null">
loadcount = #{loadcount,jdbcType=INTEGER},
</if>
<if test="errorcount != null">
errorcount = #{errorcount,jdbcType=INTEGER},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
<if test="createtime != null">
createtime = #{createtime,jdbcType=TIMESTAMP},
</if>
<if test="updatetime != null">
updatetime = #{updatetime,jdbcType=TIMESTAMP},
</if>
</set>
where filename = #{filename,jdbcType=VARCHAR}
</update>
<select id="getReportedRecord" resultMap="BaseResultMap">
<select id="getReportedRecord" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
from reportrecord
where status = 1
and
createtime &lt; date_add(NOW(),interval -10 minute)
and (issearch !=1 or feedback='正在处理' or feedback='等待处理')
</select>
<insert id="banchInsert" parameterType="ArrayList">
INSERT INTO
report_data_tmp(name,pidType,pid,businessHappenOrgan,loanId,businessType,businessKind,openDate,dueDate,creditMoney,businessHappenDate,balance,currentOverdueTotal,repaymentStatus,type,createTime)
VALUES
<foreach collection="records" item="emp" separator=",">
(#{emp.name}
,#{emp.pidType}
,#{emp.pid}
,#{emp.businessHappenOrgan}
,#{emp.loanId}
,#{emp.businessType}
,#{emp.businessKind}
,#{emp.openDate}
,#{emp.dueDate}
,#{emp.creditMoney}
,#{emp.businessHappenDate}
,#{emp.balance}
,#{emp.currentOverdueTotal}
,#{emp.repaymentStatus}
,#{emp.type}
,now()
)
</foreach>
</insert>
<select id="getDataByTYpe" parameterType="String" resultType="HashMap">
SELECT
<include refid="Base_Column_List" />
from reportrecord
where status = 1
and
createtime &lt; date_add(NOW(),interval -10 minute)
and (issearch !=1 or feedback='正在处理' or feedback='等待处理')
name,pidType,pid,businessHappenOrgan,loanId,businessType,businessKind,openDate,dueDate,creditMoney,businessHappenDate,balance,currentOverdueTotal,repaymentStatus
from report_data_tmp WHERE type =#{type} ORDER BY businessHappenDate asc
</select>
<insert id="banchInsert" parameterType="ArrayList">
INSERT INTO report_data_tmp(name,pidType,pid,businessHappenOrgan,loanId,businessType,businessKind,openDate,dueDate,creditMoney,businessHappenDate,balance,currentOverdueTotal,repaymentStatus,type,createTime)
VALUES
<foreach collection="records" item="emp" separator=",">
(#{emp.name}
,#{emp.pidType}
,#{emp.pid}
,#{emp.businessHappenOrgan}
,#{emp.loanId}
,#{emp.businessType}
,#{emp.businessKind}
,#{emp.openDate}
,#{emp.dueDate}
,#{emp.creditMoney}
,#{emp.businessHappenDate}
,#{emp.balance}
,#{emp.currentOverdueTotal}
,#{emp.repaymentStatus}
,#{emp.type}
,now()
)
</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