Просмотр исходного кода

分销查询以及商家分类自动添加

liude 1 год назад
Родитель
Сommit
c98b2fe7c7

+ 6 - 2
vehicle-api/src/main/java/com/chelvc/cloud/vehicle/api/dto/TeamDetailsDTO.java

@@ -20,14 +20,18 @@ public class TeamDetailsDTO implements Serializable {
      * 用户标识
      * 用户标识
      */
      */
     private Long userId;
     private Long userId;
+    /**
+     *用户名称
+     */
+    private String nickname;
 
 
     /**
     /**
-     * 邀请用户
+     * 邀请用户
      */
      */
     private Long inviteUserId;
     private Long inviteUserId;
 
 
     /**
     /**
-     * 用户名称
+     * 被邀请用户名称
      */
      */
     private String name;
     private String name;
 
 

+ 7 - 0
vehicle-api/src/main/java/com/chelvc/cloud/vehicle/api/service/UserInviteService.java

@@ -16,4 +16,11 @@ public interface UserInviteService {
      * @return
      * @return
      */
      */
     Long queryUserByTarget(Long userId, Integer type);
     Long queryUserByTarget(Long userId, Integer type);
+
+    /**
+     * 查询用户邀请得用户列表
+     * @param param
+     * @return
+     */
+    TeamDTO inviteList(TeamInvitePageParam param);
 }
 }

+ 2 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/dao/CategoryMapper.java

@@ -22,4 +22,6 @@ public interface CategoryMapper extends BaseMapper<Category> {
      * @return 分类信息列表
      * @return 分类信息列表
      */
      */
     List<Category> listRecommendCategories(@Param("size") int size);
     List<Category> listRecommendCategories(@Param("size") int size);
+
+    void deleteByMerchantId(Long merchantId);
 }
 }

+ 6 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/dao/UserInviteMapper.java

@@ -15,4 +15,10 @@ public interface UserInviteMapper extends BaseMapper<UserInvite> {
                                               @Param("pageSize") int pageSize, @Param("userId") Long userId);
                                               @Param("pageSize") int pageSize, @Param("userId") Long userId);
 
 
     TeamDTO teamTotalStatistics(@Param("type") Integer type, @Param("userId") Long userId);
     TeamDTO teamTotalStatistics(@Param("type") Integer type, @Param("userId") Long userId);
+
+
+    List<TeamDetailsDTO> inviteList(@Param("type") Integer type, @Param("pageNum") int pageNum,
+                                  @Param("pageSize") int pageSize);
+
+    TeamDTO inviteTotalStatistics(@Param("type") Integer type);
 }
 }

+ 19 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/CategoryService.java

@@ -21,4 +21,23 @@ public interface CategoryService extends IService<Category> {
     List<CategoryDTO> listCategories(List<Long> categories);
     List<CategoryDTO> listCategories(List<Long> categories);
 
 
     List<Long> queryFirstLevelIds();
     List<Long> queryFirstLevelIds();
+
+    /**
+     * 查询分类
+     * @param ids
+     * @return
+     */
+    List<Category> getCategories(List<Long> ids);
+
+    /**
+     * 批量保存
+     * @param categories
+     */
+    void saveBatchCategories(List<Category> categories);
+
+    /**
+     * 删除商家所有分类
+     * @param merchant
+     */
+    void deleteByMerchantId(Long merchant);
 }
 }

+ 3 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/MerchantService.java

@@ -59,4 +59,7 @@ public interface MerchantService extends IService<Merchant> {
      * @return
      * @return
      */
      */
     MerchantDTO getMerchantByUserId(Long userId);
     MerchantDTO getMerchantByUserId(Long userId);
+
+
+
 }
 }

+ 13 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/CategoryServiceImpl.java

@@ -222,4 +222,17 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
         categories.sort(Comparator.comparing(Category::getType).thenComparing(Category::getSort));
         categories.sort(Comparator.comparing(Category::getType).thenComparing(Category::getSort));
         return CategoryCopier.INSTANCE.copying(categories);
         return CategoryCopier.INSTANCE.copying(categories);
     }
     }
