Browse Source

商家的后台维护

liude 1 year ago
parent
commit
d3e7dc95b0

+ 97 - 0
vehicle-api/src/main/java/com/chelvc/cloud/vehicle/api/param/MerchantModifyParam.java

@@ -0,0 +1,97 @@
+package com.chelvc.cloud.vehicle.api.param;
+
+import com.chelvc.cloud.vehicle.api.constant.MerchantStatus;
+import com.chelvc.framework.base.model.File;
+import lombok.*;
+import lombok.experimental.SuperBuilder;
+
+import java.util.List;
+
+/**
+ * 商家数据模型
+ *
+ * @author xp
+ * @data 2023/4/10
+ */
+@Data
+@SuperBuilder
+@NoArgsConstructor
+@AllArgsConstructor
+@ToString(callSuper = true)
+public class MerchantModifyParam { /**
+
+    /**
+     * 用户ID
+     */
+    private Long userId;
+
+    /**
+     * 商家名称
+     */
+    private String name;
+
+    /**
+     * 商家Logo
+     */
+    private String logo;
+
+    /**
+     * 轮播图列表
+     */
+    private List<File> banners;
+
+    /**
+     * 联系人
+     */
+    private String liaison;
+
+    /**
+     * 联系电话
+     */
+    private String mobile;
+
+    /**
+     * 营业时间
+     */
+    private String opening;
+
+    /**
+     * 详细地址
+     */
+    private String address;
+
+    /**
+     * 商家评分
+     */
+    private Double score;
+
+    /**
+     * 订单销量
+     */
+    private Integer sale;
+
+    /**
+     * 所属地区
+     */
+    private Integer region;
+
+    /**
+     * 经度
+     */
+    private Double longitude;
+
+    /**
+     * 纬度
+     */
+    private Double latitude;
+
+    /**
+     * 是否推荐
+     */
+    private Boolean recommend;
+
+    /**
+     * 商家状态
+     */
+    private MerchantStatus status;
+}

+ 26 - 3
vehicle-api/src/main/java/com/chelvc/cloud/vehicle/api/service/MerchantService.java

@@ -1,11 +1,10 @@
 package com.chelvc.cloud.vehicle.api.service;
 
 import java.util.List;
-
 import com.chelvc.cloud.vehicle.api.dto.MerchantDTO;
 import com.chelvc.cloud.vehicle.api.dto.MerchantDetailDTO;
-import com.chelvc.cloud.vehicle.api.param.LocationQueryParam;
-import com.chelvc.cloud.vehicle.api.param.MerchantQueryParam;
+import com.chelvc.cloud.vehicle.api.param.*;
+import com.chelvc.framework.base.model.Pagination;
 
 /**
  * 商家业务接口
@@ -48,4 +47,28 @@ public interface MerchantService {
      * @return 商家详情
      */
     MerchantDetailDTO getMerchantDetail(Long id);
+
+    /**
+     * 新增商家
+     *
+     * @param param 新增参数
+     * @return 商家主键
+     */
+    Long addMerchant(MerchantModifyParam param);
+
+    /**
+     * 修改商家
+     *
+     * @param id    分类主键
+     * @param param 修改参数
+     */
+    void updateMerchant(Long id, MerchantModifyParam param);
+
+    /**
+     * 查询商家
+     *
+     * @param param 查询参数
+     * @return 分类分页信息
+     */
+    Pagination<MerchantDTO> getMerchantPaging(MerchantPagingParam param);
 }

+ 18 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/copier/MerchantCopier.java

@@ -4,7 +4,9 @@ import java.util.Collection;
 import java.util.List;
 
 import com.chelvc.cloud.vehicle.api.dto.MerchantDTO;
+import com.chelvc.cloud.vehicle.api.param.MerchantModifyParam;
 import com.chelvc.cloud.vehicle.server.entity.Merchant;
+import org.mapstruct.MappingTarget;
 import org.mapstruct.factory.Mappers;
 
 /**
@@ -34,4 +36,20 @@ public interface MerchantCopier {
      * @return 商家信息列表
      */
     List<MerchantDTO> copying(Collection<Merchant> merchants);
+
+    /**
+     * 商家信息拷贝
+     *
+     * @param param 商家更新参数
+     * @return 商家信息
+     */
+    Merchant copying(MerchantModifyParam param);
+
+    /**
+     * 商家信息拷贝
+     *
+     * @param param    商家更新参数
+     * @param  merchant 商家信息
+     */
+    void copying( MerchantModifyParam param, @MappingTarget  Merchant merchant);
 }

+ 28 - 3
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/MerchantServiceImpl.java

@@ -2,20 +2,22 @@ package com.chelvc.cloud.vehicle.server.service.impl;
 
 import java.util.List;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.chelvc.cloud.vehicle.api.constant.CategoryType;
 import com.chelvc.cloud.vehicle.api.dto.GoodsDTO;
 import com.chelvc.cloud.vehicle.api.dto.MerchantDTO;
 import com.chelvc.cloud.vehicle.api.dto.MerchantDetailDTO;
-import com.chelvc.cloud.vehicle.api.param.GoodsQueryParam;
-import com.chelvc.cloud.vehicle.api.param.LocationQueryParam;
-import com.chelvc.cloud.vehicle.api.param.MerchantQueryParam;
+import com.chelvc.cloud.vehicle.api.param.*;
 import com.chelvc.cloud.vehicle.server.copier.MerchantCopier;
 import com.chelvc.cloud.vehicle.server.dao.MerchantMapper;
 import com.chelvc.cloud.vehicle.server.entity.Merchant;
 import com.chelvc.cloud.vehicle.server.service.GoodsService;
 import com.chelvc.cloud.vehicle.server.service.MerchantService;
+import com.chelvc.framework.base.model.Pagination;
+import com.chelvc.framework.base.util.StringUtils;
 import com.chelvc.framework.database.context.DatabaseContextHolder;
+import com.chelvc.framework.database.util.PagingUtils;
 import lombok.NonNull;
 import lombok.RequiredArgsConstructor;
 import org.apache.dubbo.config.annotation.DubboService;
@@ -64,4 +66,27 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
         List<CategoryType> types = this.goodsService.listMerchantGoodsCategoryTypes(id);
         return MerchantDetailDTO.builder().merchant(merchant).goods(goods).categories(types).build();
     }
+
+
+    @Override
+    public Long addMerchant(MerchantModifyParam param){
+        Merchant merchant = MerchantCopier.INSTANCE.copying(param);
+        this.save(merchant);
+        return merchant.getId();
+    }
+
+    @Override
+    public void updateMerchant(@NonNull Long id, @NonNull MerchantModifyParam param) {
+        Merchant merchant = DatabaseContextHolder.getRequireEntity(this, id, "分类不存在");
+        MerchantCopier.INSTANCE.copying(param, merchant);
+        this.updateById(merchant);
+    }
+
+    @Override
+    public Pagination<MerchantDTO> getMerchantPaging(@NonNull MerchantPagingParam param) {
+        Page<Merchant> page = this.lambdaQuery()
+                .like(StringUtils.nonEmpty(param.getName()), Merchant::getName, param.getName())
+                .orderByAsc(Merchant::getStatus).page(PagingUtils.convert(param.getPaging()));
+        return PagingUtils.convert(page, MerchantCopier.INSTANCE::copying);
+    }
 }