package com.bonus.core.customer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bonus.core.customer.dto.CustInfoDTO;
import com.bonus.core.customer.dto.CustPayDTO;
import com.bonus.core.customer.model.CustInfo;
import com.bonus.core.customer.vo.CustInfoForRechargeVO;
import com.bonus.core.customer.vo.CustInfoVo;
import com.bonus.core.customer.vo.CustPayVO;
import com.bonus.core.order.vo.MacOrdCurrWriteOffVO;
import com.bonus.domain.CustCasual;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CustInfoMapper extends BaseMapper<CustInfo> {

   CustInfo selectOne(CustInfo custInfo);
   int updateById(CustInfo custInfo);

   CustInfoVo queryCustInfoDetail(@Param("info") CustInfo info);

   CustInfoVo queryCustInfo(@Param("info") CustInfoDTO info);

   @Select({"select c.cust_id, c.cust_name, c.mobile from cust_info c inner join acc_card a on c.cust_id = a.cust_id where a.serial_num = #{serialNum}"})
   CustInfo queryCustBySerialNum(String serialNum);


   @Select({"select cust_id from cust_info where cust_num = #{custNum} and cust_state=1"})
   Long selectCustIdByCustNum(String custNum);

   @Select({"SELECT cust_id FROM cust_info where cust_third_id = #{custThirdId} and cust_state = 1"})
   Long queryCustIdByCustThirdId(String custThirdId);

   @Select({"select cust_num, cust_name, org_full_name, cust_photo_url, ai.acc_bal from cust_info ci left join acc_info ai on ci.cust_id = ai.cust_id where ci.cust_id = #{custId} "})
   MacOrdCurrWriteOffVO getCustAccInfoByCustId(@Param("custId") Long custId);

   CustInfoForRechargeVO getCustInfoForRechargeByCustNum(@Param("custNum") String custNum, @Param("custState") Integer custState);

   List<CustInfoForRechargeVO> listCustInfoForRechargeByCustNums(@Param("custNumList") List<String> custNumList, @Param("custState") Integer custState);

   @Select({"SELECT DISTINCT t1.cust_num FROM cust_info t1 LEFT JOIN cust_photo t2 ON t1.cust_id = t2.cust_id WHERE t1.cust_state = 1 AND t2.features_build_status IS NULL OR t2.features_build_status = 1"})
   List<String> listCustNumNonFeatures();

   Long queryOrgManagerCustIdByCustId(@Param("custId") Long custId);

   Long getOrgManagerCustIdByCustId(@Param("custId") Long custId);

   List<CustPayVO> getCustPayVO(@Param("custPayDTO") CustPayDTO custPayDTO);

   public CustCasual selectCustCasualByCustId(@Param("custId") Long custId, @Param("sourceType") Integer sourceType, @Param("ifDel") Integer ifDel);

   int addCustCasual(CustCasual custCasual);

   int updateCustCasual(CustCasual custCasual);
}
