diff --git a/src/main/java/com/gxwebsoft/cms/controller/MpController.java b/src/main/java/com/gxwebsoft/cms/controller/MpController.java index 06ac3c5..41c6fe1 100644 --- a/src/main/java/com/gxwebsoft/cms/controller/MpController.java +++ b/src/main/java/com/gxwebsoft/cms/controller/MpController.java @@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.gxwebsoft.cms.entity.*; import com.gxwebsoft.cms.param.MpParam; import com.gxwebsoft.cms.service.*; +import com.gxwebsoft.common.core.utils.JSONUtil; import com.gxwebsoft.common.core.utils.RedisUtil; import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.BaseController; @@ -67,7 +68,9 @@ public class MpController extends BaseController { } // 从缓存读取信息 if (StrUtil.isNotBlank(mpInfo)) { -// return success(JSONObject.parseObject(siteInfo,Website.class)); + final Object object = JSONUtil.parseObject(mpInfo, Object.class); + System.out.println("object = " + object); + return success(object); } // 获取小程序信息 diff --git a/src/main/java/com/gxwebsoft/cms/entity/MpPages.java b/src/main/java/com/gxwebsoft/cms/entity/MpPages.java index 794d97c..5aead59 100644 --- a/src/main/java/com/gxwebsoft/cms/entity/MpPages.java +++ b/src/main/java/com/gxwebsoft/cms/entity/MpPages.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.*; import java.time.LocalDateTime; import java.io.Serializable; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -84,4 +85,8 @@ public class MpPages implements Serializable { @TableField(exist = false) private List ads; + @ApiModelProperty(value = "页面参数") + @TableField(exist = false) + private HashMap config; + } diff --git a/src/main/java/com/gxwebsoft/cms/service/impl/MpPagesServiceImpl.java b/src/main/java/com/gxwebsoft/cms/service/impl/MpPagesServiceImpl.java index 178eada..5890497 100644 --- a/src/main/java/com/gxwebsoft/cms/service/impl/MpPagesServiceImpl.java +++ b/src/main/java/com/gxwebsoft/cms/service/impl/MpPagesServiceImpl.java @@ -1,11 +1,14 @@ package com.gxwebsoft.cms.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gxwebsoft.cms.entity.MpAd; +import com.gxwebsoft.cms.entity.MpField; import com.gxwebsoft.cms.entity.MpMenu; import com.gxwebsoft.cms.mapper.MpPagesMapper; import com.gxwebsoft.cms.service.MpAdService; +import com.gxwebsoft.cms.service.MpFieldService; import com.gxwebsoft.cms.service.MpMenuService; import com.gxwebsoft.cms.service.MpPagesService; import com.gxwebsoft.cms.entity.MpPages; @@ -16,6 +19,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -32,21 +36,31 @@ public class MpPagesServiceImpl extends ServiceImpl impl private MpMenuService mpMenuService; @Resource private MpAdService mpAdService; + @Resource + private MpFieldService mpFieldService; @Override public PageResult pageRel(MpPagesParam param) { PageParam page = new PageParam<>(param); page.setDefaultOrder("sort_number asc, create_time asc"); List list = baseMapper.selectPageRel(page, param); - System.out.println("param = " + param); + System.out.println("param = " + param); System.out.println("list2 = " + list); if (!CollectionUtils.isEmpty(list) && param.getSceneType() != null && param.getSceneType().equals("showMpMenus")) { - final List mpMenus = mpMenuService.list(new LambdaUpdateWrapper().eq(MpMenu::getPageId, list.get(0).getId())); + final Integer pageId = list.get(0).getId(); + final List mpMenus = mpMenuService.list(new LambdaUpdateWrapper().eq(MpMenu::getPageId, pageId)); final Map> collect = mpMenus.stream().collect(Collectors.groupingBy(MpMenu::getParentId)); - final List ads = mpAdService.list(new LambdaUpdateWrapper().eq(MpAd::getPageId, list.get(0).getId())); + final List ads = mpAdService.list(new LambdaUpdateWrapper().eq(MpAd::getPageId, pageId).eq(MpAd::getStatus,0)); + final List mpFields = mpFieldService.list(new LambdaQueryWrapper().eq(MpField::getPageId, pageId)); + // 配置信息 + HashMap fields = new HashMap<>(); + mpFields.forEach(d -> { + fields.put(d.getName(), d.getValue()); + }); list.forEach(d -> { d.setMpMenus(collect); d.setAds(ads); + d.setConfig(fields); }); } return new PageResult<>(list, page.getTotal()); diff --git a/src/main/java/com/gxwebsoft/shop/controller/DealerApplyController.java b/src/main/java/com/gxwebsoft/shop/controller/DealerApplyController.java index b2bbd4b..d531450 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/DealerApplyController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/DealerApplyController.java @@ -2,6 +2,7 @@ package com.gxwebsoft.shop.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.gxwebsoft.common.core.web.BaseController; +import com.gxwebsoft.shop.entity.DealerReferee; import com.gxwebsoft.shop.entity.DealerUser; import com.gxwebsoft.shop.service.DealerApplyService; import com.gxwebsoft.shop.entity.DealerApply; @@ -12,10 +13,12 @@ import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.BatchParam; import com.gxwebsoft.common.core.annotation.OperationLog; import com.gxwebsoft.common.system.entity.User; +import com.gxwebsoft.shop.service.DealerRefereeService; import com.gxwebsoft.shop.service.DealerUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -35,6 +38,8 @@ public class DealerApplyController extends BaseController { private DealerApplyService dealerApplyService; @Resource private DealerUserService dealerUserService; + @Resource + private DealerRefereeService dealerRefereeService; @ApiOperation("分页查询分销商申请记录表") @GetMapping("/page") @@ -57,6 +62,7 @@ public class DealerApplyController extends BaseController { return success(dealerApplyService.getByIdRel(id)); } + @Transactional(rollbackFor = {Exception.class}) @ApiOperation("添加分销商申请记录表") @PostMapping() public ApiResult save(@RequestBody DealerApply dealerApply) { @@ -70,14 +76,24 @@ public class DealerApplyController extends BaseController { dealerUser.setMobile(loginUser.getPhone()); dealerUser.setTenantId(loginUser.getTenantId()); } - if (dealerUserService.count(new LambdaQueryWrapper().eq(DealerUser::getUserId,refereeId)) == 0) { + final int count = dealerUserService.count(new LambdaQueryWrapper().eq(DealerUser::getUserId, refereeId)); + System.out.println("count = " + count); + if (dealerUserService.count(new LambdaQueryWrapper().eq(DealerUser::getUserId,refereeId)) == 0) { return fail("邀请人ID不存在"); } if (dealerApplyService.save(dealerApply)) { + // 加入正式分销商 dealerUser.setRealName(dealerApply.getRealName()); dealerUser.setRefereeId(dealerApply.getRefereeId()); - System.out.println("dealerUser = " + dealerUser); dealerUserService.save(dealerUser); + // 添加关系 + final DealerReferee referee = new DealerReferee(); + referee.setDealerId(refereeId); + referee.setUserId(dealerUser.getUserId()); + referee.setLevel(1); + referee.setTenantId(dealerApply.getTenantId()); + dealerRefereeService.save(referee); + return success("添加成功"); } return fail("添加失败"); diff --git a/src/main/java/com/gxwebsoft/shop/controller/DealerUserController.java b/src/main/java/com/gxwebsoft/shop/controller/DealerUserController.java index eeac55f..c963188 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/DealerUserController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/DealerUserController.java @@ -1,114 +1,192 @@ package com.gxwebsoft.shop.controller; +import cn.hutool.core.io.FileUtil; +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.gxwebsoft.common.core.config.ConfigProperties; +import com.gxwebsoft.common.core.utils.RedisUtil; +import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.BaseController; -import com.gxwebsoft.shop.service.DealerUserService; +import com.gxwebsoft.common.core.web.BatchParam; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.shop.entity.DealerUser; import com.gxwebsoft.shop.param.DealerUserParam; -import com.gxwebsoft.common.core.web.ApiResult; -import com.gxwebsoft.common.core.web.PageResult; -import com.gxwebsoft.common.core.web.PageParam; -import com.gxwebsoft.common.core.web.BatchParam; -import com.gxwebsoft.common.core.annotation.OperationLog; -import com.gxwebsoft.common.system.entity.User; +import com.gxwebsoft.shop.service.DealerUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.io.File; +import java.util.HashMap; import java.util.List; +import static com.gxwebsoft.common.core.constants.RedisConstants.ACCESS_TOKEN_KEY; + /** * 分销商用户记录表控制器 * * @author 科技小王子 - * @since 2024-07-28 11:57:41 + * @since 2024-07-28 19:21:15 */ @Api(tags = "分销商用户记录表管理") @RestController @RequestMapping("/api/shop/dealer-user") public class DealerUserController extends BaseController { - @Resource - private DealerUserService dealerUserService; + @Resource + private DealerUserService dealerUserService; + @Resource + private RedisUtil redisUtil; + @Resource + private ConfigProperties config; - @ApiOperation("分页查询分销商用户记录表") - @GetMapping("/page") - public ApiResult> page(DealerUserParam param) { - // 使用关联查询 - return success(dealerUserService.pageRel(param)); + + @ApiOperation("生成专属二维码") + @GetMapping("/getDealerUserQrcode") + public ApiResult getDealerUserQrcode() { + final Integer loginUserId = getLoginUserId(); + if(loginUserId == null){ + return fail("请先登录"); } - @ApiOperation("查询全部分销商用户记录表") - @GetMapping() - public ApiResult> list(DealerUserParam param) { - // 使用关联查询 - return success(dealerUserService.listRel(param)); + final DealerUser dealerUser = dealerUserService.getOne(new LambdaQueryWrapper().eq(DealerUser::getUserId, loginUserId).last("limit 1")); + + // 生成小程序码 + String apiUrl = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + getAccessToken(); + final HashMap map = new HashMap<>(); + map.put("path", "package/dealer/invite?id=" + loginUserId); + map.put("env_version", "trial"); // 正式版为"release",体验版为"trial",开发版为"develop" + + // 获取图片 Buffer + byte[] qrCode = HttpRequest.post(apiUrl) + .body(JSON.toJSONString(map)) + .execute().bodyBytes(); + + // 保存的文件名称 + final String fileName = loginUserId.toString().concat(".png"); + // 保存路径 + String filePath = getUploadDir().concat("user-code/") + fileName; + File file = FileUtil.writeBytes(qrCode, filePath); + + if (file != null) { + final String qrcode = config.getFileServer().concat("/user-code/").concat(fileName); + dealerUser.setQrcode(qrcode); + dealerUserService.updateById(dealerUser); + return success("操作成功",qrcode); + } + return success(dealerUser); + } + + @ApiOperation("分页查询分销商用户记录表") + @GetMapping("/page") + public ApiResult> page(DealerUserParam param) { + // 使用关联查询 + return success(dealerUserService.pageRel(param)); + } + + @ApiOperation("查询全部分销商用户记录表") + @GetMapping() + public ApiResult> list(DealerUserParam param) { + // 使用关联查询 + return success(dealerUserService.listRel(param)); + } + + @ApiOperation("根据id查询分销商用户记录表") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + // 分销商信息 + final DealerUser dealerUser = dealerUserService.getOne(new LambdaQueryWrapper() + .eq(DealerUser::getUserId, id) + .eq(DealerUser::getIsDelete, 0) + .last("limit 1") + ); + // 上级分销商 + final DealerUser dealerUser1 = dealerUserService.getOne(new LambdaQueryWrapper() + .eq(DealerUser::getUserId, dealerUser.getRefereeId()) + .eq(DealerUser::getIsDelete, 0)); + dealerUser.setDealerName(dealerUser1.getRealName()); + dealerUser.setDealerUser(dealerUser1); + return success(dealerUser); + } + + @ApiOperation("添加分销商用户记录表") + @PostMapping() + public ApiResult save(@RequestBody DealerUser dealerUser) { + // 记录当前登录用户id + User loginUser = getLoginUser(); + if (loginUser != null) { + dealerUser.setUserId(loginUser.getUserId()); + } + if (dealerUserService.save(dealerUser)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("修改分销商用户记录表") + @PutMapping() + public ApiResult update(@RequestBody DealerUser dealerUser) { + if (dealerUserService.updateById(dealerUser)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("删除分销商用户记录表") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (dealerUserService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @ApiOperation("批量添加分销商用户记录表") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List list) { + if (dealerUserService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("批量修改分销商用户记录表") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(dealerUserService, "id")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("批量删除分销商用户记录表") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (dealerUserService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + + private String getAccessToken() { + String key = ACCESS_TOKEN_KEY.concat(":").concat(getTenantId().toString()); + // 从缓存获取access_token + final String value = redisUtil.get(key); + if (value != null) { + // 解析access_token + JSONObject response = JSON.parseObject(value); + return response.getString("access_token"); } - @ApiOperation("根据id查询分销商用户记录表") - @GetMapping("/{id}") - public ApiResult get(@PathVariable("id") Integer id) { - // 使用关联查询 - return success(dealerUserService.getByIdRel(id)); - } + return null; + } - @ApiOperation("添加分销商用户记录表") - @PostMapping() - public ApiResult save(@RequestBody DealerUser dealerUser) { - // 记录当前登录用户id - User loginUser = getLoginUser(); - if (loginUser != null) { - dealerUser.setUserId(loginUser.getUserId()); - } - if (dealerUserService.save(dealerUser)) { - return success("添加成功"); - } - return fail("添加失败"); - } - - @ApiOperation("修改分销商用户记录表") - @PutMapping() - public ApiResult update(@RequestBody DealerUser dealerUser) { - if (dealerUserService.updateById(dealerUser)) { - return success("修改成功"); - } - return fail("修改失败"); - } - - @ApiOperation("删除分销商用户记录表") - @DeleteMapping("/{id}") - public ApiResult remove(@PathVariable("id") Integer id) { - if (dealerUserService.removeById(id)) { - return success("删除成功"); - } - return fail("删除失败"); - } - - @ApiOperation("批量添加分销商用户记录表") - @PostMapping("/batch") - public ApiResult saveBatch(@RequestBody List list) { - if (dealerUserService.saveBatch(list)) { - return success("添加成功"); - } - return fail("添加失败"); - } - - @ApiOperation("批量修改分销商用户记录表") - @PutMapping("/batch") - public ApiResult removeBatch(@RequestBody BatchParam batchParam) { - if (batchParam.update(dealerUserService, "user_id")) { - return success("修改成功"); - } - return fail("修改失败"); - } - - @ApiOperation("批量删除分销商用户记录表") - @DeleteMapping("/batch") - public ApiResult removeBatch(@RequestBody List ids) { - if (dealerUserService.removeByIds(ids)) { - return success("删除成功"); - } - return fail("删除失败"); - } + private String getUploadDir() { + return config.getUploadPath() + "file/"; + } } diff --git a/src/main/java/com/gxwebsoft/shop/controller/GoodsCategoryController.java b/src/main/java/com/gxwebsoft/shop/controller/GoodsCategoryController.java index e9cb3c9..ef22b44 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/GoodsCategoryController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/GoodsCategoryController.java @@ -2,6 +2,7 @@ package com.gxwebsoft.shop.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper; +import com.gxwebsoft.cms.entity.Navigation; import com.gxwebsoft.common.core.utils.JSONUtil; import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.BaseController; @@ -16,6 +17,7 @@ import com.gxwebsoft.shop.service.GoodsService; import com.gxwebsoft.shop.service.GoodsSpecService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.poi.ss.formula.functions.T; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; @@ -37,132 +39,212 @@ import static com.gxwebsoft.common.core.utils.CommonUtil.toTreeData; @RestController @RequestMapping("/api/shop/goods-category") public class GoodsCategoryController extends BaseController { - @Resource - private GoodsCategoryService goodsCategoryService; - @Resource - private GoodsSpecService goodsSpecService; - @Resource - private GoodsService goodsService; + @Resource + private GoodsCategoryService goodsCategoryService; + @Resource + private GoodsSpecService goodsSpecService; + @Resource + private GoodsService goodsService; - @ApiOperation("查询全部商品分类(树型结构)") - @GetMapping("/getTree") - public ApiResult> getTree(GoodsCategoryParam param) { - final List list = goodsCategoryService.listRel(param); - final Set categoryIds = list.stream().map(GoodsCategory::getCategoryId).collect(Collectors.toSet()); - if (categoryIds.isEmpty()) { - return success(list); + @ApiOperation("查询商城菜单分类级商品数据(不联动)") + @GetMapping("/listCategoryTree") + public ApiResult> listCategoryTree(GoodsCategoryParam param) { + // 查询非店铺分类 + param.setMerchantId(0); + final List goodsCategoryList = goodsCategoryService.listRel(param); + // 收集分类ID + final Set categoryIds = goodsCategoryList.stream().map(GoodsCategory::getCategoryId).collect(Collectors.toSet()); + if (categoryIds.isEmpty()) { + return success(goodsCategoryList); + } + // List转为树形结构 + final List list = toTreeData(goodsCategoryList, 0, GoodsCategory::getParentId, GoodsCategory::getCategoryId, GoodsCategory::setChildren); + // 查询所有商品 + final List goods = goodsService.list(new LambdaQueryWrapper() + .in(Goods::getCategoryId, categoryIds) + .eq(Goods::getIsShow, 1) + .eq(Goods::getDeleted, 0)); + + final Map> collectGoods = goods.stream().collect(Collectors.groupingBy(Goods::getCategoryId)); + + final Set goodsIds = goods.stream().map(Goods::getGoodsId).collect(Collectors.toSet()); + + final List specs = goodsSpecService.list(new LambdaQueryWrapper().in(GoodsSpec::getGoodsId, goodsIds)); + + final Map> collectGoodsSpec = specs.stream().collect(Collectors.groupingBy(GoodsSpec::getGoodsId)); + + list.forEach(d -> { + d.setName(d.getTitle()); + final List goodsList = collectGoods.get(d.getCategoryId()); + if (!CollectionUtils.isEmpty(goodsList)) { + goodsList.forEach(v -> { + final List goodsSpecs = collectGoodsSpec.get(v.getGoodsId()); + if (!CollectionUtils.isEmpty(goodsSpecs)) { + final GoodsSpec spec = goodsSpecs.get(0); + v.setSpecValue(spec.getSpecValue()); + v.setGoodsSpecValue(JSONUtil.parseObject(spec.getSpecValue(), Object.class)); + } + }); + d.setGoods(collectGoods.get(d.getCategoryId())); } -// System.out.println("param.getType() = " + param.getType()); -// final List goods = goodsService.getGoodsSpecType0(); -// System.out.println("goodsBySpec = " + goods); + }); + return success(list); + } - final List goods = goodsService.list(new LambdaQueryWrapper().in(Goods::getCategoryId, categoryIds).eq(Goods::getIsShow,1).eq(Goods::getDeleted,0)); - final Map> collectGoods = goods.stream().collect(Collectors.groupingBy(Goods::getCategoryId)); + @ApiOperation("查询商城菜单分类级商品数据(不联动)") + @GetMapping("/listCategoryParentIdTree/{parentId}") + public ApiResult> listCategoryParentIdTree(@PathVariable("parentId") Integer parentId) { + // 查询非店铺分类 + final List list = goodsCategoryService.list(new LambdaQueryWrapper() + .eq(GoodsCategory::getParentId,parentId) + .eq(GoodsCategory::getType,0) + .eq(GoodsCategory::getMerchantId,0)); - final Set goodsIds = goods.stream().map(Goods::getGoodsId).collect(Collectors.toSet()); - System.out.println("goodsIds = " + goodsIds); + final Set categoryIds = list.stream().map(GoodsCategory::getCategoryId).collect(Collectors.toSet()); + final List goods = goodsService.list(new LambdaQueryWrapper().in(Goods::getCategoryId, categoryIds)); + final Map> collect = goods.stream().collect(Collectors.groupingBy(Goods::getCategoryId)); - final List specs = goodsSpecService.list(new LambdaQueryWrapper().in(GoodsSpec::getGoodsId, goodsIds)); - System.out.println("specs = " + specs); - final Map> collectGoodsSpec = specs.stream().collect(Collectors.groupingBy(GoodsSpec::getGoodsId)); + final Map> collectGoods = goods.stream().collect(Collectors.groupingBy(Goods::getCategoryId)); - list.forEach(d -> { - d.setName(d.getTitle()); - final List goodsList = collectGoods.get(d.getCategoryId()); - if (!CollectionUtils.isEmpty(goodsList)) { - goodsList.forEach(v -> { - System.out.println("v = " + v.getSpecValue()); - final String specValue = v.getSpecValue(); - final List goodsSpecs = collectGoodsSpec.get(v.getGoodsId()); - if (!CollectionUtils.isEmpty(goodsSpecs)) { - final GoodsSpec spec = goodsSpecs.get(0); - v.setSpecValue(spec.getSpecValue()); - v.setGoodsSpecValue(JSONUtil.parseObject(spec.getSpecValue(),Object.class)); - } - }); - d.setChildrens(collectGoods.get(d.getCategoryId())); - } - }); + final Set goodsIds = goods.stream().map(Goods::getGoodsId).collect(Collectors.toSet()); + + final List specs = goodsSpecService.list(new LambdaQueryWrapper().in(GoodsSpec::getGoodsId, goodsIds)); + + final Map> collectGoodsSpec = specs.stream().collect(Collectors.groupingBy(GoodsSpec::getGoodsId)); + + list.forEach(d -> { + d.setName(d.getTitle()); + final List goodsList = collectGoods.get(d.getCategoryId()); + if (!CollectionUtils.isEmpty(goodsList)) { + goodsList.forEach(v -> { + final List goodsSpecs = collectGoodsSpec.get(v.getGoodsId()); + if (!CollectionUtils.isEmpty(goodsSpecs)) { + final GoodsSpec spec = goodsSpecs.get(0); + v.setSpecValue(spec.getSpecValue()); + v.setGoodsSpecValue(JSONUtil.parseObject(spec.getSpecValue(), Object.class)); + } + }); + d.setGoods(collectGoods.get(d.getCategoryId())); + } + }); + return success("请求成功",list); + } + + @ApiOperation("查询门店菜单分类及菜品数据(联动)") + @GetMapping("/listShopCategoryTree") + public ApiResult> listShopCategoryTree(GoodsCategoryParam param) { + final List list = goodsCategoryService.listRel(param); + final Set categoryIds = list.stream().map(GoodsCategory::getCategoryId).collect(Collectors.toSet()); + if (categoryIds.isEmpty()) { return success(list); } - @ApiOperation("分页查询商品分类") - @GetMapping("/page") - public ApiResult> page(GoodsCategoryParam param) { - // 使用关联查询 - return success(goodsCategoryService.pageRel(param)); - } - @ApiOperation("查询全部商品分类") - @GetMapping() - public ApiResult> list(GoodsCategoryParam param) { - // 使用关联查询 - return success(goodsCategoryService.listRel(param)); - } + final List goods = goodsService.list(new LambdaQueryWrapper().in(Goods::getCategoryId, categoryIds).eq(Goods::getIsShow, 1).eq(Goods::getDeleted, 0)); + final Map> collectGoods = goods.stream().collect(Collectors.groupingBy(Goods::getCategoryId)); - @ApiOperation("根据id查询商品分类") - @GetMapping("/{id}") - public ApiResult get(@PathVariable("id") Integer id) { - // 使用关联查询 - return success(goodsCategoryService.getByIdRel(id)); - } + final Set goodsIds = goods.stream().map(Goods::getGoodsId).collect(Collectors.toSet()); - @ApiOperation("添加商品分类") - @PostMapping() - public ApiResult save(@RequestBody GoodsCategory goodsCategory) { - // 记录当前登录用户id - User loginUser = getLoginUser(); - if (loginUser != null) { - goodsCategory.setUserId(loginUser.getUserId()); - } - if (goodsCategoryService.save(goodsCategory)) { - return success("添加成功"); - } - return fail("添加失败"); - } + final List specs = goodsSpecService.list(new LambdaQueryWrapper().in(GoodsSpec::getGoodsId, goodsIds)); - @ApiOperation("修改商品分类") - @PutMapping() - public ApiResult update(@RequestBody GoodsCategory goodsCategory) { - if (goodsCategoryService.updateById(goodsCategory)) { - return success("修改成功"); - } - return fail("修改失败"); - } + final Map> collectGoodsSpec = specs.stream().collect(Collectors.groupingBy(GoodsSpec::getGoodsId)); - @ApiOperation("删除商品分类") - @DeleteMapping("/{id}") - public ApiResult remove(@PathVariable("id") Integer id) { - if (goodsCategoryService.removeById(id)) { - return success("删除成功"); - } - return fail("删除失败"); - } + list.forEach(d -> { + d.setName(d.getTitle()); + final List goodsList = collectGoods.get(d.getCategoryId()); + if (!CollectionUtils.isEmpty(goodsList)) { + goodsList.forEach(v -> { + final List goodsSpecs = collectGoodsSpec.get(v.getGoodsId()); + if (!CollectionUtils.isEmpty(goodsSpecs)) { + final GoodsSpec spec = goodsSpecs.get(0); + v.setSpecValue(spec.getSpecValue()); + v.setGoodsSpecValue(JSONUtil.parseObject(spec.getSpecValue(), Object.class)); + } + }); + d.setGoods(collectGoods.get(d.getCategoryId())); + } + }); + return success(list); + } - @ApiOperation("批量添加商品分类") - @PostMapping("/batch") - public ApiResult saveBatch(@RequestBody List list) { - if (goodsCategoryService.saveBatch(list)) { - return success("添加成功"); - } - return fail("添加失败"); - } - @ApiOperation("批量修改商品分类") - @PutMapping("/batch") - public ApiResult removeBatch(@RequestBody BatchParam batchParam) { - if (batchParam.update(goodsCategoryService, "category_id")) { - return success("修改成功"); - } - return fail("修改失败"); - } + @ApiOperation("分页查询商品分类") + @GetMapping("/page") + public ApiResult> page(GoodsCategoryParam param) { + // 使用关联查询 + return success(goodsCategoryService.pageRel(param)); + } - @ApiOperation("批量删除商品分类") - @DeleteMapping("/batch") - public ApiResult removeBatch(@RequestBody List ids) { - if (goodsCategoryService.removeByIds(ids)) { - return success("删除成功"); - } - return fail("删除失败"); + @ApiOperation("查询全部商品分类") + @GetMapping() + public ApiResult> list(GoodsCategoryParam param) { + // 使用关联查询 + return success(goodsCategoryService.listRel(param)); + } + + @ApiOperation("根据id查询商品分类") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + // 使用关联查询 + return success(goodsCategoryService.getByIdRel(id)); + } + + @ApiOperation("添加商品分类") + @PostMapping() + public ApiResult save(@RequestBody GoodsCategory goodsCategory) { + // 记录当前登录用户id + User loginUser = getLoginUser(); + if (loginUser != null) { + goodsCategory.setUserId(loginUser.getUserId()); } + if (goodsCategoryService.save(goodsCategory)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("修改商品分类") + @PutMapping() + public ApiResult update(@RequestBody GoodsCategory goodsCategory) { + if (goodsCategoryService.updateById(goodsCategory)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("删除商品分类") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (goodsCategoryService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @ApiOperation("批量添加商品分类") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List list) { + if (goodsCategoryService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("批量修改商品分类") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(goodsCategoryService, "category_id")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("批量删除商品分类") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (goodsCategoryService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } } diff --git a/src/main/java/com/gxwebsoft/shop/entity/DealerUser.java b/src/main/java/com/gxwebsoft/shop/entity/DealerUser.java index 8f1709f..3ced884 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/DealerUser.java +++ b/src/main/java/com/gxwebsoft/shop/entity/DealerUser.java @@ -2,13 +2,14 @@ package com.gxwebsoft.shop.entity; import java.math.BigDecimal; -import cn.hutool.core.util.DesensitizedUtil; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.IdType; -import java.time.LocalDateTime; import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; import java.io.Serializable; +import java.util.Date; + import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -18,7 +19,7 @@ import lombok.EqualsAndHashCode; * 分销商用户记录表 * * @author 科技小王子 - * @since 2024-07-28 11:57:41 + * @since 2024-07-28 19:21:15 */ @Data @EqualsAndHashCode(callSuper = false) @@ -27,8 +28,11 @@ import lombok.EqualsAndHashCode; public class DealerUser implements Serializable { private static final long serialVersionUID = 1L; - @ApiModelProperty(value = "分销商用户ID") - @TableId(value = "user_id", type = IdType.AUTO) + @ApiModelProperty(value = "主键ID") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "自增ID") private Integer userId; @ApiModelProperty(value = "姓名") @@ -61,6 +65,9 @@ public class DealerUser implements Serializable { @ApiModelProperty(value = "成员数量(三级)") private Integer thirdNum; + @ApiModelProperty(value = "专属二维码") + private String qrcode; + @ApiModelProperty(value = "是否删除") private Integer isDelete; @@ -68,10 +75,14 @@ public class DealerUser implements Serializable { private Integer tenantId; @ApiModelProperty(value = "创建时间") - private LocalDateTime createTime; + private Date createTime; @ApiModelProperty(value = "修改时间") - private LocalDateTime updateTime; + private Date updateTime; + + @ApiModelProperty(value = "推荐人信息") + @TableField(exist = false) + private DealerUser dealerUser; @ApiModelProperty(value = "推荐人姓名(脱敏)") @TableField(exist = false) diff --git a/src/main/java/com/gxwebsoft/shop/entity/GoodsCategory.java b/src/main/java/com/gxwebsoft/shop/entity/GoodsCategory.java index e862b63..a98e78a 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/GoodsCategory.java +++ b/src/main/java/com/gxwebsoft/shop/entity/GoodsCategory.java @@ -7,6 +7,7 @@ import java.io.Serializable; import java.util.Date; import java.util.List; +import com.gxwebsoft.cms.entity.Navigation; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -99,6 +100,10 @@ public class GoodsCategory implements Serializable { @ApiModelProperty("商品列表") @TableField(exist = false) - private List childrens; + private List goods; + + @ApiModelProperty("子菜单") + @TableField(exist = false) + private List children; } diff --git a/src/main/java/com/gxwebsoft/shop/mapper/DealerUserMapper.java b/src/main/java/com/gxwebsoft/shop/mapper/DealerUserMapper.java index ba03cf1..0561ec2 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/DealerUserMapper.java +++ b/src/main/java/com/gxwebsoft/shop/mapper/DealerUserMapper.java @@ -12,7 +12,7 @@ import java.util.List; * 分销商用户记录表Mapper * * @author 科技小王子 - * @since 2024-07-28 11:57:41 + * @since 2024-07-28 19:21:15 */ public interface DealerUserMapper extends BaseMapper { diff --git a/src/main/java/com/gxwebsoft/shop/mapper/xml/DealerUserMapper.xml b/src/main/java/com/gxwebsoft/shop/mapper/xml/DealerUserMapper.xml index 4ea1e58..caae59b 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/xml/DealerUserMapper.xml +++ b/src/main/java/com/gxwebsoft/shop/mapper/xml/DealerUserMapper.xml @@ -4,10 +4,12 @@ - SELECT a.*,b.real_name as dealerName + SELECT a.* FROM shop_dealer_user a - LEFT JOIN shop_dealer_user b ON a.referee_id = b.user_id + + AND a.id = #{param.id} + AND a.user_id = #{param.userId} @@ -51,9 +53,9 @@ AND a.create_time <= #{param.createTimeEnd} - AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%') - ) - + AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%') + ) + diff --git a/src/main/java/com/gxwebsoft/shop/mapper/xml/MerchantMapper.xml b/src/main/java/com/gxwebsoft/shop/mapper/xml/MerchantMapper.xml index 2aa871d..80eef6f 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/xml/MerchantMapper.xml +++ b/src/main/java/com/gxwebsoft/shop/mapper/xml/MerchantMapper.xml @@ -16,6 +16,9 @@ AND a.merchant_code LIKE CONCAT('%', #{param.merchantCode}, '%') + + AND a.type = #{param.type} + AND a.image LIKE CONCAT('%', #{param.image}, '%') diff --git a/src/main/java/com/gxwebsoft/shop/param/DealerUserParam.java b/src/main/java/com/gxwebsoft/shop/param/DealerUserParam.java index ae947b4..0d7f8ae 100644 --- a/src/main/java/com/gxwebsoft/shop/param/DealerUserParam.java +++ b/src/main/java/com/gxwebsoft/shop/param/DealerUserParam.java @@ -14,7 +14,7 @@ import lombok.EqualsAndHashCode; * 分销商用户记录表查询参数 * * @author 科技小王子 - * @since 2024-07-28 11:57:41 + * @since 2024-07-28 19:21:15 */ @Data @EqualsAndHashCode(callSuper = false) @@ -23,7 +23,11 @@ import lombok.EqualsAndHashCode; public class DealerUserParam extends BaseParam { private static final long serialVersionUID = 1L; - @ApiModelProperty(value = "分销商用户ID") + @ApiModelProperty(value = "主键ID") + @QueryField(type = QueryType.EQ) + private Integer id; + + @ApiModelProperty(value = "自增ID") @QueryField(type = QueryType.EQ) private Integer userId; diff --git a/src/main/java/com/gxwebsoft/shop/param/MerchantParam.java b/src/main/java/com/gxwebsoft/shop/param/MerchantParam.java index 6cb7bbc..3482f31 100644 --- a/src/main/java/com/gxwebsoft/shop/param/MerchantParam.java +++ b/src/main/java/com/gxwebsoft/shop/param/MerchantParam.java @@ -37,6 +37,10 @@ public class MerchantParam extends BaseParam { @ApiModelProperty(value = "商户标识") private String merchantCode; + @ApiModelProperty(value = "店铺类型") + @QueryField(type = QueryType.EQ) + private Integer type; + @ApiModelProperty(value = "商户图标") private String image; diff --git a/src/main/java/com/gxwebsoft/shop/service/DealerUserService.java b/src/main/java/com/gxwebsoft/shop/service/DealerUserService.java index 152f9f1..ab0940a 100644 --- a/src/main/java/com/gxwebsoft/shop/service/DealerUserService.java +++ b/src/main/java/com/gxwebsoft/shop/service/DealerUserService.java @@ -11,7 +11,7 @@ import java.util.List; * 分销商用户记录表Service * * @author 科技小王子 - * @since 2024-07-28 11:57:41 + * @since 2024-07-28 19:21:15 */ public interface DealerUserService extends IService { @@ -34,9 +34,9 @@ public interface DealerUserService extends IService { /** * 根据id查询 * - * @param userId 分销商用户ID + * @param id 主键ID * @return DealerUser */ - DealerUser getByIdRel(Integer userId); + DealerUser getByIdRel(Integer id); } diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/DealerUserServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/DealerUserServiceImpl.java index e2a047e..8ec4acf 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/DealerUserServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/DealerUserServiceImpl.java @@ -15,7 +15,7 @@ import java.util.List; * 分销商用户记录表Service实现 * * @author 科技小王子 - * @since 2024-07-28 11:57:41 + * @since 2024-07-28 19:21:15 */ @Service public class DealerUserServiceImpl extends ServiceImpl implements DealerUserService { @@ -38,9 +38,9 @@ public class DealerUserServiceImpl extends ServiceImpl