Commit dc10ac1d authored by wujiang's avatar wujiang

添加orgcode过滤

parent 92744707
package com.yeejoin.amos.boot.module.tzs.api.mapper; package com.yeejoin.amos.boot.module.tzs.api.mapper;
import java.util.List;
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.annotations.DataAuth;
import com.yeejoin.amos.boot.module.tzs.api.dto.EquEnterDto; import com.yeejoin.amos.boot.module.tzs.api.dto.EquEnterDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.TzBaseEnterpriseInfoDto; import com.yeejoin.amos.boot.module.tzs.api.dto.TzBaseEnterpriseInfoDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.TzBaseEnterpriseInfo; import com.yeejoin.amos.boot.module.tzs.api.entity.TzBaseEnterpriseInfo;
import java.util.List;
/** /**
* 企业数据信息 Mapper 接口 * 企业数据信息 Mapper 接口
* *
...@@ -40,5 +41,6 @@ public interface TzBaseEnterpriseInfoMapper extends BaseMapper<TzBaseEnterpriseI ...@@ -40,5 +41,6 @@ public interface TzBaseEnterpriseInfoMapper extends BaseMapper<TzBaseEnterpriseI
*/ */
TzBaseEnterpriseInfo selectByUseUnit(String useUnit); TzBaseEnterpriseInfo selectByUseUnit(String useUnit);
@DataAuth(interfacePath = "enterprise")
IPage<TzBaseEnterpriseInfoDto> page(Page<TzBaseEnterpriseInfoDto> page, TzBaseEnterpriseInfoDto tzBaseEnterpriseInfoDto); IPage<TzBaseEnterpriseInfoDto> page(Page<TzBaseEnterpriseInfoDto> page, TzBaseEnterpriseInfoDto tzBaseEnterpriseInfoDto);
} }
package com.yeejoin.amos.boot.module.tzs.api.mapper; package com.yeejoin.amos.boot.module.tzs.api.mapper;
import java.util.List;
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.annotations.DataAuth;
import com.yeejoin.amos.boot.module.tzs.api.dto.TzsJgBasicInfoDto; import com.yeejoin.amos.boot.module.tzs.api.dto.TzsJgBasicInfoDto;
public interface TzsJgMapper { public interface TzsJgMapper {
@DataAuth(interfacePath = "equipment")
IPage<TzsJgBasicInfoDto> page(Page<TzsJgBasicInfoDto> page, TzsJgBasicInfoDto tzsJgBasicInfoDto); IPage<TzsJgBasicInfoDto> page(Page<TzsJgBasicInfoDto> page, TzsJgBasicInfoDto tzsJgBasicInfoDto);
} }
...@@ -6,6 +6,7 @@ import java.util.Collections; ...@@ -6,6 +6,7 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -54,160 +55,165 @@ import com.yeejoin.amos.feign.privilege.model.RoleModel; ...@@ -54,160 +55,165 @@ import com.yeejoin.amos.feign.privilege.model.RoleModel;
* @date 2022-08-09 * @date 2022-08-09
*/ */
@Service @Service
public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitInfo, RegUnitInfoMapper> implements IRegUnitInfoService { public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitInfo, RegUnitInfoMapper>
implements IRegUnitInfoService {
@Autowired @Autowired
BaseUnitLicenceServiceImpl baseUnitLicenceService; BaseUnitLicenceServiceImpl baseUnitLicenceService;
@Autowired @Autowired
DataDictionaryServiceImpl iDataDictionaryService; DataDictionaryServiceImpl iDataDictionaryService;
@Autowired @Autowired
OrgUsrServiceImpl iOrgUsrService; OrgUsrServiceImpl iOrgUsrService;
@Autowired @Autowired
RegUnitIcServiceImpl regUnitIcService; RegUnitIcServiceImpl regUnitIcService;
@Autowired @Autowired
private TzsAuthServiceImpl tzsAuthServiceImpl; private TzsAuthServiceImpl tzsAuthServiceImpl;
@Autowired @Autowired
TzBaseEnterpriseInfoServiceImpl tzBaseEnterpriseInfoService; TzBaseEnterpriseInfoServiceImpl tzBaseEnterpriseInfoService;
@Autowired @Autowired
RestTemplate restTemplate; RestTemplate restTemplate;
/** /**
* 使用单位的类型,数据来源:cb_data_dictionary code = 1232 * 使用单位的类型,数据来源:cb_data_dictionary code = 1232
*/ */
private static String USE_UNIT_TYPE_CODE = "1232"; private static String USE_UNIT_TYPE_CODE = "1232";
/** /**
* 单位类型,数据来源:cb_data_dictionary type = UNIT_TYPE * 单位类型,数据来源:cb_data_dictionary type = UNIT_TYPE
*/ */
private static String DICT_TYPE_UNIT_TYPE = "UNIT_TYPE_NEW"; private static String DICT_TYPE_UNIT_TYPE = "UNIT_TYPE_NEW";
@Override
@Override @Transactional(rollbackFor = Exception.class)
@Transactional(rollbackFor = Exception.class) public RegUnitInfoDto registerUnit(RegUnitInfoDto model) {
public RegUnitInfoDto registerUnit(RegUnitInfoDto model) { RegUnitInfo regUnitInfo = new RegUnitInfo();
RegUnitInfo regUnitInfo = new RegUnitInfo(); try {
try { tzsAuthServiceImpl.setRequestContext();
tzsAuthServiceImpl.setRequestContext(); // 注册用统一信用码注册,默认证件类型为营业执照,数据来源:cb_data_dictionary code = 1060
// 注册用统一信用码注册,默认证件类型为营业执照,数据来源:cb_data_dictionary code = 1060 model.setUnitCodeType("1060");
model.setUnitCodeType("1060"); model.setUnitCodeTypeName("营业执照");
model.setUnitCodeTypeName("营业执照"); Bean.copyExistPropertis(model, regUnitInfo);
Bean.copyExistPropertis(model, regUnitInfo); regUnitInfo.setUnitType(StringUtils.join(model.getUnitTypeList(), ","));
regUnitInfo.setUnitType(StringUtils.join(model.getUnitTypeList(),",")); regUnitInfo.setUnitTypeCode(StringUtils.join(model.getUnitTypeCodeList(), ","));
regUnitInfo.setUnitTypeCode(StringUtils.join(model.getUnitTypeCodeList(),",")); // 1.插入单位注册许可信息表: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()); s.setUnitName(model.getName());
s.setUnitName(model.getName()); BaseUnitLicence target = new BaseUnitLicence();
BaseUnitLicence target = new BaseUnitLicence(); Bean.copyExistPropertis(s, target);
Bean.copyExistPropertis(s, target); return target;
return target; }).collect(Collectors.toList());
}).collect(Collectors.toList()); if (!baseUnitLicences.isEmpty()) {
if(!baseUnitLicences.isEmpty()){ baseUnitLicenceService.saveOrUpdateBatch(baseUnitLicences);
baseUnitLicenceService.saveOrUpdateBatch(baseUnitLicences); }
} // 2.插入工商单位信息表: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.saveOrUpdate(regUnitIc);
regUnitIcService.saveOrUpdate(regUnitIc); // 3.调用平台进行创建单位、用户信息,同步用户信息
// 3.调用平台进行创建单位、用户信息,同步用户信息
// if (UnitReviewStateEnum.NO_NEED_REVIEW.getCode().equals(model.getState())) { // if (UnitReviewStateEnum.NO_NEED_REVIEW.getCode().equals(model.getState())) {
// 3.1 创建企业信息 // 3.1 创建企业信息
this.createBaseEnterpriseInfo(model); this.createBaseEnterpriseInfo(model);
// 3.2 自动创建:调用平台进行创建单位、用户信息 // 3.2 自动创建:调用平台进行创建单位、用户信息
this.createCompanyAndUser(regUnitInfo); this.createCompanyAndUser(regUnitInfo);
// } // }
// 4.插入注册单位基本信息表:tz_flc_reg_unit_info // 4.插入注册单位基本信息表:tz_flc_reg_unit_info
this.save(regUnitInfo); this.save(regUnitInfo);
// 5.组织返回数据 // 5.组织返回数据
// 5.1企业基本信息 // 5.1企业基本信息
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) {
log.error(e.getMessage(),e); log.error(e.getMessage(), e);
// 失败后回滚:删除已经创建的企业信息 // 失败后回滚:删除已经创建的企业信息
if (StringUtils.isNotEmpty(regUnitInfo.getAmosCompanySeq())) { if (StringUtils.isNotEmpty(regUnitInfo.getAmosCompanySeq())) {
FeignClientResult<CompanyModel> feignClientResult = Privilege.companyClient.seleteOne(Long.parseLong(regUnitInfo.getAmosCompanySeq())); FeignClientResult<CompanyModel> feignClientResult = Privilege.companyClient
if (feignClientResult != null) { .seleteOne(Long.parseLong(regUnitInfo.getAmosCompanySeq()));
Privilege.companyClient.deleteCompany(regUnitInfo.getAmosCompanySeq()); if (feignClientResult != null) {
} Privilege.companyClient.deleteCompany(regUnitInfo.getAmosCompanySeq());
} }
// 失败后回滚:删除已经创建的管理员账号 }
if (StringUtils.isNotEmpty(regUnitInfo.getAdminUserId())) { // 失败后回滚:删除已经创建的管理员账号
FeignClientResult<AgencyUserModel> feignClientResult = Privilege.agencyUserClient.queryByUserId(regUnitInfo.getAdminUserId()); if (StringUtils.isNotEmpty(regUnitInfo.getAdminUserId())) {
if (feignClientResult != null) { FeignClientResult<AgencyUserModel> feignClientResult = Privilege.agencyUserClient
Privilege.agencyUserClient.multDeleteUser(regUnitInfo.getAdminUserId()); .queryByUserId(regUnitInfo.getAdminUserId());
} if (feignClientResult != null) {
} Privilege.agencyUserClient.multDeleteUser(regUnitInfo.getAdminUserId());
throw new RuntimeException(e.getMessage()); }
} }
return model; throw new RuntimeException(e.getMessage());
} }
return model;
}
public void createBaseEnterpriseInfo(RegUnitInfoDto regUnitInfo) { public void createBaseEnterpriseInfo(RegUnitInfoDto regUnitInfo) {
// 1.查询管辖公司的信息 // 1.查询管辖公司的信息
FeignClientResult<CompanyModel> feignClientResult = Privilege.companyClient.seleteOne(Long.parseLong(regUnitInfo.getManagementUnitId())); FeignClientResult<CompanyModel> feignClientResult = Privilege.companyClient
CompanyModel managementCompany = feignClientResult.getResult(); .seleteOne(Long.parseLong(regUnitInfo.getManagementUnitId()));
// 2.填充数据 CompanyModel managementCompany = feignClientResult.getResult();
TzBaseEnterpriseInfo baseEnterpriseInfo = new TzBaseEnterpriseInfo(); // 2.填充数据
baseEnterpriseInfo.setUseUnitCertificate(regUnitInfo.getUnitCodeTypeName()); TzBaseEnterpriseInfo baseEnterpriseInfo = new TzBaseEnterpriseInfo();
baseEnterpriseInfo.setUnitType(StringUtils.join(regUnitInfo.getUnitTypeList(),"#")); baseEnterpriseInfo.setUseUnitCertificate(regUnitInfo.getUnitCodeTypeName());
baseEnterpriseInfo.setUseCode(regUnitInfo.getUnitCode()); baseEnterpriseInfo.setUnitType(StringUtils.join(regUnitInfo.getUnitTypeList(), "#"));
baseEnterpriseInfo.setUseUnit(regUnitInfo.getName()); baseEnterpriseInfo.setUseCode(regUnitInfo.getUnitCode());
baseEnterpriseInfo.setProvince(regUnitInfo.getProvince()); baseEnterpriseInfo.setUseUnit(regUnitInfo.getName());
baseEnterpriseInfo.setCity(regUnitInfo.getCity()); baseEnterpriseInfo.setProvince(regUnitInfo.getProvince());
baseEnterpriseInfo.setDistrict(regUnitInfo.getDistrict()); baseEnterpriseInfo.setCity(regUnitInfo.getCity());
baseEnterpriseInfo.setStreet(regUnitInfo.getStree()); baseEnterpriseInfo.setDistrict(regUnitInfo.getDistrict());
baseEnterpriseInfo.setCommunity(regUnitInfo.getCommunity()); baseEnterpriseInfo.setStreet(regUnitInfo.getStree());
baseEnterpriseInfo.setAddress(regUnitInfo.getAddress()); baseEnterpriseInfo.setCommunity(regUnitInfo.getCommunity());
baseEnterpriseInfo.setLegalPerson(regUnitInfo.getLegalPerson()); baseEnterpriseInfo.setAddress(regUnitInfo.getAddress());
baseEnterpriseInfo.setLegalPhone(regUnitInfo.getLegalPersonTel()); baseEnterpriseInfo.setLegalPerson(regUnitInfo.getLegalPerson());
baseEnterpriseInfo.setUseContact(regUnitInfo.getContactPerson()); baseEnterpriseInfo.setLegalPhone(regUnitInfo.getLegalPersonTel());
baseEnterpriseInfo.setContactPhone(regUnitInfo.getContactPersonTel()); baseEnterpriseInfo.setUseContact(regUnitInfo.getContactPerson());
baseEnterpriseInfo.setLongitude(regUnitInfo.getLongitude()); baseEnterpriseInfo.setContactPhone(regUnitInfo.getContactPersonTel());
baseEnterpriseInfo.setLatitude(regUnitInfo.getLatitude()); baseEnterpriseInfo.setLongitude(regUnitInfo.getLongitude());
// 管辖机构信息 baseEnterpriseInfo.setLatitude(regUnitInfo.getLatitude());
baseEnterpriseInfo.setSuperviseCode(managementCompany.getCompanyCode()); // 管辖机构信息
baseEnterpriseInfo.setSuperviseOrgCode(managementCompany.getOrgCode()); baseEnterpriseInfo.setSuperviseCode(managementCompany.getCompanyCode());
// 这个表有两个字段所以赋值两字段 baseEnterpriseInfo.setSuperviseOrgCode(managementCompany.getOrgCode());
baseEnterpriseInfo.setSuperviseOrgName(regUnitInfo.getManagementUnit()); // 这个表有两个字段所以赋值两字段
baseEnterpriseInfo.setGoverningBody(regUnitInfo.getManagementUnit()); baseEnterpriseInfo.setSuperviseOrgName(regUnitInfo.getManagementUnit());
baseEnterpriseInfo.setDataSources("企业注册"); baseEnterpriseInfo.setGoverningBody(regUnitInfo.getManagementUnit());
baseEnterpriseInfo.setIndustry(regUnitInfo.getRegUnitIc().getIndustryName()); baseEnterpriseInfo.setDataSources("企业注册");
baseEnterpriseInfo.setRegistrationAuthority(regUnitInfo.getRegUnitIc().getRegisteredOrgan()); baseEnterpriseInfo.setIndustry(regUnitInfo.getRegUnitIc().getIndustryName());
baseEnterpriseInfo.setApprovalTime(regUnitInfo.getRegUnitIc().getApprovedDate()); baseEnterpriseInfo.setRegistrationAuthority(regUnitInfo.getRegUnitIc().getRegisteredOrgan());
baseEnterpriseInfo.setOperatingStatus(regUnitInfo.getRegUnitIc().getBusinessState()); baseEnterpriseInfo.setApprovalTime(regUnitInfo.getRegUnitIc().getApprovedDate());
baseEnterpriseInfo.setSyncDate(new Date()); baseEnterpriseInfo.setOperatingStatus(regUnitInfo.getRegUnitIc().getBusinessState());
baseEnterpriseInfo.setSyncState(0); baseEnterpriseInfo.setSyncDate(new Date());
tzBaseEnterpriseInfoService.save(baseEnterpriseInfo); baseEnterpriseInfo.setSyncState(0);
} tzBaseEnterpriseInfoService.save(baseEnterpriseInfo);
}
@Override @Override
public RegUnitInfoDto unitCheck(String unitCode, String unitType) { public RegUnitInfoDto unitCheck(String unitCode, String unitType) {
// 1.校验重复性 // 1.校验重复性
RegUnitInfo regUnitInfo = this.getOne(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getUnitCode, unitCode)); RegUnitInfo regUnitInfo = this
if (regUnitInfo != null) { .getOne(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getUnitCode, unitCode));
throw new RuntimeException("该单位已注册,请联系企业管理员!"); if (regUnitInfo != null) {
} throw new RuntimeException("该单位已注册,请联系企业管理员!");
// 2.组织返回数据 }
RegUnitInfoDto regUnitInfoDto = new RegUnitInfoDto(); // 2.组织返回数据
if (USE_UNIT_TYPE_CODE.equals(unitType)) { RegUnitInfoDto regUnitInfoDto = new RegUnitInfoDto();
// 本地库有的化 就不去其他系统查询 if (USE_UNIT_TYPE_CODE.equals(unitType)) {
RegUnitIc regUnitIc = regUnitIcService.getOne(new LambdaQueryWrapper<RegUnitIc>().eq(RegUnitIc::getUnitCode, unitCode)); // 本地库有的化 就不去其他系统查询
regUnitInfoDto.setRegUnitIc(Bean.toModel(regUnitIc, new RegUnitIcDto())); RegUnitIc regUnitIc = regUnitIcService
if(regUnitIc == null){ .getOne(new LambdaQueryWrapper<RegUnitIc>().eq(RegUnitIc::getUnitCode, unitCode));
// 2.1 使用单位调用行政许可系统接口进行查询工商信息 regUnitInfoDto.setRegUnitIc(Bean.toModel(regUnitIc, new RegUnitIcDto()));
if (regUnitIc == null) {
// 2.1 使用单位调用行政许可系统接口进行查询工商信息
// MultiValueMap<String, String> headers = new HttpHeaders(); // MultiValueMap<String, String> headers = new HttpHeaders();
// headers.add("header-1","v1"); // headers.add("header-1","v1");
// headers.add("header-2","v2"); // headers.add("header-2","v2");
...@@ -218,200 +224,230 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -218,200 +224,230 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
// URI.create("url")); // URI.create("url"));
// ResponseEntity<JSONObject> responseEntity = restTemplate.exchange(requestEntity,JSONObject.class); // ResponseEntity<JSONObject> responseEntity = restTemplate.exchange(requestEntity,JSONObject.class);
// JSONObject result = responseEntity.getBody(); // JSONObject result = responseEntity.getBody();
// 2.2 工商信息组装 // 2.2 工商信息组装
// regUnitInfoDto.setRegUnitIc(); // regUnitInfoDto.setRegUnitIc();
} }
} else {
RegUnitIc regUnitIc = regUnitIcService
.getOne(new LambdaQueryWrapper<RegUnitIc>().eq(RegUnitIc::getUnitCode, unitCode));
regUnitInfoDto.setRegUnitIc(Bean.toModel(regUnitIc, new RegUnitIcDto()));
}
// 2.3 许可信息组装
List<BaseUnitLicence> unitLicences = baseUnitLicenceService
.list(new LambdaQueryWrapper<BaseUnitLicence>().eq(BaseUnitLicence::getUnitCode, unitCode));
regUnitInfoDto.setUnitLicences(Bean.toModels(unitLicences, BaseUnitLicenceDto.class));
return regUnitInfoDto;
}
} else { @Override
RegUnitIc regUnitIc = regUnitIcService.getOne(new LambdaQueryWrapper<RegUnitIc>().eq(RegUnitIc::getUnitCode, unitCode)); public List<DataDictionary> getUnitTypeList() {
regUnitInfoDto.setRegUnitIc(Bean.toModel(regUnitIc, new RegUnitIcDto())); return iDataDictionaryService.getByType(DICT_TYPE_UNIT_TYPE);
} }
// 2.3 许可信息组装
List<BaseUnitLicence> unitLicences = baseUnitLicenceService.list(new LambdaQueryWrapper<BaseUnitLicence>().eq(BaseUnitLicence::getUnitCode, unitCode));
regUnitInfoDto.setUnitLicences(Bean.toModels(unitLicences, BaseUnitLicenceDto.class));
return regUnitInfoDto;
}
@Override @Override
public List<DataDictionary> getUnitTypeList() { public Collection getManagementUnitTree(String orgCode) {
return iDataDictionaryService.getByType(DICT_TYPE_UNIT_TYPE); tzsAuthServiceImpl.setRequestContext();
} // 组织架构中单位级别为:省级、地市级、区县级的单位
List<CompanyModel> companyModels = new ArrayList<CompanyModel>();
if (StringUtils.isEmpty(orgCode)) {
companyModels = (List<CompanyModel>) Privilege.companyClient.queryAgencyTree(null).getResult();
} else {
@Override LinkedHashMap<Object, Object> l = (LinkedHashMap<Object, Object>) Privilege.companyClient
public Collection getManagementUnitTree(String orgCode) { .queryByOrgcode(orgCode).getResult();
tzsAuthServiceImpl.setRequestContext(); for (Map.Entry<Object, Object> it : l.entrySet()) {
// 组织架构中单位级别为:省级、地市级、区县级的单位 Privilege.companyClient.queryByOrgcode(orgCode).getResult();
List<CompanyModel> companyModels = new ArrayList<CompanyModel>(); CompanyModel companyModel = JSONObject.parseObject(JSONObject.toJSONString(it.getValue()),
if(StringUtils.isEmpty(orgCode)) CompanyModel.class);
{ if(companyModel!=null)
companyModels = (List<CompanyModel>) Privilege.companyClient.queryAgencyTree(null).getResult(); {
}else companyModels = (List<CompanyModel>) Privilege.companyClient
{ .querySubAgencyTree(companyModel.getSequenceNbr()).getResult();
companyModels = (List<CompanyModel>) Privilege.companyClient.queryByOrgcode(orgCode).getResult(); }
} break;
return companyModels.stream().filter(c -> "headquarter".equals(c.getLevel()) || "prefecture-level".equals(c.getLevel()) || "county".equals(c.getLevel())).map(this::dealChildCompany).collect(Collectors.toList()); }
} }
return companyModels.stream().filter(c -> "headquarter".equals(c.getLevel())
|| "prefecture-level".equals(c.getLevel()) || "county".equals(c.getLevel())).map(this::dealChildCompany)
.collect(Collectors.toList());
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean unitLogOut(String unitCode) { public Boolean unitLogOut(String unitCode) {
RegUnitInfo regUnitInfo = this.getOne(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getUnitCode, unitCode)); RegUnitInfo regUnitInfo = this
if (regUnitInfo == null) { .getOne(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getUnitCode, unitCode));
return Boolean.FALSE; if (regUnitInfo == null) {
} return Boolean.FALSE;
try { }
// 1.删除已经创建的企业信息 try {
if (StringUtils.isNotEmpty(regUnitInfo.getAmosCompanySeq())) { // 1.删除已经创建的企业信息
CompanyModel companyModel = Privilege.companyClient.seleteOne(Long.parseLong(regUnitInfo.getAmosCompanySeq())).getResult(); if (StringUtils.isNotEmpty(regUnitInfo.getAmosCompanySeq())) {
if (companyModel != null) { CompanyModel companyModel = Privilege.companyClient
Privilege.companyClient.deleteCompany(regUnitInfo.getAmosCompanySeq()); .seleteOne(Long.parseLong(regUnitInfo.getAmosCompanySeq())).getResult();
} if (companyModel != null) {
} Privilege.companyClient.deleteCompany(regUnitInfo.getAmosCompanySeq());
// 2.删除已经创建的管理员账号 }
FeignClientResult<AgencyUserModel> feignClientResult = Privilege.agencyUserClient.queryByUserId(regUnitInfo.getAdminUserId()); }
if (feignClientResult != null) { // 2.删除已经创建的管理员账号
Privilege.agencyUserClient.multDeleteUser(regUnitInfo.getAdminUserId()); FeignClientResult<AgencyUserModel> feignClientResult = Privilege.agencyUserClient
} .queryByUserId(regUnitInfo.getAdminUserId());
} catch (Exception e) { if (feignClientResult != null) {
log.error(e.getMessage(), e); Privilege.agencyUserClient.multDeleteUser(regUnitInfo.getAdminUserId());
} }
// 3.企业注册表删除 } catch (Exception e) {
this.remove(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getUnitCode, unitCode)); log.error(e.getMessage(), e);
// 4.工商信息表删除 }
regUnitIcService.remove(new LambdaQueryWrapper<RegUnitIc>().eq(RegUnitIc::getUnitCode, unitCode)); // 3.企业注册表删除
// 5.许可信息删除 this.remove(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getUnitCode, unitCode));
baseUnitLicenceService.remove(new LambdaQueryWrapper<BaseUnitLicence>().eq(BaseUnitLicence::getUnitCode, unitCode)); // 4.工商信息表删除
// 6.企业数据信息删除 regUnitIcService.remove(new LambdaQueryWrapper<RegUnitIc>().eq(RegUnitIc::getUnitCode, unitCode));
tzBaseEnterpriseInfoService.remove(new LambdaQueryWrapper<TzBaseEnterpriseInfo>().eq(TzBaseEnterpriseInfo::getUseCode, unitCode)); // 5.许可信息删除
// 7.机场单位表信息删除 baseUnitLicenceService
iOrgUsrService.remove(new LambdaQueryWrapper<OrgUsr>().eq(OrgUsr::getAmosOrgId, regUnitInfo.getAmosCompanySeq())); .remove(new LambdaQueryWrapper<BaseUnitLicence>().eq(BaseUnitLicence::getUnitCode, unitCode));
return Boolean.TRUE; // 6.企业数据信息删除
} tzBaseEnterpriseInfoService
.remove(new LambdaQueryWrapper<TzBaseEnterpriseInfo>().eq(TzBaseEnterpriseInfo::getUseCode, unitCode));
// 7.机场单位表信息删除
iOrgUsrService
.remove(new LambdaQueryWrapper<OrgUsr>().eq(OrgUsr::getAmosOrgId, regUnitInfo.getAmosCompanySeq()));
return Boolean.TRUE;
}
@Override @Override
public Boolean checkRepeatAccount(String userName) { public Boolean checkRepeatAccount(String userName) {
return this.count(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getAdminLoginName,userName)) > 0; return this.count(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getAdminLoginName, userName)) > 0;
} }
@Override @Override
public Boolean checkRepeatPhone(String phoneNo) { public Boolean checkRepeatPhone(String phoneNo) {
return this.count(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getAdminTel,phoneNo)) > 0; return this.count(new LambdaQueryWrapper<RegUnitInfo>().eq(RegUnitInfo::getAdminTel, phoneNo)) > 0;
} }
private CompanyModel dealChildCompany(CompanyModel cm) { private CompanyModel dealChildCompany(CompanyModel cm) {
cm.setChildren(this.getFilterChild(cm.getChildren() != null ? cm.getChildren() : new ArrayList())); cm.setChildren(this.getFilterChild(cm.getChildren() != null ? cm.getChildren() : new ArrayList()));
cm.getChildren().stream().filter(n -> { cm.getChildren().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())
}).map(n -> { || "county".equals(c.getLevel());
CompanyModel c = JSONObject.parseObject(JSON.toJSONString(n), CompanyModel.class); }).map(n -> {
return dealChildCompany(c); CompanyModel c = JSONObject.parseObject(JSON.toJSONString(n), CompanyModel.class);
}).collect(Collectors.toList()); return dealChildCompany(c);
return cm; }).collect(Collectors.toList());
} return cm;
}
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())
}).map(s -> { || "county".equals(c.getLevel());
CompanyModel c = JSONObject.parseObject(JSON.toJSONString(s), CompanyModel.class); }).map(s -> {
c.setChildren(this.getFilterChild(c.getChildren() != null ? c.getChildren() : new ArrayList())); CompanyModel c = JSONObject.parseObject(JSON.toJSONString(s), CompanyModel.class);
return c; c.setChildren(this.getFilterChild(c.getChildren() != null ? c.getChildren() : new ArrayList()));
}).collect(Collectors.toList()); return c;
} }).collect(Collectors.toList());
}
private void createCompanyAndUser(RegUnitInfo regUnitInfo) { private void createCompanyAndUser(RegUnitInfo regUnitInfo) {
CompanyModel companyInfo = new CompanyModel(); CompanyModel companyInfo = new CompanyModel();
FeignClientResult<AgencyUserModel> userResult = null; FeignClientResult<AgencyUserModel> userResult = null;
try { 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创建公司
companyInfo.setAddress(dealNull2EmptyString(regUnitInfo.getProvince()) + dealNull2EmptyString(regUnitInfo.getCity()) + dealNull2EmptyString(regUnitInfo.getDistrict()) + dealNull2EmptyString(regUnitInfo.getStree()) + dealNull2EmptyString(regUnitInfo.getCommunity()) + dealNull2EmptyString(regUnitInfo.getAddress())); companyInfo.setAddress(dealNull2EmptyString(regUnitInfo.getProvince())
companyInfo.setAgencyCode("tzs"); + dealNull2EmptyString(regUnitInfo.getCity()) + dealNull2EmptyString(regUnitInfo.getDistrict())
companyInfo.setParentId(Long.parseLong(regUnitInfo.getManagementUnitId())); + dealNull2EmptyString(regUnitInfo.getStree()) + dealNull2EmptyString(regUnitInfo.getCommunity())
companyInfo.setLevel("company"); + dealNull2EmptyString(regUnitInfo.getAddress()));
companyInfo.setCompanyName(regUnitInfo.getName()); companyInfo.setAgencyCode("tzs");
companyInfo.setCompanyCode(regUnitInfo.getUnitCode()); companyInfo.setParentId(Long.parseLong(regUnitInfo.getManagementUnitId()));
companyInfo.setContact(regUnitInfo.getLegalPerson()); companyInfo.setLevel("company");
companyInfo.setCompanyType(regUnitInfo.getUnitType()); companyInfo.setCompanyName(regUnitInfo.getName());
companyInfo.setLandlinePhone(regUnitInfo.getLegalPersonTel()); companyInfo.setCompanyCode(regUnitInfo.getUnitCode());
FeignClientResult<CompanyModel> companyResult = Privilege.companyClient.create(companyInfo); companyInfo.setContact(regUnitInfo.getLegalPerson());
if (companyResult == null || companyResult.getResult() == null) { companyInfo.setCompanyType(regUnitInfo.getUnitType());
throw new BadRequest("单位注册失败"); companyInfo.setLandlinePhone(regUnitInfo.getLegalPersonTel());
} FeignClientResult<CompanyModel> companyResult = Privilege.companyClient.create(companyInfo);
String adminUserName = regUnitInfo.getAdminName(); if (companyResult == null || companyResult.getResult() == null) {
String loginName = regUnitInfo.getAdminLoginName(); throw new BadRequest("单位注册失败");
String pwd = regUnitInfo.getAdminLoginPwd(); }
String adminTel = regUnitInfo.getAdminTel(); String adminUserName = regUnitInfo.getAdminName();
// 3.2 创建平台用户 String loginName = regUnitInfo.getAdminLoginName();
companyInfo = companyResult.getResult(); String pwd = regUnitInfo.getAdminLoginPwd();
AgencyUserModel agencyUserModel = new AgencyUserModel(); String adminTel = regUnitInfo.getAdminTel();
agencyUserModel.setUserName(loginName); // 3.2 创建平台用户
agencyUserModel.setRealName(adminUserName); companyInfo = companyResult.getResult();
agencyUserModel.setLockStatus("UNLOCK"); AgencyUserModel agencyUserModel = new AgencyUserModel();
agencyUserModel.setPassword(pwd); agencyUserModel.setUserName(loginName);
agencyUserModel.setRePassword(pwd); agencyUserModel.setRealName(adminUserName);
agencyUserModel.setAgencyCode("tzs"); agencyUserModel.setLockStatus("UNLOCK");
agencyUserModel.setMobile(adminTel); agencyUserModel.setPassword(pwd);
String unitTypeCode = regUnitInfo.getUnitTypeCode(); agencyUserModel.setRePassword(pwd);
// 根据unitTypeCode 获取应用和角色 数据字典配置 agencyUserModel.setAgencyCode("tzs");
String[] units = unitTypeCode.split(","); agencyUserModel.setMobile(adminTel);
Set<String> appCodesSet = new HashSet<>(); String unitTypeCode = regUnitInfo.getUnitTypeCode();
Map<Long, List<Long>> roleSeqMap = new HashMap<>(); // 根据unitTypeCode 获取应用和角色 数据字典配置
Map<Long, List<RoleModel>> orgRoles = new HashMap<>(); String[] units = unitTypeCode.split(",");
for(String TypeCode: units) { Set<String> appCodesSet = new HashSet<>();
DataDictionary unitType = iDataDictionaryService.getOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getCode, TypeCode)); Map<Long, List<Long>> roleSeqMap = new HashMap<>();
String appCode = unitType.getTypeDesc() != null ? unitType.getTypeDesc() : ""; Map<Long, List<RoleModel>> orgRoles = new HashMap<>();
String[] appCodes = appCode.split(","); for (String TypeCode : units) {
Collections.addAll(appCodesSet, appCodes); DataDictionary unitType = iDataDictionaryService
roleNameSet.add(unitType.getName()); .getOne(new LambdaQueryWrapper<DataDictionary>().eq(DataDictionary::getCode, TypeCode));
userRoleList = allRoleList.stream().filter(r -> r.getRoleName().equals(unitType.getName())).collect(Collectors.toList()); String appCode = unitType.getTypeDesc() != null ? unitType.getTypeDesc() : "";
for(RoleModel roleModel : allRoleList.stream().filter(r -> r.getRoleName().equals(unitType.getExtend())).collect(Collectors.toList())){ String[] appCodes = appCode.split(",");
userRoleList.add(roleModel); Collections.addAll(appCodesSet, appCodes);
} roleNameSet.add(unitType.getName());
userRoleList.forEach(r -> roleIds.add(r.getSequenceNbr())); userRoleList = allRoleList.stream().filter(r -> r.getRoleName().equals(unitType.getName()))
roleSeqMap.put(companyInfo.getSequenceNbr(), roleIds); .collect(Collectors.toList());
orgRoles.put(companyInfo.getSequenceNbr(), userRoleList); for (RoleModel roleModel : allRoleList.stream()
} .filter(r -> r.getRoleName().equals(unitType.getExtend())).collect(Collectors.toList())) {
agencyUserModel.setAppCodes(new ArrayList<>(appCodesSet)); userRoleList.add(roleModel);
agencyUserModel.setOrgRoles(orgRoles); }
agencyUserModel.setOrgRoleSeqs(roleSeqMap); userRoleList.forEach(r -> roleIds.add(r.getSequenceNbr()));
userResult = Privilege.agencyUserClient.create(agencyUserModel); roleSeqMap.put(companyInfo.getSequenceNbr(), roleIds);
if (userResult == null || userResult.getResult() == null) { orgRoles.put(companyInfo.getSequenceNbr(), userRoleList);
throw new BadRequest("单位注册失败"); }
} agencyUserModel.setAppCodes(new ArrayList<>(appCodesSet));
regUnitInfo.setAdminUserId(userResult.getResult().getUserId()); agencyUserModel.setOrgRoles(orgRoles);
regUnitInfo.setAmosCompanySeq(companyInfo.getSequenceNbr().toString()); agencyUserModel.setOrgRoleSeqs(roleSeqMap);
// 3.3 org_user 创建组织机构 userResult = Privilege.agencyUserClient.create(agencyUserModel);
OrgUsr org = new OrgUsr(); if (userResult == null || userResult.getResult() == null) {
org.setBizOrgCode(TreeParser.genTreeCode()); throw new BadRequest("单位注册失败");
org.setBizOrgType(CommonConstant.BIZ_ORG_TYPE_COMPANY); }
org.setBizOrgName(regUnitInfo.getName()); regUnitInfo.setAdminUserId(userResult.getResult().getUserId());
org.setRecDate(new Date()); regUnitInfo.setAmosCompanySeq(companyInfo.getSequenceNbr().toString());
org.setRecUserId(userResult.getResult().getUserId()); // 3.3 org_user 创建组织机构
org.setRecUserName(userResult.getResult().getUserName()); OrgUsr org = new OrgUsr();
org.setAmosOrgId(companyInfo.getSequenceNbr() + ""); org.setBizOrgCode(TreeParser.genTreeCode());
org.setAmosOrgCode(companyInfo.getOrgCode()); org.setBizOrgType(CommonConstant.BIZ_ORG_TYPE_COMPANY);
iOrgUsrService.save(org); org.setBizOrgName(regUnitInfo.getName());
} catch (Exception e) { org.setRecDate(new Date());
// 删除已经创建的 企业信息 org.setRecUserId(userResult.getResult().getUserId());
if (companyInfo != null && companyInfo.getSequenceNbr() != null) { org.setRecUserName(userResult.getResult().getUserName());
Privilege.companyClient.deleteCompany(companyInfo.getSequenceNbr() + ""); org.setAmosOrgId(companyInfo.getSequenceNbr() + "");
} org.setAmosOrgCode(companyInfo.getOrgCode());
if (userResult != null && userResult.getResult() != null && StringUtils.isNotEmpty(userResult.getResult().getUserId())) { iOrgUsrService.save(org);
Privilege.agencyUserClient.multDeleteUser(userResult.getResult().getUserId()); } catch (Exception e) {
} // 删除已经创建的 企业信息
log.error(e.getMessage(), e); if (companyInfo != null && companyInfo.getSequenceNbr() != null) {
throw new RuntimeException(e.getMessage()); 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());
}
}
private String dealNull2EmptyString( String t){ private String dealNull2EmptyString(String t) {
return StringUtils.isEmpty(t) ? "" : t; return StringUtils.isEmpty(t) ? "" : t;
} }
} }
\ 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