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

添加数据权限相关代码

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