package com.lightinit.hsdataplatform.impl.admin;

import com.lightinit.hsdataplatform.dictionary.DicOfflineConferenceOrderState;
import com.lightinit.hsdataplatform.entity.BaseExample;
import com.lightinit.hsdataplatform.mapper.OfflineConferenceMapper;
import com.lightinit.hsdataplatform.model.ResultState;
import com.lightinit.hsdataplatform.model.ResultStateCode;
import com.lightinit.hsdataplatform.model.admin.OfflineConferenceHeableModel;
import com.lightinit.hsdataplatform.model.admin.OfflineConferenceListModel;
import com.lightinit.hsdataplatform.model.admin.OfflineConferenceSearchModel;
import com.lightinit.hsdataplatform.service.admin.IOfflineConferenceService;
import com.lightinit.hsdataplatform.spring.DynamicDataContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OfflineConferenceServiceImpl implements IOfflineConferenceService {

    @Autowired
    private OfflineConferenceMapper offlineConferenceMapper ;

    @Override
    public List<OfflineConferenceListModel> queryList(OfflineConferenceSearchModel inputModel, BaseExample.Page page) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        inputModel.setPage(page);
        List<OfflineConferenceListModel> list = offlineConferenceMapper.queryList(inputModel) ;
        return list;
    }

    @Override
    public long queryCount(OfflineConferenceSearchModel inputModel) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        return offlineConferenceMapper.queryCount(inputModel);
    }

    @Override
    public OfflineConferenceListModel queryOne(long id) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        return offlineConferenceMapper.queryOne(id);
    }

    @Override
    public ResultState<Long> handle(OfflineConferenceHeableModel inputModel) {
        inputModel.setOrderState(DicOfflineConferenceOrderState.ALREADY_PROCESSED);
        ResultState<Long> resultState = new ResultState<Long>();
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        long sqlResult = offlineConferenceMapper.handle(inputModel);
        if (!(sqlResult > 0)){
            resultState.setStateCode(ResultStateCode.INVALID_DATA);
            resultState.setMsg("处理操作失败");
        }
        resultState.setData(inputModel.getId());
        return resultState;
    }
}
