给系统管理模块增加操作的判断条件

This commit is contained in:
季圣华
2023-02-03 19:27:21 +08:00
parent c58f519dc3
commit ca4efaa3d8
4 changed files with 120 additions and 63 deletions

View File

@@ -10,6 +10,7 @@ import com.jsh.erp.datasource.mappers.UserMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger;
@@ -37,6 +38,9 @@ public class TenantService {
@Resource
private UserMapperEx userMapperEx;
@Resource
private UserService userService;
@Resource
private LogService logService;
@@ -70,11 +74,13 @@ public class TenantService {
public List<TenantEx> select(String loginName, String type, String enabled, int offset, int rows)throws Exception {
List<TenantEx> list= new ArrayList<>();
try{
list = tenantMapperEx.selectByConditionTenant(loginName, type, enabled, offset, rows);
if (null != list) {
for (TenantEx tenantEx : list) {
tenantEx.setCreateTimeStr(Tools.getCenternTime(tenantEx.getCreateTime()));
tenantEx.setExpireTimeStr(Tools.getCenternTime(tenantEx.getExpireTime()));
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
list = tenantMapperEx.selectByConditionTenant(loginName, type, enabled, offset, rows);
if (null != list) {
for (TenantEx tenantEx : list) {
tenantEx.setCreateTimeStr(Tools.getCenternTime(tenantEx.getCreateTime()));
tenantEx.setExpireTimeStr(Tools.getCenternTime(tenantEx.getExpireTime()));
}
}
}
}catch(Exception e){
@@ -86,7 +92,9 @@ public class TenantService {
public Long countTenant(String loginName, String type, String enabled)throws Exception {
Long result=null;
try{
result=tenantMapperEx.countsByTenant(loginName, type, enabled);
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
result = tenantMapperEx.countsByTenant(loginName, type, enabled);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
@@ -105,7 +113,9 @@ public class TenantService {
if(tenant.getExpireTime()==null) {
tenant.setExpireTime(Tools.addDays(new Date(), tryDayLimit)); //租户允许试用的天数
}
result=tenantMapper.insertSelective(tenant);
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
result = tenantMapper.insertSelective(tenant);
}
}catch(Exception e){
JshException.writeFail(logger, e);
}
@@ -117,11 +127,13 @@ public class TenantService {
Tenant tenant = JSONObject.parseObject(obj.toJSONString(), Tenant.class);
int result=0;
try{
//如果租户下的用户限制数量为1则将该租户之外的用户全部禁用
if(1 == tenant.getUserNumLimit()) {
userMapperEx.disableUserByLimit(tenant.getTenantId());
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
//如果租户下的用户限制数量为1则将该租户之外的用户全部禁用
if (1 == tenant.getUserNumLimit()) {
userMapperEx.disableUserByLimit(tenant.getTenantId());
}
result = tenantMapper.updateByPrimaryKeySelective(tenant);
}
result=tenantMapper.updateByPrimaryKeySelective(tenant);
}catch(Exception e){
JshException.writeFail(logger, e);
}
@@ -132,7 +144,9 @@ public class TenantService {
public int deleteTenant(Long id, HttpServletRequest request)throws Exception {
int result=0;
try{
result= tenantMapper.deleteByPrimaryKey(id);
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
result = tenantMapper.deleteByPrimaryKey(id);
}
}catch(Exception e){
JshException.writeFail(logger, e);
}
@@ -146,7 +160,9 @@ public class TenantService {
example.createCriteria().andIdIn(idList);
int result=0;
try{
result= tenantMapper.deleteByExample(example);
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
result = tenantMapper.deleteByExample(example);
}
}catch(Exception e){
JshException.writeFail(logger, e);
}
@@ -179,21 +195,23 @@ public class TenantService {
public int batchSetStatus(Boolean status, String ids)throws Exception {
int result=0;
try{
String statusStr ="";
if(status) {
statusStr ="批量启用";
} else {
statusStr ="批量禁用";
if(BusinessConstants.DEFAULT_MANAGER.equals(userService.getCurrentUser().getLoginName())) {
String statusStr = "";
if (status) {
statusStr = "批量启用";
} else {
statusStr = "批量禁用";
}
logService.insertLog("用户",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ids).append("-").append(statusStr).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
List<Long> idList = StringUtil.strToLongList(ids);
Tenant tenant = new Tenant();
tenant.setEnabled(status);
TenantExample example = new TenantExample();
example.createCriteria().andIdIn(idList);
result = tenantMapper.updateByExampleSelective(tenant, example);
}
logService.insertLog("用户",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ids).append("-").append(statusStr).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
List<Long> idList = StringUtil.strToLongList(ids);
Tenant tenant = new Tenant();
tenant.setEnabled(status);
TenantExample example = new TenantExample();
example.createCriteria().andIdIn(idList);
result = tenantMapper.updateByExampleSelective(tenant, example);
}catch(Exception e){
JshException.writeFail(logger, e);
}