Commit d8cbac02 authored by suhuiguang's avatar suhuiguang

1.完善事务回滚问题

parent b33b8be4
...@@ -3,7 +3,6 @@ package com.yeejoin.amos.boot.module.tzs.flc.biz.service.impl; ...@@ -3,7 +3,6 @@ package com.yeejoin.amos.boot.module.tzs.flc.biz.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.yeejoin.amos.boot.biz.common.constants.CommonConstant; import com.yeejoin.amos.boot.biz.common.constants.CommonConstant;
import com.yeejoin.amos.boot.biz.common.entity.DataDictionary; import com.yeejoin.amos.boot.biz.common.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl; import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
...@@ -23,7 +22,6 @@ import com.yeejoin.amos.boot.module.tzs.flc.api.dto.RegUnitInfoDto; ...@@ -23,7 +22,6 @@ import com.yeejoin.amos.boot.module.tzs.flc.api.dto.RegUnitInfoDto;
import com.yeejoin.amos.boot.module.tzs.flc.api.entity.RegUnitIc; import com.yeejoin.amos.boot.module.tzs.flc.api.entity.RegUnitIc;
import com.yeejoin.amos.boot.module.tzs.flc.api.enums.UnitReviewStateEnum; import com.yeejoin.amos.boot.module.tzs.flc.api.enums.UnitReviewStateEnum;
import com.yeejoin.amos.boot.module.tzs.flc.api.mapper.RegUnitInfoMapper; import com.yeejoin.amos.boot.module.tzs.flc.api.mapper.RegUnitInfoMapper;
import com.yeejoin.amos.component.feign.config.InnerInvokException;
import com.yeejoin.amos.component.feign.model.FeignClientResult; import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.Privilege; import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel; import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
...@@ -121,18 +119,24 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -121,18 +119,24 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
Bean.copyExistPropertis(regUnitInfo, model); Bean.copyExistPropertis(regUnitInfo, model);
// 5.2行政许可数据 // 5.2行政许可数据
model.setUnitLicences(Bean.toModels(baseUnitLicences, BaseUnitLicenceDto.class)); model.setUnitLicences(Bean.toModels(baseUnitLicences, BaseUnitLicenceDto.class));
// 5.3工商信息 // 5.3工商信息
model.setRegUnitIc(Bean.toModel(regUnitIc, new RegUnitIcDto())); model.setRegUnitIc(Bean.toModel(regUnitIc, new RegUnitIcDto()));
} catch (Exception e) { } catch (Exception e) {
// 失败后回滚:删除已经创建的企业信息 // 失败后回滚:删除已经创建的企业信息
if(StringUtils.isNotEmpty(regUnitInfo.getAmosCompanySeq())){ if (StringUtils.isNotEmpty(regUnitInfo.getAmosCompanySeq())) {
Privilege.companyClient.deleteCompany(regUnitInfo.getAmosCompanySeq()); FeignClientResult<CompanyModel> feignClientResult = Privilege.companyClient.seleteOne(Long.parseLong(regUnitInfo.getAmosCompanySeq()));
if (feignClientResult != null) {
Privilege.companyClient.deleteCompany(regUnitInfo.getAmosCompanySeq());
}
} }
// 失败后回滚:删除已经创建的管理员账号 // 失败后回滚:删除已经创建的管理员账号
if(StringUtils.isNotEmpty(regUnitInfo.getAdminUserId())){ if (StringUtils.isNotEmpty(regUnitInfo.getAdminUserId())) {
Privilege.agencyUserClient.multDeleteUser(regUnitInfo.getAdminUserId()); FeignClientResult<AgencyUserModel> feignClientResult = Privilege.agencyUserClient.queryByUserId(regUnitInfo.getAdminUserId());
if (feignClientResult != null) {
Privilege.agencyUserClient.multDeleteUser(regUnitInfo.getAdminUserId());
}
} }
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e.getMessage());
} }
return model; return model;
} }
...@@ -214,21 +218,27 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -214,21 +218,27 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean unitLogOut(String unitCode) { public Boolean unitLogOut(String unitCode) {
tzsAuthServiceImpl.setRequestContext();
RegUnitInfo regUnitInfo = this.getOne(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getUnitCode, unitCode)); RegUnitInfo regUnitInfo = this.getOne(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getUnitCode, unitCode));
if(regUnitInfo == null){ if (regUnitInfo == null) {
return Boolean.FALSE; return Boolean.FALSE;
} }
String companyId = regUnitInfo.getAmosCompanySeq(); try {
// 1.删除已经创建的 企业信息 tzsAuthServiceImpl.setRequestContext();
if (StringUtils.isNotEmpty(companyId)) { // 1.删除已经创建的企业信息
CompanyModel companyModel = Privilege.companyClient.seleteOne(Long.parseLong(companyId)).getResult(); if (StringUtils.isNotEmpty(regUnitInfo.getAmosCompanySeq())) {
if (companyModel != null) { CompanyModel companyModel = Privilege.companyClient.seleteOne(Long.parseLong(regUnitInfo.getAmosCompanySeq())).getResult();
Privilege.companyClient.deleteCompany(companyId); if (companyModel != null) {
Privilege.companyClient.deleteCompany(regUnitInfo.getAmosCompanySeq());
}
}
// 2.删除已经创建的管理员账号
FeignClientResult<AgencyUserModel> feignClientResult = Privilege.agencyUserClient.queryByUserId(regUnitInfo.getAdminUserId());
if (feignClientResult != null) {
Privilege.agencyUserClient.multDeleteUser(regUnitInfo.getAdminUserId());
} }
} catch (Exception e) {
log.error(e.getMessage(), e);
} }
// 2.删除管理员账号
Privilege.agencyUserClient.multDeleteUser(regUnitInfo.getAdminUserId());
// 3.企业注册表删除 // 3.企业注册表删除
this.remove(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getUnitCode, unitCode)); this.remove(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getUnitCode, unitCode));
// 4.工商信息表删除 // 4.工商信息表删除
...@@ -238,7 +248,7 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -238,7 +248,7 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
// 6.企业数据信息删除 // 6.企业数据信息删除
tzBaseEnterpriseInfoService.remove(new LambdaQueryWrapper<TzBaseEnterpriseInfo>().eq(TzBaseEnterpriseInfo::getUseCode, unitCode)); tzBaseEnterpriseInfoService.remove(new LambdaQueryWrapper<TzBaseEnterpriseInfo>().eq(TzBaseEnterpriseInfo::getUseCode, unitCode));
// 7.机场单位表信息删除 // 7.机场单位表信息删除
iOrgUsrService.remove(new LambdaQueryWrapper<OrgUsr>().eq(OrgUsr::getAmosOrgId, companyId)); iOrgUsrService.remove(new LambdaQueryWrapper<OrgUsr>().eq(OrgUsr::getAmosOrgId, regUnitInfo.getAmosCompanySeq()));
return Boolean.TRUE; return Boolean.TRUE;
} }
...@@ -255,10 +265,10 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -255,10 +265,10 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
} }
private List getFilterChild(Collection children) { private List getFilterChild(Collection children) {
return (List)children.stream().filter(n -> { return (List) children.stream().filter(n -> {
CompanyModel c = JSONObject.parseObject(JSON.toJSONString(n), CompanyModel.class); CompanyModel c = JSONObject.parseObject(JSON.toJSONString(n), CompanyModel.class);
return "headquarter".equals(c.getLevel()) || "prefecture-level".equals(c.getLevel()) || "county".equals(c.getLevel()); return "headquarter".equals(c.getLevel()) || "prefecture-level".equals(c.getLevel()) || "county".equals(c.getLevel());
}).map(s->{ }).map(s -> {
CompanyModel c = JSONObject.parseObject(JSON.toJSONString(s), CompanyModel.class); CompanyModel c = JSONObject.parseObject(JSON.toJSONString(s), CompanyModel.class);
c.setChildren(this.getFilterChild(c.getChildren() != null ? c.getChildren() : new ArrayList())); c.setChildren(this.getFilterChild(c.getChildren() != null ? c.getChildren() : new ArrayList()));
return c; return c;
...@@ -337,13 +347,13 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -337,13 +347,13 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
iOrgUsrService.save(org); iOrgUsrService.save(org);
} catch (Exception e) { } catch (Exception e) {
// 删除已经创建的 企业信息 // 删除已经创建的 企业信息
if(companyInfo != null && companyInfo.getSequenceNbr() != null){ if (companyInfo != null && companyInfo.getSequenceNbr() != null) {
Privilege.companyClient.deleteCompany(companyInfo.getSequenceNbr() + ""); Privilege.companyClient.deleteCompany(companyInfo.getSequenceNbr() + "");
} }
if(userResult != null && userResult.getResult() != null && StringUtils.isNotEmpty(userResult.getResult().getUserId())){ if (userResult != null && userResult.getResult() != null && StringUtils.isNotEmpty(userResult.getResult().getUserId())) {
Privilege.agencyUserClient.multDeleteUser(userResult.getResult().getUserId()); Privilege.agencyUserClient.multDeleteUser(userResult.getResult().getUserId());
} }
log.error(e.getMessage(),e); log.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e.getMessage());
} }
} }
......
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