package com.pj.ht_import_declare_people;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pj.api.dto.ImportDeclarePeopleDto;
import com.pj.common.core.exception.ServiceException;
import com.pj.utils.so.SoMap;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import com.pj.utils.sg.*;

/**
 * Service: ht_import_declare_people -- 进口申报单边民确认表
 * @author yzs 
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class HtImportDeclarePeopleService extends ServiceImpl<HtImportDeclarePeopleMapper, HtImportDeclarePeople> implements IService<HtImportDeclarePeople>{

	/** 底层 Mapper 对象 */
	@Autowired
	HtImportDeclarePeopleMapper htImportDeclarePeopleMapper;

	/** 增 */
	void add(HtImportDeclarePeople h){
		save(h);
	}

	/** 删 */
	void delete(Long id){
		removeById(id);
	}

	/** 改 */
	void update(HtImportDeclarePeople h){
		updateById(h);

	}

	/** 查 */
	HtImportDeclarePeople getById(Integer id){
		return super.getById(id);
	}

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */  
	List<HtImportDeclarePeople> getList(SoMap so) { 
		return htImportDeclarePeopleMapper.getList(so);	
	}
	

	/** 远程调用: 根据便民身份证号 和 进出口结算单号查询[进口申报单边民确认] 将该对象返还航通 */
	public ImportDeclarePeopleDto getByIdNoAndPreleportNo(String idNo,String preleportNo){
		ImportDeclarePeopleDto importDeclarePeopleDto = new ImportDeclarePeopleDto();
		List<HtImportDeclarePeople> htImportDeclarePeople = htImportDeclarePeopleMapper.selectList(new LambdaQueryWrapper<HtImportDeclarePeople>().eq(HtImportDeclarePeople::getIdno, idNo).eq(HtImportDeclarePeople::getPreIeportNo, preleportNo));
		if(htImportDeclarePeople.size() == 1){
			BeanUtils.copyProperties(htImportDeclarePeople.get(0),importDeclarePeopleDto);
			return importDeclarePeopleDto;
		}
		if(htImportDeclarePeople.size() > 1)
			throw new ServiceException("当前边民 申报信息有误");
		return null;
	}
}
