package thyyxxk.webserver.dao.his.medicine;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
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 thyyxxk.webserver.entity.medicine.YpInDetlVo;

import java.util.List;

/**
 * @ClassName YpInDetlDao
 * @Author hsh
 * @Date 2025/6/30 0030 14:51
 * @Version 1.0
 * @Description 入库
 **/
@Mapper
public interface YpInDetlDao extends BaseMapper<YpInDetlVo> {


    @Select(" select convert(varchar(100), de.in_date, 20) as inDate, rtrim(de.in_docu_no) as inDocuNo, rtrim(de.rept_no) as reptNo, " +
            "   de.confirm_flag, de.in_type, de.group_no, rtrim(de.charge_code) as chargeCode, de.serial, de.in_seri, de.buy_amt, de.buy_price, " +
            "   convert(varchar(100), de.producing_date, 20) as producingDate, convert(varchar(100), de.eff_date, 23) as effDate, " +
            "   rtrim(de.manu_no) as manuNo, de.manu_code, de.manufacture, de.supply_code, rtrim(de.license_no) as licenseNo, " +
            "   de.acct_id, de.input_id, de.checker, de.purchaser, de.acct_type, de.stock_amount, de.rept_date, " +
            "   rtrim(zd.name) as chargeName, rtrim(zd.specification) as specification, " +
            "   rtrim(mi.name) as purchaserName, rtrim(sy.name) as supplyName, sy.supply_code as supplyId " +
            " from yp_in_detl as de " +
            " left join yp_zd_dict as zd on de.charge_code = zd.code and de.serial = zd.serial " +
            " left join a_employee_mi as mi on de.purchaser = mi.code " +
            " left join yp_zd_supply as sy on de.supply_code = sy.code " +
            " where ${ew.sqlSegment} " +
            " and de.confirm_flag = '1' and de.buy_amt > 0 " +
            " order by de.in_docu_no desc, de.in_seri ")
    List<YpInDetlVo> selectYpInDetlVoList(@Param(Constants.WRAPPER) QueryWrapper<?> qw);

    @Select(" select top 1 * from yp_in_detl where confirm_flag = '1' and buy_amt > 0 and rept_no = #{reptNo} and manu_no = #{manuNo} ")
    YpInDetlVo selectYpInDetlListByNo(@Param("reptNo") String reptNo, @Param("manuNo") String manuNo);

    @Select(" select convert(varchar(100), d.in_date, 20) as inDate, rtrim(d.in_docu_no) as inDocuNo, rtrim(d.rept_no) as reptNo, " +
            "   d.confirm_flag, d.in_type, d.group_no, rtrim(d.charge_code) as chargeCode, d.serial, d.in_seri, d.buy_amt, d.buy_price, " +
            "   convert(varchar(100), d.producing_date, 20) as producingDate, convert(varchar(100), d.eff_date, 23) as effDate, " +
            "   rtrim(d.manu_no) as manuNo, d.manu_code, d.manufacture, d.supply_code, rtrim(d.license_no) as licenseNo, " +
            "   d.acct_id, d.input_id, d.checker, d.purchaser, d.acct_type, d.stock_amount, d.rept_date, " +
            "   rtrim(s.name) as chargeName, rtrim(s.specification) as specification, " +
            "   rtrim(mi.name) as purchaserName, rtrim(sy.name) as supplyName, sy.supply_code as supplyId " +
            " from yp_in_detl as d " +
            " inner join yp_zd_dict as s on d.charge_code = s.code and d.serial = s.serial" +
            " left join a_employee_mi as mi on d.purchaser = mi.code " +
            " left join yp_zd_supply as sy on d.supply_code = sy.code " +
            " where d.confirm_flag = '1' " +
            " and d.buy_amt > 0 " +
            " and d.manu_no = #{manuNo} " +
            " and s.name like '%${drugName}%' " +
            " order by d.in_date desc ")
    List<YpInDetlVo> selectYpInDetlListByName(@Param("manuNo") String manuNo, @Param("drugName") String drugName);
}
