package com.njcn.serviceimpl.user;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import com.njcn.pojo.user.TfLgAssByMe;
import com.njcn.pojo.user.TfLgAssDetail;
import com.njcn.serviceimpl.weeklyreport.WeeklyReportDataServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.njcn.mapper.user.TfLgAssMapper;
import com.njcn.pojo.configuration.SysSet;
import com.njcn.pojo.user.TfLgAss;
import com.njcn.sso.pojo.user.User;
import com.njcn.service.user.TfLgAssService;
import com.njcn.shiro.token.TokenManager;

import tk.mybatis.mapper.entity.Example;

@Service
public class TfLgAssServiceImpl implements TfLgAssService {
	private static final Logger logger = LoggerFactory.getLogger(TfLgAssServiceImpl.class);
	@Resource
	private TfLgAssMapper tflg;
	
	@Override
	public List<TfLgAss> selectIdAll(String tfIndex) {
		// TODO Auto-generated method stub
		return tflg.selectIdAll(tfIndex);
	}


	@Override
	public int updateTfLgAss(String tfIndex,String userIndex, int logicBefore, int logicNext) {
		// TODO Auto-generated method stub
		int flag=0;
		try {
			User user = TokenManager.getToken();
			userIndex=user.getUserIndex();
			tflg.updateTfLgAss(tfIndex, userIndex, logicBefore, logicNext);
			flag=1;
		} catch (Exception e) {
			// TODO: handle exception
			flag=0;
		}
		return flag;
	}

	@Override
	public int insertTfLgAss(String tfLgAss_Index, Date updatetime, String tfIndex, String userIndex, int logicBefore,
			int logicNext,Integer state) {
		int flag=0;
		try{
			
			tfLgAss_Index=java.util.UUID.randomUUID().toString();
			User user = TokenManager.getToken();
			userIndex=user.getUserIndex();
			updatetime=new Date();
			state=1;
			tflg.insertTfLgAss(tfLgAss_Index, updatetime, tfIndex, userIndex, logicBefore, logicNext,state);
			flag=1;
		}catch (Exception e) {
			// TODO: handle exception
			flag=0;
		}
		return flag;
	}


	@Override
	public List<TfLgAssByMe> selectByMe(String tfIndex) {
		// TODO Auto-generated method stub
		List<TfLgAssByMe> list=tflg.selectByMe(tfIndex);
		return list;
	}

	@Override
	public int getSubvIndex(int subIndex) {
		return tflg.getSubvIndex(subIndex);
	}

	@Override
	public TfLgAssDetail getBeforeNext(int subIndex, String tfIndex) {
		TfLgAssDetail tfLgAssDetail = new TfLgAssDetail();
		try {
			tfLgAssDetail.setLogicBefore(tflg.getLogicBefore(subIndex,tfIndex));
			tfLgAssDetail.setLogicNext(tflg.getLogicNext(subIndex,tfIndex));
		}catch (Exception e){
			logger.error(e.getMessage());
		}


		return tfLgAssDetail;
	}

	@Override
	public TfLgAssDetail getKBeforeNext(int subIndex) {
		TfLgAssDetail tfLgAssDetail = new TfLgAssDetail();
		try {
			tfLgAssDetail.setLogicBefore(tflg.getKBefore(subIndex));
			tfLgAssDetail.setLogicNext(tflg.getKNext(subIndex));
		}catch (Exception e){
			logger.error(e.getMessage());
		}


		return tfLgAssDetail;
	}

}
