dev
袁野 6 months ago
parent 0467919a1a
commit a29275ef9a
  1. 130
      bweb/src/main/java/com/bweb/controller/goods/GoodsBrandController.java
  2. 26
      bweb/src/main/java/com/bweb/controller/goods/GoodsTypeController.java
  3. 1
      service/src/main/java/com/hfkj/common/exception/ErrorCode.java
  4. 2
      service/src/main/java/com/hfkj/model/GoodsTypeModel.java
  5. 77
      service/src/main/java/com/hfkj/service/goods/GoodsBrandService.java
  6. 48
      service/src/main/java/com/hfkj/service/goods/impl/GoodsBrandServiceImpl.java
  7. 57
      service/src/main/java/com/hfkj/service/goods/impl/GoodsTypeServiceImpl.java

@ -0,0 +1,130 @@
package com.bweb.controller.goods;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.SessionObject;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.GoodsBrand;
import com.hfkj.model.GoodsBrandModel;
import com.hfkj.model.ResponseData;
import com.hfkj.model.SecUserSessionObject;
import com.hfkj.service.goods.GoodsBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value="/goodsBrand")
@Api(value="商品品牌")
public class GoodsBrandController {
private static final Logger log = LoggerFactory.getLogger(GoodsBrandController.class);
@Resource
private GoodsBrandService goodsBrandService;
@Resource
private UserCenter userCenter;
@RequestMapping(value="/editGoodsBrand",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "编辑商品类型")
public ResponseData editGoodsBrand(@RequestBody GoodsBrand body, HttpServletRequest request) {
SessionObject sessionObject = userCenter.getSessionObject(request);
SecUserSessionObject userModel = (SecUserSessionObject) sessionObject.getObject();
if (body == null
|| body.getImgUrl() == null
|| StringUtils.isBlank(body.getTitle())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
GoodsBrand GoodsBrand;
if (body.getId() != null) {
// 查询商品类型
GoodsBrand = goodsBrandService.queryDetail(body.getId());
if (GoodsBrand == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
} else {
GoodsBrand = new GoodsBrand();
GoodsBrand.setCreateTime(new Date());
}
GoodsBrand.setUpdateTime(new Date());
GoodsBrand.setStatus(1);
GoodsBrand.setTitle(body.getTitle());
GoodsBrand.setParentId(body.getParentId());
GoodsBrand.setBusinessType(body.getBusinessType());
GoodsBrand.setImgUrl(body.getImgUrl());
GoodsBrand.setOpId(userModel.getAccount().getId());
GoodsBrand.setOpName(userModel.getAccount().getUserName());
if (body.getId() != null) {
GoodsBrandService.update(GoodsBrand);
} else {
GoodsBrandService.create(GoodsBrand);
}
return ResponseMsgUtil.success("操作成功");
}
@RequestMapping(value="/getList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询列表")
public ResponseData getList() {
try {
List<GoodsBrand> list = GoodsBrandService.getList(new HashMap<>());
List<GoodsBrandModel> GoodsBrandModels = GoodsBrandService.getGoodsBrandModelList(list);
return ResponseMsgUtil.success(GoodsBrandModels);
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/delete",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "删除")
public ResponseData delete(@RequestParam(value = "id" , required = false) Long id) {
try {
Map<String , Object> map = new HashMap<>();
map.put("parentId" , id);
List<GoodsBrand> list = GoodsBrandService.getList(map);
if (!list.isEmpty()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "存在下级分类,不可删除!");
}
GoodsBrandService.delete(id , false);
return ResponseMsgUtil.success("删除成功");
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -9,6 +9,7 @@ import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.GoodsType;
import com.hfkj.entity.SecMenu;
import com.hfkj.model.GoodsTypeModel;
import com.hfkj.model.ResponseData;
import com.hfkj.model.SecUserSessionObject;
import com.hfkj.service.goods.GoodsTypeService;
@ -22,16 +23,14 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Controller
@RequestMapping(value="/goodsType")
@Api(value="商品类型")
public class GoodsTypeController {
private static final Logger log = LoggerFactory.getLogger(FileUploadController.class);
private static final Logger log = LoggerFactory.getLogger(GoodsTypeController.class);
@Resource
private GoodsTypeService goodsTypeService;
@ -90,12 +89,13 @@ public class GoodsTypeController {
public ResponseData getList() {
try {
Map<String , Object> map = new HashMap<>();
map.put("parentId" , null);
List<GoodsType> list = goodsTypeService.getList(map);
List<GoodsType> list = goodsTypeService.getList(new HashMap<>());
List<GoodsTypeModel> goodsTypeModels = goodsTypeService.getGoodsTypeModelList(list);
return ResponseMsgUtil.success(goodsTypeService.getGoodsTypeModelList(list));
return ResponseMsgUtil.success(goodsTypeModels);
} catch (Exception e) {
log.error("error!",e);
@ -109,6 +109,14 @@ public class GoodsTypeController {
public ResponseData delete(@RequestParam(value = "id" , required = false) Long id) {
try {
Map<String , Object> map = new HashMap<>();
map.put("parentId" , id);
List<GoodsType> list = goodsTypeService.getList(map);
if (!list.isEmpty()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "存在下级分类,不可删除!");
}
goodsTypeService.delete(id , false);
return ResponseMsgUtil.success("删除成功");

@ -24,6 +24,7 @@ public enum ErrorCode {
//////////////////业务异常/////////////
COMMON_ERROR("2000",""),
REQ_PARAMS_ERROR("2001","请求参数校验失败"),
CONTENT_ERROR("2001","请求参数校验失败"),
ACCOUNT_LOGIN_EXPIRE("2002","登录账户已过期"),
ACCOUNT_LOGIN_NOT("2003","账户未登录"),

@ -11,5 +11,5 @@ import java.util.List;
@Data
public class GoodsTypeModel extends GoodsType {
List<GoodsType> children;
List<GoodsTypeModel> children;
}

@ -0,0 +1,77 @@
package com.hfkj.service.goods;
import com.hfkj.entity.GoodsBrand;
import java.util.List;
import java.util.Map;
/**
* @serviceName GoodsBrandService.java
* @author Sum1Dream
* @version 1.0.0
* @Description // 商品品牌管理
* @createTime 15:07 2024/4/19
**/
public interface GoodsBrandService {
/**
* @Author Sum1Dream
* @Name create
* @Description // 创建
* @Date 15:11 2024/4/19
* @Param GoodsBrand
* @return void
*/
void create(GoodsBrand GoodsBrand);
/**
* @Author Sum1Dream
* @Name update
* @Description // 修改
* @Date 15:12 2024/4/19
* @Param GoodsBrand
* @return void
*/
void update(GoodsBrand GoodsBrand);
/**
* @Author Sum1Dream
* @Name delete
* @Description // 修改
* @Date 15:12 2024/4/19
* @Param id
* @return void
*/
void delete(Long id , Boolean fullDelete);
/**
* @Author Sum1Dream
* @Name queryDetail
* @Description // 根据ID查询产品类型详情
* @Date 15:12 2024/4/19
* @Param id
* @return com.hfkj.entity.GoodsBrand
*/
GoodsBrand queryDetail(Long id);
/**
* @Author Sum1Dream
* @Name queryDetailByMap
* @Description // 根据多条件查询产品类型
* @Date 15:12 2024/4/19
* @Param map
* @return com.hfkj.entity.GoodsBrand
*/
GoodsBrand queryDetailByMap(Map<String , Object> map);
/**
* @Author Sum1Dream
* @Name getList
* @Description // 根据多条件查询列表
* @Date 15:13 2024/4/19
* @Param map
* @return java.util.List<com.hfkj.entity.GoodsBrand>
*/
List<GoodsBrand> getList(Map<String , Object> map);
}

@ -0,0 +1,48 @@
package com.hfkj.service.goods.impl;
import com.hfkj.dao.GoodsBrandMapper;
import com.hfkj.entity.GoodsBrand;
import com.hfkj.service.goods.GoodsBrandService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@Service("goodsBrandService")
public class GoodsBrandServiceImpl implements GoodsBrandService {
@Resource
private GoodsBrandMapper goodsBrandMapper;
@Override
public void create(GoodsBrand GoodsBrand) {
goodsBrandMapper.insert(GoodsBrand);
}
@Override
public void update(GoodsBrand GoodsBrand) {
goodsBrandMapper.updateByPrimaryKeySelective(GoodsBrand);
}
@Override
public void delete(Long id, Boolean fullDelete) {
}
@Override
public GoodsBrand queryDetail(Long id) {
return goodsBrandMapper.selectByPrimaryKey(id);
}
@Override
public GoodsBrand queryDetailByMap(Map<String, Object> map) {
return null;
}
@Override
public List<GoodsBrand> getList(Map<String, Object> map) {
return Collections.emptyList();
}
}

@ -3,7 +3,9 @@ package com.hfkj.service.goods.impl;
import com.hfkj.dao.GoodsTypeMapper;
import com.hfkj.entity.GoodsType;
import com.hfkj.entity.GoodsTypeExample;
import com.hfkj.entity.SecMenu;
import com.hfkj.model.GoodsTypeModel;
import com.hfkj.model.MenuTreeModel;
import com.hfkj.service.goods.GoodsTypeService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.BeanUtils;
@ -11,6 +13,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@Service("goodsTypeService")
public class GoodsTypeServiceImpl implements GoodsTypeService {
@ -54,9 +57,11 @@ public class GoodsTypeServiceImpl implements GoodsTypeService {
if (MapUtils.getLong(map, "parentId") != null) {
criteria.andParentIdEqualTo(MapUtils.getLong(map, "parentId"));
}
if (MapUtils.getString(map, "title") != null) {
criteria.andTitleEqualTo(MapUtils.getString(map, "title"));
}
if (MapUtils.getInteger(map, "businessType") != null) {
criteria.andBusinessTypeEqualTo(MapUtils.getInteger(map, "businessType"));
}
@ -78,8 +83,6 @@ public class GoodsTypeServiceImpl implements GoodsTypeService {
if (MapUtils.getLong(map, "parentId") != null) {
criteria.andParentIdEqualTo(MapUtils.getLong(map, "parentId"));
} else {
criteria.andParentIdIsNull();
}
if (MapUtils.getString(map, "title") != null) {
criteria.andTitleEqualTo(MapUtils.getString(map, "title"));
@ -94,26 +97,52 @@ public class GoodsTypeServiceImpl implements GoodsTypeService {
@Override
public List<GoodsTypeModel> getGoodsTypeModelList(List<GoodsType> list) {
Map<String , Object> map = new HashMap<>();
List<GoodsTypeModel> goodsTypeModels = new ArrayList<>();
GoodsTypeModel goodsTypeModel;
for (GoodsType goodsType : list) {
GoodsTypeModel goodsTypeModel = new GoodsTypeModel();
BeanUtils.copyProperties(goodsType, goodsTypeModel);
map.clear();
map.put("parentId" , goodsType.getId());
List<GoodsType> goodsTypes = getList(map);
// 获取最顶层菜单
List<GoodsType> goodsTypeList = list.stream()
.filter(o -> o.getParentId() == null)
.collect(Collectors.toList());
if (goodsTypes != null) {
goodsTypeModel.setChildren(goodsTypes);
getGoodsTypeModelList(goodsTypes);
}
for (GoodsType goodsType : goodsTypeList) {
goodsTypeModel = new GoodsTypeModel();
BeanUtils.copyProperties(goodsType, goodsTypeModel);
// 获取下级菜单
goodsTypeModel.setChildren(recursionGoodsType(list , goodsType.getId()));
goodsTypeModels.add(goodsTypeModel);
}
return goodsTypeModels;
}
/**
* 递归获取菜单
* @param dataSource 数据源
* @param parentId 父级菜单id
* @return
*/
public List<GoodsTypeModel> recursionGoodsType(List<GoodsType> dataSource, Long parentId){
List<GoodsTypeModel> goodsTypeModels = new ArrayList<>();
GoodsTypeModel goodsTypeModel;
// 获取最顶层菜单
List<GoodsType> goodsTypeList = dataSource.stream()
.filter(o -> Objects.equals(o.getParentId(), parentId))
.collect(Collectors.toList());
for (GoodsType goodsType : goodsTypeList) {
goodsTypeModel = new GoodsTypeModel();
BeanUtils.copyProperties(goodsType, goodsTypeModel);
// 获取下级菜单
goodsTypeModel.setChildren(recursionGoodsType(dataSource , goodsType.getId()));
if (goodsTypeModel.getChildren().isEmpty()){
goodsTypeModel.setChildren(null);
}
goodsTypeModels.add(goodsTypeModel);
}
return goodsTypeModels;
}
}

Loading…
Cancel
Save