mirror of
https://github.com/chatopera/cosin.git
synced 2025-06-16 18:30:03 +08:00
https://gitee.com/cskefu/cskefu/issues/I836RO enable organ creation as billing resource
Signed-off-by: Hai Liang Wang <hai@chatopera.com>
This commit is contained in:
parent
2e4a71c175
commit
9d703b1ad2
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd.
|
||||
* <https://www.chatopera.com>, Licensed under the Chunsong Public
|
||||
* License, Version 1.0 (the "License"), https://docs.cskefu.com/licenses/v1.html
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.cskefu.cc.aspect;
|
||||
|
||||
import com.cskefu.cc.basic.MainContext;
|
||||
import com.cskefu.cc.exception.BillingQuotaException;
|
||||
import com.cskefu.cc.exception.BillingResourceException;
|
||||
import com.cskefu.cc.model.Channel;
|
||||
import com.cskefu.cc.model.Organ;
|
||||
import com.cskefu.cc.proxy.LicenseProxy;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class OrganAspect {
|
||||
private final static Logger logger = LoggerFactory.getLogger(OrganAspect.class);
|
||||
|
||||
@Autowired
|
||||
private LicenseProxy licenseProxy;
|
||||
|
||||
@Before("execution(* com.cskefu.cc.persistence.repository.OrganRepository.save(..))")
|
||||
public void beforeSave(final JoinPoint joinPoint) throws BillingResourceException, BillingQuotaException {
|
||||
final Organ organ = (Organ) joinPoint.getArgs()[0];
|
||||
logger.info("[beforeSave] before organ id {}", organ.getId());
|
||||
if (StringUtils.isBlank(organ.getId())) {
|
||||
// create new organ
|
||||
licenseProxy.writeDownResourceUsageInStore(MainContext.BillingResource.ORGAN, 1);
|
||||
} else {
|
||||
// update existed Channel
|
||||
}
|
||||
}
|
||||
}
|
@ -228,5 +228,4 @@ public class LicenseController extends Handler {
|
||||
return request(super.createView("/public/error"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd.
|
||||
* <https://www.chatopera.com>, Licensed under the Chunsong Public
|
||||
* Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd.
|
||||
* <https://www.chatopera.com>, Licensed under the Chunsong Public
|
||||
* License, Version 1.0 (the "License"), https://docs.cskefu.com/licenses/v1.html
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright (C) 2018- Jun. 2023 Chatopera Inc, <https://www.chatopera.com>, Licensed under the Apache License, Version 2.0,
|
||||
* Copyright (C) 2018- Jun. 2023 Chatopera Inc, <https://www.chatopera.com>, Licensed under the Apache License, Version 2.0,
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统, Licensed under the Apache License, Version 2.0,
|
||||
* Copyright (C) 2017 优客服-多渠道客服系统, Licensed under the Apache License, Version 2.0,
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package com.cskefu.cc.controller.admin;
|
||||
@ -17,6 +17,7 @@ package com.cskefu.cc.controller.admin;
|
||||
import com.cskefu.cc.basic.Constants;
|
||||
import com.cskefu.cc.cache.Cache;
|
||||
import com.cskefu.cc.controller.Handler;
|
||||
import com.cskefu.cc.exception.BillingQuotaException;
|
||||
import com.cskefu.cc.model.*;
|
||||
import com.cskefu.cc.persistence.repository.*;
|
||||
import com.cskefu.cc.proxy.OrganProxy;
|
||||
@ -34,6 +35,8 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -157,16 +160,26 @@ public class OrganController extends Handler {
|
||||
public ModelAndView save(HttpServletRequest request, @Valid Organ organ) {
|
||||
Organ tempOrgan = organRepository.findByName(organ.getName());
|
||||
String msg = "admin_organ_new_success";
|
||||
String firstId = null;
|
||||
String createdId = null;
|
||||
if (tempOrgan != null) {
|
||||
msg = "admin_organ_update_name_not"; // 分类名字重复
|
||||
} else {
|
||||
firstId = organ.getId();
|
||||
|
||||
organRepository.save(organ);
|
||||
try {
|
||||
organRepository.save(organ);
|
||||
createdId = organ.getId();
|
||||
} catch (Exception e) {
|
||||
if (e instanceof UndeclaredThrowableException) {
|
||||
logger.error("[save] BillingQuotaException", e);
|
||||
if (StringUtils.startsWith(e.getCause().getMessage(), BillingQuotaException.SUFFIX)) {
|
||||
msg = e.getCause().getMessage();
|
||||
}
|
||||
} else {
|
||||
logger.error("[save] err", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return request(super.createView(
|
||||
"redirect:/admin/organ/index.html?msg=" + msg + "&organ=" + firstId));
|
||||
"redirect:/admin/organ/index.html?msg=" + msg + "&organ=" + createdId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,6 +189,8 @@ block content
|
||||
layer.msg('修改无法完成,上级机构选择错误', {icon: 2, time: 2000})
|
||||
} else if (msg == 'not_allow_remove_user') {
|
||||
layer.msg('用户只有一个组织,不允许移除', {icon: 2, time: 2000})
|
||||
} else {
|
||||
handleGeneralCodeInQueryPathOrApiResp(msg);
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user