|
|
@@ -9,9 +9,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result;
|
|
|
import com.ylx.common.core.domain.R;
|
|
|
+import com.ylx.common.core.domain.entity.SysDictData;
|
|
|
import com.ylx.common.core.domain.model.WxLoginUser;
|
|
|
import com.ylx.common.exception.ServiceException;
|
|
|
import com.ylx.common.utils.DateUtils;
|
|
|
+import com.ylx.common.utils.DictUtils;
|
|
|
import com.ylx.common.utils.SecurityUtils;
|
|
|
import com.ylx.common.utils.StringUtils;
|
|
|
import com.ylx.common.weixinPay.enums.WxPayTypeEnum;
|
|
|
@@ -110,6 +112,7 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
private MaProjectMapper maProjectMapper;
|
|
|
@Resource
|
|
|
private IAfterSalesServiceService afterSalesServiceService;
|
|
|
+ private static final String DICT_TYPE = "unit_type";
|
|
|
|
|
|
@Override
|
|
|
public TOrder addOrder(TOrder order) {
|
|
|
@@ -505,7 +508,10 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
order.setProjectCover(project.getCover());
|
|
|
order.setHighlight(project.getHighlight());
|
|
|
order.setAppointmentStartTime(dto.getAppointmentStartTime());
|
|
|
- order.setProjectDuration(project.getStandardDuration());
|
|
|
+
|
|
|
+ // 根据项目的unitType字段将小时转换为分钟
|
|
|
+ Integer projectDuration = this.convertToMinutes(project.getStandardDuration(), project.getUnitType());
|
|
|
+ order.setProjectDuration(projectDuration);
|
|
|
order.setMerchantId(dto.getMerchantId());
|
|
|
order.setMerchantType(maTechnician.getTechType());
|
|
|
order.setMerchantNickName(maTechnician.getTeNickName());
|
|
|
@@ -519,7 +525,6 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
order.setFinalAmount(finalAmount);
|
|
|
order.setCouponId(dto.getCouponId());
|
|
|
order.setCreateTime(DateUtils.getNowDate());
|
|
|
- order.setAppointmentStartTime(dto.getAppointmentStartTime());
|
|
|
order.setStatus(0);
|
|
|
order.setExecStatus(0);
|
|
|
order.setDispatchedStatus(0);
|
|
|
@@ -835,4 +840,41 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据单位类型将时长转换为分钟
|
|
|
+ * @param duration 原始时长
|
|
|
+ * @param unitType 单位类型 (对应字典表: 1-分钟, 2-小时, 3-小时/次)
|
|
|
+ * @return 转换后的分钟数
|
|
|
+ */
|
|
|
+ private Integer convertToMinutes(Integer duration, Integer unitType) {
|
|
|
+ // 1. 防御性校验:避免自动拆箱导致的 NPE
|
|
|
+ if (duration == null || duration <= 0 || unitType == null) {
|
|
|
+ return duration;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 从字典缓存中获取数据(若依的 DictUtils 读取成本极低,无需自己做 DCL 锁)
|
|
|
+ List<SysDictData> dictList = DictUtils.getSortedDictCache(DICT_TYPE);
|
|
|
+ if (CollUtil.isEmpty(dictList)) {
|
|
|
+ return duration;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 使用局部变量构建映射,彻底杜绝多线程并发修改 HashMap 的风险
|
|
|
+ Map<Integer, Integer> localCoeffMap = new HashMap<>(dictList.size());
|
|
|
+ for (SysDictData data : dictList) {
|
|
|
+ try {
|
|
|
+ int type = Integer.parseInt(data.getDictValue());
|
|
|
+ // 根据业务规则设置倍率
|
|
|
+ int ratio = (type == 1) ? 1 : 60;
|
|
|
+ localCoeffMap.put(type, ratio);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("字典数据格式错误,跳过该条记录: {}", data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 获取倍率并计算,默认倍率为 1(即不转换)
|
|
|
+ int factor = localCoeffMap.getOrDefault(unitType, 1);
|
|
|
+ return duration * factor;
|
|
|
+ }
|
|
|
+
|
|
|
}
|