package com.sw.mes.yb.pc.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.inspect.entity.YbInspectData;
import com.sw.mes.yb.pc.dao.DataInspectLogDao;
import com.sw.mes.yb.pc.dto.InspectDataBaseDto;
import com.sw.mes.yb.pc.entity.DataInspectLog;
import com.sw.mes.yb.pc.service.DataInspectLogService;
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 DataInspectLogServiceImpl extends BaseServiceImpl<DataInspectLog> implements DataInspectLogService {
    DataInspectLogDao dao;
	@Autowired
    public void setDao(DataInspectLogDao dao) {
        super.setBaseDao(dao);
        this.dao=dao;
    }

    @Override
    public ResponsePage<InspectDataBaseDto> getListPageInfo(String search_EQ_sectionNo, String search_EQ_crystalNo, String search_EQ_inspector,
                                                            String search_GTE_levelTime, String search_LT_levelTime, Pageable pageable) {
        Page<Map<String, Object>> page = dao.getPageListInfo(search_EQ_sectionNo, search_EQ_crystalNo, search_EQ_inspector,
                search_GTE_levelTime,search_LT_levelTime, pageable);
        List<InspectDataBaseDto> list = JSON.parseArray(JSON.toJSONString(page.getContent()), InspectDataBaseDto.class);

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

    @Override
    public List<InspectDataBaseDto> getListInfo(String search_EQ_sectionNo, String search_EQ_crystalNo, String search_EQ_inspector,
                                                String search_GTE_levelTime, String search_LT_levelTime) {
        Page<Map<String, Object>> page = dao.getPageListInfo(search_EQ_sectionNo, search_EQ_crystalNo, search_EQ_inspector,
                search_GTE_levelTime,search_LT_levelTime, null);
        List<InspectDataBaseDto> list = JSON.parseArray(JSON.toJSONString(page.getContent()), InspectDataBaseDto.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), InspectDataBaseDto.class);
    }

    @Override
    public List<DataInspectLog> getDataInspectLogBySectionNo(String sectionNo) {
        return dao.findBySectionNoAndIsCutBack(sectionNo, 0);
    }

    @Override
    public List<DataInspectLog> getDataInspectLog(String sectionNo) {
	    sectionNo = sectionNo + "%";
        return dao.getDataInspectLog(sectionNo);
    }
}
