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; ...@@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* Mapper 接口 * Mapper 接口
...@@ -49,14 +50,14 @@ public interface JgUseRegistrationMapper extends BaseMapper<JgUseRegistration> { ...@@ -49,14 +50,14 @@ public interface JgUseRegistrationMapper extends BaseMapper<JgUseRegistration> {
Map<String, Object> getUseRegistrationDetail(@Param("id")String id); 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); Page<JSONObject> queryForEquipUsedByVehiclePage(@Param("page") Page<JSONObject> page, @Param("jsonObject")JSONObject jsonObject);
@MapKey("records") @MapKey("records")
List<Map<String, Object>> queryForUnitVesselEquipment(@Param("records")List<String> 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") @MapKey("records")
List<Map<String, Object>> queryForUnitPipelineEquipment(@Param("records")List<String> records); List<Map<String, Object>> queryForUnitPipelineEquipment(@Param("records")List<String> records);
......
...@@ -39,4 +39,12 @@ public interface IEquipUsedCheck { ...@@ -39,4 +39,12 @@ public interface IEquipUsedCheck {
* 数据初始化方法 * 数据初始化方法
*/ */
void init(); void init();
/**
* 删除流程中的数据,释放redis空间(异常处理及驳回到发起节点、撤回到发起节点、完成时时进行)
*
* @param records 设备唯一标识
* @param redisKey key
*/
void delDataForCheckWithKey(List<String> records, String redisKey);
} }
...@@ -451,9 +451,19 @@ ...@@ -451,9 +451,19 @@
<if test="jsonObject.useUnitCreditCode != null and jsonObject.useUnitCreditCode != ''" > <if test="jsonObject.useUnitCreditCode != null and jsonObject.useUnitCreditCode != ''" >
and ui."USE_UNIT_CREDIT_CODE" = #{jsonObject.useUnitCreditCode} and ui."USE_UNIT_CREDIT_CODE" = #{jsonObject.useUnitCreditCode}
</if> </if>
<if test="jsonObject.record != null and jsonObject.record != ''" > <choose>
and ui."RECORD" = #{jsonObject.record} <when test="jsonObject.record != null and jsonObject.record != ''">
</if> 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 ORDER BY ui.REC_DATE DESC
</select> </select>
...@@ -510,9 +520,19 @@ ...@@ -510,9 +520,19 @@
<if test="jsonObject.useUnitCreditCode != null and jsonObject.useUnitCreditCode != ''"> <if test="jsonObject.useUnitCreditCode != null and jsonObject.useUnitCreditCode != ''">
and ui."USE_UNIT_CREDIT_CODE" = #{jsonObject.useUnitCreditCode} and ui."USE_UNIT_CREDIT_CODE" = #{jsonObject.useUnitCreditCode}
</if> </if>
<if test="jsonObject.record != null and jsonObject.record != ''" > <choose>
and ui."RECORD" = #{jsonObject.record} <when test="jsonObject.record != null and jsonObject.record != ''">
</if> 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 ORDER BY ui.REC_DATE DESC
</select> </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 ...@@ -1840,12 +1840,13 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
} }
jsonObject.put("useUnitCreditCode", useUnitCreditCode); jsonObject.put("useUnitCreditCode", useUnitCreditCode);
Page<JSONObject> page = new Page<>(jsonObject.getLong("number"), jsonObject.getLong("size")); 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"))) { 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"))) { } else if ("2300".equals(jsonObject.get("EQU_CATEGORY_CODE"))) {
List<DictionarieValueModel> fillingMedium = Systemctl.dictionarieClient.dictValues("FILLING_MEDIUM").getResult(); List<DictionarieValueModel> fillingMedium = Systemctl.dictionarieClient.dictValues("FILLING_MEDIUM").getResult();
Map<String, Object> fillingMediumMap = fillingMedium.stream().collect(Collectors.toMap(DictionarieValueModel::getDictDataKey, DictionarieValueModel::getDictDataValue)); 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 -> { result.getRecords().forEach(i -> {
i.put("chargingMedium", fillingMediumMap.get(i.get("chargingMedium"))); i.put("chargingMedium", fillingMediumMap.get(i.get("chargingMedium")));
}); });
......
package com.yeejoin.amos.boot.module.jg.biz.service.impl; 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.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.mapper.JgInstallationNoticeMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IEquipUsedCheck; 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 lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBucket; import org.redisson.api.RBucket;
import org.redisson.api.RLock; import org.redisson.api.RLock;
...@@ -58,6 +60,7 @@ public class InstallNoticeEquipUsedCheckImpl implements IEquipUsedCheck { ...@@ -58,6 +60,7 @@ public class InstallNoticeEquipUsedCheckImpl implements IEquipUsedCheck {
} }
equipListOfUsed.add(record); equipListOfUsed.add(record);
redissonClient.getBucket(this.getFlowingEquipRedisKey(companyCode, bizType)).set(equipListOfUsed); redissonClient.getBucket(this.getFlowingEquipRedisKey(companyCode, bizType)).set(equipListOfUsed);
FlowingEquipRedisContext.setRedisKeyInfo(new FlowingEquipRedisKeyDTO(this.getFlowingEquipRedisKey(companyCode, bizType), Collections.singletonList(record)));
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
...@@ -89,6 +92,17 @@ public class InstallNoticeEquipUsedCheckImpl implements IEquipUsedCheck { ...@@ -89,6 +92,17 @@ public class InstallNoticeEquipUsedCheckImpl implements IEquipUsedCheck {
rBucket.set(equipListOfUsed); rBucket.set(equipListOfUsed);
} }
/**
* 删除流程中的数据,释放redis空间(异常处理及驳回到发起节点、撤回到发起节点、完成时时进行)
*
* @param records 设备唯一标识
* @param redisKey key
*/
@Override
public void delDataForCheckWithKey(List<String> records, String redisKey) {
UseRegisterEquipUsedCheckImpl.delRedisData(records, redisKey, redissonClient);
}
@Override @Override
public Set<String> getEquipInFlow(String companyCode) { public Set<String> getEquipInFlow(String companyCode) {
RBucket<Set<String>> rBucket = redissonClient.getBucket(this.getFlowingEquipRedisKey(companyCode, bizType)); RBucket<Set<String>> rBucket = redissonClient.getBucket(this.getFlowingEquipRedisKey(companyCode, bizType));
......
...@@ -26,6 +26,7 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.JgInstallationNoticeMapper; ...@@ -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.mapper.JgUseRegistrationMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IJgInstallationNoticeService; 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.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.feign.TzsServiceFeignClient;
import com.yeejoin.amos.boot.module.jg.biz.service.ICmWorkflowService; import com.yeejoin.amos.boot.module.jg.biz.service.ICmWorkflowService;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgConstructionInfoService; import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgConstructionInfoService;
...@@ -509,56 +510,73 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -509,56 +510,73 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
@SuppressWarnings({"Duplicates", "rawtypes"}) @SuppressWarnings({"Duplicates", "rawtypes"})
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public List<JgInstallationNotice> saveNotice(String submitType, JSONObject jgInstallationNoticeDtoMap, ReginParams reginParams) { 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); // 启动工作流并返回信息
// 字段转换 List<WorkflowResultDto> workflowResultList = workFlowInfo(submitType, deviceList, model.getReceiveOrgCreditCode());
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<JgInstallationNotice> list = new ArrayList<>(); List<JgInstallationNotice> list = new ArrayList<>();
List<JgInstallationNoticeEq> equipList = new ArrayList<>(); List<JgInstallationNoticeEq> equipList = new ArrayList<>();
// 业务数据组装等 // 业务数据组装等
businessData(submitType, reginParams, model, deviceList, applyNoList, list, equipList, workflowResultList); businessData(submitType, reginParams, model, deviceList, applyNoList, list, equipList, workflowResultList);
jgInstallationNoticeMapper.insertBatchSomeColumn(list); jgInstallationNoticeMapper.insertBatchSomeColumn(list);
// 如果为保存并提交,则创建代办 // 如果为保存并提交,则创建代办
if (SUBMIT_TYPE_FLOW.equals(submitType)) { if (SUBMIT_TYPE_FLOW.equals(submitType)) {
buildTask(list, workflowResultList, Boolean.TRUE); buildTask(list, workflowResultList, Boolean.TRUE);
} else { } else {
// 暂存任务 // 暂存任务
buildTaskDraft(list); 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(); private void rollBackForDelRedisData() {
return jgRelationEquip.setEquipTransferId(String.valueOf(sequenceNbr)); FlowingEquipRedisContext.getContext().forEach(e -> {
}).collect(Collectors.toList()); EquipUsedCheckStrategyContext.getUsedStrategy("installNotice").delDataForCheckWithKey(e.getData(), e.getRedisKey());
jgInstallationNoticeEqMapper.insertBatchSomeColumn(jgRelationEquipList); });
this.updateRedisBatch(list);
return list;
} }
private void repeatUsedEquipCheck(List<Map<String, Object>> equipList, String companyCode) { private void repeatUsedEquipCheck(List<Map<String, Object>> equipList, String companyCode) {
......
...@@ -29,6 +29,7 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationEqMapper; ...@@ -29,6 +29,7 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationEqMapper;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationMapper; import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IJgUseRegistrationService; import com.yeejoin.amos.boot.module.jg.api.service.IJgUseRegistrationService;
import com.yeejoin.amos.boot.module.jg.api.vo.SortVo; 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.feign.TzsServiceFeignClient;
import com.yeejoin.amos.boot.module.jg.biz.service.ICommonService; import com.yeejoin.amos.boot.module.jg.biz.service.ICommonService;
import com.yeejoin.amos.boot.module.jg.biz.utils.CodeUtil; import com.yeejoin.amos.boot.module.jg.biz.utils.CodeUtil;
...@@ -142,7 +143,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -142,7 +143,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
@Autowired @Autowired
private JgUseRegistrationMapper jgUseRegistrationMapper; private JgUseRegistrationMapper jgUseRegistrationMapper;
private final List<String> NOT_FLOWING_STATE = Arrays.asList("使用单位待提交","一级受理已驳回", "使用单位已撤回", "已完成"); private final List<String> NOT_FLOWING_STATE = Arrays.asList("使用单位待提交", "一级受理已驳回", "使用单位已撤回", "已完成");
/** /**
* @param auditPassDate 通过时间 * @param auditPassDate 通过时间
...@@ -161,9 +162,9 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -161,9 +162,9 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
exportParamsMap.put("giveOutDay", today.getDayOfMonth()); exportParamsMap.put("giveOutDay", today.getDayOfMonth());
} }
public Page<Map<String, Object>> getList(JgUseRegistrationDto dto,String sort, Page<Map<String, Object>> page, List<String> roleIds) { public Page<Map<String, Object>> getList(JgUseRegistrationDto dto, String sort, Page<Map<String, Object>> page, List<String> roleIds) {
SortVo sortMap = commonServiceImpl.sortFieldConversion(sort); SortVo sortMap = commonServiceImpl.sortFieldConversion(sort);
return this.baseMapper.getListPage(page,sortMap, dto, roleIds); return this.baseMapper.getListPage(page, sortMap, dto, roleIds);
} }
public Page<Map<String, Object>> getEquipList(Page<Map<String, Object>> page, String factoryNum, String equList, String equCategory) { public Page<Map<String, Object>> getEquipList(Page<Map<String, Object>> page, String factoryNum, String equList, String equCategory) {
...@@ -323,7 +324,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -323,7 +324,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
* @param map map * @param map map
* @return list * @return list
*/ */
@Transactional @Transactional(rollbackFor = Exception.class)
public List<Map<String, Object>> save(JSONObject map) { public List<Map<String, Object>> save(JSONObject map) {
Map<String, Function<JSONObject, List<Map<String, Object>>>> functionMap = MapBuilder.<String, Function<JSONObject, List<Map<String, Object>>>>create() Map<String, Function<JSONObject, List<Map<String, Object>>>> functionMap = MapBuilder.<String, Function<JSONObject, List<Map<String, Object>>>>create()
.put("unit", this::handleUnitUseRegistration).build(); .put("unit", this::handleUnitUseRegistration).build();
...@@ -338,165 +339,183 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -338,165 +339,183 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
* @return list * @return list
*/ */
private List<Map<String, Object>> handleUseRegistration(JSONObject map) { private List<Map<String, Object>> handleUseRegistration(JSONObject map) {
ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class); try {
// 提交时进行校验设备是否在流程中使用(并发及同时打开多个相同的页面时才会出现此种情况) ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
checkForRepeatUsedEquip(map, reginParams); // 提交时进行校验设备是否在流程中使用(并发及同时打开多个相同的页面时才会出现此种情况)
// 使用登记信息 checkForRepeatUsedEquip(map, reginParams);
JgUseRegistration jgUseRegistration = new JgUseRegistration(); // 使用登记信息
jgUseRegistration.setRegDate(new Date()); JgUseRegistration jgUseRegistration = new JgUseRegistration();
LambdaQueryWrapper<IdxBizJgOtherInfo> otherLambda = new QueryWrapper<IdxBizJgOtherInfo>().lambda(); jgUseRegistration.setRegDate(new Date());
otherLambda.eq(IdxBizJgOtherInfo::getRecord, map.get("equipId")); LambdaQueryWrapper<IdxBizJgOtherInfo> otherLambda = new QueryWrapper<IdxBizJgOtherInfo>().lambda();
IdxBizJgOtherInfo otherInfo = otherInfoMapper.selectOne(otherLambda); otherLambda.eq(IdxBizJgOtherInfo::getRecord, map.get("equipId"));
String supervisoryCode = otherInfo.getSupervisoryCode(); IdxBizJgOtherInfo otherInfo = otherInfoMapper.selectOne(otherLambda);
jgUseRegistration.setSupervisoryCode(supervisoryCode); String supervisoryCode = otherInfo.getSupervisoryCode();
jgUseRegistration.setUseUnitName(String.valueOf(map.get("useUnitName"))); jgUseRegistration.setSupervisoryCode(supervisoryCode);
jgUseRegistration.setUseUnitCreditCode(String.valueOf(map.get("useUnitCreditCode"))); jgUseRegistration.setUseUnitName(String.valueOf(map.get("useUnitName")));
if (!ObjectUtils.isEmpty(map.get("otherAccessories"))) { jgUseRegistration.setUseUnitCreditCode(String.valueOf(map.get("useUnitCreditCode")));
jgUseRegistration.setOtherAccessories(JSONObject.toJSONString(map.get("otherAccessories"))); if (!ObjectUtils.isEmpty(map.get("otherAccessories"))) {
} jgUseRegistration.setOtherAccessories(JSONObject.toJSONString(map.get("otherAccessories")));
String equType = this.baseMapper.getEquType(String.valueOf(map.get("equipId")));
if (map.containsKey("receiveOrgCode")) {
// 接收单位信息
String[] splitMaintenanceUnitCode = String.valueOf(map.getString("receiveOrgCode")).split("_");
jgUseRegistration.setReceiveCompanyCode(splitMaintenanceUnitCode[0]);
jgUseRegistration.setReceiveOrgName(splitMaintenanceUnitCode[1]);
jgUseRegistration.setReceiveCompanyOrgCode(commonService.getOneCompany(jgUseRegistration.getReceiveCompanyCode()).getOrgCode());
}
// 安全管理员
if (map.containsKey("safetyManager")) {
String[] data = String.valueOf(map.getString("safetyManager")).split("_");
map.put("safetyManagerId", data[0]);
map.put("safetyManagerName", data[1]);
}
// 使用单位提交
jgUseRegistration.setUseUnitCreditCode(reginParams.getCompany().getCompanyCode());
jgUseRegistration.setCreateUserId(reginParams.getUserModel().getUserId());
if (!ObjectUtils.isEmpty(map.get("inspectUnitCreditCode"))) {
jgUseRegistration.setInspectUnitCreditCode(map.get("inspectUnitCreditCode").toString());
}
if (!ObjectUtils.isEmpty(map.get("inspectOrgName"))) {
jgUseRegistration.setInspectUnitName(map.get("inspectOrgName").toString());
}
// 是否西咸
if (!ObjectUtils.isEmpty(map.get("isXixian"))) {
jgUseRegistration.setIsXixian(String.valueOf(map.get("isXixian")));
}
// 使用地点
// 市
List<LinkedHashMap> city = (List<LinkedHashMap>) redisUtils.get("CITY");
// 区
List<LinkedHashMap> region = (List<LinkedHashMap>) redisUtils.get("REGION");
// 街道
List<LinkedHashMap> street = (List<LinkedHashMap>) redisUtils.get("STREET");
jgUseRegistration.setUseAddress("陕西省");
// 城市
if (!ObjectUtils.isEmpty(map.get("city")) && !ObjectUtils.isEmpty(city)) {
city.forEach(item -> {
if (String.valueOf(item.get("regionCode")).equals(String.valueOf(map.get("city")))) {
jgUseRegistration.setUseAddress(jgUseRegistration.getUseAddress() + item.get("regionName"));
}
});
}
// 区县
if (!ObjectUtils.isEmpty(map.get("county")) && !ObjectUtils.isEmpty(city)) {
region.forEach(item -> {
if (String.valueOf(item.get("regionCode")).equals(String.valueOf(map.get("county")))) {
jgUseRegistration.setUseAddress(jgUseRegistration.getUseAddress() + item.get("regionName"));
}
});
}
// 街道
if (!ObjectUtils.isEmpty(map.get("factoryUseSiteStreet")) && !ObjectUtils.isEmpty(city)) {
street.forEach(item -> {
if (String.valueOf(item.get("regionCode")).equals(String.valueOf(map.get("factoryUseSiteStreet")))) {
jgUseRegistration.setUseAddress(jgUseRegistration.getUseAddress() + item.get("regionName"));
}
});
}
jgUseRegistration.setUseAddress(jgUseRegistration.getUseAddress() + map.get("address"));
if (map.containsKey("type") && "edit".equals(String.valueOf(map.get("type")))) {
jgUseRegistration.setUseUnitCreditCode(null);
jgUseRegistration.setSequenceNbr(Long.valueOf(String.valueOf(map.get("sequenceNbr"))));
this.getBaseMapper().updateById(jgUseRegistration);
// 更新设备关联表
LambdaQueryWrapper<JgUseRegistrationEq> lambda = new QueryWrapper<JgUseRegistrationEq>().lambda();
lambda.eq(JgUseRegistrationEq::getEquipTransferId, jgUseRegistration.getSequenceNbr());
JgUseRegistrationEq jgUseRegistrationEq = new JgUseRegistrationEq();
jgUseRegistrationEq.setEquId(map.get("equipId").toString());
jgRelationEquipMapper.update(jgUseRegistrationEq, lambda);
} else {
// 业务管理设备信息保存
JgUseRegistrationEq jgRelationEquip = new JgUseRegistrationEq();
jgRelationEquip.setEquId(map.get("equipId").toString());
// List<String> applicationFormCode = iCreateCodeServicevice.createApplicationFormCode(ApplicationFormTypeEnum.SYDJ.getCode(), 1);
// jgUseRegistration.setApplyNo(applicationFormCode.get(0));
// ResponseModel<List<String>> listResponseModel = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.SYDJ.getCode(), 1);
ResponseModel<List<String>> listResponseModel = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.getCode.get(String.valueOf(map.get("businessCode"))), 1);
if (!ObjectUtils.isEmpty(listResponseModel)) {
jgUseRegistration.setApplyNo(listResponseModel.getResult().get(0));
} }
jgUseRegistration.setAuditStatus("待提交"); String equType = this.baseMapper.getEquType(String.valueOf(map.get("equipId")));
jgUseRegistration.setStatus(WorkFlowStatusEnum.USE_SUBMIT.getPass()); if (map.containsKey("receiveOrgCode")) {
this.save(jgUseRegistration); // 接收单位信息
jgRelationEquip.setEquipTransferId(jgUseRegistration.getSequenceNbr().toString()); String[] splitMaintenanceUnitCode = String.valueOf(map.getString("receiveOrgCode")).split("_");
jgRelationEquipMapper.insert(jgRelationEquip); jgUseRegistration.setReceiveCompanyCode(splitMaintenanceUnitCode[0]);
} jgUseRegistration.setReceiveOrgName(splitMaintenanceUnitCode[1]);
// 暂存历史表 jgUseRegistration.setReceiveCompanyOrgCode(commonService.getOneCompany(jgUseRegistration.getReceiveCompanyCode()).getOrgCode());
updateHistory(map, map.get("equipId").toString(), String.valueOf(jgUseRegistration.getSequenceNbr()), jgUseRegistration.getSupervisoryCode()); }
if (!ObjectUtils.isEmpty(map.get("submit"))) { // 安全管理员
// 删除暂存代办 if (map.containsKey("safetyManager")) {
commonServiceImpl.deleteTaskModel(String.valueOf(jgUseRegistration.getSequenceNbr())); String[] data = String.valueOf(map.getString("safetyManager")).split("_");
String instanceId = ""; map.put("safetyManagerId", data[0]);
if (!ObjectUtils.isEmpty(map.get("instanceId"))) { map.put("safetyManagerName", data[1]);
instanceId = map.get("instanceId").toString(); }
// 使用单位提交
jgUseRegistration.setUseUnitCreditCode(reginParams.getCompany().getCompanyCode());
jgUseRegistration.setCreateUserId(reginParams.getUserModel().getUserId());
if (!ObjectUtils.isEmpty(map.get("inspectUnitCreditCode"))) {
jgUseRegistration.setInspectUnitCreditCode(map.get("inspectUnitCreditCode").toString());
}
if (!ObjectUtils.isEmpty(map.get("inspectOrgName"))) {
jgUseRegistration.setInspectUnitName(map.get("inspectOrgName").toString());
}
// 是否西咸
if (!ObjectUtils.isEmpty(map.get("isXixian"))) {
jgUseRegistration.setIsXixian(String.valueOf(map.get("isXixian")));
}
// 使用地点
// 市
List<LinkedHashMap> city = (List<LinkedHashMap>) redisUtils.get("CITY");
// 区
List<LinkedHashMap> region = (List<LinkedHashMap>) redisUtils.get("REGION");
// 街道
List<LinkedHashMap> street = (List<LinkedHashMap>) redisUtils.get("STREET");
jgUseRegistration.setUseAddress("陕西省");
// 城市
if (!ObjectUtils.isEmpty(map.get("city")) && !ObjectUtils.isEmpty(city)) {
city.forEach(item -> {
if (String.valueOf(item.get("regionCode")).equals(String.valueOf(map.get("city")))) {
jgUseRegistration.setUseAddress(jgUseRegistration.getUseAddress() + item.get("regionName"));
}
});
}
// 区县
if (!ObjectUtils.isEmpty(map.get("county")) && !ObjectUtils.isEmpty(city)) {
region.forEach(item -> {
if (String.valueOf(item.get("regionCode")).equals(String.valueOf(map.get("county")))) {
jgUseRegistration.setUseAddress(jgUseRegistration.getUseAddress() + item.get("regionName"));
}
});
}
// 街道
if (!ObjectUtils.isEmpty(map.get("factoryUseSiteStreet")) && !ObjectUtils.isEmpty(city)) {
street.forEach(item -> {
if (String.valueOf(item.get("regionCode")).equals(String.valueOf(map.get("factoryUseSiteStreet")))) {
jgUseRegistration.setUseAddress(jgUseRegistration.getUseAddress() + item.get("regionName"));
}
});
}
jgUseRegistration.setUseAddress(jgUseRegistration.getUseAddress() + map.get("address"));
if (map.containsKey("type") && "edit".equals(String.valueOf(map.get("type")))) {
jgUseRegistration.setUseUnitCreditCode(null);
jgUseRegistration.setSequenceNbr(Long.valueOf(String.valueOf(map.get("sequenceNbr"))));
this.getBaseMapper().updateById(jgUseRegistration);
// 更新设备关联表
LambdaQueryWrapper<JgUseRegistrationEq> lambda = new QueryWrapper<JgUseRegistrationEq>().lambda();
lambda.eq(JgUseRegistrationEq::getEquipTransferId, jgUseRegistration.getSequenceNbr());
JgUseRegistrationEq jgUseRegistrationEq = new JgUseRegistrationEq();
jgUseRegistrationEq.setEquId(map.get("equipId").toString());
jgRelationEquipMapper.update(jgUseRegistrationEq, lambda);
} else { } else {
// 启动并执行流程
// instanceId = startByVariable();
ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO();
ActWorkflowStartDTO dto = new ActWorkflowStartDTO();
ArrayList<ActWorkflowStartDTO> list = new ArrayList<>();
dto.setProcessDefinitionKey(DEFINITION_KEY);
dto.setBusinessKey("1");
dto.setCompleteFirstTask(Boolean.TRUE);
// 接受机构
dto.setNextExecuteUserCompanyCode(jgUseRegistration.getReceiveCompanyCode());
list.add(dto);
actWorkflowBatchDTO.setProcess(list);
List<ProcessTaskDTO> processTaskDTOS = cmWorkflowService.startBatch(actWorkflowBatchDTO);
List<WorkflowResultDto> resultDto = commonServiceImpl.buildWorkFlowInfo(processTaskDTOS);
if (!ObjectUtils.isEmpty(resultDto) && !ObjectUtils.isEmpty(resultDto.get(0))) {
WorkflowResultDto workflowResultDto = resultDto.get(0);
updateData(jgUseRegistration.getSequenceNbr(), "0", workflowResultDto, Boolean.TRUE, "");
}
// 业务管理设备信息保存
JgUseRegistrationEq jgRelationEquip = new JgUseRegistrationEq();
jgRelationEquip.setEquId(map.get("equipId").toString());
// List<String> applicationFormCode = iCreateCodeServicevice.createApplicationFormCode(ApplicationFormTypeEnum.SYDJ.getCode(), 1);
// jgUseRegistration.setApplyNo(applicationFormCode.get(0));
// ResponseModel<List<String>> listResponseModel = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.SYDJ.getCode(), 1);
ResponseModel<List<String>> listResponseModel = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.getCode.get(String.valueOf(map.get("businessCode"))), 1);
if (!ObjectUtils.isEmpty(listResponseModel)) {
jgUseRegistration.setApplyNo(listResponseModel.getResult().get(0));
}
jgUseRegistration.setAuditStatus("待提交");
jgUseRegistration.setStatus(WorkFlowStatusEnum.USE_SUBMIT.getPass());
this.save(jgUseRegistration);
jgRelationEquip.setEquipTransferId(jgUseRegistration.getSequenceNbr().toString());
jgRelationEquipMapper.insert(jgRelationEquip);
} }
// 暂存历史表
updateHistory(map, map.get("equipId").toString(), String.valueOf(jgUseRegistration.getSequenceNbr()), jgUseRegistration.getSupervisoryCode());
if (!ObjectUtils.isEmpty(map.get("submit"))) {
// 删除暂存代办
commonServiceImpl.deleteTaskModel(String.valueOf(jgUseRegistration.getSequenceNbr()));
String instanceId = "";
if (!ObjectUtils.isEmpty(map.get("instanceId"))) {
instanceId = map.get("instanceId").toString();
} else {
// 启动并执行流程
// instanceId = startByVariable();
ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO();
ActWorkflowStartDTO dto = new ActWorkflowStartDTO();
ArrayList<ActWorkflowStartDTO> list = new ArrayList<>();
dto.setProcessDefinitionKey(DEFINITION_KEY);
dto.setBusinessKey("1");
dto.setCompleteFirstTask(Boolean.TRUE);
// 接受机构
dto.setNextExecuteUserCompanyCode(jgUseRegistration.getReceiveCompanyCode());
list.add(dto);
actWorkflowBatchDTO.setProcess(list);
List<ProcessTaskDTO> processTaskDTOS = cmWorkflowService.startBatch(actWorkflowBatchDTO);
List<WorkflowResultDto> resultDto = commonServiceImpl.buildWorkFlowInfo(processTaskDTOS);
if (!ObjectUtils.isEmpty(resultDto) && !ObjectUtils.isEmpty(resultDto.get(0))) {
WorkflowResultDto workflowResultDto = resultDto.get(0);
updateData(jgUseRegistration.getSequenceNbr(), "0", workflowResultDto, Boolean.TRUE, "");
}
if (!ObjectUtils.isEmpty(instanceId)) { }
// 执行流程
flowExecute(jgUseRegistration.getSequenceNbr(), instanceId, "0", "", "", map.getString("manageType"), String.valueOf(map.get("nextTaskId"))); if (!ObjectUtils.isEmpty(instanceId)) {
// 执行流程
flowExecute(jgUseRegistration.getSequenceNbr(), instanceId, "0", "", "", map.getString("manageType"), String.valueOf(map.get("nextTaskId")));
}
} else {
ArrayList<TaskModelDto> list = new ArrayList<>();
TaskModelDto dto = new TaskModelDto();
TaskMessageDto taskMessageDto = new TaskMessageDto();
BeanUtil.copyProperties(jgUseRegistration, taskMessageDto);
taskMessageDto.setEquipId(String.valueOf(map.get("equipId")));
// 数据参数
dto.setModel(taskMessageDto);
// 摘要
dto.setTaskContent("来自" + equType + "【" + (ObjectUtils.isEmpty(jgUseRegistration.getSupervisoryCode()) ? "无" : jgUseRegistration.getSupervisoryCode()) + "】的业务办理," + "【申请单号:" + jgUseRegistration.getApplyNo() + "】");
// 申请单号
dto.setTaskCode(jgUseRegistration.getApplyNo());
// 业务类型
dto.setTaskType(String.valueOf(BusinessTypeEnum.JG_USAGE_REGISTRATION.getCode()));
// 业务主键
dto.setRelationId(String.valueOf(jgUseRegistration.getSequenceNbr()));
dto.setNextExecuteUser("");
list.add(dto);
commonServiceImpl.buildTaskModel(list);
} }
} else { return this.baseMapper.getDetailById(jgUseRegistration.getSequenceNbr());
ArrayList<TaskModelDto> list = new ArrayList<>(); } catch (BadRequest e) {
TaskModelDto dto = new TaskModelDto(); log.error(e.getMessage(), e);
TaskMessageDto taskMessageDto = new TaskMessageDto(); this.rollBackForDelRedisData();
BeanUtil.copyProperties(jgUseRegistration, taskMessageDto); throw e;
taskMessageDto.setEquipId(String.valueOf(map.get("equipId"))); } catch (Exception e) {
// 数据参数 log.error(e.getMessage(), e);
dto.setModel(taskMessageDto); this.rollBackForDelRedisData();
// 摘要 throw new BadRequest("使用登记保存失败!");
dto.setTaskContent("来自" + equType + "【" + (ObjectUtils.isEmpty(jgUseRegistration.getSupervisoryCode()) ? "无" : jgUseRegistration.getSupervisoryCode()) + "】的业务办理," + "【申请单号:" + jgUseRegistration.getApplyNo() + "】"); } finally {
// 申请单号 FlowingEquipRedisContext.clean();
dto.setTaskCode(jgUseRegistration.getApplyNo());
// 业务类型
dto.setTaskType(String.valueOf(BusinessTypeEnum.JG_USAGE_REGISTRATION.getCode()));
// 业务主键
dto.setRelationId(String.valueOf(jgUseRegistration.getSequenceNbr()));
dto.setNextExecuteUser("");
list.add(dto);
commonServiceImpl.buildTaskModel(list);
} }
return this.baseMapper.getDetailById(jgUseRegistration.getSequenceNbr()); }
private void rollBackForDelRedisData() {
FlowingEquipRedisContext.getContext().forEach(e -> {
EquipUsedCheckStrategyContext.getUsedStrategy("useRegister").delDataForCheckWithKey(e.getData(), e.getRedisKey());
});
} }
private void checkForRepeatUsedEquip(JSONObject map, ReginParams reginParams) { private void checkForRepeatUsedEquip(JSONObject map, ReginParams reginParams) {
...@@ -505,6 +524,14 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -505,6 +524,14 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
} }
} }
private void checkForRepeatUsedEquip(JSONObject map, List<Map<String, Object>> equList, ReginParams reginParams) {
if (!ObjectUtils.isEmpty(map.get("submit"))) {
equList.forEach(equip -> {
EquipUsedCheckStrategyContext.getUsedStrategy("useRegister").equipRepeatUsedCheck(equip.get("record").toString(), reginParams.getCompany().getCompanyCode());
});
}
}
/** /**
* 按单位办理 * 按单位办理
* *
...@@ -512,153 +539,167 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -512,153 +539,167 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
* @return list * @return list
*/ */
private List<Map<String, Object>> handleUnitUseRegistration(JSONObject map) { private List<Map<String, Object>> handleUnitUseRegistration(JSONObject map) {
ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())) + "", ReginParams.class); try {
CompanyBo company = reginParams.getCompany(); ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())) + "", ReginParams.class);
CompanyBo company = reginParams.getCompany();
List<Map<String, Object>> equipmentLists = (List<Map<String, Object>>) map.get("equipmentLists");
if (org.springframework.util.CollectionUtils.isEmpty(equipmentLists) || equipmentLists.stream() List<Map<String, Object>> equipmentLists = (List<Map<String, Object>>) map.get("equipmentLists");
.map(v -> (String) v.get("EQU_DEFINE_CODE")) if (org.springframework.util.CollectionUtils.isEmpty(equipmentLists) || equipmentLists.stream()
.distinct() .map(v -> (String) v.get("EQU_DEFINE_CODE"))
.count() != 1) { .distinct()
throw new BadRequest(CollectionUtils.isEmpty(equipmentLists) ? "请选择设备信息!" : "请选择相同设备种类!"); .count() != 1) {
} throw new BadRequest(CollectionUtils.isEmpty(equipmentLists) ? "请选择设备信息!" : "请选择相同设备种类!");
List<IdxBizJgInspectionDetectionInfo> inspectionDetectionInfoList = idxBizJgInspectionDetectionInfoService.checkInspectionInfo( }
equipmentLists.stream() // 提交时进行校验设备是否在流程中使用(并发及同时打开多个相同的页面时才会出现此种情况)
.map(v -> (String) v.get("record")) checkForRepeatUsedEquip(map, equipmentLists, reginParams);
.collect(Collectors.toList()) List<IdxBizJgInspectionDetectionInfo> inspectionDetectionInfoList = idxBizJgInspectionDetectionInfoService.checkInspectionInfo(
); equipmentLists.stream()
if (!CylinderTypeEnum.CYLINDER.getCode().equals(map.get("EQU_CATEGORY_CODE")) && inspectionDetectionInfoList.stream().anyMatch(info -> .map(v -> (String) v.get("record"))
ObjectUtils.isEmpty(info) || ObjectUtils.isEmpty(info.getInspectType()) || .collect(Collectors.toList())
ObjectUtils.isEmpty(info.getInspectConclusion()) || ObjectUtils.isEmpty(info.getInspectOrgCode()) || );
ObjectUtils.isEmpty(info.getInspectOrgName()))) { if (!CylinderTypeEnum.CYLINDER.getCode().equals(map.get("EQU_CATEGORY_CODE")) && inspectionDetectionInfoList.stream().anyMatch(info ->
throw new BadRequest("请补充设备检验检测信息后提交!"); ObjectUtils.isEmpty(info) || ObjectUtils.isEmpty(info.getInspectType()) ||
} ObjectUtils.isEmpty(info.getInspectConclusion()) || ObjectUtils.isEmpty(info.getInspectOrgCode()) ||
ObjectUtils.isEmpty(info.getInspectOrgName()))) {
throw new BadRequest("请补充设备检验检测信息后提交!");
}
JgUseRegistration useRegistration = JSON.parseObject(JSON.toJSONString(map), JgUseRegistration.class); JgUseRegistration useRegistration = JSON.parseObject(JSON.toJSONString(map), JgUseRegistration.class);
useRegistration.setRegDate(new Date()); useRegistration.setRegDate(new Date());
useRegistration.setManageType(map.getString("manageType")); useRegistration.setManageType(map.getString("manageType"));
useRegistration.setPromoter(reginParams.getUserModel().getUserId()); useRegistration.setPromoter(reginParams.getUserModel().getUserId());
useRegistration.setCreateUserId(reginParams.getUserModel().getUserId()); useRegistration.setCreateUserId(reginParams.getUserModel().getUserId());
// 使用单位信息 // 使用单位信息
useRegistration.setUseUnitName(company.getCompanyName()); useRegistration.setUseUnitName(company.getCompanyName());
useRegistration.setUseUnitCreditCode(company.getCompanyCode()); useRegistration.setUseUnitCreditCode(company.getCompanyCode());
List<LinkedHashMap> tree = commonService.getCreatTree(); List<LinkedHashMap> tree = commonService.getCreatTree();
// 接收单位信息 // 接收单位信息
Optional.ofNullable(useRegistration.getReceiveOrgCode()) Optional.ofNullable(useRegistration.getReceiveOrgCode())
.filter(code -> code.contains("_")) .filter(code -> code.contains("_"))
.map(code -> code.split("_")) .map(code -> code.split("_"))
.ifPresent(splitReceiveOrgCode -> { .ifPresent(splitReceiveOrgCode -> {
CompanyModel result = Privilege.companyClient.queryByCompanyCode(splitReceiveOrgCode[0]).getResult(); CompanyModel result = Privilege.companyClient.queryByCompanyCode(splitReceiveOrgCode[0]).getResult();
useRegistration.setReceiveOrgCode(splitReceiveOrgCode[0]); useRegistration.setReceiveOrgCode(splitReceiveOrgCode[0]);
useRegistration.setReceiveCompanyOrgCode(splitReceiveOrgCode[0]); useRegistration.setReceiveCompanyOrgCode(splitReceiveOrgCode[0]);
useRegistration.setReceiveCompanyCode(result.getCompanyCode()); useRegistration.setReceiveCompanyCode(result.getCompanyCode());
useRegistration.setReceiveOrgName(splitReceiveOrgCode[1]); useRegistration.setReceiveOrgName(splitReceiveOrgCode[1]);
}); });
// 安全管理员 // 安全管理员
Optional.ofNullable(map.getString("safetyManager")) Optional.ofNullable(map.getString("safetyManager"))
.filter(manager -> manager.contains("_")) .filter(manager -> manager.contains("_"))
.map(manager -> manager.split("_")) .map(manager -> manager.split("_"))
.ifPresent(data -> { .ifPresent(data -> {
map.put("safetyManagerId", data[0]); map.put("safetyManagerId", data[0]);
map.put("safetyManagerName", data[1]); map.put("safetyManagerName", data[1]);
}); });
// 其他附件 // 其他附件
if (!ObjectUtils.isEmpty(map.get("otherAccessories"))) { if (!ObjectUtils.isEmpty(map.get("otherAccessories"))) {
useRegistration.setOtherAccessories(JSONObject.toJSONString(map.get("otherAccessories"))); useRegistration.setOtherAccessories(JSONObject.toJSONString(map.get("otherAccessories")));
} }
// 使用地点 // 使用地点
Map<String, List<LinkedHashMap>> locationMap = MapBuilder.<String, List<LinkedHashMap>>create() Map<String, List<LinkedHashMap>> locationMap = MapBuilder.<String, List<LinkedHashMap>>create()
.put("city", (List<LinkedHashMap>) redisUtils.get("CITY")) .put("city", (List<LinkedHashMap>) redisUtils.get("CITY"))
.put("county", (List<LinkedHashMap>) redisUtils.get("REGION")) .put("county", (List<LinkedHashMap>) redisUtils.get("REGION"))
.put("factoryUseSiteStreet", (List<LinkedHashMap>) redisUtils.get("STREET")) .put("factoryUseSiteStreet", (List<LinkedHashMap>) redisUtils.get("STREET"))
.build(); .build();
String fullAddress = locationMap.entrySet().stream() String fullAddress = locationMap.entrySet().stream()
.map(entry -> { .map(entry -> {
String mapKey = String.valueOf(map.get(entry.getKey())); String mapKey = String.valueOf(map.get(entry.getKey()));
List<LinkedHashMap> locations = entry.getValue(); List<LinkedHashMap> locations = entry.getValue();
return (!ObjectUtils.isEmpty(mapKey) && !ObjectUtils.isEmpty(locations)) ? return (!ObjectUtils.isEmpty(mapKey) && !ObjectUtils.isEmpty(locations)) ?
locations.stream() locations.stream()
.filter(item -> mapKey.equals(String.valueOf(item.get("regionCode")))) .filter(item -> mapKey.equals(String.valueOf(item.get("regionCode"))))
.map(item -> String.valueOf(item.get("regionName"))) .map(item -> String.valueOf(item.get("regionName")))
.findFirst() .findFirst()
.orElse("") : .orElse("") :
""; "";
}) })
.collect(Collectors.joining()); .collect(Collectors.joining());
// 具体地址 // 具体地址
useRegistration.setUseAddress("陕西省" + fullAddress + map.get("address")); useRegistration.setUseAddress("陕西省" + fullAddress + map.get("address"));
// 新增或编辑保存 // 新增或编辑保存
if (StringUtils.isEmpty(useRegistration.getSequenceNbr())) { if (StringUtils.isEmpty(useRegistration.getSequenceNbr())) {
ResponseModel<List<String>> listResponseModel = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.getCode.get(String.valueOf(map.get("businessCode"))), 1); ResponseModel<List<String>> listResponseModel = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.getCode.get(String.valueOf(map.get("businessCode"))), 1);
if (!ObjectUtils.isEmpty(listResponseModel) && listResponseModel.getStatus() != HttpStatus.OK.value()) { if (!ObjectUtils.isEmpty(listResponseModel) && listResponseModel.getStatus() != HttpStatus.OK.value()) {
log.error("使用登记申请单单号获取失败!"); log.error("使用登记申请单单号获取失败!");
throw new BadRequest("使用登记申请单单号获取失败!"); throw new BadRequest("使用登记申请单单号获取失败!");
}
useRegistration.setApplyNo(listResponseModel.getResult().get(0));
useRegistration.setAuditStatus("待提交");
useRegistration.setStatus(WorkFlowStatusEnum.USE_SUBMIT.getPass());
this.save(useRegistration);
} else {
this.updateById(useRegistration);
// 删除设备关联表记录
jgRelationEquipMapper.delete(new QueryWrapper<JgUseRegistrationEq>().lambda().eq(JgUseRegistrationEq::getEquipTransferId, useRegistration.getSequenceNbr()));
} }
useRegistration.setApplyNo(listResponseModel.getResult().get(0)); // 更新关联气瓶信息
useRegistration.setAuditStatus("待提交"); List<JgUseRegistrationEq> equipList = equipmentLists.stream()
useRegistration.setStatus(WorkFlowStatusEnum.USE_SUBMIT.getPass()); .map(x -> new JgUseRegistrationEq()
this.save(useRegistration); .setEquId(String.valueOf(x.get("record")))
} else { .setEquipTransferId(String.valueOf(useRegistration.getSequenceNbr())))
this.updateById(useRegistration); .collect(Collectors.toList());
// 删除设备关联表记录 // 保存关联设备信息
jgRelationEquipMapper.delete(new QueryWrapper<JgUseRegistrationEq>().lambda().eq(JgUseRegistrationEq::getEquipTransferId, useRegistration.getSequenceNbr())); jgUseRegistrationEqService.saveBatch(equipList);
}
// 更新关联气瓶信息 // 启动流程
List<JgUseRegistrationEq> equipList = equipmentLists.stream() if (!ObjectUtils.isEmpty(map.get("submit"))) {
.map(x -> new JgUseRegistrationEq() // 删除暂存代办
.setEquId(String.valueOf(x.get("record"))) commonServiceImpl.deleteTaskModel(String.valueOf(useRegistration.getSequenceNbr()));
.setEquipTransferId(String.valueOf(useRegistration.getSequenceNbr()))) // 新增提交,没有instanceId需要发起流程
.collect(Collectors.toList()); if (StringUtils.isEmpty(useRegistration.getInstanceId())) {
// 保存关联设备信息 ActWorkflowStartDTO dto = new ActWorkflowStartDTO();
jgUseRegistrationEqService.saveBatch(equipList); dto.setProcessDefinitionKey(DEFINITION_KEY);
dto.setBusinessKey(useRegistration.getApplyNo());
// 启动流程 dto.setCompleteFirstTask(true);
if (!ObjectUtils.isEmpty(map.get("submit"))) { dto.setNextExecuteUserCompanyCode(useRegistration.getReceiveCompanyCode());
// 删除暂存代办 ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO();
commonServiceImpl.deleteTaskModel(String.valueOf(useRegistration.getSequenceNbr())); actWorkflowBatchDTO.setProcess(Collections.singletonList(dto));
// 新增提交,没有instanceId需要发起流程
if (StringUtils.isEmpty(useRegistration.getInstanceId())) { List<ProcessTaskDTO> processTaskDTOS = cmWorkflowService.startBatch(actWorkflowBatchDTO);
ActWorkflowStartDTO dto = new ActWorkflowStartDTO(); List<WorkflowResultDto> resultDto = commonServiceImpl.buildWorkFlowInfo(processTaskDTOS);
dto.setProcessDefinitionKey(DEFINITION_KEY);
dto.setBusinessKey(useRegistration.getApplyNo()); resultDto.stream()
dto.setCompleteFirstTask(true); .findFirst()
dto.setNextExecuteUserCompanyCode(useRegistration.getReceiveCompanyCode()); .ifPresent(workflowResultDto ->
ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO(); this.updateUseRegUnitData(useRegistration.getSequenceNbr(), "0", workflowResultDto, true));
actWorkflowBatchDTO.setProcess(Collections.singletonList(dto)); } else {
// 执行流程
List<ProcessTaskDTO> processTaskDTOS = cmWorkflowService.startBatch(actWorkflowBatchDTO); flowExecute(useRegistration.getSequenceNbr(), useRegistration.getInstanceId(), "0", "", "", map.getString("manageType"), String.valueOf(map.get("nextTaskId")));
List<WorkflowResultDto> resultDto = commonServiceImpl.buildWorkFlowInfo(processTaskDTOS); }
resultDto.stream()
.findFirst()
.ifPresent(workflowResultDto ->
this.updateUseRegUnitData(useRegistration.getSequenceNbr(), "0", workflowResultDto, true));
} else { } else {
// 执行流程 String equType = this.baseMapper.getEquType(String.valueOf(map.get("EQU_LIST_CODE")));
flowExecute(useRegistration.getSequenceNbr(), useRegistration.getInstanceId(), "0", "", "", map.getString("manageType"), String.valueOf(map.get("nextTaskId"))); TaskModelDto dto = TaskModelDto.builder()
.model(BeanUtil.copyProperties(useRegistration, TaskMessageDto.class))
.taskContent("来自" + equType + "【" + (ObjectUtils.isEmpty(useRegistration.getSupervisoryCode()) ? "无" : useRegistration.getSupervisoryCode()) + "】等的业务办理,"
+ "【申请单号:" + useRegistration.getApplyNo() + "】")
.taskCode(useRegistration.getApplyNo())
.taskType(String.valueOf(BusinessTypeEnum.JG_USAGE_REGISTRATION.getCode()))
.relationId(String.valueOf(useRegistration.getSequenceNbr()))
.nextExecuteUser("")
.build();
commonServiceImpl.buildTaskModel(Collections.singletonList(dto));
} }
} else { // 设备数据存历史数据,在流程完成时使用
String equType = this.baseMapper.getEquType(String.valueOf(map.get("EQU_LIST_CODE"))); updateHistory(map, null, String.valueOf(useRegistration.getSequenceNbr()), useRegistration.getSupervisoryCode());
TaskModelDto dto = TaskModelDto.builder() return this.baseMapper.getDetailById(useRegistration.getSequenceNbr());
.model(BeanUtil.copyProperties(useRegistration, TaskMessageDto.class)) } catch (BadRequest e) {
.taskContent("来自" + equType + "【" + (ObjectUtils.isEmpty(useRegistration.getSupervisoryCode()) ? "无" : useRegistration.getSupervisoryCode()) + "】等的业务办理," log.error(e.getMessage(), e);
+ "【申请单号:" + useRegistration.getApplyNo() + "】") this.rollBackForDelRedisData();
.taskCode(useRegistration.getApplyNo()) throw e;
.taskType(String.valueOf(BusinessTypeEnum.JG_USAGE_REGISTRATION.getCode())) } catch (Exception e) {
.relationId(String.valueOf(useRegistration.getSequenceNbr())) log.error(e.getMessage(), e);
.nextExecuteUser("") this.rollBackForDelRedisData();
.build(); throw new BadRequest("使用登记保存失败!");
} finally {
commonServiceImpl.buildTaskModel(Collections.singletonList(dto)); FlowingEquipRedisContext.clean();
} }
// 设备数据存历史数据,在流程完成时使用
updateHistory(map, null, String.valueOf(useRegistration.getSequenceNbr()), useRegistration.getSupervisoryCode());
return this.baseMapper.getDetailById(useRegistration.getSequenceNbr());
} }
/** /**
...@@ -1142,7 +1183,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -1142,7 +1183,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
} }
} }
private void clearDataForCheckEquipRepeatUsed(JgUseRegistration useRegistration){ private void clearDataForCheckEquipRepeatUsed(JgUseRegistration useRegistration) {
// 新查询原因 useRegistration 数据状态是旧的 // 新查询原因 useRegistration 数据状态是旧的
JgUseRegistration useRegistrationDb = this.getById(useRegistration.getSequenceNbr()); JgUseRegistration useRegistrationDb = this.getById(useRegistration.getSequenceNbr());
LambdaQueryWrapper<JgUseRegistrationEq> lambda = new QueryWrapper<JgUseRegistrationEq>().lambda(); LambdaQueryWrapper<JgUseRegistrationEq> lambda = new QueryWrapper<JgUseRegistrationEq>().lambda();
...@@ -1150,9 +1191,9 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -1150,9 +1191,9 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
lambda.select(JgUseRegistrationEq::getEquId); lambda.select(JgUseRegistrationEq::getEquId);
List<JgUseRegistrationEq> eqList = jgRelationEquipMapper.selectList(lambda); List<JgUseRegistrationEq> eqList = jgRelationEquipMapper.selectList(lambda);
// 在使用单位待提交、一级受理已驳回、使用单位已撤回后清除关联的设备,保证可以再次新提单子选择相同的设备进行提交及原有单子的提交校验数据准备 // 在使用单位待提交、一级受理已驳回、使用单位已撤回后清除关联的设备,保证可以再次新提单子选择相同的设备进行提交及原有单子的提交校验数据准备
if(NOT_FLOWING_STATE.contains(useRegistrationDb.getStatus())){ if (NOT_FLOWING_STATE.contains(useRegistrationDb.getStatus())) {
List<String> records = eqList.stream().map(JgUseRegistrationEq::getEquId).collect(Collectors.toList()); List<String> records = eqList.stream().map(JgUseRegistrationEq::getEquId).collect(Collectors.toList());
EquipUsedCheckStrategyContext.getUsedStrategy("useRegister").delDataForCheckEquipRepeatUsed(records,useRegistration.getUseUnitCreditCode()); EquipUsedCheckStrategyContext.getUsedStrategy("useRegister").delDataForCheckEquipRepeatUsed(records, useRegistration.getUseUnitCreditCode());
} }
} }
...@@ -1192,7 +1233,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -1192,7 +1233,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
jsonObject.remove("equipmentLists"); jsonObject.remove("equipmentLists");
if (CylinderTypeEnum.CYLINDER.getCode().equals(jsonObject.get("EQU_CATEGORY_CODE"))) { if (CylinderTypeEnum.CYLINDER.getCode().equals(jsonObject.get("EQU_CATEGORY_CODE"))) {
List<DictionarieValueModel> fillingMedium = Systemctl.dictionarieClient.dictValues("FILLING_MEDIUM").getResult(); List<DictionarieValueModel> fillingMedium = Systemctl.dictionarieClient.dictValues("FILLING_MEDIUM").getResult();
Map<String, Object> fillingMediumMap = fillingMedium.stream().collect(Collectors.toMap(DictionarieValueModel::getDictDataKey,DictionarieValueModel::getDictDataValue)); Map<String, Object> fillingMediumMap = fillingMedium.stream().collect(Collectors.toMap(DictionarieValueModel::getDictDataKey, DictionarieValueModel::getDictDataValue));
List<Map<String, Object>> result = jgUseRegistrationMapper.queryForUnitVesselEquipment(records); List<Map<String, Object>> result = jgUseRegistrationMapper.queryForUnitVesselEquipment(records);
result.forEach(i -> { result.forEach(i -> {
i.put("chargingMedium", fillingMediumMap.get(i.get("chargingMedium"))); i.put("chargingMedium", fillingMediumMap.get(i.get("chargingMedium")));
......
...@@ -107,4 +107,16 @@ public class UseRegisterEquipUsedCheckImpl implements IEquipUsedCheck { ...@@ -107,4 +107,16 @@ public class UseRegisterEquipUsedCheckImpl implements IEquipUsedCheck {
rBucket.set(Arrays.stream(c.getRecords().split(",")).collect(Collectors.toSet())); 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