Commit 78a66ed0 authored by xyt's avatar xyt

调整树形参数

parent fadac665
......@@ -19,6 +19,11 @@ import java.util.List;
@AllArgsConstructor
public class Node {
/**
* id
*/
@NotEmpty
private Long id;
/**
* 节点key
*/
@NotEmpty
......
......@@ -22,6 +22,7 @@ dependencies {
implementation project(':common')
implementation project(':platform-manage-service:platform-manage-service-api')
implementation project(':sms-service:sms-service-api')
implementation project(':warehouse-service:warehouse-service-api')
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
......
......@@ -2,7 +2,6 @@ package com.ssy.lingxi.product.common.tree;
import com.ssy.common.constant.treeNode.Node;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;
......@@ -19,7 +18,7 @@ public class TreeUtils {
//建立树形结构
public static List<Node> builTree(List<Node> sourceList, List<Node> rootNodeList){
allNodeList = sourceList;
List<Node> treeList =new ArrayList<Node>();
List<Node> treeList =new ArrayList<>();
for(Node node : rootNodeList) {
node = buildChilTree(node);
treeList.add(node);
......@@ -29,7 +28,7 @@ public class TreeUtils {
//递归,建立子树形结构
private static Node buildChilTree(Node pNode){
List<Node> childrenList = new ArrayList<Node>();
List<Node> childrenList = new ArrayList<>();
for(Node node : allNodeList) {
String[] nodeSplit = node.getKey().split("-");
String[] pNodeSplit = pNode.getKey().split("-");
......
......@@ -2,16 +2,20 @@ package com.ssy.lingxi.product.controller;
import com.ssy.common.model.vo.PageVO;
import com.ssy.common.response.PageData;
import com.ssy.common.response.ResponseCode;
import com.ssy.common.response.Wrapper;
import com.ssy.lingxi.product.entity.Commodity;
import com.ssy.lingxi.product.entity.CommodityCheckRecord;
import com.ssy.lingxi.product.model.request.commodity.CommodityRequest;
import com.ssy.lingxi.product.service.ICommodityService;
import com.ssy.lingxi.warhouse.api.dto.response.ShopResponse;
import com.ssy.lingxi.warhouse.api.feign.ShopControllerFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
/**
* @menu: 商品管理
......@@ -27,6 +31,9 @@ public class CommodityController extends BaseController{
@Autowired
private ICommodityService commodityService;
@Autowired
private ShopControllerFeign shopControllerFeign;
/**
* 查询商品信息--商品能力
* @param id 商品id
......@@ -71,24 +78,29 @@ public class CommodityController extends BaseController{
}
/**
* 启用/停用商品--商品能力
* 提交审核商品--商品能力
* @param id 商品id
* @param isEnable 是否启用
* @return
*/
@RequestMapping(value = "/updateCommodityEnable", method = RequestMethod.GET)
public Wrapper<String> updateCommodityEnable(@RequestParam("id") Long id, @RequestParam("isEnable") Boolean isEnable) {
return Wrapper.success(commodityService.updateCommodityEnable(id, isEnable));
@RequestMapping(value = "/applyCheckCommodity", method = RequestMethod.GET)
public Wrapper<String> applyCheckCommodity(@RequestParam("id") Long id) {
return Wrapper.success(commodityService.applyCheckCommodity(id));
}
/**
* 提交审核商品--商品能力
* @param id 商品id
* 获取上架商城--商品能力
* @return
*/
@RequestMapping(value = "/applyCheckCommodity", method = RequestMethod.GET)
public Wrapper<String> applyCheckCommodity(@RequestParam("id") Long id) {
return Wrapper.success(commodityService.applyCheckCommodity(id));
@RequestMapping(value = "/getShop", method = RequestMethod.GET)
public Wrapper<List<ShopResponse>> getShop() {
Wrapper<List<ShopResponse>> listWrapper = shopControllerFeign.shopAll();
if(ResponseCode.SUCCESS.getCode() == listWrapper.getCode()){
List<ShopResponse> data = listWrapper.getData();
List<ShopResponse> collect = data.stream().filter(shop -> (shop.getType() == 1 || shop.getType() == 3) && shop.getState() == 1 && shop.getEnvironment() == 1).collect(Collectors.toList());
return Wrapper.success(collect);
}else{
return Wrapper.fail("获取上架商城失败");
}
}
/**
......@@ -97,8 +109,8 @@ public class CommodityController extends BaseController{
* @return
*/
@RequestMapping(value = "/publishCommodity", method = RequestMethod.GET)
public Wrapper<String> publishCommodity(@RequestParam("id") Long id) {
return Wrapper.success(commodityService.publishCommodity(id));
public Wrapper<String> publishCommodity(@RequestParam("id") Long id, @RequestParam("shopIdList") List<Integer> shopIdList) {
return Wrapper.success(commodityService.publishCommodity(id, shopIdList));
}
/**
......
......@@ -50,7 +50,7 @@ public class Commodity {
* 货品id列表
*/
@JsonManagedReference
@ManyToMany(cascade=CascadeType.ALL)
@ManyToMany(cascade=CascadeType.PERSIST)
@JoinTable(name="product_commodity_goods",
joinColumns={ @JoinColumn(name="commodity_id", referencedColumnName="id")},
inverseJoinColumns={@JoinColumn(name="goods_id", referencedColumnName="id")})
......@@ -143,4 +143,14 @@ public class Commodity {
*/
@Column(columnDefinition = "varchar(300)", nullable = true)
private String afterService;
// /**
// * 商城id列表
// */
// @JsonManagedReference
// @OneToMany(cascade=CascadeType.PERSIST)
// @JoinTable(name="product_commodity_shop",
// joinColumns={ @JoinColumn(name="commodity_id", referencedColumnName="id")},
// inverseJoinColumns={@JoinColumn(name="shop_id")})
// private List<Integer> shopIdList;
}
package com.ssy.lingxi.product.model.response;
import lombok.Data;
/**
* @description: 商城实体
* @author: jw.chen
* @version: 2.0.0
* @date: 2020/6/28
*/
@Data
public class ShopResponse {
/**
* 商城ID
*/
private Long id;
/**
* 商城名称
*/
private String name;
/**
* 是否已选择
*/
private Boolean state;
}
......@@ -55,14 +55,6 @@ public interface ICommodityService {
String deleteCommodity(Long id);
/**
* 启用/停用
* @param id
* @param isEnable
* @return
*/
String updateCommodityEnable(Long id, Boolean isEnable);
/**
* 提交审核
* @param id
* @return
......@@ -72,9 +64,10 @@ public interface ICommodityService {
/**
* 上架商品--商品能力
* @param id
* @param shopIdList
* @return
*/
String publishCommodity(Long id);
String publishCommodity(Long id, List<Integer> shopIdList);
/**
* 下架商品--商品能力
......
......@@ -19,7 +19,6 @@ import com.ssy.lingxi.product.repository.CommodityRepository;
import com.ssy.lingxi.product.repository.GoodsRepository;
import com.ssy.lingxi.product.repository.customer.CustomerAttributeRepository;
import com.ssy.lingxi.product.repository.platform.AttributeRepository;
import com.ssy.lingxi.product.repository.platform.AttributeValueRepository;
import com.ssy.lingxi.product.service.ICommodityService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -55,9 +54,6 @@ public class CommodityServiceImpl implements ICommodityService {
private CustomerAttributeRepository customerAttributeRepository;
@Autowired
private AttributeValueRepository attributeValueRepository;
@Autowired
private CommodityCheckRecordRepository commodityCheckRecordRepository;
/**
......@@ -197,27 +193,14 @@ public class CommodityServiceImpl implements ICommodityService {
@Override
public String deleteCommodity(Long id) {
//TODO 是否有商品还在使用,如在使用,不能删除
commodityRepository.deleteById(id);
return "删除成功";
}
/**
* 启用/停用
* @param id
* @param isEnable
* @return
*/
@Override
public String updateCommodityEnable(Long id, Boolean isEnable){
//TODO 是否有商品还在使用,如在使用,不能删除
//验证数据库中是否存在该数据
Commodity commodity = commodityRepository.findById(id).orElse(null);
if(commodity != null){
//持久化数据
commodity.setGoodsList(null);
commodityRepository.saveAndFlush(commodity);
return "设置成功";
commodityRepository.deleteById(id);
return "删除成功";
}else{
throw new BusinessException(ResponseCode.PRODUCT_BRAND_NOT_EXIST);
throw new BusinessException(ResponseCode.PRODUCT_COMMODITY_NOT_EXIST);
}
}
......@@ -233,7 +216,7 @@ public class CommodityServiceImpl implements ICommodityService {
if(commodity != null){
Integer current_status = commodity.getStatus();
if(StatusEnum.Not_Submitted.getCode() != current_status){
throw new BusinessException(ResponseCode.PRODUCT_BRAND_STATUS_UNLEGAL);
throw new BusinessException(ResponseCode.PRODUCT_COMMODITY_STATUS_UNLEGAL);
}
String time = DateUtil.formatDateTime(new Date());
Integer new_status = StatusEnum.Not_Check.getCode();
......@@ -252,31 +235,33 @@ public class CommodityServiceImpl implements ICommodityService {
commodityCheckRecordRepository.saveAndFlush(commodityCheckRecord);
return "设置成功";
}else{
throw new BusinessException(ResponseCode.PRODUCT_BRAND_NOT_EXIST);
throw new BusinessException(ResponseCode.PRODUCT_COMMODITY_NOT_EXIST);
}
}
/**
* 发布商品--商品能力
* 上架商品--商品能力
* @param id
* @param shopIdList
* @return
*/
@Override
public String publishCommodity(Long id) {
public String publishCommodity(Long id, List<Integer> shopIdList) {
//验证数据库中是否存在该数据
Commodity commodity = commodityRepository.findById(id).orElse(null);
if(commodity != null){
Integer current_status = commodity.getStatus();
if(StatusEnum.Pass.getCode() != current_status || StatusEnum.Off_Shelf.getCode() != current_status){
throw new BusinessException(ResponseCode.PRODUCT_BRAND_STATUS_UNLEGAL);
if(StatusEnum.Pass.getCode() != current_status && StatusEnum.Off_Shelf.getCode() != current_status){
throw new BusinessException(ResponseCode.PRODUCT_COMMODITY_STATUS_UNLEGAL);
}
Integer new_status = StatusEnum.On_Shelf.getCode();
//持久化数据
commodity.setStatus(new_status);
// commodity.setShopIdList(shopIdList);
commodityRepository.saveAndFlush(commodity);
return "设置成功";
}else{
throw new BusinessException(ResponseCode.PRODUCT_BRAND_NOT_EXIST);
throw new BusinessException(ResponseCode.PRODUCT_COMMODITY_NOT_EXIST);
}
}
......@@ -292,7 +277,7 @@ public class CommodityServiceImpl implements ICommodityService {
if(commodity != null){
Integer current_status = commodity.getStatus();
if(StatusEnum.On_Shelf.getCode() != current_status){
throw new BusinessException(ResponseCode.PRODUCT_BRAND_STATUS_UNLEGAL);
throw new BusinessException(ResponseCode.PRODUCT_COMMODITY_STATUS_UNLEGAL);
}
Integer new_status = StatusEnum.Off_Shelf.getCode();
//持久化数据
......@@ -300,7 +285,7 @@ public class CommodityServiceImpl implements ICommodityService {
commodityRepository.saveAndFlush(commodity);
return "设置成功";
}else{
throw new BusinessException(ResponseCode.PRODUCT_BRAND_NOT_EXIST);
throw new BusinessException(ResponseCode.PRODUCT_COMMODITY_NOT_EXIST);
}
}
......
......@@ -47,8 +47,8 @@ public class CustomerCategoryServiceImpl implements ICustomerCategoryService {
List<CustomerCategory> customerCategoryList = customerCategoryRepository.findAll();
if(!customerCategoryList.isEmpty()){
//组装树结构
List<Node> sourceList = customerCategoryList.stream().map(c -> new Node(c.getKey(), c.getName(), false, new ArrayList<>())).collect(Collectors.toList());
List<Node> resultList = customerCategoryList.stream().filter(c -> c.getLevel() == 1).map(c -> new Node(c.getKey(), c.getName(), false, new ArrayList<>())).collect(Collectors.toList());
List<Node> sourceList = customerCategoryList.stream().map(c -> new Node(c.getId(), c.getKey(), c.getName(), false, new ArrayList<>())).collect(Collectors.toList());
List<Node> resultList = customerCategoryList.stream().filter(c -> c.getLevel() == 1).map(c -> new Node(c.getId(), c.getKey(), c.getName(), false, new ArrayList<>())).collect(Collectors.toList());
return TreeUtils.builTree(sourceList, resultList);
}else{
return new ArrayList<>();
......
......@@ -44,8 +44,8 @@ public class CategoryServiceImpl implements ICategoryService {
List<Category> categoryList = categoryRepository.findAll();
if(!categoryList.isEmpty()){
//组装树结构
List<Node> sourceList = categoryList.stream().map(c -> new Node(c.getKey(), c.getName(), false, new ArrayList<>())).collect(Collectors.toList());
List<Node> resultList = categoryList.stream().filter(c -> c.getLevel() == 1).map(c -> new Node(c.getKey(), c.getName(), false, new ArrayList<>())).collect(Collectors.toList());
List<Node> sourceList = categoryList.stream().map(c -> new Node(c.getId(), c.getKey(), c.getName(), false, new ArrayList<>())).collect(Collectors.toList());
List<Node> resultList = categoryList.stream().filter(c -> c.getLevel() == 1).map(c -> new Node(c.getId(), c.getKey(), c.getName(), false, new ArrayList<>())).collect(Collectors.toList());
return TreeUtils.builTree(sourceList, resultList);
}else{
return new ArrayList<>();
......
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