|
|
@@ -14,17 +14,21 @@ import com.ylx.fareSetting.domian.vo.FareCalculateResultVO;
|
|
|
import com.ylx.fareSetting.mapper.MaProjectFareSettingMapper;
|
|
|
import com.ylx.fareSetting.service.IMaProjectFareSettingService;
|
|
|
import com.ylx.massage.domain.TAddress;
|
|
|
+import com.ylx.massage.domain.TFareFreeRule;
|
|
|
+import com.ylx.massage.domain.dto.DriverFeeDTO;
|
|
|
import com.ylx.massage.domain.vo.TFareSettingVo;
|
|
|
import com.ylx.massage.service.TAddressService;
|
|
|
import com.ylx.massage.service.TFareSettingService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
@@ -233,4 +237,74 @@ public class MaProjectFareSettingServiceImpl extends ServiceImpl<MaProjectFareSe
|
|
|
return targetTime.equals(startTime);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 保存免车费设置信息
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void saveOrUpdateFee(DriverFeeDTO dto){
|
|
|
+ // 1. 基础校验:检查是否有空值 (对应UI中的“判断必填项是否为空”)
|
|
|
+ validateInput(dto);
|
|
|
+
|
|
|
+ if (dto.getMode() == 1) {
|
|
|
+ // --- 模式一:统一设置 ---
|
|
|
+ // 逻辑:删除该用户所有具体的项目配置,只保留一条 categoryId=null 的记录
|
|
|
+ baseMapper.delete(new LambdaQueryWrapper<MaProjectFareSetting>()
|
|
|
+ .eq(MaProjectFareSetting::getMerchantId, dto.getMerchantId()));
|
|
|
+
|
|
|
+ MaProjectFareSetting config = new MaProjectFareSetting();
|
|
|
+ config.setMerchantId(dto.getMerchantId());
|
|
|
+ config.setProjectId(null);
|
|
|
+ config.setDayFreeKm(dto.getUnifiedConfig().getDayFreeKm());
|
|
|
+ config.setNightFreeKm(dto.getUnifiedConfig().getNightFreeKm());
|
|
|
+ baseMapper.insert(config);
|
|
|
+
|
|
|
+ } else if (dto.getMode() == 2) {
|
|
|
+ // --- 模式二:按项目设置 ---
|
|
|
+ // 逻辑:先删除旧数据,再批量插入新数据
|
|
|
+ baseMapper.delete(new LambdaQueryWrapper<MaProjectFareSetting>()
|
|
|
+ .eq(MaProjectFareSetting::getMerchantId, dto.getMerchantId()));
|
|
|
+
|
|
|
+ List<MaProjectFareSetting> list = new ArrayList<>();
|
|
|
+ for (DriverFeeDTO.CategoryFeeItem item : dto.getCategoryConfigs()) {
|
|
|
+ MaProjectFareSetting config = new MaProjectFareSetting();
|
|
|
+ config.setMerchantId(dto.getMerchantId());
|
|
|
+ config.setIsUnified(0);
|
|
|
+ config.setProjectId(item.getCategoryId());
|
|
|
+ config.setProjectName(item.getCategoryName());
|
|
|
+ config.setDayFreeKm(item.getDayFreeKm());
|
|
|
+ config.setNightFreeKm(item.getNightFreeKm());
|
|
|
+ list.add(config);
|
|
|
+ }
|
|
|
+ // 批量保存
|
|
|
+ for (MaProjectFareSetting config : list) {
|
|
|
+ baseMapper.insert(config);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 校验输入是否合法 (对应UI中的 Toast 提示逻辑)
|
|
|
+ */
|
|
|
+ private void validateInput(DriverFeeDTO dto) {
|
|
|
+ if (dto.getMode() == 1) {
|
|
|
+ if (dto.getUnifiedConfig() == null ||
|
|
|
+ dto.getUnifiedConfig().getDayFreeKm() == null ||
|
|
|
+ dto.getUnifiedConfig().getNightFreeKm() == null) {
|
|
|
+ throw new RuntimeException("请输入完整的统一设置里程");
|
|
|
+ }
|
|
|
+ } else if (dto.getMode() == 2) {
|
|
|
+ if (CollectionUtils.isEmpty(dto.getCategoryConfigs())) {
|
|
|
+ throw new RuntimeException("请至少配置一个项目的免车费");
|
|
|
+ }
|
|
|
+ for (DriverFeeDTO.CategoryFeeItem item : dto.getCategoryConfigs()) {
|
|
|
+ if (item.getDayFreeKm() == null || item.getNightFreeKm() == null) {
|
|
|
+ throw new RuntimeException("分类ID[" + item.getCategoryId() + "]的里程设置不完整");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|