package thyyxxk.webserver.dao.his.outpatient.interactive;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.outpatient.interactive.comments.response.WechatPatientComment;

import java.util.Date;
import java.util.List;

@Mapper
public interface CommentsDao {
    @Select("select * from " +
            "(SELECT ROW_NUMBER() OVER(ORDER BY id) AS idx,*, " +
            "department=(select rtrim(d.dept_code) from a_employee_mi d where d.code=doctor_code), " +
            "patPhoneNo=(select rtrim(d.phone_no) from mz_patient_mi d where d.patient_id=a.patient_id) " +
            "from t_wechat_patient_comment a ${ew.customSqlSegment}) t " +
            "where t.idx>(#{page}-1)*#{size} and t.idx<=#{page}*#{size}")
    List<WechatPatientComment> selectComments(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper,
                                              @Param("page") int page, @Param("size") int size);

    @Select("select count(1) from t_wechat_patient_comment ${ew.customSqlSegment}")
    int selectValidCount(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);

    @Update("update t_wechat_patient_comment set deleted=#{val},delete_staff=#{staff},delete_time=#{date} where id=#{id}")
    int updateCommentStatus(int id, int val, String staff, Date date);
}
