package shop.alien.mapper.second;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import shop.alien.entity.second.SecondGoodsRecord;
import shop.alien.entity.second.SecondRiskControlRecord;
import shop.alien.entity.second.vo.SecondRiskControlRecordVo;

import java.util.List;

/**
 * 二手商品风控记录映射器
 */
public interface SecondRiskControlRecordMapper extends BaseMapper<SecondRiskControlRecord> {


    @Select(" select r.*, case when r.rule_type = 1 then '洗钱嫌疑' when r.rule_type = 2 then '账号异常' " +
            " when r.rule_type = 3 then '交易欺诈' when r.rule_type = 4 then '异常发布' end ruleTypeName,  " +
            " case when r.rule_type = 1 then '高频高价交易' when r.rule_type = 2 then '同一设备/mac 24小时内注册超过3个账号' " +
            " when r.rule_type = 3 then '用户频繁修改商品' when r.rule_type = 4 then '短时间大量发布同类商品' end ruleName, " +
            " case when r.rule_type = 1 or r.rule_type = 2 then '中风险' when r.rule_type = 3 or r.rule_type = 4 then '高风险' end ruleRisk,  " +
            " case when r.risk_status = 0 then '待处理' when r.risk_status = 1 then '已处理' " +
            " when r.risk_status = 2 then '已忽略' end riskStatusName,  " +
            " case when r.rule_type = 1 or r.rule_type = 3 or r.rule_type = 4 then u.user_phone " +
            " else '--' end userPhone " +
            " from second_risk_control_record r left join life_user u on r.user_id = u.id " +
            " ${ew.customSqlSegment} ")
    IPage<SecondRiskControlRecordVo> queryRiskControlRecords(IPage<SecondRiskControlRecordVo> page, @Param(Constants.WRAPPER) QueryWrapper<SecondRiskControlRecordVo> queryWrapper);


    @Select(" select * from second_risk_control_record " +
            " WHERE created_time BETWEEN DATE_FORMAT(#{starDate}, '%Y-%m-%d %H:%i:%s') " +
            " AND DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%s') AND business_id = #{macIp} ")
    List<SecondRiskControlRecord> selectByBusinessId(@Param("starDate") String starDate, @Param("endDate") String endDate, @Param("macIp") String macIp);
}