排序
This commit is contained in:
1 parent
8e5c8ea24c
commit
b0b16ae58f
2 files changed
+34
-2
No files matched your search
@@ -0,0 +1,32 @@
|
||||
-- 回填 mch_manage.discounts_rate:
|
||||
-- 从 discounts_price 文案(如"享9.5折"、"享菜品7.8折(不含酒水)"、"全场95折")中提取"折"前面的数字,
|
||||
-- 折算规则与 discounts_rate 语义(1-99,10=1折)一致:
|
||||
-- 小数或个位整数("9.5折"->95、"9折"->90、"0.5折"->5) 乘以10;
|
||||
-- 两位整数("95折")本身即百分比,保持原值 -> 95。
|
||||
-- 仅填充 discounts_rate 为空的行,已配置的值不覆盖;提取不到"数字+折"或折算结果不在 1-99 的行跳过。
|
||||
|
||||
-- ① 预览:执行前先跑这条,人工确认折算结果
|
||||
SELECT id, name, discounts_price,
|
||||
ROUND(CAST(REPLACE(REGEXP_SUBSTR(discounts_price, '[0-9]+(\\.[0-9]+)?折'), '折', '') AS DECIMAL(10, 2))
|
||||
* IF(CAST(REPLACE(REGEXP_SUBSTR(discounts_price, '[0-9]+(\\.[0-9]+)?折'), '折', '') AS DECIMAL(10, 2)) < 10, 10, 1)) AS will_rate
|
||||
FROM mch_manage
|
||||
WHERE discounts_rate IS NULL
|
||||
AND discounts_price REGEXP '[0-9]+(\\.[0-9]+)?折';
|
||||
|
||||
-- ② 执行回填
|
||||
UPDATE mch_manage m
|
||||
JOIN (SELECT id,
|
||||
ROUND(CAST(REPLACE(REGEXP_SUBSTR(discounts_price, '[0-9]+(\\.[0-9]+)?折'), '折', '') AS DECIMAL(10, 2))
|
||||
* IF(CAST(REPLACE(REGEXP_SUBSTR(discounts_price, '[0-9]+(\\.[0-9]+)?折'), '折', '') AS DECIMAL(10, 2)) < 10,
|
||||
10, 1)) AS rate
|
||||
FROM mch_manage
|
||||
WHERE discounts_rate IS NULL
|
||||
AND discounts_price REGEXP '[0-9]+(\\.[0-9]+)?折') t ON t.id = m.id
|
||||
SET m.discounts_rate = t.rate
|
||||
WHERE t.rate BETWEEN 1 AND 99;
|
||||
|
||||
-- ③ 核对:回填结果与原文对照
|
||||
SELECT id, name, discounts_price, discounts_rate
|
||||
FROM mch_manage
|
||||
WHERE discounts_rate IS NOT NULL
|
||||
ORDER BY update_time DESC;
|
||||
+2
-2
@@ -30,8 +30,8 @@ public interface MchManageMapper extends PjcloudBaseMapper<MchManageEntity> {
|
||||
.likeIfExists(MchManageEntity::getName, dto.getName())
|
||||
.in(ObjectUtil.isNotEmpty(dto.getDeptIds()), MchManageEntity::getDeptId, dto.getDeptIds())
|
||||
.apply(ObjectUtil.isNotEmpty(dto.getType()), "FIND_IN_SET({0}, types)", dto.getType())
|
||||
// 优惠折扣(1-99,10=1折)越小折扣越大:有折扣的排在无折扣(ifnull补100)前面,1折排在2折前面
|
||||
.last("order by ifnull(discounts_rate, 100) asc, sort desc, create_time desc, id desc");
|
||||
// 排序:优惠折扣(1-99,10=1折)越小折扣越大优先;同档内有优惠价格文案(discounts_price非空)的靠前;再按sort/创建时间/id
|
||||
.last("order by ifnull(discounts_rate, 100) asc, (ifnull(discounts_price, '') = '') asc, sort desc, create_time desc, id desc");
|
||||
return selectJoinPage(page, MchManageVo.class, wrapper);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user