+
+    @Override
+    public List<Category> getCategories(List<Long> ids){
+        return this.listByIds(ids);
+    }
+    @Override
+    public void saveBatchCategories(List<Category> categories){
+        this.saveBatch(categories);
+    }
+    @Override
+    public void deleteByMerchantId(Long merchant){
+        this.baseMapper.deleteByMerchantId(merchant);
+    }
 }
 }

+ 38 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/MerchantServiceImpl.java

@@ -14,6 +14,7 @@ import com.chelvc.cloud.vehicle.api.util.DateTimeUtils;
 import com.chelvc.cloud.vehicle.server.copier.MerchantCopier;
 import com.chelvc.cloud.vehicle.server.copier.MerchantCopier;
 import com.chelvc.cloud.vehicle.server.dao.MerchantMapper;
 import com.chelvc.cloud.vehicle.server.dao.MerchantMapper;
 import com.chelvc.cloud.vehicle.server.dao.RegionMapper;
 import com.chelvc.cloud.vehicle.server.dao.RegionMapper;
+import com.chelvc.cloud.vehicle.server.entity.Category;
 import com.chelvc.cloud.vehicle.server.entity.Merchant;
 import com.chelvc.cloud.vehicle.server.entity.Merchant;
 import com.chelvc.cloud.vehicle.server.entity.Region;
 import com.chelvc.cloud.vehicle.server.entity.Region;
 import com.chelvc.cloud.vehicle.server.service.CategoryService;
 import com.chelvc.cloud.vehicle.server.service.CategoryService;
@@ -34,6 +35,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
 import org.apache.dubbo.config.annotation.DubboService;
 import org.apache.dubbo.config.annotation.DubboService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.context.annotation.Lazy;
+import org.springframework.util.CollectionUtils;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.time.LocalTime;
 import java.time.LocalTime;
@@ -148,6 +150,23 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
         merchant.setSale(0);
         merchant.setSale(0);
         merchant.setStatus(MerchantStatus.ONLINE);
         merchant.setStatus(MerchantStatus.ONLINE);
         this.save(merchant);
         this.save(merchant);
+        List<Long> business = param.getAncillaryBusiness();
+        if (StringUtils.notEmpty(param.getMainBusiness())){
+            business.add(param.getMainBusiness());
+        }
+//        this.categoryService.removeByIds(business);
+        List<Category> categories = this.categoryService.getCategories(business);
+        if (!CollectionUtils.isEmpty(categories)){
+            categories.forEach(item ->{
+                item.setSourceId(item.getId());
+                item.setId(null);
+                item.setMerchantId(merchant.getId());
+                item.setType("1");
+                item.setParentId(0L);
+                this.categoryService.save(item);
+            });
+           // this.categoryService.saveBatchCategories(categories);
+        }
         return merchant.getId();
         return merchant.getId();
     }
     }
 
 
@@ -156,6 +175,25 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
         Merchant merchant = AssertUtils.available(this.getById(id), "商家不存在");
         Merchant merchant = AssertUtils.available(this.getById(id), "商家不存在");
         MerchantCopier.INSTANCE.copying(param, merchant);
         MerchantCopier.INSTANCE.copying(param, merchant);
         this.updateById(merchant);
         this.updateById(merchant);
+        List<Long> business = param.getAncillaryBusiness();
+        if (StringUtils.notEmpty(param.getMainBusiness())){
+            business.add(param.getMainBusiness());
+        }
+//        this.categoryService.removeByIds(business);
+        this.categoryService.deleteByMerchantId(merchant.getId());
+        List<Category> categories = this.categoryService.getCategories(business);
+        if (!CollectionUtils.isEmpty(categories)){
+            categories.forEach(item ->{
+                item.setSourceId(item.getId());
+                item.setId(null);
+                item.setMerchantId(merchant.getId());
+                item.setType("1");
+                item.setParentId(0L);
+//                this.categoryService.save(item);
+            });
+            this.categoryService.saveBatchCategories(categories);
+        }
+
     }
     }
 
 
     @Override
     @Override

+ 34 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/UserInviteServiceImpl.java

