|
|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.qw.domain.QwCompany;
|
|
|
import com.fs.qw.mapper.QwCompanyMapper;
|
|
|
import com.fs.qw.param.QwCompanyTenantSetParam;
|
|
|
@@ -119,8 +120,27 @@ public class QwCompanyServiceImpl implements IQwCompanyService
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteQwCompanyByIds(Long[] ids)
|
|
|
+ public int deleteQwCompanyByIds(Long[] ids,String tenantCode)
|
|
|
{
|
|
|
+ if (StringUtils.isNotBlank(tenantCode) && "undefined".equals(tenantCode)) {
|
|
|
+ if (ids != null){
|
|
|
+ for (Long id : ids) {
|
|
|
+ QwCompany qwCompany = selectQwCompanyById(id);
|
|
|
+ Long tenantId = qwCompany.getTenantId();
|
|
|
+ if (tenantId != null){
|
|
|
+ TenantInfo tenantInfo = tenantInfoMapper.selectTenantInfoById(tenantId.toString());
|
|
|
+ if (tenantInfo != null) {
|
|
|
+ try {
|
|
|
+ deleteQwCompanyInTenantDatabase(tenantInfo, qwCompany);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("停用租户企微主体失败:{}",e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return qwCompanyMapper.deleteQwCompanyByIds(ids);
|
|
|
}
|
|
|
|
|
|
@@ -131,8 +151,22 @@ public class QwCompanyServiceImpl implements IQwCompanyService
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteQwCompanyById(Long id)
|
|
|
+ public int deleteQwCompanyById(Long id,String tenantCode)
|
|
|
{
|
|
|
+ if (StringUtils.isNotBlank(tenantCode) && "undefined".equals(tenantCode)) {
|
|
|
+ QwCompany qwCompany = selectQwCompanyById(id);
|
|
|
+ Long tenantId = qwCompany.getTenantId();
|
|
|
+ if (tenantId != null){
|
|
|
+ TenantInfo tenantInfo = tenantInfoMapper.selectTenantInfoById(tenantId.toString());
|
|
|
+ if (tenantInfo != null) {
|
|
|
+ try {
|
|
|
+ deleteQwCompanyInTenantDatabase(tenantInfo, qwCompany);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("停用租户企微主体失败:{}",e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return qwCompanyMapper.deleteQwCompanyById(id);
|
|
|
}
|
|
|
|
|
|
@@ -180,6 +214,35 @@ public class QwCompanyServiceImpl implements IQwCompanyService
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 在租户库中按 corpId 停用企微主体。
|
|
|
+ * 直接走 Mapper,避免复用 updateQwCompany 时用租户库主键覆盖按 corpId 缓存的 Redis。
|
|
|
+ */
|
|
|
+ private boolean deleteQwCompanyInTenantDatabase(TenantInfo tenantInfo, QwCompany masterCompany) {
|
|
|
+ if (!switchToTenantDataSource(tenantInfo)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ boolean flag = false;
|
|
|
+ try {
|
|
|
+ String corpId = masterCompany.getCorpId();
|
|
|
+ QwCompany tenantRow = qwCompanyMapper.selectQwCompanyByCorpId(corpId);
|
|
|
+ if (tenantRow != null) {
|
|
|
+ tenantRow.setId(tenantRow.getId());
|
|
|
+ tenantRow.setStatus(0L);
|
|
|
+ tenantRow.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ tenantRow.setUpdateBy("master");
|
|
|
+
|
|
|
+ qwCompanyMapper.updateQwCompany(tenantRow);
|
|
|
+ }
|
|
|
+ flag = true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步 qw_company 到租户库失败 tenantId={}, corpId={}", tenantInfo.getId(), masterCompany.getCorpId(), e);
|
|
|
+ } finally {
|
|
|
+ clearTenantDataSourceType();
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 在租户库中按 corpId 同步企微主体:已存在则更新,否则新增。
|
|
|
* 直接走 Mapper,避免复用 updateQwCompany 时用租户库主键覆盖按 corpId 缓存的 Redis。
|
|
|
@@ -192,9 +255,8 @@ public class QwCompanyServiceImpl implements IQwCompanyService
|
|
|
try {
|
|
|
String corpId = masterCompany.getCorpId();
|
|
|
QwCompany tenantRow = qwCompanyMapper.selectQwCompanyByCorpId(corpId);
|
|
|
- Long tenantPk = tenantInfo.getId();
|
|
|
if (tenantRow != null) {
|
|
|
- tenantRow.setId(tenantPk);
|
|
|
+ tenantRow.setId(tenantRow.getId());
|
|
|
tenantRow.setCorpId(masterCompany.getCorpId());
|
|
|
tenantRow.setCorpName(masterCompany.getCorpName());
|
|
|
tenantRow.setOpenSecret(masterCompany.getOpenSecret());
|