package com.uas.eis.service;

import com.uas.eis.dao.BaseDao;
import com.uas.eis.entity.ProdIODetail;
import com.uas.eis.entity.ProdInOut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @author: zhouy
 * @date: 2021/9/26 10:58
 * @desc: 出入库单据业务
 */
@Service
public class ProdInOutService{

    @Autowired
    private BaseDao baseDao;

    public ProdInOut findById(Integer id) {
        try {
            ProdInOut prodInOut = baseDao.getJdbcTemplate().queryForObject("SELECT * FROM PRODINOUT WHERE PI_ID=?", new BeanPropertyRowMapper<ProdInOut>(ProdInOut.class), id);
            List<ProdIODetail> prodIODetails = baseDao.getJdbcTemplate().query("SELECT * FROM PRODIODETAIL WHERE PD_PIID=? ORDER BY PD_PDNO ASC ", new BeanPropertyRowMapper<ProdIODetail>(ProdIODetail.class), prodInOut.getPi_id());
            prodInOut.setDetailList(prodIODetails);
            return prodInOut;
        } catch (EmptyResultDataAccessException e) {
            e.printStackTrace();
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
