Commit cba67f5a authored by 周健威's avatar 周健威

添加数据权限相关代码

parent 1e124bd8
......@@ -25,5 +25,5 @@ public class CommonConstants {
//数据权限相关
public final static Integer DATA_ALL_TRUE = 1;
public final static Integer DATA_ALL_FALSE = 1;
public final static Integer DATA_ALL_FALSE = 2;
}
......@@ -81,7 +81,7 @@ public class UserBiz extends BaseBiz<UserMapper,User> {
example.createCriteria().andIn("companyId", Arrays.asList(currentUser.getDataCompany().split(",")));
}
if(StringUtils.isNotBlank(currentUser.getDataZone())){
example.createCriteria().andIn("zone", Arrays.asList(currentUser.getDataZone().split(",")));
example.createCriteria().andIn("zoneId", Arrays.asList(currentUser.getDataZone().split(",")));
}
Page<Object> result = PageHelper.startPage(query.getPage(), query.getLimit());
List<User> list = mapper.selectByExample(example);
......
......@@ -6,6 +6,7 @@ import javax.persistence.*;
@Table(name = "base_user")
public class User {
@Id
@GeneratedValue(generator = "JDBC")//此处加上注解
private Integer id;
private String username;
......@@ -36,6 +37,9 @@ public class User {
@Column(name = "zone_id")
private Integer zoneId;
@Column(name = "company_id")
private Integer companyId;
private String description;
@Column(name = "crt_time")
......@@ -249,6 +253,22 @@ public class User {
this.status = status;
}
public Integer getZoneId() {
return zoneId;
}
public void setZoneId(Integer zoneId) {
this.zoneId = zoneId;
}
public Integer getCompanyId() {
return companyId;
}
public void setCompanyId(Integer companyId) {
this.companyId = companyId;
}
/**
* @return description
*/
......
package com.github.wxiaoqi.security.admin.rest;
import com.github.wxiaoqi.security.admin.biz.GroupBiz;
import com.github.wxiaoqi.security.admin.biz.MenuBiz;
import com.github.wxiaoqi.security.admin.biz.UserBiz;
import com.github.wxiaoqi.security.admin.entity.Menu;
......@@ -10,18 +11,23 @@ import com.github.wxiaoqi.security.admin.vo.MenuTree;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
import com.github.wxiaoqi.security.auth.client.jwt.UserAuthUtil;
import com.github.wxiaoqi.security.common.context.BaseContextHandler;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.msg.TableResultResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.util.Query;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import static com.github.wxiaoqi.security.auth.common.constatns.CommonConstants.DATA_ALL_TRUE;
/**
* ${DESCRIPTION}
*
......@@ -31,24 +37,61 @@ import java.util.Map;
@RestController
@RequestMapping("user")
@Slf4j
public class UserController extends BaseController<UserBiz,User> {
public class UserController{
public final static Integer CURRENT_COMPANY = 1;
public final static Integer CURRENT_ZONE = 2;
public final static Integer DATA_ALL = 3;
@Autowired
protected HttpServletRequest request;
@Autowired
private PermissionService permissionService;
@Autowired
private MenuBiz menuBiz;
@Autowired
private GroupBiz groupBiz;
@Autowired
private UserBiz userBiz;
@Autowired
private UserAuthUtil userAuthUtil;
@Autowired
private UserAuthConfig userAuthConfig;
@Override
//内部类
@Data
public static class AddUserDTO extends User {
List<Integer> dataLimit;
List<Integer> members;
}
@RequestMapping(value = "",method = RequestMethod.POST)
@IgnoreClientToken
public ObjectRestResponse<User> add(@RequestBody User entity){
return super.add(entity);
public ObjectRestResponse<User> add(@RequestBody AddUserDTO dto){
if(null != dto.getDataLimit()) {
if(dto.getDataLimit().contains(CURRENT_COMPANY)) {
dto.setDataCompany(dto.getCompanyId().toString());
}
if(dto.getDataLimit().contains(CURRENT_ZONE)) {
dto.setDataZone(dto.getZoneId().toString());
}
if(dto.getDataLimit().contains(DATA_ALL)) {
dto.setDataAll(DATA_ALL_TRUE);
}
}
userBiz.insertSelective(dto);
//添加权限关系
for(Integer groupId : dto.getMembers()) {
groupBiz.modifyGroupUsers(groupId, dto.getId().toString(), null);
}
return new ObjectRestResponse();
}
@RequestMapping(value = "/front/info", method = RequestMethod.GET)
......@@ -74,17 +117,45 @@ public class UserController extends BaseController<UserBiz,User> {
return menuBiz.selectListAll();
}
// @RequestMapping(value = "/page",method = RequestMethod.GET)
// @ResponseBody
// @Override
// public TableResultResponse<User> list(@RequestParam Map<String, Object> params){
// //查询列表数据
// Query query = new Query(params);
// try {
// return baseBiz.selectPage(query, baseBiz.getUserByUsername(userAuthUtil.getInfoFromToken(userAuthConfig.getToken(request)).getUniqueName()));
// }catch (Exception e) {
// log.error(e.getMessage());
// return new TableResultResponse<User>();
// }
// }
@RequestMapping(value = "/page",method = RequestMethod.GET)
@ResponseBody
public TableResultResponse<User> list(@RequestParam Map<String, Object> params){
//查询列表数据
Query query = new Query(params);
try {
return userBiz.selectPage(query, userBiz.getUserByUsername(userAuthUtil.getInfoFromToken(userAuthConfig.getToken(request)).getUniqueName()));
}catch (Exception e) {
log.error(e.getMessage());
return new TableResultResponse<User>();
}
}
@RequestMapping(value = "/{id}",method = RequestMethod.GET)
@ResponseBody
public ObjectRestResponse<User> get(@PathVariable int id){
ObjectRestResponse<User> entityObjectRestResponse = new ObjectRestResponse<>();
User o = userBiz.selectById(id);
entityObjectRestResponse.data(o);
return entityObjectRestResponse;
}
@RequestMapping(value = "/{id}",method = RequestMethod.PUT)
@ResponseBody
public ObjectRestResponse<User> update(@RequestBody User entity){
userBiz.updateSelectiveById(entity);
return new ObjectRestResponse<User>();
}
@RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
@ResponseBody
public ObjectRestResponse<User> remove(@PathVariable int id){
userBiz.deleteById(id);
return new ObjectRestResponse<User>();
}
@RequestMapping(value = "/all",method = RequestMethod.GET)
@ResponseBody
public List<User> all(){
return userBiz.selectListAll();
}
}
......@@ -9,6 +9,7 @@ import com.google.common.collect.Lists;
import com.xinxincaravan.caravan.vehicle.common.RestResponse;
import com.xinxincaravan.caravan.vehicle.constant.RedisKey;
import com.xinxincaravan.caravan.vehicle.entity.BranchCompany;
import com.xinxincaravan.caravan.vehicle.feign.dto.UserDTO;
import com.xinxincaravan.caravan.vehicle.mapper.BranchCompanyMapper;
import com.xinxincaravan.caravan.vehicle.vo.BranchCompanyVo;
import com.xinxincaravan.caravan.vehicle.vo.PageDataVo;
......@@ -34,6 +35,10 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.github.wxiaoqi.security.auth.common.constatns.CommonConstants.DATA_ALL_FALSE;
import static com.xinxincaravan.caravan.vehicle.constant.DbColumnConstant.*;
import static com.xinxincaravan.caravan.vehicle.constant.RedisKey.BRANCH_COMPANY_CACHE_DATAZONE;
@Service
@Slf4j
public class BranchCompanyBiz extends BaseBiz<BranchCompanyMapper, BranchCompany> {
......@@ -79,8 +84,8 @@ public class BranchCompanyBiz extends BaseBiz<BranchCompanyMapper, BranchCompany
return branchCompanyVoList;
}
public PageDataVo<BranchCompany> getAll(Integer page,Integer limit,Integer addrProvince, Integer addrCity,
Integer addrTown){
public PageDataVo<BranchCompany> getAll(Integer page, Integer limit, Integer addrProvince, Integer addrCity,
Integer addrTown, UserDTO userDTO){
Example example = new Example(BranchCompany.class);
Example.Criteria criteria = example.createCriteria();
if(addrProvince!=null) {
......@@ -92,6 +97,14 @@ public class BranchCompanyBiz extends BaseBiz<BranchCompanyMapper, BranchCompany
if(addrTown!=null) {
criteria.andCondition(" addr_town = '" + addrTown + "'");
}
if(DATA_ALL_FALSE.equals(userDTO.getDataAll())) {
if(StringUtils.isNotBlank(userDTO.getDataZone())) {
criteria.andIn(COMPANY_ZONE_ID, userDTO.dataZone2List());
}
if(StringUtils.isNotBlank(userDTO.getDataCompany())) {
criteria.andIn(ID, userDTO.dataCompany2List());
}
}
example.setOrderByClause("`id` asc");
PageHelper.startPage(page,limit);
PageInfo<BranchCompany> branchCompanyPageInfo = new PageInfo<>(mapper.selectByExample(example));
......@@ -108,7 +121,7 @@ public class BranchCompanyBiz extends BaseBiz<BranchCompanyMapper, BranchCompany
* @param branchCompanyVo
* @return
*/
@CacheClear(key= RedisKey.BRANCH_COMPANY_CACHE_ALL)
@CacheClear(key= RedisKey.BRANCH_COMPANY_CACHE)
public Integer add(BranchCompanyVo branchCompanyVo){
BranchCompany branchCompany = new BranchCompany();
BeanUtils.copyProperties(branchCompanyVo,branchCompany);
......@@ -116,7 +129,7 @@ public class BranchCompanyBiz extends BaseBiz<BranchCompanyMapper, BranchCompany
return branchCompany.getId();
}
@CacheClear(key= RedisKey.BRANCH_COMPANY_CACHE_ALL)
@CacheClear(key= RedisKey.BRANCH_COMPANY_CACHE)
public void del(Integer id){
mapper.deleteByPrimaryKey(id);
}
......@@ -126,7 +139,7 @@ public class BranchCompanyBiz extends BaseBiz<BranchCompanyMapper, BranchCompany
* @param branchCompany
* @return
*/
@CacheClear(key= RedisKey.BRANCH_COMPANY_CACHE_ALL)
@CacheClear(key= RedisKey.BRANCH_COMPANY_CACHE)
public Integer update(BranchCompany branchCompany){
return mapper.updateByPrimaryKeySelective(branchCompany);
}
......@@ -154,7 +167,7 @@ public class BranchCompanyBiz extends BaseBiz<BranchCompanyMapper, BranchCompany
return RestResponse.suc(realFileRelPath);
}
@Cache(key="branchCompany:dataCompany{1}")
@Cache(key=BRANCH_COMPANY_CACHE_DATAZONE)
public List<BranchCompany> dataCompany(String dataZone) {
if(StringUtils.isBlank(dataZone)) {
return new ArrayList<BranchCompany>();
......
package com.xinxincaravan.caravan.vehicle.constant;
public class DbColumnConstant {
/**
* 字段
*/
public static final String ID ="id";
public static final String COMPANY_ZONE_ID ="zoneId";
public static final String COMPANY_COMPANY_ID ="companyId";
}
......@@ -36,11 +36,20 @@ public class RedisKey {
*/
public static final String TRANSFER_BOOK_RECORD_LOCK_PREFIX ="lock:bookRecord:transfer";
/**
* 子公司列表缓存key前缀
*/
public static final String BRANCH_COMPANY_CACHE ="cache:brachCompany";
/**
* 子公司列表缓存key前缀
*/
public static final String BRANCH_COMPANY_CACHE_ALL ="cache:bracnCompany:all";
public static final String BRANCH_COMPANY_CACHE_ALL = BRANCH_COMPANY_CACHE + ":all";
/**
* 片区对应的子公司缓存key前缀
*/
public static final String BRANCH_COMPANY_CACHE_DATAZONE = BRANCH_COMPANY_CACHE + ":dataZone{1}";
// 随车物品相关key
......
package com.xinxincaravan.caravan.vehicle.constant;
public class VehicleConstant {
}
package com.xinxincaravan.caravan.vehicle.feign.dto;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Data
public class UserDTO {
......@@ -57,4 +62,20 @@ public class UserDTO {
private String dataCompany;
public List<Integer> dataZone2List() {
return str2List(this.dataZone);
}
public List<Integer> dataCompany2List() {
return str2List(this.dataCompany);
}
private List<Integer> str2List(String str) {
if(StringUtils.isNotBlank(str)) {
return Arrays.asList(str.split(",")).parallelStream().map(s -> Integer.valueOf(s)).collect(Collectors.toList());
}else {
return new ArrayList<Integer>();
}
}
}
\ No newline at end of file
......@@ -47,10 +47,9 @@ public class BranchCompanyController extends BaseController<BranchCompanyBiz> {
@RequestParam(required = false) Integer addrProvince, @RequestParam(required = false) Integer addrCity,
@RequestParam(required = false) Integer addrTown) {
UserDTO userDTO = userFeign.userinfoByToken(userAuthConfig.getToken(request)).getData();
log.info(JSONObject.toJSONString(userDTO));
log.info(JSONObject.toJSONString(vehicleBiz.dataCompany(userDTO.getDataZone(), userDTO.getDataCompany())));
return RestResponse.data(baseBiz.getAll(page,limit,addrProvince, addrCity,
addrTown));
// log.info(JSONObject.toJSONString(userDTO));
// log.info(JSONObject.toJSONString(vehicleBiz.dataCompany(userDTO.getDataZone(), userDTO.getDataCompany())));
return RestResponse.data(baseBiz.getAll(page,limit,addrProvince, addrCity, addrTown, userDTO));
}
@RequestMapping(value ="",method = RequestMethod.GET)
......
......@@ -77,4 +77,9 @@ public class BranchCompanyVo {
*/
private BigDecimal longitude;
/**
* 片区Id
*/
private Integer zoneId;
}
\ 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