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,43 +85,55 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -84,43 +85,55 @@ 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();
// 注册用统一信用码注册,默认证件类型为营业执照,数据来源:cb_data_dictionary code = 1060 try {
model.setUnitCodeType("1060"); tzsAuthServiceImpl.setRequestContext();
Bean.copyExistPropertis(model, regUnitInfo); // 注册用统一信用码注册,默认证件类型为营业执照,数据来源:cb_data_dictionary code = 1060
// 2.插入单位注册许可信息表:tz_base_unit_licence model.setUnitCodeType("1060");
List<BaseUnitLicenceDto> unitLicenceDtos = model.getUnitLicences(); Bean.copyExistPropertis(model, regUnitInfo);
List<BaseUnitLicence> baseUnitLicences = unitLicenceDtos.stream().map(s -> { // 1.插入单位注册许可信息表:tz_base_unit_licence
s.setUnitCode(model.getUnitCode()); List<BaseUnitLicenceDto> unitLicenceDtos = model.getUnitLicences();
s.setUnitName(model.getName()); List<BaseUnitLicence> baseUnitLicences = unitLicenceDtos.stream().map(s -> {
BaseUnitLicence target = new BaseUnitLicence(); s.setUnitCode(model.getUnitCode());
Bean.copyExistPropertis(s, target); s.setUnitName(model.getName());
return target; BaseUnitLicence target = new BaseUnitLicence();
}).collect(Collectors.toList()); Bean.copyExistPropertis(s, target);
baseUnitLicenceService.saveOrUpdateBatch(baseUnitLicences); return target;
// 3.插入工商单位信息表:tz_flc_reg_unit_ic }).collect(Collectors.toList());
RegUnitIc regUnitIc = new RegUnitIc(); baseUnitLicenceService.saveOrUpdateBatch(baseUnitLicences);
model.getRegUnitIc().setUnitCode(model.getUnitCode()); // 2.插入工商单位信息表:tz_flc_reg_unit_ic
model.getRegUnitIc().setUnitName(model.getName()); RegUnitIc regUnitIc = new RegUnitIc();
Bean.copyExistPropertis(model.getRegUnitIc(), regUnitIc); model.getRegUnitIc().setUnitCode(model.getUnitCode());
regUnitIcService.save(regUnitIc); model.getRegUnitIc().setUnitName(model.getName());
// 4.调用平台进行创建单位、用户信息,同步用户信息 Bean.copyExistPropertis(model.getRegUnitIc(), regUnitIc);
if (UnitReviewStateEnum.NO_NEED_REVIEW.getCode().equals(model.getState())) { regUnitIcService.save(regUnitIc);
// 4.1 自动创建:调用平台进行创建单位、用户信息 // 3.调用平台进行创建单位、用户信息,同步用户信息
this.createCompanyAndUser(regUnitInfo); if (UnitReviewStateEnum.NO_NEED_REVIEW.getCode().equals(model.getState())) {
// 4.2 创建企业信息 // 4.1 创建企业信息
this.createBaseEnterpriseInfo(model); this.createBaseEnterpriseInfo(model);
// 4.2 自动创建:调用平台进行创建单位、用户信息
this.createCompanyAndUser(regUnitInfo);
}
// 4.插入注册单位基本信息表:tz_flc_reg_unit_info
this.save(regUnitInfo);
// 5.组织返回数据
// 5.1企业基本信息
Bean.copyExistPropertis(regUnitInfo, model);
// 5.2行政许可数据
model.setUnitLicences(Bean.toModels(baseUnitLicences, BaseUnitLicenceDto.class));
// 5.3工商信息
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());
} }
this.save(regUnitInfo);
// 5.组织返回数据
// 5.1企业基本信息
Bean.copyExistPropertis(regUnitInfo, model);
// 5.2行政许可数据
model.setUnitLicences(Bean.toModels(baseUnitLicences, BaseUnitLicenceDto.class));
// 5.3工商信息
model.setRegUnitIc(Bean.toModel(regUnitIc, new RegUnitIcDto()));
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,82 +266,85 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -252,82 +266,85 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
} }
private void createCompanyAndUser(RegUnitInfo regUnitInfo) { private void createCompanyAndUser(RegUnitInfo regUnitInfo) {
FeignClientResult<List<RoleModel>> roleListResult = Privilege.roleClient.queryRoleList(null, null);
List<RoleModel> allRoleList = roleListResult.getResult();
List<RoleModel> userRoleList;
List<Long> roleIds = new ArrayList<>();
Set<String> roleNameSet = new HashSet<>();
// 3.1创建公司
CompanyModel companyInfo = new CompanyModel(); CompanyModel companyInfo = new CompanyModel();
companyInfo.setAddress(regUnitInfo.getProvince() + regUnitInfo.getCity() + regUnitInfo.getDistrict() + regUnitInfo.getStree() + regUnitInfo.getCommunity() + regUnitInfo.getAddress()); FeignClientResult<AgencyUserModel> userResult = null;
companyInfo.setAgencyCode("tzs");
companyInfo.setParentId(Long.parseLong(regUnitInfo.getManagementUnitId()));
companyInfo.setLevel("company");
companyInfo.setCompanyName(regUnitInfo.getName());
companyInfo.setCompanyCode(regUnitInfo.getUnitCode());
companyInfo.setContact(regUnitInfo.getLegalPerson());
companyInfo.setLandlinePhone(regUnitInfo.getLegalPersonTel());
FeignClientResult<CompanyModel> companyResult = Privilege.companyClient.create(companyInfo);
if (companyResult == null || companyResult.getResult() == null) {
throw new BadRequest("单位注册失败");
}
String adminUserName = regUnitInfo.getAdminName();
String loginName = regUnitInfo.getAdminLoginName();
String pwd = regUnitInfo.getAdminLoginPwd();
String adminTel = regUnitInfo.getAdminTel();
// 3.2 创建平台用户
companyInfo = companyResult.getResult();
AgencyUserModel agencyUserModel = new AgencyUserModel();
agencyUserModel.setUserName(loginName);
agencyUserModel.setRealName(adminUserName);
agencyUserModel.setLockStatus("UNLOCK");
agencyUserModel.setPassword(pwd);
agencyUserModel.setRePassword(pwd);
agencyUserModel.setAgencyCode("tzs");
agencyUserModel.setMobile(adminTel);
String unitTypeCode = regUnitInfo.getUnitTypeCode();
// 根据unitTypeCode 获取应用和角色 数据字典配置
DataDictionary unitType = iDataDictionaryService.getOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getCode, unitTypeCode));
String appCode = unitType.getTypeDesc() != null ? unitType.getTypeDesc() : "";
String[] appCodes = appCode.split(",");
Set<String> appCodesSet = new HashSet<>();
Collections.addAll(appCodesSet, appCodes);
Map<Long, List<Long>> roleSeqMap = new HashMap<>();
roleNameSet.add(unitType.getName());
userRoleList = allRoleList.stream().filter(r -> r.getRoleName().equals(unitType.getName())).collect(Collectors.toList());
userRoleList.forEach(r -> {
roleIds.add(r.getSequenceNbr());
});
roleSeqMap.put(companyInfo.getSequenceNbr(), roleIds);
Map<Long, List<RoleModel>> orgRoles = new HashMap<>();
orgRoles.put(companyInfo.getSequenceNbr(), userRoleList);
agencyUserModel.setAppCodes(new ArrayList<>(appCodesSet));
agencyUserModel.setOrgRoles(orgRoles);
agencyUserModel.setOrgRoleSeqs(roleSeqMap);
FeignClientResult<AgencyUserModel> userResult;
try { try {
FeignClientResult<List<RoleModel>> roleListResult = Privilege.roleClient.queryRoleList(null, null);
List<RoleModel> allRoleList = roleListResult.getResult();
List<RoleModel> userRoleList;
List<Long> roleIds = new ArrayList<>();
Set<String> roleNameSet = new HashSet<>();
// 3.1创建公司
companyInfo.setAddress(regUnitInfo.getProvince() + regUnitInfo.getCity() + regUnitInfo.getDistrict() + regUnitInfo.getStree() + regUnitInfo.getCommunity() + regUnitInfo.getAddress());
companyInfo.setAgencyCode("tzs");
companyInfo.setParentId(Long.parseLong(regUnitInfo.getManagementUnitId()));
companyInfo.setLevel("company");
companyInfo.setCompanyName(regUnitInfo.getName());
companyInfo.setCompanyCode(regUnitInfo.getUnitCode());
companyInfo.setContact(regUnitInfo.getLegalPerson());
companyInfo.setLandlinePhone(regUnitInfo.getLegalPersonTel());
FeignClientResult<CompanyModel> companyResult = Privilege.companyClient.create(companyInfo);
if (companyResult == null || companyResult.getResult() == null) {
throw new BadRequest("单位注册失败");
}
String adminUserName = regUnitInfo.getAdminName();
String loginName = regUnitInfo.getAdminLoginName();
String pwd = regUnitInfo.getAdminLoginPwd();
String adminTel = regUnitInfo.getAdminTel();
// 3.2 创建平台用户
companyInfo = companyResult.getResult();
AgencyUserModel agencyUserModel = new AgencyUserModel();
agencyUserModel.setUserName(loginName);
agencyUserModel.setRealName(adminUserName);
agencyUserModel.setLockStatus("UNLOCK");
agencyUserModel.setPassword(pwd);
agencyUserModel.setRePassword(pwd);
agencyUserModel.setAgencyCode("tzs");
agencyUserModel.setMobile(adminTel);
String unitTypeCode = regUnitInfo.getUnitTypeCode();
// 根据unitTypeCode 获取应用和角色 数据字典配置
DataDictionary unitType = iDataDictionaryService.getOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getCode, unitTypeCode));
String appCode = unitType.getTypeDesc() != null ? unitType.getTypeDesc() : "";
String[] appCodes = appCode.split(",");
Set<String> appCodesSet = new HashSet<>();
Collections.addAll(appCodesSet, appCodes);
Map<Long, List<Long>> roleSeqMap = new HashMap<>();
roleNameSet.add(unitType.getName());
userRoleList = allRoleList.stream().filter(r -> r.getRoleName().equals(unitType.getName())).collect(Collectors.toList());
userRoleList.forEach(r -> roleIds.add(r.getSequenceNbr()));
roleSeqMap.put(companyInfo.getSequenceNbr(), roleIds);
Map<Long, List<RoleModel>> orgRoles = new HashMap<>();
orgRoles.put(companyInfo.getSequenceNbr(), userRoleList);
agencyUserModel.setAppCodes(new ArrayList<>(appCodesSet));
agencyUserModel.setOrgRoles(orgRoles);
agencyUserModel.setOrgRoleSeqs(roleSeqMap);
userResult = Privilege.agencyUserClient.create(agencyUserModel); userResult = Privilege.agencyUserClient.create(agencyUserModel);
} catch (InnerInvokException e) { if (userResult == null || userResult.getResult() == null) {
throw new BadRequest("单位注册失败");
}
regUnitInfo.setAdminUserId(userResult.getResult().getUserId());
regUnitInfo.setAmosCompanySeq(companyInfo.getSequenceNbr().toString());
// 3.3 org_user 创建组织机构
OrgUsr org = new OrgUsr();
org.setBizOrgCode(TreeParser.genTreeCode());
org.setBizOrgType(CommonConstant.BIZ_ORG_TYPE_COMPANY);
org.setBizOrgName(regUnitInfo.getName());
org.setRecDate(new Date());
org.setRecUserId(userResult.getResult().getUserId());
org.setRecUserName(userResult.getResult().getUserName());
org.setAmosOrgId(companyInfo.getSequenceNbr() + "");
org.setAmosOrgCode(companyInfo.getOrgCode());
iOrgUsrService.save(org);
} catch (Exception e) {
// 删除已经创建的 企业信息 // 删除已经创建的 企业信息
Privilege.companyClient.deleteCompany(companyInfo.getSequenceNbr() + ""); if(companyInfo != null && companyInfo.getSequenceNbr() != null){
throw new BadRequest(e.getMessage()); Privilege.companyClient.deleteCompany(companyInfo.getSequenceNbr() + "");
} }
if(userResult != null && userResult.getResult() != null && StringUtils.isNotEmpty(userResult.getResult().getUserId())){
if (userResult == null || userResult.getResult() == null) { Privilege.agencyUserClient.multDeleteUser(userResult.getResult().getUserId());
throw new BadRequest("注册失败"); }
log.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage());
} }
// 3.3 org_user 创建组织机构
OrgUsr org = new OrgUsr();
org.setBizOrgCode(TreeParser.genTreeCode());
org.setBizOrgType(CommonConstant.BIZ_ORG_TYPE_COMPANY);
org.setBizOrgName(regUnitInfo.getName());
org.setRecDate(new Date());
org.setRecUserId(userResult.getResult().getUserId());
org.setRecUserName(userResult.getResult().getUserName());
org.setAmosOrgId(companyInfo.getSequenceNbr() + "");
org.setAmosOrgCode(companyInfo.getOrgCode());
iOrgUsrService.save(org);
regUnitInfo.setAdminUserId(userResult.getResult().getUserId());
regUnitInfo.setAmosCompanySeq(companyInfo.getSequenceNbr().toString());
} }
} }
\ 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