Commit 5968e325 authored by suhuiguang's avatar suhuiguang

1.事务回滚调整

2.调整为baseEntry为common
parent 59c1cf45
package com.yeejoin.amos.boot.module.tzs.api.entity; package com.yeejoin.amos.boot.module.tzs.api.entity;
import java.util.Date; import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity;
import java.util.Date;
/** /**
* 企业数据信息 * 企业数据信息
...@@ -13,15 +17,16 @@ import org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity; ...@@ -13,15 +17,16 @@ import org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity;
* @author duanwei * @author duanwei
* @date 2022-08-10 * @date 2022-08-10
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true) @Accessors(chain = true)
@ApiModel(value="TzBaseEnterpriseInfo对象", description="企业数据信息") @ApiModel(value = "TzBaseEnterpriseInfo对象", description = "企业数据信息")
public class TzBaseEnterpriseInfo extends BaseEntity { public class TzBaseEnterpriseInfo extends BaseEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "使用单位唯一标识") @ApiModelProperty(value = "使用单位唯一标识")
private String useUnitCode; private String useUnitCode;
...@@ -116,8 +121,6 @@ public class TzBaseEnterpriseInfo extends BaseEntity { ...@@ -116,8 +121,6 @@ public class TzBaseEnterpriseInfo extends BaseEntity {
private String appId; private String appId;
@ApiModelProperty(value = "管辖机构") @ApiModelProperty(value = "管辖机构")
private String governingBody; private String governingBody;
......
...@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.tzs.flc.biz.service.impl; ...@@ -3,6 +3,7 @@ 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;
...@@ -84,13 +85,13 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -84,13 +85,13 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public RegUnitInfoDto registerUnit(RegUnitInfoDto model) { public RegUnitInfoDto registerUnit(RegUnitInfoDto model) {
tzsAuthServiceImpl.setRequestContext();
// 1.插入注册单位基本信息表:tz_flc_reg_unit_info
RegUnitInfo regUnitInfo = new RegUnitInfo(); RegUnitInfo regUnitInfo = new RegUnitInfo();
try {
tzsAuthServiceImpl.setRequestContext();
// 注册用统一信用码注册,默认证件类型为营业执照,数据来源:cb_data_dictionary code = 1060 // 注册用统一信用码注册,默认证件类型为营业执照,数据来源:cb_data_dictionary code = 1060
model.setUnitCodeType("1060"); model.setUnitCodeType("1060");
Bean.copyExistPropertis(model, regUnitInfo); Bean.copyExistPropertis(model, regUnitInfo);
// 2.插入单位注册许可信息表:tz_base_unit_licence // 1.插入单位注册许可信息表:tz_base_unit_licence
List<BaseUnitLicenceDto> unitLicenceDtos = model.getUnitLicences(); List<BaseUnitLicenceDto> unitLicenceDtos = model.getUnitLicences();
List<BaseUnitLicence> baseUnitLicences = unitLicenceDtos.stream().map(s -> { List<BaseUnitLicence> baseUnitLicences = unitLicenceDtos.stream().map(s -> {
s.setUnitCode(model.getUnitCode()); s.setUnitCode(model.getUnitCode());
...@@ -100,19 +101,20 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -100,19 +101,20 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
return target; return target;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
baseUnitLicenceService.saveOrUpdateBatch(baseUnitLicences); baseUnitLicenceService.saveOrUpdateBatch(baseUnitLicences);
// 3.插入工商单位信息表:tz_flc_reg_unit_ic // 2.插入工商单位信息表:tz_flc_reg_unit_ic
RegUnitIc regUnitIc = new RegUnitIc(); RegUnitIc regUnitIc = new RegUnitIc();
model.getRegUnitIc().setUnitCode(model.getUnitCode()); model.getRegUnitIc().setUnitCode(model.getUnitCode());
model.getRegUnitIc().setUnitName(model.getName()); model.getRegUnitIc().setUnitName(model.getName());
Bean.copyExistPropertis(model.getRegUnitIc(), regUnitIc); Bean.copyExistPropertis(model.getRegUnitIc(), regUnitIc);
regUnitIcService.save(regUnitIc); regUnitIcService.save(regUnitIc);
// 4.调用平台进行创建单位、用户信息,同步用户信息 // 3.调用平台进行创建单位、用户信息,同步用户信息
if (UnitReviewStateEnum.NO_NEED_REVIEW.getCode().equals(model.getState())) { if (UnitReviewStateEnum.NO_NEED_REVIEW.getCode().equals(model.getState())) {
// 4.1 自动创建:调用平台进行创建单位、用户信息 // 4.1 创建企业信息
this.createCompanyAndUser(regUnitInfo);
// 4.2 创建企业信息
this.createBaseEnterpriseInfo(model); this.createBaseEnterpriseInfo(model);
// 4.2 自动创建:调用平台进行创建单位、用户信息
this.createCompanyAndUser(regUnitInfo);
} }
// 4.插入注册单位基本信息表:tz_flc_reg_unit_info
this.save(regUnitInfo); this.save(regUnitInfo);
// 5.组织返回数据 // 5.组织返回数据
// 5.1企业基本信息 // 5.1企业基本信息
...@@ -121,6 +123,17 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -121,6 +123,17 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
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) {
// 删除已经创建的企业信息
if(StringUtils.isNotEmpty(regUnitInfo.getAmosCompanySeq())){
Privilege.companyClient.deleteCompany(regUnitInfo.getAmosCompanySeq());
}
// 删除已经创建的管理员账号
if(StringUtils.isNotEmpty(regUnitInfo.getAdminUserId())){
Privilege.agencyUserClient.multDeleteUser(regUnitInfo.getAdminUserId());
}
throw new RuntimeException(e.getMessage());
}
return model; return model;
} }
...@@ -128,6 +141,7 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -128,6 +141,7 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
TzBaseEnterpriseInfo baseEnterpriseInfo = new TzBaseEnterpriseInfo(); TzBaseEnterpriseInfo baseEnterpriseInfo = new TzBaseEnterpriseInfo();
baseEnterpriseInfo.setUnitType(regUnitInfo.getUnitType()); baseEnterpriseInfo.setUnitType(regUnitInfo.getUnitType());
baseEnterpriseInfo.setUseCode(regUnitInfo.getUnitCode()); baseEnterpriseInfo.setUseCode(regUnitInfo.getUnitCode());
baseEnterpriseInfo.setUseUnit(regUnitInfo.getName());
baseEnterpriseInfo.setProvince(regUnitInfo.getProvince()); baseEnterpriseInfo.setProvince(regUnitInfo.getProvince());
baseEnterpriseInfo.setCity(regUnitInfo.getCity()); baseEnterpriseInfo.setCity(regUnitInfo.getCity());
baseEnterpriseInfo.setDistrict(regUnitInfo.getDistrict()); baseEnterpriseInfo.setDistrict(regUnitInfo.getDistrict());
...@@ -252,13 +266,15 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -252,13 +266,15 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
} }
private void createCompanyAndUser(RegUnitInfo regUnitInfo) { private void createCompanyAndUser(RegUnitInfo regUnitInfo) {
CompanyModel companyInfo = new CompanyModel();
FeignClientResult<AgencyUserModel> userResult = null;
try {
FeignClientResult<List<RoleModel>> roleListResult = Privilege.roleClient.queryRoleList(null, null); FeignClientResult<List<RoleModel>> roleListResult = Privilege.roleClient.queryRoleList(null, null);
List<RoleModel> allRoleList = roleListResult.getResult(); List<RoleModel> allRoleList = roleListResult.getResult();
List<RoleModel> userRoleList; List<RoleModel> userRoleList;
List<Long> roleIds = new ArrayList<>(); List<Long> roleIds = new ArrayList<>();
Set<String> roleNameSet = new HashSet<>(); Set<String> roleNameSet = new HashSet<>();
// 3.1创建公司 // 3.1创建公司
CompanyModel companyInfo = new CompanyModel();
companyInfo.setAddress(regUnitInfo.getProvince() + regUnitInfo.getCity() + regUnitInfo.getDistrict() + regUnitInfo.getStree() + regUnitInfo.getCommunity() + regUnitInfo.getAddress()); companyInfo.setAddress(regUnitInfo.getProvince() + regUnitInfo.getCity() + regUnitInfo.getDistrict() + regUnitInfo.getStree() + regUnitInfo.getCommunity() + regUnitInfo.getAddress());
companyInfo.setAgencyCode("tzs"); companyInfo.setAgencyCode("tzs");
companyInfo.setParentId(Long.parseLong(regUnitInfo.getManagementUnitId())); companyInfo.setParentId(Long.parseLong(regUnitInfo.getManagementUnitId()));
...@@ -295,27 +311,19 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -295,27 +311,19 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
Map<Long, List<Long>> roleSeqMap = new HashMap<>(); Map<Long, List<Long>> roleSeqMap = new HashMap<>();
roleNameSet.add(unitType.getName()); roleNameSet.add(unitType.getName());
userRoleList = allRoleList.stream().filter(r -> r.getRoleName().equals(unitType.getName())).collect(Collectors.toList()); userRoleList = allRoleList.stream().filter(r -> r.getRoleName().equals(unitType.getName())).collect(Collectors.toList());
userRoleList.forEach(r -> { userRoleList.forEach(r -> roleIds.add(r.getSequenceNbr()));
roleIds.add(r.getSequenceNbr());
});
roleSeqMap.put(companyInfo.getSequenceNbr(), roleIds); roleSeqMap.put(companyInfo.getSequenceNbr(), roleIds);
Map<Long, List<RoleModel>> orgRoles = new HashMap<>(); Map<Long, List<RoleModel>> orgRoles = new HashMap<>();
orgRoles.put(companyInfo.getSequenceNbr(), userRoleList); orgRoles.put(companyInfo.getSequenceNbr(), userRoleList);
agencyUserModel.setAppCodes(new ArrayList<>(appCodesSet)); agencyUserModel.setAppCodes(new ArrayList<>(appCodesSet));
agencyUserModel.setOrgRoles(orgRoles); agencyUserModel.setOrgRoles(orgRoles);
agencyUserModel.setOrgRoleSeqs(roleSeqMap); agencyUserModel.setOrgRoleSeqs(roleSeqMap);
FeignClientResult<AgencyUserModel> userResult;
try {
userResult = Privilege.agencyUserClient.create(agencyUserModel); userResult = Privilege.agencyUserClient.create(agencyUserModel);
} catch (InnerInvokException e) {
// 删除已经创建的 企业信息
Privilege.companyClient.deleteCompany(companyInfo.getSequenceNbr() + "");
throw new BadRequest(e.getMessage());
}
if (userResult == null || userResult.getResult() == null) { if (userResult == null || userResult.getResult() == null) {
throw new BadRequest("注册失败"); throw new BadRequest("单位注册失败");
} }
regUnitInfo.setAdminUserId(userResult.getResult().getUserId());
regUnitInfo.setAmosCompanySeq(companyInfo.getSequenceNbr().toString());
// 3.3 org_user 创建组织机构 // 3.3 org_user 创建组织机构
OrgUsr org = new OrgUsr(); OrgUsr org = new OrgUsr();
org.setBizOrgCode(TreeParser.genTreeCode()); org.setBizOrgCode(TreeParser.genTreeCode());
...@@ -327,7 +335,16 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -327,7 +335,16 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
org.setAmosOrgId(companyInfo.getSequenceNbr() + ""); org.setAmosOrgId(companyInfo.getSequenceNbr() + "");
org.setAmosOrgCode(companyInfo.getOrgCode()); org.setAmosOrgCode(companyInfo.getOrgCode());
iOrgUsrService.save(org); iOrgUsrService.save(org);
regUnitInfo.setAdminUserId(userResult.getResult().getUserId()); } catch (Exception e) {
regUnitInfo.setAmosCompanySeq(companyInfo.getSequenceNbr().toString()); // 删除已经创建的 企业信息
if(companyInfo != null && companyInfo.getSequenceNbr() != null){
Privilege.companyClient.deleteCompany(companyInfo.getSequenceNbr() + "");
}
if(userResult != null && userResult.getResult() != null && StringUtils.isNotEmpty(userResult.getResult().getUserId())){
Privilege.agencyUserClient.multDeleteUser(userResult.getResult().getUserId());
}
log.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage());
}
} }
} }
\ No newline at end of file
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