Commit f5a9fad4 authored by shenxin's avatar shenxin

蓉易办推送数据

parent e6016e5e
package com.mortals.xhx.common.code;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.IBaseEnum;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 审核状态
* @author
*
*/
public enum PushTypeEnum implements IBaseEnum {
RYB(1, "蓉易办", "ryb"),
SYTH(2, "省一体化", "syth");
private int value;
private String desc;
private String style;
PushTypeEnum(int value, String desc, String style) {
this.value = value;
this.desc = desc;
this.style = style;
}
@Override
public int getValue() {
return this.value;
}
public String getDesc() {
return desc;
}
public String getStyle()
{
return style;
}
public static PushTypeEnum getByValue(int value) {
for (PushTypeEnum examStatus : PushTypeEnum.values()) {
if (examStatus.getValue() == value) {
return examStatus;
}
}
return null;
}
/**
* 获取Map集合
* @param eItem 不包含项
* @return
*/
public static Map<String,String> getEnumMap(int... eItem) {
Map<String,String> resultMap= new LinkedHashMap<String,String>();
for (PushTypeEnum item : PushTypeEnum.values()) {
try{
boolean hasE = false;
for (int e : eItem){
if(item.getValue()==e){
hasE = true;
break;
}
}
if(!hasE){
resultMap.put(item.getValue()+"", item.getDesc());
}
}catch(Exception ex){
}
}
return resultMap;
}
}
package com.mortals.xhx.modules.implementlist.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.modules.implementlist.model.ImplementlistEntity;
import com.mortals.xhx.modules.implementlist.model.RybMatterListEntry;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface RybMatterDao extends ICRUDDao<ImplementlistEntity,Long> {
List<RybMatterListEntry> find(String eventCode);
void inserts(List<RybMatterListEntry> informationQueries);
}
package com.mortals.xhx.modules.implementlist.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.modules.implementlist.model.ImplementlistEntity;
import com.mortals.xhx.modules.implementlist.model.RybWorkEntry;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface RybWorkDao extends ICRUDDao<ImplementlistEntity,Long> {
List<RybWorkEntry> find(String deptCode);
}
package com.mortals.xhx.modules.implementlist.dao.ibatis;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.xhx.modules.implementlist.dao.RybMatterDao;
import com.mortals.xhx.modules.implementlist.model.ImplementlistEntity;
import com.mortals.xhx.modules.implementlist.model.RybMatterListEntry;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <p>Title: 实施清单主表</p>
* <p>Description: ImplementlistDaoImpl DAO接口 </p>
* @author
* @version 1.0.0
*/
@Repository("rybMatterDao")
public class RybMatterDaoImpl extends BaseCRUDDaoMybatis<ImplementlistEntity,Long> implements RybMatterDao {
@Override
public List<RybMatterListEntry> find(String eventCode) {
return getSqlSession().selectList(getSqlId("findRyb"),eventCode);
}
@Override
public void inserts(List<RybMatterListEntry> informationQueries) {
getSqlSession().insert(getSqlId("insertRyb"),informationQueries);
}
}
package com.mortals.xhx.modules.implementlist.dao.ibatis;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.xhx.modules.implementlist.dao.RybWorkDao;
import com.mortals.xhx.modules.implementlist.model.ImplementlistEntity;
import com.mortals.xhx.modules.implementlist.model.RybWorkEntry;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <p>Title: 实施清单主表</p>
* <p>Description: ImplementlistDaoImpl DAO接口 </p>
* @author
* @version 1.0.0
*/
@Repository("rybWordDao")
public class RybWorkDaoImpl extends BaseCRUDDaoMybatis<ImplementlistEntity,Long> implements RybWorkDao {
@Override
public List<RybWorkEntry> find(String deptCode) {
return getSqlSession().selectList(getSqlId("findRyb"),deptCode);
}
}
package com.mortals.xhx.modules.implementlist.model;
/**
* 蓉易办对接实体类
*/
import com.mortals.framework.model.BaseEntityLong;
import lombok.Data;
import java.util.Date;
@Data
public class RybMatterListEntry extends BaseEntityLong {
//部门编码
private String deptCode;
//部门名称
private String deptName;
//事项名称
private String matterName;
//事项编码
private String matterCode;
//taskId
private String taskId;
//事项类型
private String matterType;
/**
* 是否推送(0 否 1是)
*/
private String isReport;
/**
* 是否成功(0 否 1是)
*/
private String isSuccess;
/**
* 失败次数
*/
private Integer failTimes;
/**
* 推送失败原因
*/
private String failReason;
private Date createTime;
}
package com.mortals.xhx.modules.implementlist.model;
/**
* 蓉易办工作人员对接实体类
*/
import com.mortals.framework.model.BaseEntityLong;
import lombok.Data;
@Data
public class RybWorkEntry extends BaseEntityLong {
//部门编码
private String deptCode;
//部门名称
private String deptName;
//'接受人'
private String receiveUserName;
//'接收人身份证号'
private String receiveUserIdcard;
//'接收人号码'
private String receiveUserPhone;
}
package com.mortals.xhx.modules.implementlist.service;
import com.mortals.xhx.modules.implementlist.model.RybMatterListEntry;
public interface RybMatterListService {
RybMatterListEntry getThImplement(String event_code);
}
\ No newline at end of file
package com.mortals.xhx.modules.implementlist.service.impl;
import com.github.benmanes.caffeine.cache.Cache;
import com.mortals.xhx.modules.implementlist.dao.RybMatterDao;
import com.mortals.xhx.modules.implementlist.model.RybMatterListEntry;
import com.mortals.xhx.modules.implementlist.service.RybMatterListService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class RybMatterListServiceImpl implements RybMatterListService {
@Resource
private RybMatterDao rybMatterDao;
private final Cache<String, Object> caffeineCache;
@Override
public RybMatterListEntry getThImplement(String event_code) {
caffeineCache.getIfPresent(event_code);
RybMatterListEntry thImplementList = (RybMatterListEntry) caffeineCache.asMap().get(event_code);
if (thImplementList != null) {
return thImplementList;
}
//根据事项编码查
List<RybMatterListEntry> rybMatterListEntries = rybMatterDao.find(event_code);
if (rybMatterListEntries.size() > 0) {
for (RybMatterListEntry entity : rybMatterListEntries) {
thImplementList=entity;
caffeineCache.put(event_code, entity);
}
}
return thImplementList;
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSONObject;
import com.mortals.xhx.common.code.PushTypeEnum;
import com.mortals.xhx.common.code.SystemConstant;
import com.mortals.xhx.common.utils.DateByAffairUtils;
import com.mortals.xhx.common.utils.SnowFlakeUtil;
......@@ -50,10 +51,12 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup
//当前系统编码
private String SYS_CODE = "";
private String AREA_CODE = "";
private String TYPE = "";
public void currentSystemCode(String sysCode, String areaCode) {
public void currentSystemCode(String sysCode, String areaCode, String type) {
this.SYS_CODE = sysCode;
this.AREA_CODE = areaCode;
this.TYPE = type;
}
//当前系统剩余多少条办件量(可推送的办件量)=固定阈值-已推送办件
......@@ -85,6 +88,7 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup
supplementEntity.setUpdateDate(supplementEntity.getCreateDate());
entityList.add(supplementEntity);
eventCodeList.add(supplementEntity.getImplCode());
if(PushTypeEnum.SYTH.getStyle().equals(TYPE)){
if (entityList.size() > FIXED_AMOUNT) {
throw new RuntimeException("数据上传失败,失败原因: 今日推送量已超过5000,请明天再试");
} else {
......@@ -103,6 +107,11 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup
}
}
}
}else if(PushTypeEnum.RYB.getStyle().equals(TYPE)){
if (entityList.size() >= BATCH_COUNT) {
supplementDao.insertBatch(entityList);
}
}
}
private Map<String, Object> judgeTheProcessingArea(List<String> eventCodeList, String areaCode) {
......@@ -114,6 +123,10 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup
//装入符合条件的办件信息
Map<String, String> stringStringHashMap = new HashMap<>();
ImplementlistEntity thImplement = implementlistService.getThImplement(eventCode);
if(thImplement == null){
log.info(eventCode + ": 没有找到该办件所对应的事项");
continue;
}
if (!shardKey.equals(thImplement.getShardKey())) {
stringStringHashMap.put("eventName", thImplement.getEventName());
stringStringHashMap.put("eventCode", thImplement.getEventCode());
......@@ -134,6 +147,7 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
if(PushTypeEnum.SYTH.getStyle().equals(TYPE)){
//判断当前上传的excel表格中那些是非本区域的办件
Map<String, Object> stringObjectMap = judgeTheProcessingArea(eventCodeList, AREA_CODE);
//判断当前是否还有数据,如果有数据,则表明当前map存在非本区域办件,则抛出异常
......@@ -143,6 +157,9 @@ public class InformationDataConversionListener extends AnalysisEventListener<Sup
} else {
throw new RuntimeException("当前excel数据存在非本区域办件:" + JSONObject.toJSONString(stringObjectMap));
}
}else if(PushTypeEnum.RYB.getStyle().equals(TYPE)){
supplementDao.insertBatch(entityList);
}
log.info("=======办件数据导入成功===========");
}
......
......@@ -19,7 +19,6 @@ import java.io.BufferedInputStream;
public interface SupplementService extends ICRUDService<SupplementEntity,Long>{
//从缓存中获得文件地址后读取后的文件流
ApiRespPdu importOfficeInformation(BufferedInputStream file,String sysCode);
ApiRespPdu importOfficeInformation(BufferedInputStream file,String sysCode, String type);
}
\ No newline at end of file
package com.mortals.xhx.modules.supplement.service.impl;
import com.alibaba.excel.EasyExcel;
import com.mortals.xhx.common.code.PushTypeEnum;
import com.mortals.xhx.common.pdu.ApiRespPdu;
import com.mortals.xhx.modules.arameter.model.ArameterEntity;
import com.mortals.xhx.modules.arameter.service.ArameterService;
......@@ -52,8 +53,37 @@ public class SupplementServiceImpl extends AbstractCRUDServiceImpl<SupplementDao
@SneakyThrows
@Override
public ApiRespPdu importOfficeInformation(BufferedInputStream file, String sysCode) {
// //1.导入之前,查询当前系统编码的阈值,以及多少办件量,并判断今天能否再次推送
public ApiRespPdu importOfficeInformation(BufferedInputStream file, String sysCode, String type) {
ApiRespPdu<Object> objectApiRespPdu = new ApiRespPdu<>();
if(PushTypeEnum.SYTH.getStyle().equals(type)){
objectApiRespPdu = sythImport(file, sysCode, type);
}else if(PushTypeEnum.RYB.getStyle().equals(type)){
objectApiRespPdu = rybImport(file, type);
}
return objectApiRespPdu;
}
private ApiRespPdu rybImport(BufferedInputStream file, String type){
ApiRespPdu<Object> objectApiRespPdu = new ApiRespPdu<>();
try {
InformationDataConversionListener informationDataConversionListener = new InformationDataConversionListener(supplementDao,implementlistService);
informationDataConversionListener.currentSystemCode(null,null, type);
EasyExcel.read(file, SupplementEntity.class, informationDataConversionListener)
.sheet(0)
.headRowNumber(3)
.doRead();
objectApiRespPdu.setCode(200);
objectApiRespPdu.setMsg("数据上传成功");
return objectApiRespPdu;
} catch (Exception e) {
objectApiRespPdu.setCode(500);
objectApiRespPdu.setMsg("数据上传失败!");
return objectApiRespPdu;
}
}
private ApiRespPdu sythImport(BufferedInputStream file, String sysCode, String type){
//1.导入之前,查询当前系统编码的阈值,以及多少办件量,并判断今天能否再次推送
ArameterEntity arameterEntity = new ArameterEntity();
arameterEntity.setSysCode(sysCode);
List<ArameterEntity> arameterEntities = arameterService.find(arameterEntity, null);
......@@ -86,7 +116,7 @@ public class SupplementServiceImpl extends AbstractCRUDServiceImpl<SupplementDao
try {
InformationDataConversionListener informationDataConversionListener = new InformationDataConversionListener(supplementDao,implementlistService);
informationDataConversionListener.theAmountOfDeliverablesThatCanBePushed(limitTheNumberOfDocuments,count);
informationDataConversionListener.currentSystemCode(sysCode,areaCode);
informationDataConversionListener.currentSystemCode(sysCode,areaCode,type);
EasyExcel.read(file, SupplementEntity.class, informationDataConversionListener)
.sheet(0)
.headRowNumber(3)
......@@ -103,5 +133,4 @@ public class SupplementServiceImpl extends AbstractCRUDServiceImpl<SupplementDao
}
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.common.code.ExcelUploadEnum;
import com.mortals.xhx.common.code.PushTypeEnum;
import com.mortals.xhx.modules.supplement.service.SupplementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -42,13 +43,15 @@ public class ExcelUploadTaskImpl implements ITaskExcuteService {
for (Map.Entry<String, String> stringStringEntry : map.entrySet()) {
JSONObject jsonObject = JSONObject.parseObject(stringStringEntry.getValue());
String sysCode = jsonObject.getString("sysCode");
String type = jsonObject.getString("type");
if (ExcelUploadEnum.未处理的文件路径.getCode().equals(jsonObject.getString("status"))){
Map<String, String> objectObjectHashMap = new HashMap<>();
objectObjectHashMap.put("sysCode",sysCode);
objectObjectHashMap.put("type",type);
objectObjectHashMap.put("status",ExcelUploadEnum.已处理的文件路径.getCode());
iCacheService.hset(ExcelUploadEnum.UPLOAD_PATH.getCode(),stringStringEntry.getKey(),objectObjectHashMap);
//存储方法
this.storageCleaningTable(stringStringEntry.getKey(),sysCode);
this.storageCleaningTable(stringStringEntry.getKey(), sysCode, type);
}
}
}
......@@ -59,12 +62,12 @@ public class ExcelUploadTaskImpl implements ITaskExcuteService {
}
private void storageCleaningTable(String filePath,String sysCode) {
private void storageCleaningTable(String filePath,String sysCode, String type) {
String fileAbsolutePath= uploadService.getFilePath(filePath);
BufferedInputStream inputStream = FileUtil.getInputStream(fileAbsolutePath);
try {
//存储到临时表
supplementService.importOfficeInformation(inputStream,sysCode);
supplementService.importOfficeInformation(inputStream,sysCode, type);
//删除redis里面的值
iCacheService.hdel(ExcelUploadEnum.UPLOAD_PATH.getCode(),filePath);
//删除本地文件里面的值
......
......@@ -101,6 +101,11 @@ public class SupplementTaskImpl implements ITaskExcuteService {
} catch (Exception ex) {
log.error("转换失败:SupplementID:" + e.getId());
log.error("转换失败:失败原因" + ex.getMessage());
// 是否执行转化(0.未执行 1.已执行)
e.setIsExecute("1");
//是否转化成功(0默认 1成功)
e.setIsSuccess("0");
e.setFailReason("转换失败");
return e;
}
}).collect(Collectors.toList());
......
......@@ -5,6 +5,7 @@ import com.mortals.framework.service.ICacheService;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.common.code.ExcelUploadEnum;
import com.mortals.xhx.common.code.PushTypeEnum;
import com.mortals.xhx.common.pdu.ApiRespPdu;
import com.mortals.xhx.modules.supplement.model.SupplementEntity;
import com.mortals.xhx.modules.supplement.service.SupplementService;
......@@ -43,20 +44,21 @@ public class SupplementController extends BaseCRUDJsonMappingController<Suppleme
* 导入办件信息,一阶段通过excel表格导入,放入磁盘中,在通过文件地址去获取文件内容进行数据清洗
*/
@PostMapping(value="importOfficeInformation")
public ApiRespPdu importOfficeInformation(@RequestPart("file") MultipartFile file,String sysCode) throws Exception{
public ApiRespPdu importOfficeInformation(@RequestPart("file") MultipartFile file, @RequestParam("sysCode") String sysCode ,@RequestParam("type") String type){
ApiRespPdu respPdu=new ApiRespPdu();
if (StringUtils.isNotEmpty(sysCode)){
String filePath = uploadService.saveFileUpload(file, null, null);
Map<String, String> objectObjectHashMap = new HashMap<>();
if(PushTypeEnum.SYTH.getStyle().equals(type) && StringUtils.isEmpty(sysCode)){
respPdu.setCode(-1);
respPdu.setMsg("缺少系统编码");
return respPdu;
}
objectObjectHashMap.put("sysCode",sysCode);
objectObjectHashMap.put("type",type);
objectObjectHashMap.put("status",ExcelUploadEnum.未处理的文件路径.getCode());
iCacheService.hset(ExcelUploadEnum.UPLOAD_PATH.getCode(),filePath,objectObjectHashMap);
respPdu.setCode(200);
respPdu.setMsg("上传文件成功");
}else {
respPdu.setCode(-1);
respPdu.setMsg("缺少系统编码");
}
return respPdu;
}
......
<?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.mortals.xhx.modules.implementlist.dao.ibatis.RybMatterDaoImpl">
<select id="findRyb" resultType="com.mortals.xhx.modules.implementlist.model.RybMatterListEntry">
select
dept_code as deptCode,
dept_name as deptName,
matter_name as matterName,
matter_code as matterCode,
task_id as taskId,
matter_type as matterType,
create_time as createTime,
is_report as isReport,
is_success as isSuccess,
fail_times as failTimes,
fail_reason as failReason
from ryb_matter_list
where matter_code = #{eventCode}
</select>
<select id="insertRyb" parameterType="collection">
insert into values
<foreach collection="collection" item="entry" index=",">
(#{entry.deptCode},#{entry.deptName},#{entry.matterName},#{entry.matterCode},#{entry.taskId},#{entry.matterType},#{entry.createTime},#{entry.isReport},#{entry.isSuccess},#{entry.failTimes},#{entry.failReason})
</foreach>
</select>
</mapper>
\ No newline at end of file
<?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.mortals.xhx.modules.implementlist.dao.ibatis.RybWorkDaoImpl">
<select id="findRyb" resultType="com.mortals.xhx.modules.implementlist.model.RybWorkEntry">
select
dept_code as deptCode,
dept_name as deptName,
receive_user_name as receiveUserName,
receive_user_idcard as receiveUserIdcard,
receive_user_phone as receiveUserPhone
from ryb_work
where dept_code = #{deptCode}
</select>
</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