Commit 3049edbf authored by suhuiguang's avatar suhuiguang

reafact(jg): 批量删除

1.设备批量删除 2.装置批量删除
parent 3ac60aac
...@@ -81,6 +81,14 @@ public interface CommonMapper extends BaseMapper<EquipmentCategory> { ...@@ -81,6 +81,14 @@ public interface CommonMapper extends BaseMapper<EquipmentCategory> {
Integer countEquipInUseTimesWithOutZF(String record); Integer countEquipInUseTimesWithOutZF(String record);
/** /**
* 统计设备被引用的次数(只有存在就算引用-作废除外)
*
* @param records 设备唯一标识
* @return 被引用次数 > 0 则设备不可删除
*/
List<CountDto> countEquipInUseTimesWithOutZFBatch(@Param("records") List<String> records);
/**
* 查询使该设备变为已纳管的业务的数量 [> 0,则纳管状态不需要更新][< 0,则纳管状态需要更新] * 查询使该设备变为已纳管的业务的数量 [> 0,则纳管状态不需要更新][< 0,则纳管状态需要更新]
* @param record 设备唯一标识 * @param record 设备唯一标识
* @return 使设备变为已纳管设备的的业务数量 * @return 使设备变为已纳管设备的的业务数量
......
...@@ -3329,4 +3329,62 @@ ...@@ -3329,4 +3329,62 @@
equ_id = #{record} and change_content = '设备编辑' equ_id = #{record} and change_content = '设备编辑'
) a ) a
</select> </select>
<select id="countEquipInUseTimesWithOutZFBatch" resultType="com.yeejoin.amos.boot.biz.common.dto.CountDto">
select
sum(inUseNumber) longValue,
record as keyStr
from (
select
count(1) as inUseNumber,
b.equ_id AS record
from
tzs_jg_use_registration a,
tzs_jg_use_registration_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = ANY(ARRAY[
<foreach collection="records" item="record" separator=",">
#{record}
</foreach>
])
and a.is_delete = 0
and ( a.status <![CDATA[ <> ]]> '已作废')
GROUP BY b.equ_id
UNION ALL
select
count(1) as inUseNumber,
b.equ_id AS record
from
tzs_jg_installation_notice a,
tzs_jg_installation_notice_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = ANY(ARRAY[
<foreach collection="records" item="record" separator=",">
#{record}
</foreach>
])
and a.is_delete = 0
and (a.notice_status <![CDATA[ <> ]]> '6617')
GROUP BY b.equ_id
UNION ALL
select
count(1) as inUseNumber,
b.equ_id AS record
from
tzs_jg_vehicle_information a,
tzs_jg_vehicle_information_eq b
where
a.sequence_nbr = b.vehicle_id
and b.equ_id = ANY(ARRAY[
<foreach collection="records" item="record" separator=",">
#{record}
</foreach>
])
and a.is_delete = 0
and (a.status <![CDATA[ <> ]]> '已作废')
GROUP BY b.equ_id
)
GROUP BY record
</select>
</mapper> </mapper>
...@@ -40,6 +40,7 @@ public class DataSourceConfiguration { ...@@ -40,6 +40,7 @@ public class DataSourceConfiguration {
dataSource.setConnectionTimeout(hikariDataSourceProperties.getConnectionTimeout()); dataSource.setConnectionTimeout(hikariDataSourceProperties.getConnectionTimeout());
dataSource.setIdleTimeout(hikariDataSourceProperties.getIdleTimeout()); dataSource.setIdleTimeout(hikariDataSourceProperties.getIdleTimeout());
dataSource.setConnectionInitSql(hikariDataSourceProperties.getConnectionInitSql()); dataSource.setConnectionInitSql(hikariDataSourceProperties.getConnectionInitSql());
dataSource.setRegisterMbeans(hikariDataSourceProperties.getRegisterMbeans());
return new DataSourceProxy(dataSource); return new DataSourceProxy(dataSource);
} }
......
...@@ -69,6 +69,20 @@ public class IdxBizJgProjectContraptionController extends BaseController { ...@@ -69,6 +69,20 @@ public class IdxBizJgProjectContraptionController extends BaseController {
} }
/** /**
* 根据sequenceNbr删除
*
* @param map 主键
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/delete-batch")
@ApiOperation(httpMethod = "POST", value = "根据sequenceNbr删除管道工程装置表及设备信息", notes = "根据sequenceNbr删除管道工程装置表及设备信息")
public ResponseModel<Boolean> deleteBatch(@RequestBody JSONObject map) {
List<String> ids = (List<String>) map.get("ids");
return ResponseHelper.buildResponse(idxBizJgProjectContraptionServiceImpl.deleteProjectAndEquInfoBatch(ids));
}
/**
* 根据入参 分页查询(当前)单位下的工程管道 * 根据入参 分页查询(当前)单位下的工程管道
* *
* @param params - isIntoManagement 是否是否纳管 true/false * @param params - isIntoManagement 是否是否纳管 true/false
......
...@@ -219,6 +219,7 @@ public class IdxBizJgProjectContraptionServiceImplService extends BaseEntityServ ...@@ -219,6 +219,7 @@ public class IdxBizJgProjectContraptionServiceImplService extends BaseEntityServ
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean deleteProjectAndEquInfoBySeq(Long sequenceNbr) { public Boolean deleteProjectAndEquInfoBySeq(Long sequenceNbr) {
this.checkForDelete(Collections.singletonList(String.valueOf(sequenceNbr)));
List<IdxBizJgUseInfo> useInfos = useInfoService.lambdaQuery().select(IdxBizJgUseInfo::getRecord).eq(IdxBizJgUseInfo::getProjectContraptionId, sequenceNbr).list(); List<IdxBizJgUseInfo> useInfos = useInfoService.lambdaQuery().select(IdxBizJgUseInfo::getRecord).eq(IdxBizJgUseInfo::getProjectContraptionId, sequenceNbr).list();
// 删除idx设备表信息 + 删除对应es数据 // 删除idx设备表信息 + 删除对应es数据
List<String> records = useInfos.stream().map(IdxBizJgUseInfo::getRecord).collect(Collectors.toList()); List<String> records = useInfos.stream().map(IdxBizJgUseInfo::getRecord).collect(Collectors.toList());
...@@ -422,8 +423,9 @@ public class IdxBizJgProjectContraptionServiceImplService extends BaseEntityServ ...@@ -422,8 +423,9 @@ public class IdxBizJgProjectContraptionServiceImplService extends BaseEntityServ
List<Long> projectContraptionIdList = pageList.getRecords().stream().map(IdxBizJgProjectContraption::getSequenceNbr).collect(Collectors.toList()); List<Long> projectContraptionIdList = pageList.getRecords().stream().map(IdxBizJgProjectContraption::getSequenceNbr).collect(Collectors.toList());
Map<String, Boolean> canEditMap = this.checkContraptionIsCanEdit(projectContraptionIdList); Map<String, Boolean> canEditMap = this.checkContraptionIsCanEdit(projectContraptionIdList);
pageList.getRecords().forEach(record -> record.setCanEdit(canEditMap.get(record.getSequenceNbr()+""))); pageList.getRecords().forEach(record -> record.setCanEdit(canEditMap.get(record.getSequenceNbr()+"")));
Map<String, Boolean> canDeleteMap = this.checkContraptionIsCanDelete(projectContraptionIdList, isIntoManagement); // 按钮放开, 删除提交时进行校验
pageList.getRecords().forEach(record -> record.setCanDelete(canDeleteMap.get(record.getSequenceNbr()+""))); // Map<String, Boolean> canDeleteMap = this.checkContraptionIsCanDelete(projectContraptionIdList, isIntoManagement);
// pageList.getRecords().forEach(record -> record.setCanDelete(canDeleteMap.get(record.getSequenceNbr()+"")));
//判断是否有检验结果录入 //判断是否有检验结果录入
judgeCheckResult(pageList.getRecords()); judgeCheckResult(pageList.getRecords());
} }
...@@ -927,4 +929,57 @@ public class IdxBizJgProjectContraptionServiceImplService extends BaseEntityServ ...@@ -927,4 +929,57 @@ public class IdxBizJgProjectContraptionServiceImplService extends BaseEntityServ
page.setTotal(totalMap.get("count")); page.setTotal(totalMap.get("count"));
return page; return page;
} }
@Transactional(rollbackFor = Exception.class)
public Boolean deleteProjectAndEquInfoBatch(List<String> ids) {
// 检验
this.checkForDelete(ids);
List<IdxBizJgUseInfo> useInfos = useInfoService.lambdaQuery().select(IdxBizJgUseInfo::getRecord).in(IdxBizJgUseInfo::getProjectContraptionId, ids).list();
// 删除idx设备表信息 + 删除对应es数据
List<String> records = useInfos.stream().map(IdxBizJgUseInfo::getRecord).collect(Collectors.toList());
if (!records.isEmpty()){
Map<String, Object> map = new HashMap<>();
map.put("recordList", records);
map.put("equList", PipelineEnum.PRESSURE_PIPELINE.getCode());
registerInfoService.batchDeleteByRecord(map);
}
// 删除装置表信息
this.removeByIds(ids);
eventPublisher.publish(new DataRefreshEvent(this, useInfos.stream().map(IdxBizJgUseInfo::getRecord).collect(Collectors.toList()), DataRefreshEvent.DataType.equipment.name(), DataRefreshEvent.Operation.DELETE));
return Boolean.TRUE;
}
/**
* 删除校验,被引用时不可删除
*
* @param pIds 装置ids
*/
private void checkForDelete(List<String> pIds) {
List<CountDto> useCounts = this.getBaseMapper().countContraptionInUseTimesForDeleteBatch(pIds);
Map<String, Long> projectContraptionIdUseNumMap = useCounts.stream().collect(Collectors.toMap(CountDto::getKeyStr, CountDto::getLongValue));
long sum = projectContraptionIdUseNumMap.values().stream().reduce(0L,Long::sum);
if(sum > 0){
String msg = getTipMsgString(projectContraptionIdUseNumMap, pIds);
throw new BadRequest(msg);
}
}
private String getTipMsgString(Map<String, Long> projectContraptionIdUseNumMap, List<String> pIds) {
List<Integer> indexes = new ArrayList<>();
for (int i = 0; i < pIds.size(); i++) {
String projectContraptionId = pIds.get(i);
if (projectContraptionIdUseNumMap.getOrDefault(projectContraptionId, 0L) > 0) {
indexes.add(i + 1);
}
}
if (pIds.size() > 1) {
return String.format("选择的第 %s 行装置已经在业务办理中,不能删除,请取消勾选!", indexes.stream()
.map(String::valueOf)
.collect(Collectors.joining(",")));
} else {
return "装置已经在业务办理中,不能删除!";
}
}
} }
\ No newline at end of file
...@@ -1250,14 +1250,30 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -1250,14 +1250,30 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
* @param records * @param records
*/ */
private void checkForDelete(List<String> records) { private void checkForDelete(List<String> records) {
for (String record : records) { List<CountDto> useCounts = commonMapper.countEquipInUseTimesWithOutZFBatch(records);
Boolean isUsed = commonService.checkEquipIsUsed(record); Map<String, Long> recordUseNumMap = useCounts.stream().collect(Collectors.toMap(CountDto::getKeyStr, CountDto::getLongValue));
if (isUsed) { long sum = recordUseNumMap.values().stream().reduce(0L,Long::sum);
String msg = getTipMsgString(record); if(sum > 0){
throw new BadRequest(msg); String msg = getTipMsgString(recordUseNumMap, records);
} throw new BadRequest(msg);
} }
}
private String getTipMsgString(Map<String, Long> recordUseNumMap, List<String> records) {
List<Integer> idxs = new ArrayList<>();
for (int i = 0; i < records.size(); i++) {
String record = records.get(i);
if(recordUseNumMap.getOrDefault(record, 0L) > 0){
idxs.add(i+1);
}
}
if (records.size() > 1) {
return String.format("选择的第 %s 行设备已经在业务办理中,不能删除,请取消勾选!", idxs.stream()
.map(String::valueOf)
.collect(Collectors.joining(",")));
} else {
return "设备已经在业务办理中,不能删除!";
}
} }
private Boolean checkEquipIsCanDelete(String record) { private Boolean checkEquipIsCanDelete(String record) {
...@@ -1265,11 +1281,6 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -1265,11 +1281,6 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
return !commonService.checkEquipIsUsed(record); return !commonService.checkEquipIsUsed(record);
} }
private String getTipMsgString(String record) {
IdxBizJgRegisterInfo registerInfo = this.getOne(new QueryWrapper<IdxBizJgRegisterInfo>().eq("RECORD", record));
return String.format("存在业务办理中的设备,设备代码:%s", registerInfo.getEquCode());
}
/** /**
* 查询设备注册信息详情 * 查询设备注册信息详情
* *
...@@ -3104,8 +3115,9 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -3104,8 +3115,9 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
} }
String fullAddress = equAddressMap.get(item.getString(SEQUENCE_NBR)); String fullAddress = equAddressMap.get(item.getString(SEQUENCE_NBR));
item.put("ADDRESS", !ValidationUtil.isEmpty(fullAddress) ? fullAddress : ""); item.put("ADDRESS", !ValidationUtil.isEmpty(fullAddress) ? fullAddress : "");
item.put("CAN_EDIT", this.checkEquipIsCanEdit(item.getString(SEQUENCE_NBR))); item.put("CAN_EDIT", this.checkEquipIsCanEdit(item.getString(SEQUENCE_NBR)));
item.put("CAN_DELETE", this.checkEquipIsCanDelete(item.getString(SEQUENCE_NBR))); // TODO 未纳管设备删除使用此字段,调整为前端始终显示删除按钮
// item.put("CAN_DELETE", this.checkEquipIsCanDelete(item.getString(SEQUENCE_NBR)));
// 单位类型区分是监管还是企业 // 单位类型区分是监管还是企业
item.put("companyType", companyLevel); item.put("companyType", companyLevel);
// 区分新增设备、历史有证设备、历史无证设备,与使用登记一致:0-新设备、1-历史有证设备、2-历史无证设备 // 区分新增设备、历史有证设备、历史无证设备,与使用登记一致:0-新设备、1-历史有证设备、2-历史无证设备
......
...@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.ymt.api.mapper; ...@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.ymt.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.dto.CountDto;
import com.yeejoin.amos.boot.module.common.api.dto.ContraptionQueryParams; import com.yeejoin.amos.boot.module.common.api.dto.ContraptionQueryParams;
import com.yeejoin.amos.boot.module.ymt.api.dto.ProjectWaitRefreshDataQualityScore; import com.yeejoin.amos.boot.module.ymt.api.dto.ProjectWaitRefreshDataQualityScore;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgProjectContraption; import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgProjectContraption;
...@@ -115,4 +116,13 @@ public interface IdxBizJgProjectContraptionMapper extends BaseMapper<IdxBizJgPro ...@@ -115,4 +116,13 @@ public interface IdxBizJgProjectContraptionMapper extends BaseMapper<IdxBizJgPro
void updateDataQualityScoreBatch(@Param("projectContraptions") List<ProjectWaitRefreshDataQualityScore> projectContraptions); void updateDataQualityScoreBatch(@Param("projectContraptions") List<ProjectWaitRefreshDataQualityScore> projectContraptions);
List<IdxBizJgTechParamsPipeline> selectPipelineListByProjectContraptionId(@Param("projectContraptionId") String projectContraptionId); List<IdxBizJgTechParamsPipeline> selectPipelineListByProjectContraptionId(@Param("projectContraptionId") String projectContraptionId);
/**
* 统计设备被引用的次数(只有存在就算引用-作废除外)
*
* @param projectContraptionIdList 装置唯一标识
* @return 被引用次数 > 0 则设备不可删除
*/
List<CountDto> countContraptionInUseTimesForDeleteBatch(@Param("projectContraptionIdList") List<String> projectContraptionIdList);
} }
\ No newline at end of file
...@@ -146,6 +146,42 @@ ...@@ -146,6 +146,42 @@
GROUP BY GROUP BY
project_contraption_id; project_contraption_id;
</select> </select>
<select id="countContraptionInUseTimesForDeleteBatch" resultType="com.yeejoin.amos.boot.biz.common.dto.CountDto">
SELECT
project_contraption_id as keyStr,
SUM(inUseNumber) longValue
FROM (
SELECT
a.project_contraption_id,
COUNT(1) AS inUseNumber
FROM
tzs_jg_use_registration a
WHERE a.project_contraption_id = ANY(ARRAY[
<foreach collection="projectContraptionIdList" item="projectContraptionId" separator=",">
#{projectContraptionId}
</foreach>
])
AND a.is_delete = 0
AND ( a.status <![CDATA[ <> ]]> '已作废')
group by a.project_contraption_id
UNION all
SELECT
a.project_contraption_id,
COUNT(1) AS inUseNumber
FROM
tzs_jg_installation_notice a
WHERE a.project_contraption_id = ANY(ARRAY[
<foreach collection="projectContraptionIdList" item="projectContraptionId" separator=",">
#{projectContraptionId}
</foreach>
])
AND (a.notice_status <![CDATA[ <> ]]> '6617')
and a.is_delete = 0
group by a.project_contraption_id
)
GROUP BY
project_contraption_id
</select>
<select id="selectErrorManagementProject" <select id="selectErrorManagementProject"
resultType="com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgProjectContraption"> resultType="com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgProjectContraption">
select select
......
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