package com.sw.mes.fb.turnstore.service.impl;


import com.alibaba.fastjson.JSON;
import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.core.response.ResponsePage;
import com.sw.mes.fb.turnstore.dao.RawMaterialReceivingDetailDao;
import com.sw.mes.fb.turnstore.dto.ReturnDetailsOfSquareRodDto;
import com.sw.mes.fb.turnstore.entity.RawMaterialReceivingDetail;
import com.sw.mes.fb.turnstore.service.RawMaterialReceivingDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


/**
* @Author
* @Description：
* @Date: Create in
* @Modified By:
*/
@Service
@Transactional
public class RawMaterialReceivingDetailServiceImpl extends BaseServiceImpl<RawMaterialReceivingDetail> implements RawMaterialReceivingDetailService {
    RawMaterialReceivingDetailDao dao;
	@Autowired
    public void setDao(RawMaterialReceivingDetailDao dao) {
        super.setBaseDao(dao);
        this.dao=dao;
    }

    @Override
    public List<RawMaterialReceivingDetail> findByTrayNoAndState(String trayNo,int state) {
        return dao.findByTrayNoAndState(trayNo,state);
    }

    @Override
    public List<RawMaterialReceivingDetail> findBySectionNoAndState(String sectionNo, int state) {
        return dao.findBySectionNoAndState(sectionNo,state);
    }

    @Override
    public ResponsePage<ReturnDetailsOfSquareRodDto> getListPageInfo(String search_EQ_crystalNo, String search_GTE_confirmTime, String search_LT_confirmTime,String search_EQ_quitType, String search_EQ_state, String search_GTE_time,
                                                                     String search_LT_time,String search_EQ_outOrderNo, Pageable pageable) {
        Page<Map<String, Object>> page = dao.getPageListInfo(search_EQ_crystalNo,search_GTE_confirmTime,search_LT_confirmTime, search_EQ_quitType,search_EQ_state,search_GTE_time,search_LT_time,search_EQ_outOrderNo, pageable);
        List<ReturnDetailsOfSquareRodDto> list = JSON.parseArray(JSON.toJSONString(page.getContent()), ReturnDetailsOfSquareRodDto.class);

        return new ResponsePage(list, page.getTotalElements());
    }

    @Override
    public List<ReturnDetailsOfSquareRodDto> getListInfo(String search_EQ_crystalNo, String search_GTE_confirmTime, String search_LT_confirmTime,String search_EQ_quitType, String search_EQ_state, String search_GTE_time,
                                                         String search_LT_time,String search_EQ_outOrderNo) {
        Page<Map<String, Object>> page = dao.getPageListInfo(search_EQ_crystalNo,search_GTE_confirmTime,search_LT_confirmTime, search_EQ_quitType, search_EQ_state, search_GTE_time,
                 search_LT_time, search_EQ_outOrderNo, null);
        List<ReturnDetailsOfSquareRodDto> list = JSON.parseArray(JSON.toJSONString(page.getContent()), ReturnDetailsOfSquareRodDto.class);
        for (int q = 0;q < list.size();q++){
            list.get(q).setState(list.get(q).getState() != null ? (list.get(q).getState().equals("1") ? "已入库" : "") : "");
        }
        return JSON.parseArray(JSON.toJSONString(list), ReturnDetailsOfSquareRodDto.class);
    }
}
