Commit 9dd93fa1 authored by shenxin's avatar shenxin

添加办件重新推送接口

parent eac698ce
...@@ -50,14 +50,17 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup ...@@ -50,14 +50,17 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup
//当前系统编码 //当前系统编码
private String SYS_CODE = ""; private String SYS_CODE = "";
private String AREA_CODE = "";
private String TYPE = ""; private String TYPE = "";
public void currentSystemCode(String sysCode, String areaCode, String type) { public void currentSystemCode(String sysCode, String type) {
this.SYS_CODE = sysCode; this.SYS_CODE = sysCode;
this.AREA_CODE = areaCode;
this.TYPE = type; this.TYPE = type;
} }
// public void currentSystemCode(String sysCode, String areaCode, String type) {
// this.SYS_CODE = sysCode;
// this.AREA_CODE = areaCode;
// this.TYPE = type;
// }
//当前系统剩余多少条办件量(可推送的办件量)=固定阈值-已推送办件 //当前系统剩余多少条办件量(可推送的办件量)=固定阈值-已推送办件
private int FIXED_AMOUNT = 0; private int FIXED_AMOUNT = 0;
...@@ -89,30 +92,37 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup ...@@ -89,30 +92,37 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup
supplementEntity.setPushType(TYPE); supplementEntity.setPushType(TYPE);
entityList.add(supplementEntity); entityList.add(supplementEntity);
eventCodeList.add(supplementEntity.getImplCode()); eventCodeList.add(supplementEntity.getImplCode());
if(PushTypeEnum.SYTH.getStyle().equals(TYPE)){ if (entityList.size() >= BATCH_COUNT) {
if (entityList.size() > FIXED_AMOUNT) { supplementDao.insertBatch(entityList);
throw new RuntimeException("数据上传失败,失败原因: 今日推送量已超过5000,请明天再试"); //存储完成清理list
} else { entityList.clear();
//达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
if (entityList.size() >= BATCH_COUNT) {
//判断当前上传的excel表格中那些是非本区域的办件
Map<String, Object> stringObjectMap = judgeTheProcessingArea(eventCodeList, AREA_CODE);
//判断当前是否还有数据,如果有数据,则表明当前map存在非本区域办件,则抛出异常
boolean easyToUseValue = stringObjectMap.get("boolean") != null ? false : true;
if (easyToUseValue) {
supplementDao.insertBatch(entityList);
//存储完成清理list
entityList.clear();
} else {
throw new RuntimeException("当前excel数据存在非本区域办件:" + stringObjectMap);
}
}
}
}else if(PushTypeEnum.RYB.getStyle().equals(TYPE)){
if (entityList.size() >= BATCH_COUNT) {
supplementDao.insertBatch(entityList);
}
} }
// if(PushTypeEnum.SYTH.getStyle().equals(TYPE)){
// if (entityList.size() > FIXED_AMOUNT) {
// throw new RuntimeException("数据上传失败,失败原因: 今日推送量已超过5000,请明天再试");
// } else {
// //达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
// if (entityList.size() >= BATCH_COUNT) {
// //判断当前上传的excel表格中那些是非本区域的办件
// Map<String, Object> stringObjectMap = judgeTheProcessingArea(eventCodeList, AREA_CODE);
// //判断当前是否还有数据,如果有数据,则表明当前map存在非本区域办件,则抛出异常
// boolean easyToUseValue = stringObjectMap.get("boolean") != null ? false : true;
// if (easyToUseValue) {
// supplementDao.insertBatch(entityList);
// //存储完成清理list
// entityList.clear();
// } else {
// throw new RuntimeException("当前excel数据存在非本区域办件:" + stringObjectMap);
// }
// }
// }
// }else if(PushTypeEnum.RYB.getStyle().equals(TYPE)){
// if (entityList.size() >= BATCH_COUNT) {
// supplementDao.insertBatch(entityList);
// //存储完成清理list
// entityList.clear();
// }
// }
} }
private Map<String, Object> judgeTheProcessingArea(List<String> eventCodeList, String areaCode) { private Map<String, Object> judgeTheProcessingArea(List<String> eventCodeList, String areaCode) {
...@@ -148,19 +158,20 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup ...@@ -148,19 +158,20 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup
@Override @Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) { public void doAfterAllAnalysed(AnalysisContext analysisContext) {
if(PushTypeEnum.SYTH.getStyle().equals(TYPE)){ // if(PushTypeEnum.SYTH.getStyle().equals(TYPE)){
//判断当前上传的excel表格中那些是非本区域的办件 // //判断当前上传的excel表格中那些是非本区域的办件
Map<String, Object> stringObjectMap = judgeTheProcessingArea(eventCodeList, AREA_CODE); // Map<String, Object> stringObjectMap = judgeTheProcessingArea(eventCodeList, AREA_CODE);
//判断当前是否还有数据,如果有数据,则表明当前map存在非本区域办件,则抛出异常 // //判断当前是否还有数据,如果有数据,则表明当前map存在非本区域办件,则抛出异常
boolean easyToUseValue = stringObjectMap.get("boolean") != null ? false : true; // boolean easyToUseValue = stringObjectMap.get("boolean") != null ? false : true;
if (easyToUseValue) { // if (easyToUseValue) {
supplementDao.insertBatch(entityList); // supplementDao.insertBatch(entityList);
} else { // } else {
throw new RuntimeException("当前excel数据存在非本区域办件:" + JSONObject.toJSONString(stringObjectMap)); // throw new RuntimeException("当前excel数据存在非本区域办件:" + JSONObject.toJSONString(stringObjectMap));
} // }
}else if(PushTypeEnum.RYB.getStyle().equals(TYPE)){ // }else if(PushTypeEnum.RYB.getStyle().equals(TYPE)){
supplementDao.insertBatch(entityList); // supplementDao.insertBatch(entityList);
} // }
supplementDao.insertBatch(entityList);
log.info("=======办件数据导入成功==========="); log.info("=======办件数据导入成功===========");
} }
......
...@@ -67,7 +67,7 @@ public class SupplementServiceImpl extends AbstractCRUDServiceImpl<SupplementDao ...@@ -67,7 +67,7 @@ public class SupplementServiceImpl extends AbstractCRUDServiceImpl<SupplementDao
ApiRespPdu<Object> objectApiRespPdu = new ApiRespPdu<>(); ApiRespPdu<Object> objectApiRespPdu = new ApiRespPdu<>();
try { try {
InformationDataConversionListener informationDataConversionListener = new InformationDataConversionListener(supplementDao,implementlistService); InformationDataConversionListener informationDataConversionListener = new InformationDataConversionListener(supplementDao,implementlistService);
informationDataConversionListener.currentSystemCode(null,null, type); informationDataConversionListener.currentSystemCode(null, type);
EasyExcel.read(file, SupplementEntity.class, informationDataConversionListener) EasyExcel.read(file, SupplementEntity.class, informationDataConversionListener)
.sheet(0) .sheet(0)
.headRowNumber(3) .headRowNumber(3)
...@@ -82,55 +82,65 @@ public class SupplementServiceImpl extends AbstractCRUDServiceImpl<SupplementDao ...@@ -82,55 +82,65 @@ public class SupplementServiceImpl extends AbstractCRUDServiceImpl<SupplementDao
} }
} }
private ApiRespPdu sythImport(BufferedInputStream file, String sysCode, String type){ private ApiRespPdu sythImport(BufferedInputStream file, String sysCode, String type) {
//1.导入之前,查询当前系统编码的阈值,以及多少办件量,并判断今天能否再次推送
ArameterEntity arameterEntity = new ArameterEntity();
arameterEntity.setSysCode(sysCode);
List<ArameterEntity> arameterEntities = arameterService.find(arameterEntity, null);
//地区编码
String areaCode = arameterEntities.get(0).getAreaCode();
// String areaCode = "513237000000";
//当前系统每天的固定办件量
// Integer limitTheNumberOfDocuments = Integer.valueOf(arameterEntities.get(0).getThresholdValue());
Integer limitTheNumberOfDocuments = Integer.valueOf("5000000");
InformationQuery informationQuery = new InformationQuery();
//设置查询条件,查询当天的办件量
informationQuery.setSystemCode(sysCode);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//当前时间毫秒数
long current=System.currentTimeMillis();
//今天零点零分零秒的毫秒数
long zero=current/(1000*3600*24)*(1000*3600*24)- TimeZone.getDefault().getRawOffset();
//今天23点59分59秒的毫秒数
long twelve=zero+24*60*60*1000-1;
informationQuery.setQueryBeginTime(simpleDateFormat.format(new Date(zero)));
informationQuery.setQueryEndTime(simpleDateFormat.format(new Date(twelve)));
//当前系统(当天)已推送的办件量
int count = informationDao.getCount(informationQuery);
ApiRespPdu<Object> objectApiRespPdu = new ApiRespPdu<>(); ApiRespPdu<Object> objectApiRespPdu = new ApiRespPdu<>();
if (count > limitTheNumberOfDocuments) { InformationDataConversionListener informationDataConversionListener = new InformationDataConversionListener(supplementDao, implementlistService);
objectApiRespPdu.setCode(500); informationDataConversionListener.currentSystemCode(sysCode, type);
objectApiRespPdu.setMsg("数据上传失败,失败原因: 今日推送量已超过: "+limitTheNumberOfDocuments+" ,请明天再试"); EasyExcel.read(file, SupplementEntity.class, informationDataConversionListener)
return objectApiRespPdu; .sheet(0)
} else { .headRowNumber(3)
try { .doRead();
InformationDataConversionListener informationDataConversionListener = new InformationDataConversionListener(supplementDao,implementlistService); objectApiRespPdu.setCode(200);
informationDataConversionListener.theAmountOfDeliverablesThatCanBePushed(limitTheNumberOfDocuments,count); objectApiRespPdu.setMsg("数据上传成功");
informationDataConversionListener.currentSystemCode(sysCode,areaCode,type); return objectApiRespPdu;
EasyExcel.read(file, SupplementEntity.class, informationDataConversionListener) // //1.导入之前,查询当前系统编码的阈值,以及多少办件量,并判断今天能否再次推送
.sheet(0) // ArameterEntity arameterEntity = new ArameterEntity();
.headRowNumber(3) // arameterEntity.setSysCode(sysCode);
.doRead(); // List<ArameterEntity> arameterEntities = arameterService.find(arameterEntity, null);
objectApiRespPdu.setCode(200); // //地区编码
objectApiRespPdu.setMsg("数据上传成功"); // String areaCode = arameterEntities.get(0).getAreaCode();
return objectApiRespPdu; //// String areaCode = "513237000000";
} catch (Exception e) { // //当前系统每天的固定办件量
e.printStackTrace(); //// Integer limitTheNumberOfDocuments = Integer.valueOf(arameterEntities.get(0).getThresholdValue());
objectApiRespPdu.setCode(500); // Integer limitTheNumberOfDocuments = Integer.valueOf("5000000");
objectApiRespPdu.setMsg("数据上传失败,失败原因:" + e.getMessage()+"目前剩余容量:"+String.valueOf(limitTheNumberOfDocuments-count)); // InformationQuery informationQuery = new InformationQuery();
return objectApiRespPdu; // //设置查询条件,查询当天的办件量
} // informationQuery.setSystemCode(sysCode);
} // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// //当前时间毫秒数
// long current=System.currentTimeMillis();
// //今天零点零分零秒的毫秒数
// long zero=current/(1000*3600*24)*(1000*3600*24)- TimeZone.getDefault().getRawOffset();
// //今天23点59分59秒的毫秒数
// long twelve=zero+24*60*60*1000-1;
// informationQuery.setQueryBeginTime(simpleDateFormat.format(new Date(zero)));
// informationQuery.setQueryEndTime(simpleDateFormat.format(new Date(twelve)));
// //当前系统(当天)已推送的办件量
// int count = informationDao.getCount(informationQuery);
// ApiRespPdu<Object> objectApiRespPdu = new ApiRespPdu<>();
// if (count > limitTheNumberOfDocuments) {
// objectApiRespPdu.setCode(500);
// objectApiRespPdu.setMsg("数据上传失败,失败原因: 今日推送量已超过: "+limitTheNumberOfDocuments+" ,请明天再试");
// return objectApiRespPdu;
// } else {
// try {
// InformationDataConversionListener informationDataConversionListener = new InformationDataConversionListener(supplementDao,implementlistService);
// informationDataConversionListener.theAmountOfDeliverablesThatCanBePushed(limitTheNumberOfDocuments,count);
// informationDataConversionListener.currentSystemCode(sysCode,areaCode,type);
// EasyExcel.read(file, SupplementEntity.class, informationDataConversionListener)
// .sheet(0)
// .headRowNumber(3)
// .doRead();
// objectApiRespPdu.setCode(200);
// objectApiRespPdu.setMsg("数据上传成功");
// return objectApiRespPdu;
// } catch (Exception e) {
// e.printStackTrace();
// objectApiRespPdu.setCode(500);
// objectApiRespPdu.setMsg("数据上传失败,失败原因:" + e.getMessage()+"目前剩余容量:"+String.valueOf(limitTheNumberOfDocuments-count));
// return objectApiRespPdu;
// }
// }
// }
} }
} }
\ No newline at end of file
...@@ -146,7 +146,7 @@ ...@@ -146,7 +146,7 @@
</sql> </sql>
<!-- 新增 区分主键自增加还是业务插入 --> <!-- 新增 区分主键自增加还是业务插入 -->
<insert id="insert" parameterType="SupplementEntity" > <insert id="insert" parameterType="SupplementEntity" >
insert into supplement insert into ${tableName}
(id,impl_name,impl_code,application_type,application_card_type,application_name,application_id,application_phone,mechanism_name,mechanism_address,mechanism_type,mechanism_id_type,mechanism_id,legal_person,apply_time,accept_name,accept_id,accept_phone,sys_code,is_execute,is_success,fail_reason,push_type,createDate,updateDate) (id,impl_name,impl_code,application_type,application_card_type,application_name,application_id,application_phone,mechanism_name,mechanism_address,mechanism_type,mechanism_id_type,mechanism_id,legal_person,apply_time,accept_name,accept_id,accept_phone,sys_code,is_execute,is_success,fail_reason,push_type,createDate,updateDate)
VALUES VALUES
(#{id},#{implName},#{implCode},#{applicationType},#{applicationCardType},#{applicationName},#{applicationId},#{applicationPhone},#{mechanismName},#{mechanismAddress},#{mechanismType},#{mechanismIdType},#{mechanismId},#{legalPerson},#{applyTime},#{acceptName},#{acceptId},#{acceptPhone},#{sysCode},#{isExecute},#{isSuccess},#{failReason},#{pushType},#{createDate},#{updateDate}) (#{id},#{implName},#{implCode},#{applicationType},#{applicationCardType},#{applicationName},#{applicationId},#{applicationPhone},#{mechanismName},#{mechanismAddress},#{mechanismType},#{mechanismIdType},#{mechanismId},#{legalPerson},#{applyTime},#{acceptName},#{acceptId},#{acceptPhone},#{sysCode},#{isExecute},#{isSuccess},#{failReason},#{pushType},#{createDate},#{updateDate})
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
<!-- 批量新增 --> <!-- 批量新增 -->
<insert id="insertBatch" parameterType="paramDto"> <insert id="insertBatch" parameterType="paramDto">
insert into supplement insert into ${tableName}
(id,impl_name,impl_code,application_type,application_card_type,application_name,application_id,application_phone,mechanism_name,mechanism_address,mechanism_type,mechanism_id_type,mechanism_id,legal_person,apply_time,accept_name,accept_id,accept_phone,sys_code,is_execute,is_success,fail_reason,push_type,createDate,updateDate) (id,impl_name,impl_code,application_type,application_card_type,application_name,application_id,application_phone,mechanism_name,mechanism_address,mechanism_type,mechanism_id_type,mechanism_id,legal_person,apply_time,accept_name,accept_id,accept_phone,sys_code,is_execute,is_success,fail_reason,push_type,createDate,updateDate)
VALUES VALUES
<foreach collection="data.dataList" item="item" index="index" separator="," > <foreach collection="data.dataList" item="item" index="index" separator="," >
...@@ -165,7 +165,7 @@ ...@@ -165,7 +165,7 @@
<!-- 根据ParamDto更新 --> <!-- 根据ParamDto更新 -->
<update id="update" parameterType="paramDto"> <update id="update" parameterType="paramDto">
update supplement as a update ${tableName} as a
set set
<trim suffixOverrides="," suffix=""> <trim suffixOverrides="," suffix="">
<if test="(colPickMode==0 and data.containsKey('implName')) or (colPickMode==1 and !data.containsKey('implName'))"> <if test="(colPickMode==0 and data.containsKey('implName')) or (colPickMode==1 and !data.containsKey('implName'))">
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</update> </update>
<!-- 批量更新 --> <!-- 批量更新 -->
<update id="updateBatch" parameterType="paramDto"> <update id="updateBatch" parameterType="paramDto">
update supplement as a update ${tableName} as a
<trim prefix="set" suffixOverrides=","> <trim prefix="set" suffixOverrides=",">
<trim prefix="impl_name=(case" suffix="ELSE impl_name end),"> <trim prefix="impl_name=(case" suffix="ELSE impl_name end),">
<foreach collection="data.dataList" item="item" index="index" separator="" > <foreach collection="data.dataList" item="item" index="index" separator="" >
...@@ -429,23 +429,23 @@ ...@@ -429,23 +429,23 @@
<!-- 根据主健查询 --> <!-- 根据主健查询 -->
<select id="getByKey" parameterType="paramDto" resultMap="SupplementEntity-Map"> <select id="getByKey" parameterType="paramDto" resultMap="SupplementEntity-Map">
select <include refid="_columns"/> select <include refid="_columns"/>
from supplement as a from ${tableName} as a
where a.id=#{condition.id} where a.id=#{condition.id}
</select> </select>
<!-- 根据主健删除 --> <!-- 根据主健删除 -->
<delete id="deleteByKey" parameterType="paramDto"> <delete id="deleteByKey" parameterType="paramDto">
delete a.* from supplement as a where a.id=#{condition.id} delete a.* from ${tableName} as a where a.id=#{condition.id}
</delete> </delete>
<!-- 根据主健删除一批,针对单一主健有效 --> <!-- 根据主健删除一批,针对单一主健有效 -->
<delete id="deleteByKeys"> <delete id="deleteByKeys">
delete from supplement where id in delete from ${tableName} where id in
<foreach collection="array" item="item" index="index" open="(" separator="," close=")"> <foreach collection="array" item="item" index="index" open="(" separator="," close=")">
#{item} #{item}
</foreach> </foreach>
</delete> </delete>
<!-- 根据paramDto删除一批 --> <!-- 根据paramDto删除一批 -->
<delete id="deleteByMap" parameterType="paramDto"> <delete id="deleteByMap" parameterType="paramDto">
delete a.* from supplement as a delete a.* from ${tableName} as a
<trim suffixOverrides="where" suffix=""> <trim suffixOverrides="where" suffix="">
where where
<trim prefixOverrides="and" prefix=""> <trim prefixOverrides="and" prefix="">
...@@ -456,7 +456,7 @@ ...@@ -456,7 +456,7 @@
<!-- 获取列表 --> <!-- 获取列表 -->
<select id="getList" parameterType="paramDto" resultMap="SupplementEntity-Map"> <select id="getList" parameterType="paramDto" resultMap="SupplementEntity-Map">
select <include refid="_columns"/> select <include refid="_columns"/>
from supplement as a from ${tableName} as a
<trim suffixOverrides="where" suffix=""> <trim suffixOverrides="where" suffix="">
where where
<trim prefixOverrides="and" prefix=""> <trim prefixOverrides="and" prefix="">
...@@ -469,7 +469,7 @@ ...@@ -469,7 +469,7 @@
<!-- 获取 --> <!-- 获取 -->
<select id="getListCount" parameterType="paramDto" resultType="int"> <select id="getListCount" parameterType="paramDto" resultType="int">
select count(1) select count(1)
from supplement as a from ${tableName} as a
<trim suffixOverrides="where" suffix=""> <trim suffixOverrides="where" suffix="">
where where
<trim prefixOverrides="and" prefix=""> <trim prefixOverrides="and" prefix="">
......
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