Commit aff6e4ef authored by suhuiguang's avatar suhuiguang

1.删除编辑增加约束无流程引用时,可编辑、可删除

parent 6dda69a4
......@@ -34,5 +34,21 @@ public interface CommonMapper extends BaseMapper<EquipmentCategory> {
void updateBusinessData(String tableName,String assignee, String transferToUserIds, String instanceId,String nextTaskId);
Map<String, Object> getUserPhone(String name ,String companyCode);
/**
* 统计指定设备流程中的引用次数(12个流程中,非待提交、非已撤回、非已驳回)
* @param record 设备唯一标识
* @return 被引用次数 > 0 则设备不可编辑
*/
Integer countEquipInUseTimesForEdit(String record);
/**
* 统计设备被引用的次数(只有存在就算引用)
* @param record 设备唯一标识
* @return 被引用次数 > 0 则设备不可删除
*/
Integer countEquipInUseTimesForDel(String record);
}
......@@ -98,5 +98,219 @@
where
instance_id = #{instanceId}
</select>
<select id="countEquipInUseTimesForEdit" resultType="java.lang.Integer">
select
sum(inUseNumber)
from (
select
count(1) as inUseNumber
from
tzs_jg_use_registration a,
tzs_jg_use_registration_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = #{record}
and (a.status <![CDATA[ <> ]]> '使用单位待提交' and a.status <![CDATA[ <> ]]> '一级受理已驳回' and a.status <![CDATA[ <> ]]> '使用单位已撤回')
UNION
select
count(1) as inUseNumber
from
tzs_jg_change_registration_reform a,
tzs_jg_change_registration_reform_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = #{record}
and (a.audit_status <![CDATA[ <> ]]> '使用单位待提交' and a.audit_status <![CDATA[ <> ]]> '一级受理已驳回' and a.audit_status <![CDATA[ <> ]]> '使用单位已撤回')
UNION
select
count(1) as inUseNumber
from
tzs_jg_change_registration_transfer a,
tzs_jg_change_registration_transfer_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = #{record}
and (a.audit_status <![CDATA[ <> ]]> '使用单位待提交' and a.audit_status <![CDATA[ <> ]]> '一级受理已驳回' and a.audit_status <![CDATA[ <> ]]> '使用单位已撤回')
UNION
select
count(1) as inUseNumber
from
tzs_jg_change_registration_unit a,
tzs_jg_change_registration_unit_eq b
where
a.sequence_nbr = b.unit_change_registration_id
and b.equ_id = #{record}
and (a.status <![CDATA[ <> ]]> '使用单位待提交' and a.status <![CDATA[ <> ]]> '一级受理已驳回' and a.status <![CDATA[ <> ]]> '使用单位已撤回')
UNION
select
count(1) as inUseNumber
from
tzs_jg_enable_disable a,
tzs_jg_enable_disable_eq b
where
a.sequence_nbr = b.enable_disable_apply_id
and b.equ_id = #{record}
and (a.audit_status <![CDATA[ <> ]]> '已驳回' and a.audit_status <![CDATA[ <> ]]> '已撤回' and a.audit_status <![CDATA[ <> ]]> '待提交')
UNION
select
count(1) as inUseNumber
from
tzs_jg_equip_transfer a,
tzs_jg_equip_transfer_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = #{record}
and (a.apply_status <![CDATA[ <> ]]> '6614' and a.apply_status <![CDATA[ <> ]]> '6615' and a.apply_status <![CDATA[ <> ]]> '6610')
UNION
select
count(1) as inUseNumber
from
tzs_jg_installation_notice a,
tzs_jg_installation_notice_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = #{record}
and (a.notice_status <![CDATA[ <> ]]> '6614' and a.notice_status <![CDATA[ <> ]]> '6615' and a.notice_status <![CDATA[ <> ]]> '6610')
UNION
select
count(1) as inUseNumber
from
tzs_jg_maintain_notice a,
tzs_jg_maintain_notice_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = #{record}
and (a.notice_status <![CDATA[ <> ]]> '6614' and a.notice_status <![CDATA[ <> ]]> '6615' and a.notice_status <![CDATA[ <> ]]> '6610')
UNION
select
count(1) as inUseNumber
from
tzs_jg_maintenance_contract a,
tzs_jg_maintenance_contract_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = #{record}
and (a.status <![CDATA[ <> ]]> '维保单位已驳回' and a.status <![CDATA[ <> ]]> '使用单位已撤回' and a.status <![CDATA[ <> ]]> '使用单位待提交')
UNION
select
count(1) as inUseNumber
from
tzs_jg_reform_notice a,
tzs_jg_reform_notice_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = #{record}
and (a.notice_status <![CDATA[ <> ]]> '6614' and a.notice_status <![CDATA[ <> ]]> '6615' and a.notice_status <![CDATA[ <> ]]> '6610')
UNION
select
count(1) as inUseNumber
from
tzs_jg_scrap_cancel a,
tzs_jg_scrap_cancel_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = #{record}
and (a.audit_status <![CDATA[ <> ]]> '使用单位已撤回' and a.audit_status <![CDATA[ <> ]]> '一级受理已驳回' and a.audit_status <![CDATA[ <> ]]> '使用单位待提交')
UNION
select
count(1) as inUseNumber
from
tzs_jg_transfer_notice a,
tzs_jg_transfer_notice_eq b
where
a.sequence_nbr = b.equip_transfer_id
and b.equ_id = #{record}
and (a.notice_status <![CDATA[ <> ]]> '6614' and a.notice_status <![CDATA[ <> ]]> '6615' and a.notice_status <![CDATA[ <> ]]> '6610')
)
</select>
<select id="countEquipInUseTimesForDel" resultType="java.lang.Integer">
select
sum(inUseNumber)
from (
select
count(1) as inUseNumber
from
tzs_jg_use_registration_eq b
where
b.equ_id = #{record}
UNION
select
count(1) as inUseNumber
from
tzs_jg_change_registration_reform_eq b
where
b.equ_id = #{record}
UNION
select
count(1) as inUseNumber
from
tzs_jg_change_registration_transfer_eq b
where
b.equ_id = #{record}
UNION
select
count(1) as inUseNumber
from
tzs_jg_change_registration_unit_eq b
where
b.equ_id = #{record}
UNION
select
count(1) as inUseNumber
from
tzs_jg_enable_disable_eq b
where
b.equ_id = #{record}
UNION
select
count(1) as inUseNumber
from
tzs_jg_equip_transfer_eq b
where
b.equ_id = #{record}
UNION
select
count(1) as inUseNumber
from
tzs_jg_installation_notice_eq b
where
b.equ_id = #{record}
UNION
select
count(1) as inUseNumber
from
tzs_jg_maintain_notice_eq b
where
b.equ_id = #{record}
UNION
select
count(1) as inUseNumber
from
tzs_jg_maintenance_contract_eq b
where
b.equ_id = #{record}
UNION
select
count(1) as inUseNumber
from
tzs_jg_reform_notice_eq b
where
b.equ_id = #{record}
UNION
select
count(1) as inUseNumber
from
tzs_jg_scrap_cancel_eq b
where
b.equ_id = #{record}
UNION
select
count(1) as inUseNumber
from
tzs_jg_transfer_notice_eq b
where
b.equ_id = #{record}
)
</select>
</mapper>
......@@ -130,4 +130,19 @@ public interface ICommonService {
* @return Object
*/
Object queryHistoryDataObj(Long currentDocumentId);
/**
* 统计指定设备流程中的引用次数(12个流程中,非待提交、非已撤回、非已驳回)
* @param record 设备唯一标识
* @return 被引用次数 > 0 则设备不可编辑
*/
Integer countEquipInUseTimesForEdit(String record);
/**
* 统计设备被引用的次数(只有存在就算引用)
* @param record 设备唯一标识
* @return 被引用次数 > 0 则设备不可删除
*/
Integer countEquipInUseTimesForDel(String record);
}
......@@ -1610,4 +1610,14 @@ public class CommonServiceImpl implements ICommonService {
}
}
@Override
public Integer countEquipInUseTimesForEdit(String record){
return commonMapper.countEquipInUseTimesForEdit(record);
}
@Override
public Integer countEquipInUseTimesForDel(String record){
return commonMapper.countEquipInUseTimesForDel(record);
}
}
\ No newline at end of file
......@@ -52,6 +52,7 @@ import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
......@@ -182,6 +183,8 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
if (count > 0) {
throw new LocalBadRequest("设备代码已存在,请重新输入!");
}
// 编辑校验
this.checkForEquipEdit(equipmentInfoForm.get("RECORD"));
//操作类型
try {
//保存数据
......@@ -209,12 +212,23 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
return ResponseHelper.buildResponse(record);
}
private void checkForEquipEdit(Object record) {
// 标识编辑
if(record != null){
Integer inUseTime = commonService.countEquipInUseTimesForEdit(record.toString());
if(inUseTime > 0){
throw new BadRequest("此设备在被其他业务引用,不可编辑!");
}
}
}
/**
* 删除设备注册信息(批量删除)
*
* @param map
* @return
*/
@Override
public boolean batchDeleteByRecord(Map<String, Object> map) {
Object recordList = map.get("recordList");
List<String> records = new ArrayList<>();
......@@ -233,6 +247,8 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
esEquipmentCategoryDto.setSEQUENCE_NBR(recordList.toString());
list.add(esEquipmentCategoryDto);
}
// 删除校验,被引用时不可删除
this.checkForDelete(records);
//删除涉及的19张表的数据
superviseInfoMapper.deleteDataAll(records);
......@@ -241,6 +257,22 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
return true;
}
private void checkForDelete(List<String> records) {
for(String record: records){
Integer useTime = commonService.countEquipInUseTimesForDel(record);
if(useTime > 0){
String msg = getTipMsgString(record);
throw new BadRequest(msg);
}
}
}
private String getTipMsgString(String record) {
IdxBizJgRegisterInfo registerInfo = this.getOne(new QueryWrapper<IdxBizJgRegisterInfo>().eq("RECORD", record));
return String.format("存在被引用的设备,设备代码:%s", registerInfo.getEquCode());
}
/**
* 查询设备注册信息详情
*
......@@ -1192,17 +1224,6 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
equIds = list.stream().map(item -> item.get("SEQUENCE_NBR").toString()).collect(Collectors.toList());
}
if(!ValidationUtil.isEmpty(equIds)){
//查询设备是否正在使用
//设备的使用标识是,安装告知和使用登记中有使用记录。
List<JgInstallationNoticeEq> installationNoticeEqList = jgInstallationNoticeEqServiceImpl.getListByEquIds(equIds);
List<JgUseRegistrationEq> useRegistrationEqList = jgUseRegistrationEqServiceImpl.getListByEquIds(equIds);
Map<String, Boolean> equIsUseMap = new HashMap<>();
if(!ValidationUtil.isEmpty(installationNoticeEqList) ){
equIsUseMap.putAll(installationNoticeEqList.stream().collect(Collectors.toMap(JgInstallationNoticeEq::getEquId, obj -> true, (oldValue, newValue) -> oldValue)));
}
if(!ValidationUtil.isEmpty(useRegistrationEqList)){
equIsUseMap.putAll(useRegistrationEqList.stream().collect(Collectors.toMap(JgUseRegistrationEq::getEquId, obj -> true, (oldValue, newValue) -> oldValue)));
}
// 查询设备地址
List<IdxBizJgUseInfo> useInfoListByEquIds = idxBizJgUseInfoService.getUseInfoListByEquIds(equIds);
Map<String, String> equAddressMap = new HashMap<>();
......@@ -1222,9 +1243,7 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
}
// 更新设备使用情况和设备地址
for(JSONObject item : list){
Boolean isUse = equIsUseMap.get(item.getString("SEQUENCE_NBR"));
String fullAddress = equAddressMap.get(item.getString("SEQUENCE_NBR"));
item.put("IS_USE", !ValidationUtil.isEmpty(isUse) ? isUse ? isUse : false : false);
item.put("ADDRESS", !ValidationUtil.isEmpty(fullAddress) ? fullAddress : "");
}
}
......
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