From e685b58fd40cf28a20844643d70cc5f5b46ca037 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期五, 10 四月 2026 11:08:17 +0800
Subject: [PATCH] Merge branch 'master' of http://139.186.142.91:10010/r/productDev/gtzxinglijicun
---
server/services/src/main/java/com/doumee/service/business/impl/PricingRuleServiceImpl.java | 601 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 601 insertions(+), 0 deletions(-)
diff --git a/server/services/src/main/java/com/doumee/service/business/impl/PricingRuleServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/PricingRuleServiceImpl.java
new file mode 100644
index 0000000..81bb4b4
--- /dev/null
+++ b/server/services/src/main/java/com/doumee/service/business/impl/PricingRuleServiceImpl.java
@@ -0,0 +1,601 @@
+package com.doumee.service.business.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.doumee.core.constants.Constants;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
+import com.doumee.core.model.PageData;
+import com.doumee.core.model.PageWrap;
+import com.doumee.core.utils.Utils;
+import com.doumee.dao.business.CategoryMapper;
+import com.doumee.dao.business.PricingRuleMapper;
+import com.doumee.dao.business.model.Category;
+import com.doumee.dao.business.model.PricingRule;
+import com.doumee.dao.dto.LocalStoragePricingItemDTO;
+import com.doumee.dao.dto.LocalStoragePricingSaveDTO;
+import com.doumee.dao.dto.RemoteDeliveryPricingItemDTO;
+import com.doumee.dao.dto.RemoteDeliveryPricingSaveDTO;
+import com.doumee.dao.dto.EstimatedDeliverySaveDTO;
+import com.doumee.dao.dto.StoreDepositItemDTO;
+import com.doumee.dao.dto.StoreDepositSaveDTO;
+import com.doumee.dao.dto.RevenueShareItemDTO;
+import com.doumee.dao.dto.RevenueShareSaveDTO;
+import com.doumee.dao.vo.LocalStoragePricingVO;
+import com.doumee.dao.vo.RemoteDeliveryPricingVO;
+import com.doumee.dao.vo.EstimatedDeliveryVO;
+import com.doumee.dao.vo.StoreDepositVO;
+import com.doumee.dao.vo.RevenueShareVO;
+import com.doumee.service.business.PricingRuleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 璁′环瑙勫垯閰嶇疆Service瀹炵幇
+ * @author rk
+ * @date 2026/04/08
+ */
+@Service
+public class PricingRuleServiceImpl implements PricingRuleService {
+
+ @Autowired
+ private PricingRuleMapper pricingRuleMapper;
+
+ @Autowired
+ private CategoryMapper categoryMapper;
+
+ @Override
+ public Integer create(PricingRule pricingRule) {
+ pricingRuleMapper.insert(pricingRule);
+ return pricingRule.getId();
+ }
+
+ @Override
+ public void deleteById(Integer id) {
+ pricingRuleMapper.deleteById(id);
+ }
+
+ @Override
+ public void delete(PricingRule pricingRule) {
+ UpdateWrapper<PricingRule> deleteWrapper = new UpdateWrapper<>(pricingRule);
+ pricingRuleMapper.delete(deleteWrapper);
+ }
+
+ @Override
+ public void deleteByIdInBatch(List<Integer> ids) {
+ if (CollectionUtils.isEmpty(ids)) {
+ return;
+ }
+ pricingRuleMapper.deleteBatchIds(ids);
+ }
+
+ @Override
+ public void updateById(PricingRule pricingRule) {
+ pricingRuleMapper.updateById(pricingRule);
+ }
+
+ @Override
+ public void updateByIdInBatch(List<PricingRule> pricingRules) {
+ if (CollectionUtils.isEmpty(pricingRules)) {
+ return;
+ }
+ for (PricingRule pricingRule : pricingRules) {
+ this.updateById(pricingRule);
+ }
+ }
+
+ @Override
+ public PricingRule findById(Integer id) {
+ PricingRule pricingRule = pricingRuleMapper.selectById(id);
+ if (Objects.isNull(pricingRule)) {
+ throw new BusinessException(ResponseStatus.DATA_EMPTY);
+ }
+ return pricingRule;
+ }
+
+ @Override
+ public PricingRule findOne(PricingRule pricingRule) {
+ QueryWrapper<PricingRule> wrapper = new QueryWrapper<>(pricingRule);
+ return pricingRuleMapper.selectOne(wrapper);
+ }
+
+ @Override
+ public List<PricingRule> findList(PricingRule pricingRule) {
+ QueryWrapper<PricingRule> wrapper = new QueryWrapper<>(pricingRule);
+ return pricingRuleMapper.selectList(wrapper);
+ }
+
+ @Override
+ public PageData<PricingRule> findPage(PageWrap<PricingRule> pageWrap) {
+ IPage<PricingRule> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
+ QueryWrapper<PricingRule> queryWrapper = new QueryWrapper<>();
+ Utils.MP.blankToNull(pageWrap.getModel());
+ pageWrap.getModel().setDeleted(Constants.ZERO);
+ if (pageWrap.getModel().getId() != null) {
+ queryWrapper.lambda().eq(PricingRule::getId, pageWrap.getModel().getId());
+ }
+ if (pageWrap.getModel().getDeleted() != null) {
+ queryWrapper.lambda().eq(PricingRule::getDeleted, pageWrap.getModel().getDeleted());
+ }
+ if (pageWrap.getModel().getCreateUser() != null) {
+ queryWrapper.lambda().eq(PricingRule::getCreateUser, pageWrap.getModel().getCreateUser());
+ }
+ if (pageWrap.getModel().getCreateTime() != null) {
+ queryWrapper.lambda().ge(PricingRule::getCreateTime, Utils.Date.getStart(pageWrap.getModel().getCreateTime()));
+ queryWrapper.lambda().le(PricingRule::getCreateTime, Utils.Date.getEnd(pageWrap.getModel().getCreateTime()));
+ }
+ if (pageWrap.getModel().getUpdateUser() != null) {
+ queryWrapper.lambda().eq(PricingRule::getUpdateUser, pageWrap.getModel().getUpdateUser());
+ }
+ if (pageWrap.getModel().getUpdateTime() != null) {
+ queryWrapper.lambda().ge(PricingRule::getUpdateTime, Utils.Date.getStart(pageWrap.getModel().getUpdateTime()));
+ queryWrapper.lambda().le(PricingRule::getUpdateTime, Utils.Date.getEnd(pageWrap.getModel().getUpdateTime()));
+ }
+ if (pageWrap.getModel().getRemark() != null) {
+ queryWrapper.lambda().eq(PricingRule::getRemark, pageWrap.getModel().getRemark());
+ }
+ if (pageWrap.getModel().getCityId() != null) {
+ queryWrapper.lambda().eq(PricingRule::getCityId, pageWrap.getModel().getCityId());
+ }
+ if (pageWrap.getModel().getType() != null) {
+ queryWrapper.lambda().eq(PricingRule::getType, pageWrap.getModel().getType());
+ }
+ if (pageWrap.getModel().getFieldA() != null) {
+ queryWrapper.lambda().eq(PricingRule::getFieldA, pageWrap.getModel().getFieldA());
+ }
+ if (pageWrap.getModel().getFieldB() != null) {
+ queryWrapper.lambda().eq(PricingRule::getFieldB, pageWrap.getModel().getFieldB());
+ }
+ if (pageWrap.getModel().getFieldC() != null) {
+ queryWrapper.lambda().eq(PricingRule::getFieldC, pageWrap.getModel().getFieldC());
+ }
+ if (pageWrap.getModel().getFieldD() != null) {
+ queryWrapper.lambda().eq(PricingRule::getFieldD, pageWrap.getModel().getFieldD());
+ }
+ if (pageWrap.getModel().getFieldE() != null) {
+ queryWrapper.lambda().eq(PricingRule::getFieldE, pageWrap.getModel().getFieldE());
+ }
+ for (PageWrap.SortData sortData : pageWrap.getSorts()) {
+ if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
+ queryWrapper.orderByDesc(sortData.getProperty());
+ } else {
+ queryWrapper.orderByAsc(sortData.getProperty());
+ }
+ }
+ return PageData.from(pricingRuleMapper.selectPage(page, queryWrapper));
+ }
+
+ @Override
+ public long count(PricingRule pricingRule) {
+ QueryWrapper<PricingRule> wrapper = new QueryWrapper<>(pricingRule);
+ return pricingRuleMapper.selectCount(wrapper);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void batchSaveLocalStoragePricing(LocalStoragePricingSaveDTO request) {
+ // 鏍¢獙鍒嗙被鏁版嵁瀹屾暣鎬�
+ Set<Integer> requestCategoryIds = request.getItems().stream()
+ .map(LocalStoragePricingItemDTO::getCategoryId)
+ .collect(Collectors.toSet());
+ validateCategoryType4(requestCategoryIds);
+
+ // 閫愰」 upsert
+ Date now = new Date();
+ for (LocalStoragePricingItemDTO item : request.getItems()) {
+ // 鏌ヨ宸叉湁瑙勫垯
+ QueryWrapper<PricingRule> qw = new QueryWrapper<>();
+ qw.lambda()
+ .eq(PricingRule::getType, Constants.ZERO)
+ .eq(PricingRule::getFieldA, String.valueOf(item.getCategoryId()))
+ .eq(PricingRule::getCityId, request.getCityId())
+ .eq(PricingRule::getDeleted, Constants.ZERO)
+ .last("limit 1");
+ PricingRule existing = pricingRuleMapper.selectOne(qw);
+
+ if (existing != null) {
+ // 鏇存柊
+ existing.setFieldB(item.getUnitPrice());
+ existing.setUpdateTime(now);
+ pricingRuleMapper.updateById(existing);
+ } else {
+ // 鏂板缓
+ PricingRule rule = new PricingRule();
+ rule.setType(Constants.ZERO);
+ rule.setFieldA(String.valueOf(item.getCategoryId()));
+ rule.setFieldB(item.getUnitPrice());
+ rule.setCityId(request.getCityId());
+ rule.setDeleted(Constants.ZERO);
+ rule.setCreateTime(now);
+ rule.setUpdateTime(now);
+ pricingRuleMapper.insert(rule);
+ }
+ }
+ }
+
+ @Override
+ public List<LocalStoragePricingVO> listLocalStoragePricing(Integer cityId) {
+ // 1. 鏌ヨ鎵�鏈� Category type=4, deleted=0
+ Category categoryQuery = new Category();
+ categoryQuery.setType(Constants.FOUR);
+ categoryQuery.setDeleted(Constants.ZERO);
+ List<Category> allCategories = categoryMapper.selectList(new QueryWrapper<>(categoryQuery));
+ Map<Integer, String> categoryNameMap = allCategories.stream()
+ .collect(Collectors.toMap(Category::getId, Category::getName));
+
+ // 2. 鏌ヨ宸叉湁瑙勫垯
+ QueryWrapper<PricingRule> qw = new QueryWrapper<>();
+ qw.lambda()
+ .eq(PricingRule::getType, Constants.ZERO)
+ .eq(PricingRule::getCityId, cityId)
+ .eq(PricingRule::getDeleted, Constants.ZERO);
+ List<PricingRule> rules = pricingRuleMapper.selectList(qw);
+ Map<String, PricingRule> existingMap = rules.stream()
+ .collect(Collectors.toMap(PricingRule::getFieldA, r -> r));
+
+ // 3. 鍩轰簬鎵�鏈夊垎绫荤粍瑁� VO锛屾棤瑙勫垯鍒欒繑鍥炵┖璁板綍
+ return allCategories.stream().map(category -> {
+ LocalStoragePricingVO vo = new LocalStoragePricingVO();
+ vo.setCategoryId(category.getId());
+ vo.setCategoryName(category.getName());
+ vo.setCityId(cityId);
+
+ PricingRule rule = existingMap.get(String.valueOf(category.getId()));
+ if (rule != null) {
+ vo.setPricingRuleId(rule.getId());
+ vo.setUnitPrice(rule.getFieldB());
+ }
+ return vo;
+ }).collect(Collectors.toList());
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void batchSaveRemoteDeliveryPricing(RemoteDeliveryPricingSaveDTO request) {
+ // 鏍¢獙鍒嗙被鏁版嵁瀹屾暣鎬�
+ Set<Integer> requestCategoryIds = request.getItems().stream()
+ .map(RemoteDeliveryPricingItemDTO::getCategoryId)
+ .collect(Collectors.toSet());
+ Map<Integer, String> categoryMap = validateCategoryType4(requestCategoryIds);
+
+ // 閫愰」 upsert
+ Date now = new Date();
+ for (RemoteDeliveryPricingItemDTO item : request.getItems()) {
+ QueryWrapper<PricingRule> qw = new QueryWrapper<>();
+ qw.lambda()
+ .eq(PricingRule::getType, Constants.ONE)
+ .eq(PricingRule::getFieldA, String.valueOf(item.getCategoryId()))
+ .eq(PricingRule::getCityId, request.getCityId())
+ .eq(PricingRule::getDeleted, Constants.ZERO)
+ .last("limit 1");
+ PricingRule existing = pricingRuleMapper.selectOne(qw);
+
+ if (existing != null) {
+ existing.setFieldB(item.getStartDistance());
+ existing.setFieldC(item.getStartPrice());
+ existing.setFieldD(item.getExtraDistance());
+ existing.setFieldE(item.getExtraPrice());
+ existing.setUpdateTime(now);
+ pricingRuleMapper.updateById(existing);
+ } else {
+ PricingRule rule = new PricingRule();
+ rule.setType(Constants.ONE);
+ rule.setFieldA(String.valueOf(item.getCategoryId()));
+ rule.setFieldB(item.getStartDistance());
+ rule.setFieldC(item.getStartPrice());
+ rule.setFieldD(item.getExtraDistance());
+ rule.setFieldE(item.getExtraPrice());
+ rule.setCityId(request.getCityId());
+ rule.setDeleted(Constants.ZERO);
+ rule.setCreateTime(now);
+ rule.setUpdateTime(now);
+ pricingRuleMapper.insert(rule);
+ }
+ }
+ }
+
+ @Override
+ public List<RemoteDeliveryPricingVO> listRemoteDeliveryPricing(Integer cityId) {
+ // 1. 鏌ヨ鎵�鏈� Category type=4, deleted=0
+ Category categoryQuery = new Category();
+ categoryQuery.setType(Constants.FOUR);
+ categoryQuery.setDeleted(Constants.ZERO);
+ List<Category> allCategories = categoryMapper.selectList(new QueryWrapper<>(categoryQuery));
+ Map<Integer, String> categoryNameMap = allCategories.stream()
+ .collect(Collectors.toMap(Category::getId, Category::getName));
+
+ // 2. 鏌ヨ宸叉湁瑙勫垯
+ QueryWrapper<PricingRule> qw = new QueryWrapper<>();
+ qw.lambda()
+ .eq(PricingRule::getType, Constants.ONE)
+ .eq(PricingRule::getCityId, cityId)
+ .eq(PricingRule::getDeleted, Constants.ZERO);
+ List<PricingRule> rules = pricingRuleMapper.selectList(qw);
+ Map<String, PricingRule> existingMap = rules.stream()
+ .collect(Collectors.toMap(PricingRule::getFieldA, r -> r));
+
+ // 3. 鍩轰簬鎵�鏈夊垎绫荤粍瑁� VO锛屾棤瑙勫垯鍒欒繑鍥炵┖璁板綍
+ return allCategories.stream().map(category -> {
+ RemoteDeliveryPricingVO vo = new RemoteDeliveryPricingVO();
+ vo.setCategoryId(category.getId());
+ vo.setCategoryName(category.getName());
+ vo.setCityId(cityId);
+
+ PricingRule rule = existingMap.get(String.valueOf(category.getId()));
+ if (rule != null) {
+ vo.setPricingRuleId(rule.getId());
+ vo.setStartDistance(rule.getFieldB());
+ vo.setStartPrice(rule.getFieldC());
+ vo.setExtraDistance(rule.getFieldD());
+ vo.setExtraPrice(rule.getFieldE());
+ }
+ return vo;
+ }).collect(Collectors.toList());
+ }
+
+ /**
+ * 鏍¢獙璇锋眰涓殑 categoryId 涓庡垎绫昏〃 type=4 鏁版嵁瀹屽叏鍖归厤
+ * @param requestCategoryIds 璇锋眰涓殑 categoryId 闆嗗悎
+ * @return 鍒嗙被琛� id->name 鏄犲皠
+ */
+ private Map<Integer, String> validateCategoryType4(Set<Integer> requestCategoryIds) {
+ Category categoryQuery = new Category();
+ categoryQuery.setType(Constants.FOUR);
+ categoryQuery.setDeleted(Constants.ZERO);
+ List<Category> allType4Categories = categoryMapper.selectList(new QueryWrapper<>(categoryQuery));
+
+ Map<Integer, String> categoryMap = allType4Categories.stream()
+ .collect(Collectors.toMap(Category::getId, Category::getName));
+ Set<Integer> allCategoryIds = categoryMap.keySet();
+
+ // 鏍¢獙锛氳姹備腑瀛樺湪浣嗗垎绫昏〃涓笉瀛樺湪鐨� categoryId
+ List<String> invalidIds = requestCategoryIds.stream()
+ .filter(id -> !allCategoryIds.contains(id))
+ .map(String::valueOf)
+ .collect(Collectors.toList());
+ if (!invalidIds.isEmpty()) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),
+ "浠ヤ笅鐗╁搧瑙勬牸涓嶅瓨鍦�: " + String.join(", ", invalidIds));
+ }
+
+ // 鏍¢獙锛氬垎绫昏〃涓瓨鍦ㄤ絾璇锋眰涓己澶辩殑 categoryId
+ List<String> missingNames = allCategoryIds.stream()
+ .filter(id -> !requestCategoryIds.contains(id))
+ .map(id -> categoryMap.get(id) + "(" + id + ")")
+ .collect(Collectors.toList());
+ if (!missingNames.isEmpty()) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),
+ "缂哄皯浠ヤ笅鐗╁搧瑙勬牸鐨勫畾浠烽厤缃�: " + String.join(", ", missingNames));
+ }
+
+ return categoryMap;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void saveEstimatedDelivery(EstimatedDeliverySaveDTO request) {
+ // 鏌ヨ宸叉湁瑙勫垯 type=2, fieldA=1, cityId, deleted=0
+ QueryWrapper<PricingRule> qw = new QueryWrapper<>();
+ qw.lambda()
+ .eq(PricingRule::getType, Constants.TWO)
+ .eq(PricingRule::getFieldA, "1")
+ .eq(PricingRule::getCityId, request.getCityId())
+ .eq(PricingRule::getDeleted, Constants.ZERO)
+ .last("limit 1");
+ PricingRule existing = pricingRuleMapper.selectOne(qw);
+
+ Date now = new Date();
+ if (existing != null) {
+ // 鏇存柊
+ existing.setFieldB(request.getStartDistance());
+ existing.setFieldC(request.getStartTime());
+ existing.setFieldD(request.getContinueDistance());
+ existing.setFieldE(request.getContinueTime());
+ existing.setUpdateTime(now);
+ pricingRuleMapper.updateById(existing);
+ } else {
+ // 鏂板
+ PricingRule rule = new PricingRule();
+ rule.setType(Constants.TWO);
+ rule.setFieldA("1");
+ rule.setFieldB(request.getStartDistance());
+ rule.setFieldC(request.getStartTime());
+ rule.setFieldD(request.getContinueDistance());
+ rule.setFieldE(request.getContinueTime());
+ rule.setCityId(request.getCityId());
+ rule.setDeleted(Constants.ZERO);
+ rule.setCreateTime(now);
+ rule.setUpdateTime(now);
+ pricingRuleMapper.insert(rule);
+ }
+ }
+
+ @Override
+ public EstimatedDeliveryVO getEstimatedDelivery(Integer cityId) {
+ QueryWrapper<PricingRule> qw = new QueryWrapper<>();
+ qw.lambda()
+ .eq(PricingRule::getType, Constants.TWO)
+ .eq(PricingRule::getFieldA, "1")
+ .eq(PricingRule::getCityId, cityId)
+ .eq(PricingRule::getDeleted, Constants.ZERO)
+ .last("limit 1");
+ PricingRule rule = pricingRuleMapper.selectOne(qw);
+
+ EstimatedDeliveryVO vo = new EstimatedDeliveryVO();
+ vo.setCityId(cityId);
+ if (rule != null) {
+ vo.setPricingRuleId(rule.getId());
+ vo.setStartDistance(rule.getFieldB());
+ vo.setStartTime(rule.getFieldC());
+ vo.setContinueDistance(rule.getFieldD());
+ vo.setContinueTime(rule.getFieldE());
+ }
+ return vo;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void batchSaveStoreDeposit(StoreDepositSaveDTO request) {
+ // 鏍¢獙锛氬繀椤诲寘鍚� fieldType=0(浼佷笟) 鍜� fieldType=1(涓汉) 鍚勪竴鏉�
+ Set<Integer> fieldTypes = request.getItems().stream()
+ .map(StoreDepositItemDTO::getFieldType)
+ .collect(Collectors.toSet());
+ if (!fieldTypes.contains(Constants.ZERO) || !fieldTypes.contains(Constants.ONE)) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),
+ "蹇呴』鍖呭惈浼佷笟(0)鍜屼釜浜�(1)涓ゆ潯鏁版嵁");
+ }
+ if (request.getItems().size() != 2) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),
+ "鏈変笖浠呮湁2鏉℃暟鎹�");
+ }
+
+ Date now = new Date();
+ for (StoreDepositItemDTO item : request.getItems()) {
+ QueryWrapper<PricingRule> qw = new QueryWrapper<>();
+ qw.lambda()
+ .eq(PricingRule::getType, Constants.THREE)
+ .eq(PricingRule::getFieldA, String.valueOf(item.getFieldType()))
+ .eq(PricingRule::getCityId, request.getCityId())
+ .eq(PricingRule::getDeleted, Constants.ZERO)
+ .last("limit 1");
+ PricingRule existing = pricingRuleMapper.selectOne(qw);
+
+ if (existing != null) {
+ existing.setFieldB(item.getDepositAmount());
+ existing.setUpdateTime(now);
+ pricingRuleMapper.updateById(existing);
+ } else {
+ PricingRule rule = new PricingRule();
+ rule.setType(Constants.THREE);
+ rule.setFieldA(String.valueOf(item.getFieldType()));
+ rule.setFieldB(item.getDepositAmount());
+ rule.setCityId(request.getCityId());
+ rule.setDeleted(Constants.ZERO);
+ rule.setCreateTime(now);
+ rule.setUpdateTime(now);
+ pricingRuleMapper.insert(rule);
+ }
+ }
+ }
+
+ @Override
+ public List<StoreDepositVO> listStoreDeposit(Integer cityId) {
+ // 鏌ヨ宸叉湁瑙勫垯
+ QueryWrapper<PricingRule> qw = new QueryWrapper<>();
+ qw.lambda()
+ .eq(PricingRule::getType, Constants.THREE)
+ .eq(PricingRule::getCityId, cityId)
+ .eq(PricingRule::getDeleted, Constants.ZERO);
+ List<PricingRule> rules = pricingRuleMapper.selectList(qw);
+
+ // 鏋勫缓宸插瓨鍦ㄦ暟鎹殑鏄犲皠 fieldA -> rule
+ Map<String, PricingRule> existingMap = rules.stream()
+ .collect(Collectors.toMap(PricingRule::getFieldA, r -> r));
+
+ // 鍥哄畾杩斿洖2鏉★細浼佷笟(0)銆佷釜浜�(1)
+ List<StoreDepositVO> result = new ArrayList<>();
+ String[] typeNames = {"浼佷笟", "涓汉"};
+ for (int i = 0; i <= 1; i++) {
+ StoreDepositVO vo = new StoreDepositVO();
+ vo.setFieldType(i);
+ vo.setFieldTypeName(typeNames[i]);
+ vo.setCityId(cityId);
+
+ PricingRule rule = existingMap.get(String.valueOf(i));
+ if (rule != null) {
+ vo.setPricingRuleId(rule.getId());
+ vo.setDepositAmount(rule.getFieldB());
+ }
+ result.add(vo);
+ }
+ return result;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void batchSaveRevenueShare(RevenueShareSaveDTO request) {
+ // 鏍¢獙锛氬繀椤诲寘鍚� fieldType 0-4 鍚勪竴鏉�
+ Set<Integer> fieldTypes = request.getItems().stream()
+ .map(RevenueShareItemDTO::getFieldType)
+ .collect(Collectors.toSet());
+ if (fieldTypes.size() != Constants.FIVE) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),
+ "蹇呴』鍖呭惈浼佷笟瀵�(0)銆佷釜浜哄瘎(1)銆佷紒涓氬彇(2)銆佷釜浜哄彇(3)銆侀厤閫佸憳(4)鍏�5鏉℃暟鎹�");
+ }
+ for (int i = 0; i <= Constants.FOUR; i++) {
+ if (!fieldTypes.contains(i)) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),
+ "缂哄皯绫诲瀷" + i + "鐨勬暟鎹�");
+ }
+ }
+
+ Date now = new Date();
+ for (RevenueShareItemDTO item : request.getItems()) {
+ QueryWrapper<PricingRule> qw = new QueryWrapper<>();
+ qw.lambda()
+ .eq(PricingRule::getType, Constants.FOUR)
+ .eq(PricingRule::getFieldA, String.valueOf(item.getFieldType()))
+ .eq(PricingRule::getCityId, request.getCityId())
+ .eq(PricingRule::getDeleted, Constants.ZERO)
+ .last("limit 1");
+ PricingRule existing = pricingRuleMapper.selectOne(qw);
+
+ if (existing != null) {
+ existing.setFieldB(item.getRatio());
+ existing.setUpdateTime(now);
+ pricingRuleMapper.updateById(existing);
+ } else {
+ PricingRule rule = new PricingRule();
+ rule.setType(Constants.FOUR);
+ rule.setFieldA(String.valueOf(item.getFieldType()));
+ rule.setFieldB(item.getRatio());
+ rule.setCityId(request.getCityId());
+ rule.setDeleted(Constants.ZERO);
+ rule.setCreateTime(now);
+ rule.setUpdateTime(now);
+ pricingRuleMapper.insert(rule);
+ }
+ }
+ }
+
+ @Override
+ public List<RevenueShareVO> listRevenueShare(Integer cityId) {
+ // 鏌ヨ宸叉湁瑙勫垯
+ QueryWrapper<PricingRule> qw = new QueryWrapper<>();
+ qw.lambda()
+ .eq(PricingRule::getType, Constants.FOUR)
+ .eq(PricingRule::getCityId, cityId)
+ .eq(PricingRule::getDeleted, Constants.ZERO);
+ List<PricingRule> rules = pricingRuleMapper.selectList(qw);
+
+ // 鏋勫缓宸插瓨鍦ㄦ暟鎹殑鏄犲皠 fieldA -> rule
+ Map<String, PricingRule> existingMap = rules.stream()
+ .collect(Collectors.toMap(PricingRule::getFieldA, r -> r));
+
+ // 鍥哄畾杩斿洖5鏉★細浼佷笟瀵�(0)銆佷釜浜哄瘎(1)銆佷紒涓氬彇(2)銆佷釜浜哄彇(3)銆侀厤閫佸憳(4)
+ List<RevenueShareVO> result = new ArrayList<>();
+ String[] typeNames = {"浼佷笟瀵�", "涓汉瀵�", "浼佷笟鍙�", "涓汉鍙�", "閰嶉�佸憳"};
+ for (int i = 0; i <= Constants.FOUR; i++) {
+ RevenueShareVO vo = new RevenueShareVO();
+ vo.setFieldType(i);
+ vo.setFieldTypeName(typeNames[i]);
+ vo.setCityId(cityId);
+
+ PricingRule rule = existingMap.get(String.valueOf(i));
+ if (rule != null) {
+ vo.setPricingRuleId(rule.getId());
+ vo.setRatio(rule.getFieldB());
+ }
+ result.add(vo);
+ }
+ return result;
+ }
+
+}
--
Gitblit v1.9.3