Commit 1db9b945 authored by 季圣华's avatar 季圣华
Browse files

给租户增加启用禁用功能

parent a176f417
...@@ -823,6 +823,7 @@ CREATE TABLE `jsh_tenant` ( ...@@ -823,6 +823,7 @@ CREATE TABLE `jsh_tenant` (
`login_name` varchar(255) DEFAULT NULL COMMENT '登录名', `login_name` varchar(255) DEFAULT NULL COMMENT '登录名',
`user_num_limit` int(11) DEFAULT NULL COMMENT '用户数量限制', `user_num_limit` int(11) DEFAULT NULL COMMENT '用户数量限制',
`bills_num_limit` int(11) DEFAULT NULL COMMENT '单据数量限制', `bills_num_limit` int(11) DEFAULT NULL COMMENT '单据数量限制',
`enabled` bit(1) DEFAULT 1 COMMENT '启用 0-禁用 1-启用',
`create_time` datetime DEFAULT NULL COMMENT '创建时间', `create_time` datetime DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 COMMENT='租户'; ) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 COMMENT='租户';
...@@ -830,7 +831,7 @@ CREATE TABLE `jsh_tenant` ( ...@@ -830,7 +831,7 @@ CREATE TABLE `jsh_tenant` (
-- ---------------------------- -- ----------------------------
-- Records of jsh_tenant -- Records of jsh_tenant
-- ---------------------------- -- ----------------------------
INSERT INTO `jsh_tenant` VALUES ('13', '63', 'jsh', '20', '2000', '2021-02-17 23:19:17'); INSERT INTO `jsh_tenant` VALUES ('13', '63', 'jsh', '20', '2000', 1, '2021-02-17 23:19:17');
-- ---------------------------- -- ----------------------------
-- Table structure for jsh_unit -- Table structure for jsh_unit
......
...@@ -1118,4 +1118,11 @@ alter table jsh_account_head add discount_money decimal(24,6) DEFAULT NULL COMME ...@@ -1118,4 +1118,11 @@ alter table jsh_account_head add discount_money decimal(24,6) DEFAULT NULL COMME
-- by jishenghua -- by jishenghua
-- 给商品表增加附件名称字段 -- 给商品表增加附件名称字段
-- -------------------------------------------------------- -- --------------------------------------------------------
alter table jsh_material add img_name varchar(500) DEFAULT NULL COMMENT '图片名称' after remark; alter table jsh_material add img_name varchar(500) DEFAULT NULL COMMENT '图片名称' after remark;
\ No newline at end of file
-- --------------------------------------------------------
-- 时间 2021年7月6日
-- by jishenghua
-- 给租户表增加字段enabled
-- --------------------------------------------------------
alter table jsh_tenant add enabled bit(1) DEFAULT 1 COMMENT '启用 0-禁用 1-启用' after bills_num_limit;
\ No newline at end of file
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.Tenant;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.entities.UserEx;
import com.jsh.erp.datasource.vo.TreeNodeEx;
import com.jsh.erp.exception.BusinessParamCheckingException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.redis.RedisService;
import com.jsh.erp.service.tenant.TenantService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author ji_sheng_hua 华夏erp
*/
@RestController
@RequestMapping(value = "/tenant")
public class TenantController {
private Logger logger = LoggerFactory.getLogger(TenantController.class);
@Resource
private TenantService tenantService;
/**
* 批量设置状态-启用或者禁用
* @param jsonObject
* @param request
* @return
*/
@PostMapping(value = "/batchSetStatus")
public String batchSetStatus(@RequestBody JSONObject jsonObject,
HttpServletRequest request)throws Exception {
Boolean status = jsonObject.getBoolean("status");
String ids = jsonObject.getString("ids");
Map<String, Object> objectMap = new HashMap<>();
int res = tenantService.batchSetStatus(status, ids);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
}
...@@ -107,6 +107,9 @@ public class UserController { ...@@ -107,6 +107,9 @@ public class UserController {
case ExceptionCodeConstants.UserExceptionCode.USER_ACCESS_EXCEPTION: case ExceptionCodeConstants.UserExceptionCode.USER_ACCESS_EXCEPTION:
msgTip = "access service error"; msgTip = "access service error";
break; break;
case ExceptionCodeConstants.UserExceptionCode.BLACK_TENANT:
msgTip = "tenant is black";
break;
case ExceptionCodeConstants.UserExceptionCode.USER_CONDITION_FIT: case ExceptionCodeConstants.UserExceptionCode.USER_CONDITION_FIT:
msgTip = "user can login"; msgTip = "user can login";
//验证通过 ,可以登录,放入session,记录登录日志 //验证通过 ,可以登录,放入session,记录登录日志
......
package com.jsh.erp.datasource.entities; package com.jsh.erp.datasource.entities;
import java.util.Date; import java.util.Date;
public class Tenant { public class Tenant {
/** private Long id;
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.id private Long tenantId;
*
* @mbggenerated private String loginName;
*/
private Long id; private Integer userNumLimit;
/** private Integer billsNumLimit;
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.tenant_id private Boolean enabled;
*
* @mbggenerated private Date createTime;
*/
private Long tenantId; public Long getId() {
return id;
/** }
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.login_name public void setId(Long id) {
* this.id = id;
* @mbggenerated }
*/
private String loginName; public Long getTenantId() {
return tenantId;
/** }
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.user_num_limit public void setTenantId(Long tenantId) {
* this.tenantId = tenantId;
* @mbggenerated }
*/
private Integer userNumLimit; public String getLoginName() {
return loginName;
/** }
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.bills_num_limit public void setLoginName(String loginName) {
* this.loginName = loginName == null ? null : loginName.trim();
* @mbggenerated }
*/
private Integer billsNumLimit; public Integer getUserNumLimit() {
return userNumLimit;
/** }
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.create_time public void setUserNumLimit(Integer userNumLimit) {
* this.userNumLimit = userNumLimit;
* @mbggenerated }
*/
private Date createTime; public Integer getBillsNumLimit() {
return billsNumLimit;
/** }
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.id public void setBillsNumLimit(Integer billsNumLimit) {
* this.billsNumLimit = billsNumLimit;
* @return the value of jsh_tenant.id }
*
* @mbggenerated public Boolean getEnabled() {
*/ return enabled;
public Long getId() { }
return id;
} public void setEnabled(Boolean enabled) {
this.enabled = enabled;
/** }
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.id public Date getCreateTime() {
* return createTime;
* @param id the value for jsh_tenant.id }
*
* @mbggenerated public void setCreateTime(Date createTime) {
*/ this.createTime = createTime;
public void setId(Long id) { }
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.tenant_id
*
* @return the value of jsh_tenant.tenant_id
*
* @mbggenerated
*/
public Long getTenantId() {
return tenantId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.tenant_id
*
* @param tenantId the value for jsh_tenant.tenant_id
*
* @mbggenerated
*/
public void setTenantId(Long tenantId) {
this.tenantId = tenantId;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.login_name
*
* @return the value of jsh_tenant.login_name
*
* @mbggenerated
*/
public String getLoginName() {
return loginName;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.login_name
*
* @param loginName the value for jsh_tenant.login_name
*
* @mbggenerated
*/
public void setLoginName(String loginName) {
this.loginName = loginName == null ? null : loginName.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.user_num_limit
*
* @return the value of jsh_tenant.user_num_limit
*
* @mbggenerated
*/
public Integer getUserNumLimit() {
return userNumLimit;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.user_num_limit
*
* @param userNumLimit the value for jsh_tenant.user_num_limit
*
* @mbggenerated
*/
public void setUserNumLimit(Integer userNumLimit) {
this.userNumLimit = userNumLimit;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.bills_num_limit
*
* @return the value of jsh_tenant.bills_num_limit
*
* @mbggenerated
*/
public Integer getBillsNumLimit() {
return billsNumLimit;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.bills_num_limit
*
* @param billsNumLimit the value for jsh_tenant.bills_num_limit
*
* @mbggenerated
*/
public void setBillsNumLimit(Integer billsNumLimit) {
this.billsNumLimit = billsNumLimit;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.create_time
*
* @return the value of jsh_tenant.create_time
*
* @mbggenerated
*/
public Date getCreateTime() {
return createTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.create_time
*
* @param createTime the value for jsh_tenant.create_time
*
* @mbggenerated
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
} }
\ No newline at end of file
package com.jsh.erp.datasource.mappers; package com.jsh.erp.datasource.mappers;
import com.jsh.erp.datasource.entities.Tenant; import com.jsh.erp.datasource.entities.Tenant;
import com.jsh.erp.datasource.entities.TenantExample; import com.jsh.erp.datasource.entities.TenantExample;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
public interface TenantMapper { public interface TenantMapper {
/** long countByExample(TenantExample example);
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant int deleteByExample(TenantExample example);
*
* @mbggenerated int deleteByPrimaryKey(Long id);
*/
int countByExample(TenantExample example); int insert(Tenant record);
/** int insertSelective(Tenant record);
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant List<Tenant> selectByExample(TenantExample example);
*
* @mbggenerated Tenant selectByPrimaryKey(Long id);
*/
int deleteByExample(TenantExample example); int updateByExampleSelective(@Param("record") Tenant record, @Param("example") TenantExample example);
/** int updateByExample(@Param("record") Tenant record, @Param("example") TenantExample example);
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant int updateByPrimaryKeySelective(Tenant record);
*
* @mbggenerated int updateByPrimaryKey(Tenant record);
*/
int deleteByPrimaryKey(Long id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int insert(Tenant record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int insertSelective(Tenant record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
List<Tenant> selectByExample(TenantExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
Tenant selectByPrimaryKey(Long id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int updateByExampleSelective(@Param("record") Tenant record, @Param("example") TenantExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int updateByExample(@Param("record") Tenant record, @Param("example") TenantExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int updateByPrimaryKeySelective(Tenant record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int updateByPrimaryKey(Tenant record);
} }
\ No newline at end of file
...@@ -264,17 +264,22 @@ public class DepotHeadService { ...@@ -264,17 +264,22 @@ public class DepotHeadService {
} }
} }
} }
/**删除单据子表数据*/ //对于零售出库单据,更新会员的预收款信息
try { if (BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())
depotItemMapperEx.batchDeleteDepotItemByDepotHeadIds(new Long[]{id}); && BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubType())){
//更新当前库存 if(BusinessConstants.PAY_TYPE_PREPAID.equals(depotHead.getPayType())) {
List<DepotItem> list = depotItemService.getListByHeaderId(id); if (depotHead.getOrganId() != null) {
for (DepotItem depotItem : list) { supplierService.updateAdvanceIn(depotHead.getOrganId(), depotHead.getTotalPrice().abs());
Long tenantId = redisService.getTenantId(request); }
depotItemService.updateCurrentStock(depotItem, tenantId);
} }
} catch (Exception e) { }
JshException.writeFail(logger, e); /**删除单据子表数据*/
depotItemMapperEx.batchDeleteDepotItemByDepotHeadIds(new Long[]{id});
//更新当前库存
List<DepotItem> list = depotItemService.getListByHeaderId(id);
for (DepotItem depotItem : list) {
Long tenantId = redisService.getTenantId(request);
depotItemService.updateCurrentStock(depotItem, tenantId);
} }
/**删除单据主表信息*/ /**删除单据主表信息*/
batchDeleteDepotHeadByIds(id.toString()); batchDeleteDepotHeadByIds(id.toString());
......
...@@ -8,6 +8,7 @@ import com.jsh.erp.datasource.mappers.TenantMapper; ...@@ -8,6 +8,7 @@ import com.jsh.erp.datasource.mappers.TenantMapper;
import com.jsh.erp.datasource.mappers.TenantMapperEx; import com.jsh.erp.datasource.mappers.TenantMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException; import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException; import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.utils.StringUtil; import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools; import com.jsh.erp.utils.Tools;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -15,6 +16,8 @@ import org.slf4j.LoggerFactory; ...@@ -15,6 +16,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -30,6 +33,9 @@ public class TenantService { ...@@ -30,6 +33,9 @@ public class TenantService {
@Resource @Resource
private TenantMapperEx tenantMapperEx; private TenantMapperEx tenantMapperEx;
@Resource
private LogService logService;
@Value("${tenant.userNumLimit}") @Value("${tenant.userNumLimit}")
private Integer userNumLimit; private Integer userNumLimit;
...@@ -161,4 +167,28 @@ public class TenantService { ...@@ -161,4 +167,28 @@ public class TenantService {
} }
return tenant; return tenant;
} }
public int batchSetStatus(Boolean status, String ids)throws Exception {
int result=0;
try{
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);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
} }
...@@ -295,6 +295,11 @@ public class UserService { ...@@ -295,6 +295,11 @@ public class UserService {
if(list.get(0).getStatus()!=0) { if(list.get(0).getStatus()!=0) {
return ExceptionCodeConstants.UserExceptionCode.BLACK_USER; return ExceptionCodeConstants.UserExceptionCode.BLACK_USER;
} }
Long tenantId = list.get(0).getTenantId();
Tenant tenant = tenantService.getTenantByTenantId(tenantId);
if(tenant!=null && tenant.getEnabled()!=null && !tenant.getEnabled()) {
return ExceptionCodeConstants.UserExceptionCode.BLACK_TENANT;
}
} }
} catch (Exception e) { } catch (Exception e) {
logger.error(">>>>>>>>访问验证用户姓名是否存在后台信息异常", e); logger.error(">>>>>>>>访问验证用户姓名是否存在后台信息异常", e);
......
...@@ -16,7 +16,7 @@ public interface ExceptionCodeConstants { ...@@ -16,7 +16,7 @@ public interface ExceptionCodeConstants {
public static final int USER_PASSWORD_ERROR = 2; public static final int USER_PASSWORD_ERROR = 2;
/** /**
* 被加入黑名单 * 用户被加入黑名单
*/ */
public static final int BLACK_USER = 3; public static final int BLACK_USER = 3;
...@@ -29,5 +29,10 @@ public interface ExceptionCodeConstants { ...@@ -29,5 +29,10 @@ public interface ExceptionCodeConstants {
* 访问数据库异常 * 访问数据库异常
*/ */
public static final int USER_ACCESS_EXCEPTION = 5; public static final int USER_ACCESS_EXCEPTION = 5;
/**
* 租户被加入黑名单
*/
public static final int BLACK_TENANT = 6;
} }
} }
Supports Markdown
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