| ¶Ô±ÈÐÂÎļþ |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |