package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.busi.bu3;

import cn.estsh.i3plus.ext.mes.api.busi.bu3.ISxProdDataToStatisticsTravelService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesProdDataToStatisticsTravel;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesProdDataToStatisticsTravelRepository;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SxProdDataToStatisticsTravelService implements ISxProdDataToStatisticsTravelService {

    @Autowired
    private MesProdDataToStatisticsTravelRepository prodDataToStatisticsTravelRepository;

    @Override
    public MesProdDataToStatisticsTravel getProdDataToStatisticsTravel(String organizeCode, String moduleCode, String statisticsType, String statisticsDate, String dataKey) {
        DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
        DdlPreparedPack.getStringEqualPack(moduleCode, MesExtConstWords.MODULE_CODE, packBean);
        DdlPreparedPack.getStringEqualPack(statisticsType, MesExtConstWords.STATISTICS_TYPE, packBean);
        DdlPreparedPack.getStringEqualPack(statisticsDate, MesExtConstWords.STATISTICS_DATE, packBean);
        DdlPreparedPack.getStringEqualPack(dataKey, MesExtConstWords.DATA_KEY, packBean);
        return prodDataToStatisticsTravelRepository.getByProperty(packBean);
    }

    @Override
    public MesProdDataToStatisticsTravel doTravel(MesProdDataToStatisticsTravel travel) {
        travel.setSystemSyncStatus(MesExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
        ConvertBean.serviceModelInitialize(travel, travel.getCreateUser());
        return prodDataToStatisticsTravelRepository.insert(travel);
    }


}
