Commit bb4feabb authored by suhuiguang's avatar suhuiguang

1.使用登记(台套、单位)增加过滤流程中的设备

2.安装告知、使用登记(台套、单位)在提交时增加异常回滚机制,在异常时清除掉写入的redis数据
parent 1a79b09d
package com.yeejoin.amos.boot.module.jg.api.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author Administrator
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class FlowingEquipRedisKeyDTO {
private String redisKey;
private List<String> data;
}
......@@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Mapper 接口
......@@ -49,14 +50,14 @@ public interface JgUseRegistrationMapper extends BaseMapper<JgUseRegistration> {
Map<String, Object> getUseRegistrationDetail(@Param("id")String id);
Page<JSONObject> queryForUnitVesselEquipmentPage(@Param("page") Page<JSONObject> page, @Param("jsonObject")JSONObject jsonObject);
Page<JSONObject> queryForUnitVesselEquipmentPage(@Param("page") Page<JSONObject> page, @Param("jsonObject") JSONObject jsonObject, @Param("records") Set<String> records);
Page<JSONObject> queryForEquipUsedByVehiclePage(@Param("page") Page<JSONObject> page, @Param("jsonObject")JSONObject jsonObject);
@MapKey("records")
List<Map<String, Object>> queryForUnitVesselEquipment(@Param("records")List<String> records);
Page<JSONObject> queryForUnitPipelineEquipmentPage(@Param("page") Page<JSONObject> page, @Param("jsonObject")JSONObject jsonObject);
Page<JSONObject> queryForUnitPipelineEquipmentPage(@Param("page") Page<JSONObject> page, @Param("jsonObject") JSONObject jsonObject,@Param("records") Set<String> records);
@MapKey("records")
List<Map<String, Object>> queryForUnitPipelineEquipment(@Param("records")List<String> records);
......
......@@ -39,4 +39,12 @@ public interface IEquipUsedCheck {
* 数据初始化方法
*/
void init();
/**
* 删除流程中的数据,释放redis空间(异常处理及驳回到发起节点、撤回到发起节点、完成时时进行)
*
* @param records 设备唯一标识
* @param redisKey key
*/
void delDataForCheckWithKey(List<String> records, String redisKey);
}
......@@ -451,9 +451,19 @@
<if test="jsonObject.useUnitCreditCode != null and jsonObject.useUnitCreditCode != ''" >
and ui."USE_UNIT_CREDIT_CODE" = #{jsonObject.useUnitCreditCode}
</if>
<if test="jsonObject.record != null and jsonObject.record != ''" >
and ui."RECORD" = #{jsonObject.record}
</if>
<choose>
<when test="jsonObject.record != null and jsonObject.record != ''">
and ui."RECORD" = #{jsonObject.record}
</when>
<otherwise>
<if test="records != null and records.size() > 0">
and ui."RECORD" not in
<foreach collection="records" item="record" separator="," open="(" close=")">
#{record}
</foreach>
</if>
</otherwise>
</choose>
ORDER BY ui.REC_DATE DESC
</select>
......@@ -510,9 +520,19 @@
<if test="jsonObject.useUnitCreditCode != null and jsonObject.useUnitCreditCode != ''">
and ui."USE_UNIT_CREDIT_CODE" = #{jsonObject.useUnitCreditCode}
</if>
<if test="jsonObject.record != null and jsonObject.record != ''" >
and ui."RECORD" = #{jsonObject.record}
</if>
<choose>
<when test="jsonObject.record != null and jsonObject.record != ''">
and ui."RECORD" = #{jsonObject.record}
</when>
<otherwise>
<if test="records != null and records.size() > 0">
and ui."RECORD" not in
<foreach collection="records" item="record" separator="," open="(" close=")">
#{record}
</foreach>
</if>
</otherwise>
</choose>
ORDER BY ui.REC_DATE DESC
</select>
......
package com.yeejoin.amos.boot.module.jg.biz.config;
import com.yeejoin.amos.boot.module.jg.biz.interceptor.ClearThreadLocalInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author Administrator
*/
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Bean
public ClearThreadLocalInterceptor clearThreadLocalInterceptor() {
return new ClearThreadLocalInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(clearThreadLocalInterceptor());
}
}
\ No newline at end of file
package com.yeejoin.amos.boot.module.jg.biz.context;
import com.yeejoin.amos.boot.module.jg.api.dto.FlowingEquipRedisKeyDTO;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
/**
* @author Administrator
*/
@Slf4j
public class FlowingEquipRedisContext {
private static ThreadLocal<List<FlowingEquipRedisKeyDTO>> threadLocal = new ThreadLocal<>();
public static List<FlowingEquipRedisKeyDTO> getContext() {
if (threadLocal.get() == null) {
threadLocal.set(new ArrayList<>());
}
return threadLocal.get();
}
public static void setRedisKeyInfo(FlowingEquipRedisKeyDTO redisKeyInfo) {
getContext().add(redisKeyInfo);
}
public static void clean() {
log.info("FlowingEquipRedisContext clean begin");
if (threadLocal != null) {
threadLocal.remove();
}
log.info("FlowingEquipRedisContext clean end");
}
}
package com.yeejoin.amos.boot.module.jg.biz.interceptor;
import com.yeejoin.amos.boot.module.jg.biz.context.FlowingEquipRedisContext;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Administrator
*/
public class ClearThreadLocalInterceptor implements HandlerInterceptor {
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) {
// 清除ThreadLocal变量
FlowingEquipRedisContext.clean();
}
}
\ No newline at end of file
......@@ -1840,12 +1840,13 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
}
jsonObject.put("useUnitCreditCode", useUnitCreditCode);
Page<JSONObject> page = new Page<>(jsonObject.getLong("number"), jsonObject.getLong("size"));
Set<String> records = EquipUsedCheckStrategyContext.getUsedStrategy("useRegister").getEquipInFlow(useUnitCreditCode);
if ("8300".equals(jsonObject.get("EQU_CATEGORY_CODE"))) {
return jgUseRegistrationMapper.queryForUnitPipelineEquipmentPage(page, jsonObject);
return jgUseRegistrationMapper.queryForUnitPipelineEquipmentPage(page, jsonObject, records);
} else if ("2300".equals(jsonObject.get("EQU_CATEGORY_CODE"))) {
List<DictionarieValueModel> fillingMedium = Systemctl.dictionarieClient.dictValues("FILLING_MEDIUM").getResult();
Map<String, Object> fillingMediumMap = fillingMedium.stream().collect(Collectors.toMap(DictionarieValueModel::getDictDataKey, DictionarieValueModel::getDictDataValue));
Page<JSONObject> result = jgUseRegistrationMapper.queryForUnitVesselEquipmentPage(page, jsonObject);
Page<JSONObject> result = jgUseRegistrationMapper.queryForUnitVesselEquipmentPage(page, jsonObject, records);
result.getRecords().forEach(i -> {
i.put("chargingMedium", fillingMediumMap.get(i.get("chargingMedium")));
});
......
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.yeejoin.amos.boot.module.jg.api.dto.CompanyEquipCountDto;
import com.yeejoin.amos.boot.module.jg.api.dto.FlowingEquipRedisKeyDTO;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgInstallationNoticeMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IEquipUsedCheck;
import com.yeejoin.amos.boot.module.jg.biz.context.FlowingEquipRedisContext;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBucket;
import org.redisson.api.RLock;
......@@ -58,6 +60,7 @@ public class InstallNoticeEquipUsedCheckImpl implements IEquipUsedCheck {
}
equipListOfUsed.add(record);
redissonClient.getBucket(this.getFlowingEquipRedisKey(companyCode, bizType)).set(equipListOfUsed);
FlowingEquipRedisContext.setRedisKeyInfo(new FlowingEquipRedisKeyDTO(this.getFlowingEquipRedisKey(companyCode, bizType), Collections.singletonList(record)));
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
......@@ -89,6 +92,17 @@ public class InstallNoticeEquipUsedCheckImpl implements IEquipUsedCheck {
rBucket.set(equipListOfUsed);
}
/**
* 删除流程中的数据,释放redis空间(异常处理及驳回到发起节点、撤回到发起节点、完成时时进行)
*
* @param records 设备唯一标识
* @param redisKey key
*/
@Override
public void delDataForCheckWithKey(List<String> records, String redisKey) {
UseRegisterEquipUsedCheckImpl.delRedisData(records, redisKey, redissonClient);
}
@Override
public Set<String> getEquipInFlow(String companyCode) {
RBucket<Set<String>> rBucket = redissonClient.getBucket(this.getFlowingEquipRedisKey(companyCode, bizType));
......
......@@ -26,6 +26,7 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.JgInstallationNoticeMapper;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IJgInstallationNoticeService;
import com.yeejoin.amos.boot.module.jg.api.vo.SortVo;
import com.yeejoin.amos.boot.module.jg.biz.context.FlowingEquipRedisContext;
import com.yeejoin.amos.boot.module.jg.biz.feign.TzsServiceFeignClient;
import com.yeejoin.amos.boot.module.jg.biz.service.ICmWorkflowService;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgConstructionInfoService;
......@@ -509,56 +510,73 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
@SuppressWarnings({"Duplicates", "rawtypes"})
@Transactional(rollbackFor = Exception.class)
public List<JgInstallationNotice> saveNotice(String submitType, JSONObject jgInstallationNoticeDtoMap, ReginParams reginParams) {
try {
JgInstallationNoticeDto model = JSON.parseObject(jgInstallationNoticeDtoMap.get(TABLE_PAGE_ID).toString(), JgInstallationNoticeDto.class);
// 字段转换
this.convertField(model);
// 获取告知设备列表
List<Map<String, Object>> deviceList = model.getDeviceList();
if (CollectionUtils.isEmpty(deviceList)) {
throw new BadRequest("设备列表为空");
}
// 提交时对设备状态进行校验(处理并发问题,一个未被使用的设备同时被多个使用这打开,同时提交发起申请) todo 回滚异常未写
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
this.repeatUsedEquipCheck(deviceList, reginParams.getCompany().getCompanyCode());
}
// 获取告知单号
ResponseModel<List<String>> listResponseModel = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.AZGZ.getCode(), deviceList.size());
if (!ObjectUtils.isEmpty(listResponseModel) && listResponseModel.getStatus() != HttpStatus.OK.value()) {
log.error("告知单获取失败: {}", listResponseModel.getMessage());
throw new BadRequest("告知单生成失败!");
}
List<String> applyNoList = listResponseModel.getResult();
if (CollectionUtils.isEmpty(applyNoList)) {
log.error("告知单返回为空");
throw new BadRequest("告知单生成失败!");
}
JgInstallationNoticeDto model = JSON.parseObject(jgInstallationNoticeDtoMap.get(TABLE_PAGE_ID).toString(), JgInstallationNoticeDto.class);
// 字段转换
this.convertField(model);
// 获取告知设备列表
List<Map<String, Object>> deviceList = model.getDeviceList();
if (CollectionUtils.isEmpty(deviceList)) {
throw new BadRequest("设备列表为空");
}
// 提交时对设备状态进行校验(处理并发问题,一个未被使用的设备同时被多个使用这打开,同时提交发起申请) todo 回滚异常未写
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
this.repeatUsedEquipCheck(deviceList, reginParams.getCompany().getCompanyCode());
}
// 获取告知单号
ResponseModel<List<String>> listResponseModel = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.AZGZ.getCode(), deviceList.size());
if (!ObjectUtils.isEmpty(listResponseModel) && listResponseModel.getStatus() != HttpStatus.OK.value()) {
log.error("告知单获取失败: {}", listResponseModel.getMessage());
throw new BadRequest("告知单生成失败!");
}
List<String> applyNoList = listResponseModel.getResult();
if (CollectionUtils.isEmpty(applyNoList)) {
log.error("告知单返回为空");
throw new BadRequest("告知单生成失败!");
}
// 启动工作流并返回信息
List<WorkflowResultDto> workflowResultList = workFlowInfo(submitType, deviceList, model.getReceiveOrgCreditCode());
// 启动工作流并返回信息
List<WorkflowResultDto> workflowResultList = workFlowInfo(submitType, deviceList, model.getReceiveOrgCreditCode());
List<JgInstallationNotice> list = new ArrayList<>();
List<JgInstallationNoticeEq> equipList = new ArrayList<>();
// 业务数据组装等
businessData(submitType, reginParams, model, deviceList, applyNoList, list, equipList, workflowResultList);
List<JgInstallationNotice> list = new ArrayList<>();
List<JgInstallationNoticeEq> equipList = new ArrayList<>();
// 业务数据组装等
businessData(submitType, reginParams, model, deviceList, applyNoList, list, equipList, workflowResultList);
jgInstallationNoticeMapper.insertBatchSomeColumn(list);
// 如果为保存并提交,则创建代办
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
buildTask(list, workflowResultList, Boolean.TRUE);
} else {
// 暂存任务
buildTaskDraft(list);
jgInstallationNoticeMapper.insertBatchSomeColumn(list);
// 如果为保存并提交,则创建代办
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
buildTask(list, workflowResultList, Boolean.TRUE);
} else {
// 暂存任务
buildTaskDraft(list);
}
List<JgInstallationNoticeEq> jgRelationEquipList = equipList.stream().map(jgRelationEquip -> {
List<JgInstallationNotice> collect = list.stream().filter(jgInstallationNotice -> jgRelationEquip.getEquipTransferId().equals(jgInstallationNotice.getApplyNo())).collect(Collectors.toList());
Long sequenceNbr = collect.get(0).getSequenceNbr();
return jgRelationEquip.setEquipTransferId(String.valueOf(sequenceNbr));
}).collect(Collectors.toList());
jgInstallationNoticeEqMapper.insertBatchSomeColumn(jgRelationEquipList);
this.updateRedisBatch(list);
return list;
} catch (BadRequest e) {
log.error(e.getMessage(), e);
this.rollBackForDelRedisData();
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
this.rollBackForDelRedisData();
throw new BadRequest("安装告知保存失败!");
} finally {
FlowingEquipRedisContext.clean();
}
List<JgInstallationNoticeEq> jgRelationEquipList = equipList.stream().map(jgRelationEquip -> {
List<JgInstallationNotice> collect = list.stream().filter(jgInstallationNotice -> jgRelationEquip.getEquipTransferId().equals(jgInstallationNotice.getApplyNo())).collect(Collectors.toList());
Long sequenceNbr = collect.get(0).getSequenceNbr();
return jgRelationEquip.setEquipTransferId(String.valueOf(sequenceNbr));
}).collect(Collectors.toList());
jgInstallationNoticeEqMapper.insertBatchSomeColumn(jgRelationEquipList);
this.updateRedisBatch(list);
return list;
}
private void rollBackForDelRedisData() {
FlowingEquipRedisContext.getContext().forEach(e -> {
EquipUsedCheckStrategyContext.getUsedStrategy("installNotice").delDataForCheckWithKey(e.getData(), e.getRedisKey());
});
}
private void repeatUsedEquipCheck(List<Map<String, Object>> equipList, String companyCode) {
......
......@@ -107,4 +107,16 @@ public class UseRegisterEquipUsedCheckImpl implements IEquipUsedCheck {
rBucket.set(Arrays.stream(c.getRecords().split(",")).collect(Collectors.toSet()));
});
}
@Override
public void delDataForCheckWithKey(List<String> records, String redisKey) {
delRedisData(records, redisKey, redissonClient);
}
static void delRedisData(List<String> records, String redisKey, RedissonClient redissonClient) {
RBucket<Set<String>> rBucket = redissonClient.getBucket(redisKey);
Set<String> equipListOfUsed = rBucket.get();
equipListOfUsed = equipListOfUsed.stream().filter(record -> !records.contains(record)).collect(Collectors.toSet());
rBucket.set(equipListOfUsed);
}
}
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