package cn.com.ty.lift.ud.liftCaseAppeal.mapper;


import java.math.BigDecimal;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import cn.com.ty.lift.ud.chat.mapper.entity.LiftCaseEntity;
import cn.com.ty.lift.ud.liftCaseAppeal.controller.query.LiftCaseAppealQuery;
import cn.com.ty.lift.ud.liftCaseAppeal.mapper.entity.LiftCaseAppealEntity;

/**
 * 诊单申诉 -Repository
 *
 * @author Xson
 * @date 2020-04-23
 */
public interface LiftCaseAppealMapper extends BaseMapper<LiftCaseAppealEntity> {

    List<LiftCaseAppealEntity> selectByQuery(@Param("ew") Wrapper condition, @Param("page") LiftCaseAppealQuery page);

    int countByQuery(@Param("ew") Wrapper condition);

    /**
     * 结束申诉
     *
     * @param id
     */
    @Update("update lift_case_appeal set statuz = 3 where id = #{id}")
    void endAppeal(Long id);

    /**
     * 查询总价格
     * @param id
     * @return
     */
    @Select("select c.service_cost from lift_case_appeal a left join lift_case c on c.id = a.data_id where a.id = #{id}")
    BigDecimal selectServiceCost(Long id);

    /**
     * 修改状态为已退款
     * @param id
     */
    @Update("update lift_case_appeal set statuz = 4 where id = #{id}")
    void refund(Long id);

    /**
     * 根据诊单ID查询当前诊单是否申诉过
     * @param dataId
     * @return LiftCaseAppealEntity
     */
    @Select("select * from lift_case_appeal  where data_id = #{dataId}")
    LiftCaseAppealEntity getByDataId(@Param("dataId") Long dataId);

    /**
     * 根据数据ID修改状态为1 未结束
     * @param dataId
     * @return
     */
    @Update("update lift_case_appeal set statuz = 1 where data_id = #{dataId}")
    int updateByDataId(@Param("dataId") Long dataId);
    
    List<LiftCaseEntity>selectListByUserForCase(@Param("page") LiftCaseAppealQuery query);
    
    int selectCountByUserForCase(@Param("page") LiftCaseAppealQuery query);
}