@@ -142,4 +142,38 @@ public class UserInviteServiceImpl extends ServiceImpl<UserInviteMapper, UserInv
         UserInvite userInvite = baseMapper.selectOne(inviteWrapper);
         UserInvite userInvite = baseMapper.selectOne(inviteWrapper);
         return userInvite == null ? null : userInvite.getUserId();
         return userInvite == null ? null : userInvite.getUserId();
     }
     }
+
+
+
+    @Override
+    public TeamDTO inviteList(TeamInvitePageParam param) {
+        TeamDTO dto = new TeamDTO();
+        Paging paging = param.getPaging();
+        int pageNum = (paging.getNumber() - 1) * paging.getSize();
+        if(pageNum < 0){
+            return dto;
+        }
+        List<TeamDetailsDTO> records = baseMapper.inviteList(param.getType(), pageNum, paging.getSize());
+        if(CollectionUtils.isEmpty(records)){
+            return dto;
+        }
+        Map<Long, UserDTO> map = new HashMap<>();
+        if(param.getType() == null || param.getType() == 1){
+            List<Long> ids = records.stream().filter(e -> e.getSourceType() == 1).map(TeamDetailsDTO::getInviteUserId).collect(Collectors.toList());
+            List<UserDTO> users = this.userService.listUsers(ids);
+            map = users.stream().collect(Collectors.toMap(UserDTO::getId, user -> user));
+        }
+        for(TeamDetailsDTO detailsDTO : records){
+            Integer sourceType = detailsDTO.getSourceType();
+            if(sourceType == 1){
+                UserDTO userDTO = map.get(detailsDTO.getInviteUserId());
+                detailsDTO.setName(userDTO == null ? "" : userDTO.getNickname());
+            } else {
+                detailsDTO.setName(merchantService.getMerchantName(detailsDTO.getInviteUserId()));
+            }
+        }
+        dto = baseMapper.inviteTotalStatistics(param.getType());
+        dto.setRecords(records);
+        return dto;
+    }
 }
 }

+ 4 - 0
vehicle-server/src/main/resources/mapper/CategoryMapper.xml

@@ -12,4 +12,8 @@
         where cy.enabled = 1 and cy.recommend = 1
         where cy.enabled = 1 and cy.recommend = 1
         order by cy.sort asc limit #{size}
         order by cy.sort asc limit #{size}
     </select>
     </select>
+
+    <delete id="deleteByMerchantId">
+        delete from category where merchant_id = #{merchantId}
+    </delete>
 </mapper>
 </mapper>

+ 45 - 0
vehicle-server/src/main/resources/mapper/UserInviteMapper.xml

@@ -43,4 +43,49 @@
         </if>
         </if>
     </select>
     </select>
 
 
+
+
+
+    <select id="inviteList" resultType="com.chelvc.cloud.vehicle.api.dto.TeamDetailsDTO">
+        SELECT
+        i.user_id,
+        target_id AS inviteUserId,
+        SUM( r.reality_amount ) amount,
+        r.source_type sourceType
+        FROM
+        user_invite i
+        LEFT JOIN currency_record r ON i.user_id = r.user_id
+        AND i.target_id = r.source_id
+        AND r.type = 0
+        AND i.type = r.source_type
+        WHERE 1=1
+        <if test="type != null">
+            and i.type = #{type}
+        </if>
+        GROUP BY
+        i.id
+        ORDER BY
+        amount DESC
+        limit #{pageNum}, #{pageSize}
+    </select>
+
+
+
+    <select id="inviteTotalStatistics" resultType="com.chelvc.cloud.vehicle.api.dto.TeamDTO">
+        SELECT
+        count(i.id) total,
+        sum(r.reality_amount) totalAmount
+        FROM
+        user_invite i
+        LEFT JOIN currency_record r ON i.user_id = r.user_id
+        AND i.target_id = r.source_user_id
+        AND r.type = 0
+        AND i.type = r.source_type
+        WHERE
+        1=1
+        <if test="type != null">
+            and i.type = #{type}
+        </if>
+    </select>
+
 </mapper>
 </mapper>