Commit 7ac03c9e by 何文超

增加权限相关的代码

parent 2278c67d
package com.gic.plug.web.controller.goods;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.contants.SortType;
import com.gic.commons.util.PageHelperUtils;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.goods.api.dto.BrandDTO;
import com.gic.goods.api.dto.GoodsRightsSelectorDTO;
import com.gic.goods.api.service.BrandApiService;
import com.gic.goods.api.service.GoodsRightsSelectorApiService;
import com.gic.goods.api.util.Constant;
import com.gic.plug.web.vo.goods.GoodsBrandVO;
@RestController
......@@ -19,9 +28,30 @@ public class GoodsBrandController {
@Autowired
private BrandApiService brandApiService;
@Autowired
private GoodsRightsSelectorApiService goodsRightsSelectorApiService;
@RequestMapping("/goods-brand-list")
public RestResponse goodsBrandList(int pageSize, int currentPage, String search, Long goodsDomainId) {
ServiceResponse<Page<BrandDTO>> serviceResponse = brandApiService.findBrandPage(currentPage, pageSize, goodsDomainId, search, SortType.sortDescType);
public RestResponse goodsBrandList(int pageSize, int currentPage, String search, Long goodsDomainId, String channelCode) {
// 是否最高权限
List<Long> branIdList = new ArrayList<>();
if (Constant.TEST_GOODS_RIGHTS_SELECTOR_ID != null) {
ServiceResponse<GoodsRightsSelectorDTO> selectorDTOServiceResponse = goodsRightsSelectorApiService.getGoodsRightsSelector(Constant.TEST_GOODS_RIGHTS_SELECTOR_ID);
if (selectorDTOServiceResponse.isSuccess()) {
GoodsRightsSelectorDTO goodsRightsSelectorDTO = selectorDTOServiceResponse.getResult();
if (goodsRightsSelectorDTO != null) {
JSONObject brandRightsObject = JSONObject.parseObject(goodsRightsSelectorDTO.getGoodsRightsBrands());
JSONArray array = brandRightsObject.getJSONArray(channelCode + "_" + goodsDomainId);
if (CollectionUtils.isNotEmpty(array)) {
for (int i = 0; i < array.size(); i++) {
Long brandId = array.getLong(i);
branIdList.add(brandId);
}
}
}
}
}
ServiceResponse<Page<BrandDTO>> serviceResponse = brandApiService.findBrandPage(currentPage, pageSize, goodsDomainId, search, branIdList, SortType.sortDescType);
if (!serviceResponse.isSuccess()) {
return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage());
}
......
......@@ -7,10 +7,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.goods.api.dto.GoodsDomainDTO;
import com.gic.goods.api.dto.GoodsRightsSelectorDTO;
import com.gic.goods.api.service.GoodsDomainApiService;
import com.gic.goods.api.service.GoodsRightsSelectorApiService;
import com.gic.goods.api.util.Constant;
import com.gic.plug.web.vo.goods.GoodsChannelVO;
import com.gic.plug.web.vo.goods.GoodsDomainVO;
......@@ -21,6 +25,9 @@ public class GoodsDomainController {
@Autowired
private GoodsDomainApiService goodsDomainApiService;
@Autowired
private GoodsRightsSelectorApiService goodsRightsSelectorApiService;
/**
* @Title: getAllGoodsDomianListWith
* @Description: 查询企业下所有的域,拼接成channelVO返回
......@@ -31,6 +38,19 @@ public class GoodsDomainController {
@RequestMapping("/get-all-goods-domain-list")
private RestResponse getAllGoodsDomianListWith() {
ServiceResponse<List<GoodsDomainDTO>> serviceResponse = goodsDomainApiService.listAll(Constant.TEST_ENTERPRISE_ID, null);
// 是否最高权限
boolean isHighestRights = true;
JSONObject json = null;
if (Constant.TEST_GOODS_RIGHTS_SELECTOR_ID != null) {
isHighestRights = false;
ServiceResponse<GoodsRightsSelectorDTO> selectorDTOServiceResponse = goodsRightsSelectorApiService.getGoodsRightsSelector(Constant.TEST_GOODS_RIGHTS_SELECTOR_ID);
if (selectorDTOServiceResponse.isSuccess()) {
GoodsRightsSelectorDTO goodsRightsSelectorDTO = selectorDTOServiceResponse.getResult();
if (goodsRightsSelectorDTO != null) {
json = JSONObject.parseObject(goodsRightsSelectorDTO.getGoodsRightsDomains());
}
}
}
if (!serviceResponse.isSuccess()) {
return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage());
}
......@@ -42,8 +62,19 @@ public class GoodsDomainController {
for (GoodsDomainDTO goodsDomainDTO : goodsDomainDTOList) {
if (CollectionUtils.isNotEmpty(goodsDomainDTO.getChannels())){
for (String channelCode : goodsDomainDTO.getChannels()) {
map.putIfAbsent(channelCode, new ArrayList<>());
map.get(channelCode).add(goodsDomainDTO);
if (isHighestRights) { // 最高权限所有都显示
map.putIfAbsent(channelCode, new ArrayList<>());
map.get(channelCode).add(goodsDomainDTO);
} else { //非最高权限按权限下有什么就刷什么来
if (json != null && json.containsKey(channelCode)) {
map.putIfAbsent(channelCode, new ArrayList<>());
JSONArray array = json.getJSONArray(channelCode);
if (CollectionUtils.isNotEmpty(array) && array.contains(goodsDomainDTO.getGoodsDomainId())) {
map.get(channelCode).add(goodsDomainDTO);
}
}
}
}
}
}
......
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