package org.ta.pddserver.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
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 org.ta.pddserver.entity.CollectOrderEntity;
import org.ta.pddserver.model.api.response.CollectOrderListResponse;
import org.ta.pddserver.model.api.response.CollectOrderResponse;

import java.util.List;

@Mapper
public interface CollectOrderMapper extends BaseMapper<CollectOrderEntity> {

    @Select("SELECT `uid`,`orderCode`, `itemQuantityTotal`, `segmentCode` FROM `collect_order` WHERE `orderCode` = #{orderCode};")
    CollectOrderResponse findByOrderCode(String orderCode);

    @Update("UPDATE `collect_order` SET `status` = #{status} WHERE `uid` = #{uid};")
    int updateOrderStatusById(int status, String uid);

    @Select("SELECT `uid`, `orderCode`, `itemQuantityTotal`, `segmentCode`, `consoType` FROM `collect_order` WHERE `orderCode` = #{orderCode} AND `status` = ${status}")
    List<CollectOrderListResponse> getList(@Param("orderCode") String orderCode, @Param("status") int status);

    @Select("SELECT `uid`, `orderCode`, `itemQuantityTotal`, `segmentCode`, `consoType` FROM `collect_order` WHERE `orderCode` = #{orderCode};")
    CollectOrderResponse getInfoByOrderCode(@Param("orderCode") String orderCode);
}
