package com.dhcc.finance.main.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhcc.common.constant.SysConstants;
import com.dhcc.common.constant.SysStatusCode;
import com.dhcc.common.model.CurrencyMeta;
import com.dhcc.common.model.response.RestfulResponse;
import com.dhcc.finance.constant.FinanceDictConsts;
import com.dhcc.finance.main.dao.CwBdProductcellDetailMapper;
import com.dhcc.finance.main.dao.CwBdProductcellMapper;
import com.dhcc.finance.main.domain.CwBdProductcell;
import com.dhcc.finance.main.domain.CwBdProductcellExample;
import com.dhcc.finance.main.domain.CwBdProductcellExample.Criteria;
import com.dhcc.finance.main.service.CwBdProductcellService;
import com.dhcc.finance.util.MetaDataUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import brave.Tracer;
/**
 * 功能描述：项目单元
 * @author dml
 * @date 2019年10月2日 上午10:05:52
 * @修改日志：
 */
@Service
public class CwBdProductcellServiceImpl implements CwBdProductcellService{
	@Autowired
	CwBdProductcellMapper cwBdProductcellMapper;
	@Autowired
	CwBdProductcellDetailMapper cwBdProductcellDetailMapper;
	@Autowired
	private Tracer tracer;
	
	/*
	 * (非 Javadoc)  
	 * Title: searchCwBdProductcellAllData 
	 * Description:查询全部项目单元
	 * @return  
	 * @see com.dhcc.finance.main.service.CwBdProductcellService#searchCwBdProductcellAllData()    
	 * @author dml
	 * @date 2019年10月2日 上午10:06:07
	 * @修改日志：
	 */
	@Override
	public RestfulResponse<List<CwBdProductcell>, CurrencyMeta> searchCwBdProductcellAllData() {
		CwBdProductcellExample cwBdProductcellExample = new CwBdProductcellExample();
		Criteria createCriteria = cwBdProductcellExample.createCriteria();
		createCriteria.andUseStateEqualTo(FinanceDictConsts.Syzt.EFFECTIVE);
		List<CwBdProductcell> res = cwBdProductcellMapper.selectByExample(cwBdProductcellExample);
		return new RestfulResponse<List<CwBdProductcell>, CurrencyMeta>(SysConstants.CODE.SUCCESS,SysConstants.DEFAULT_MESSAGE.OPERATION_SUCCESS,res,
				MetaDataUtil.getMeta(tracer,SysStatusCode.OPERATION_SUCCESS));
	}
	/*
	 * (非 Javadoc)  
	 * <p>Title: searchCwBdProductcellOfList</p>  
	 * <p>Description:获取项目单元表数据列表 </p>
	 * @param code
	 * @param name
	 * @param pageNum
	 * @param pageSize
	 * @param navigatePages
	 * @return  
	 * @see com.dhcc.finance.main.service.CwBdProductcellService#searchCwBdProductcellOfList(java.lang.String, java.lang.String, int, int, int)    
	 * @author huangpeng
	 * @date 2019年10月5日 下午1:38:56
	 * @修改日志：
	 */
	@Override
	public RestfulResponse<PageInfo<CwBdProductcell>, CurrencyMeta> searchCwBdProductcellOfList(String code,
			String name, int pageNum, int pageSize, int navigatePages) {
		PageHelper.startPage(pageNum, pageSize,"CELL_CODE");
		CwBdProductcellExample cwBdProductcellExample = new CwBdProductcellExample();
		Criteria createCriteria = cwBdProductcellExample.createCriteria();
		createCriteria.andUseStateEqualTo(FinanceDictConsts.Syzt.EFFECTIVE);
		if(code!=null) {
			createCriteria.andCellCodeLike("%"+code+"%");
		}
		if(name!=null) {
			createCriteria.andCellNameLike("%"+name+"%");
		}
		List<CwBdProductcell> list = cwBdProductcellMapper.selectByExample(cwBdProductcellExample);
		PageInfo<CwBdProductcell> pageInfo = new PageInfo<>(list, navigatePages);
		return new RestfulResponse<PageInfo<CwBdProductcell>, CurrencyMeta>(SysConstants.CODE.SUCCESS,SysConstants.DEFAULT_MESSAGE.OPERATION_SUCCESS,pageInfo,MetaDataUtil.getMeta(tracer,SysStatusCode.OPERATION_SUCCESS));
	}
	/*
	 * (非 Javadoc)  
	 * <p>Title: deleteCwBdProductcellById</p>  
	 * <p>Description:删除单元数据 </p>
	 * @param idList
	 * @return  
	 * @see com.dhcc.finance.main.service.CwBdProductcellService#deleteCwBdProductcellById(java.util.List)    
	 * @author huangpeng
	 * @date 2019年10月5日 下午2:37:37
	 * @修改日志：
	 */
	@Override
	public RestfulResponse<Object, CurrencyMeta> deleteCwBdProductcellById(List<String> idList) {
		cwBdProductcellMapper.deleteCwBdProductcellById(idList);
		cwBdProductcellDetailMapper.deleteDetailByCellId(idList);
		return new RestfulResponse<Object, CurrencyMeta>(SysConstants.CODE.SUCCESS,SysConstants.DEFAULT_MESSAGE.OPERATION_SUCCESS,
				MetaDataUtil.getMeta(tracer,SysStatusCode.OPERATION_SUCCESS));
	}

}
