diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java index 3291b06e..f1843f03 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java @@ -8,9 +8,13 @@ import com.ghy.common.enums.BusinessType; import com.ghy.common.utils.ExceptionUtil; import com.ghy.common.utils.ShiroUtils; import com.ghy.common.utils.StringUtils; +import com.ghy.common.utils.bean.BeanUtils; import com.ghy.common.utils.poi.ExcelUtil; import com.ghy.goods.domain.*; import com.ghy.goods.service.*; +import com.ghy.system.domain.SysArea; +import com.ghy.system.service.ISysAreaService; +import io.swagger.annotations.ApiModel; import org.apache.commons.collections.CollectionUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.stereotype.Controller; @@ -41,6 +45,8 @@ public class GoodsController extends BaseController { private GoodsAreaService goodsAreaService; @Resource private GoodsStandardService goodsStandardService; + @Resource + private ISysAreaService sysAreaService; @RequiresPermissions("goods:goods:view") @GetMapping() @@ -66,6 +72,83 @@ public class GoodsController extends BaseController { return getDataTable(list); } + @PostMapping("/app/detail") + @ResponseBody + public AjaxResult appDetail(@RequestBody Goods goods){ + try { + GoodsEditReq goodsEditReq = new GoodsEditReq(); + List list = goodsService.selectGoodsList(goods); + if(CollectionUtils.isNotEmpty(list)){ + BeanUtils.copyProperties(list.get(0), goodsEditReq); + } + // 补全商品服务区域 + List goodsAreas = goodsAreaService.selectByGoodsId(goodsEditReq.getGoodsId()); + if(CollectionUtils.isNotEmpty(goodsAreas)){ + String areaName; + GoodsArea goodsArea = goodsAreas.get(0); + // 第三级 + SysArea sysArea3 = sysAreaService.selectById(goodsArea.getCountryAreaId()); + // 第二级 + SysArea sysArea2 = sysAreaService.selectByAreaCode(sysArea3.getParentCode()); + // 第一级 + SysArea sysArea1 = sysAreaService.selectByAreaCode(sysArea2.getParentCode()); + areaName = sysArea1.getAreaName() + "-" + sysArea2.getAreaName(); + goodsEditReq.setAreaConcatName(areaName); + goodsEditReq.setParentAreaId(sysArea2.getAreaId()); + } + goodsEditReq.setGoodsAreaList(goodsAreas); + + + // 补全商品规格 + List goodsStandards = goodsStandardService.selectByGoodsId(goodsEditReq.getGoodsId()); + if(CollectionUtils.isNotEmpty(goodsStandards)){ + String standardConcatName; + GoodsStandard goodsStandard = goodsStandards.get(0); + DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.get(goodsStandard.getDeptGoodsCategoryId()); + // 当前层级4 + GoodsCategory goodsCategory4 = goodsCategoryService.selectById(deptGoodsCategory.getGoodsCategoryId()); + GoodsCategory goodsCategory3 = goodsCategoryService.selectById(goodsCategory4.getParentCategoryId()); + GoodsCategory goodsCategory2 = goodsCategoryService.selectById(goodsCategory3.getParentCategoryId()); + GoodsCategory goodsCategory1 = goodsCategoryService.selectById(goodsCategory2.getParentCategoryId()); + standardConcatName = goodsCategory1.getGoodsCategoryName() + "-" + goodsCategory2.getGoodsCategoryName() + "-" + goodsCategory3.getGoodsCategoryName(); + goodsEditReq.setCategoryConcatName(standardConcatName); + } + // + goodsStandards.forEach(goodsStandard -> { + DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.get(goodsStandard.getDeptGoodsCategoryId()); + GoodsCategory category = goodsCategoryService.selectById(deptGoodsCategory.getGoodsCategoryId()); + goodsStandard.setGoodsCategoryName(category.getGoodsCategoryName()); + goodsStandard.setChecked(true); + }); + goodsEditReq.setGoodsStandardList(goodsStandards); + + // 补全商品类目及父级类目信息 + GoodsCategory goodsCategory = goodsCategoryService.selectById(goodsEditReq.getDeptGoodsCategoryId()); + goodsEditReq.setDeptGoodsCategoryName(goodsCategory.getGoodsCategoryName()); + if (goodsCategory.getParentCategoryId() != null) { + GoodsCategory parGoodsCategory = goodsCategoryService.selectById(goodsCategory.getParentCategoryId()); + goodsEditReq.setParGoodsCategoryId(parGoodsCategory.getGoodsCategoryId()); + goodsEditReq.setParGoodsCategoryName(parGoodsCategory.getGoodsCategoryName()); + } + List detailUrl = new ArrayList<>(); + List lbUrl = new ArrayList<>(); + List goodsImgs = goodsImgsService.selectByGoodsId(goods.getGoodsId()); + goodsImgs.forEach(imgs -> { + if(imgs.getImgType() == 0){ + lbUrl.add(imgs.getImgUrl()); + }else if(imgs.getImgType() == 1){ + detailUrl.add(imgs.getImgUrl()); + } + }); + goodsEditReq.setLbUrl(lbUrl); + goodsEditReq.setDetailUrl(detailUrl); + return AjaxResult.success(goodsEditReq); + }catch (Exception e){ + e.printStackTrace(); + return AjaxResult.error(e.getMessage()); + } + } + @PostMapping("/app/list") @ResponseBody public TableDataInfo appList(@RequestBody Goods goods) { diff --git a/ghy-goods/src/main/java/com/ghy/goods/domain/Goods.java b/ghy-goods/src/main/java/com/ghy/goods/domain/Goods.java index 13055b61..44a29976 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/domain/Goods.java +++ b/ghy-goods/src/main/java/com/ghy/goods/domain/Goods.java @@ -5,6 +5,7 @@ import com.ghy.common.core.domain.BaseEntity; import lombok.Data; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -40,6 +41,8 @@ public class Goods extends BaseEntity { private String expectDuration; + private String areaDesc; + @Excel(name = "商品排序", cellType = Excel.ColumnType.NUMERIC) private Integer goodsSort; @@ -80,4 +83,9 @@ public class Goods extends BaseEntity { private List goodsImgsList; private List goodsStandardList; + + private List detailUrl; + + private List lbUrl; + } diff --git a/ghy-goods/src/main/java/com/ghy/goods/domain/GoodsArea.java b/ghy-goods/src/main/java/com/ghy/goods/domain/GoodsArea.java index 16d6354e..f12ae8c6 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/domain/GoodsArea.java +++ b/ghy-goods/src/main/java/com/ghy/goods/domain/GoodsArea.java @@ -21,4 +21,6 @@ public class GoodsArea { private String areaName; + private boolean checked; + } diff --git a/ghy-goods/src/main/java/com/ghy/goods/domain/GoodsEditReq.java b/ghy-goods/src/main/java/com/ghy/goods/domain/GoodsEditReq.java new file mode 100644 index 00000000..9988ca95 --- /dev/null +++ b/ghy-goods/src/main/java/com/ghy/goods/domain/GoodsEditReq.java @@ -0,0 +1,21 @@ +package com.ghy.goods.domain; + +import lombok.Data; + +import java.util.List; + +/** + * @author clunt + */ +@Data +public class GoodsEditReq extends Goods{ + + private String categoryConcatName; + + private List goodsStandards; + + private String areaConcatName; + + private Long parentAreaId; + +} diff --git a/ghy-goods/src/main/java/com/ghy/goods/domain/GoodsStandard.java b/ghy-goods/src/main/java/com/ghy/goods/domain/GoodsStandard.java index d5c703f6..39524824 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/domain/GoodsStandard.java +++ b/ghy-goods/src/main/java/com/ghy/goods/domain/GoodsStandard.java @@ -43,4 +43,8 @@ public class GoodsStandard extends BaseEntity { private BigDecimal finalPrice; + private boolean checked; + + private String goodsCategoryName; + } diff --git a/ghy-goods/src/main/resources/mapper/goods/GoodsMapper.xml b/ghy-goods/src/main/resources/mapper/goods/GoodsMapper.xml index d3201552..19fd68f0 100644 --- a/ghy-goods/src/main/resources/mapper/goods/GoodsMapper.xml +++ b/ghy-goods/src/main/resources/mapper/goods/GoodsMapper.xml @@ -24,16 +24,17 @@ + SELECT goods_id, goods_code, dept_id, goods_name, goods_desc, warranty_period, serv_activity, goods_unit, expect_duration, goods_sort, worker_id, - dept_goods_category_id, goods_img_url, goods_video_url, status, create_by, create_time, remark + dept_goods_category_id, goods_img_url, goods_video_url, status, create_by, create_time, remark, area_desc FROM goods SELECT DISTINCT g.goods_id, goods_code, dept_id, goods_name, goods_desc, goods_sort, worker_id, goods_unit, warranty_period, serv_activity, expect_duration, - dept_goods_category_id, goods_img_url, goods_video_url, status, g.create_by, g.create_time, g.remark + dept_goods_category_id, goods_img_url, goods_video_url, status, g.create_by, g.create_time, g.remark, g.area_desc FROM goods g LEFT JOIN goods_area ga ON g.goods_id = ga.goods_id @@ -53,6 +54,7 @@ serv_activity = #{servActivity}, expect_duration = #{expectDuration}, update_by = #{updateBy}, + area_desc = #{areaDesc}, update_time = sysdate() WHERE goods_id = #{goodsId} @@ -81,6 +83,7 @@ goods_video_url, status, remark, + area_desc, create_by, create_time )values( @@ -99,6 +102,7 @@ #{goodsVideoUrl}, #{status}, #{remark}, + #{areaDesc}, #{createBy}, sysdate() ) @@ -141,6 +145,9 @@ AND worker_id = #{workerId} + + AND g.goods_id = #{goodsId} + /* 默认生成时间排序 */ order by create_time