package cn.superdesk.uniorder.dubbo.provider.organisation;

import cn.hutool.core.date.DateUtil;
import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.organisation.SysEnterpriseExtAccounting;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dto.param.organisation.SysEnterpriseExtAccountingParam;
import cn.superdesk.uniorder.dubbo.facade.organisation.DubboSysEnterpriseExtAccountingService;
import cn.superdesk.uniorder.service.organisation.SysEnterpriseExtAccountingService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * @Description: 企业信息-扩展-对账相关
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2020-08-20 20:23:17
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020-08-20 20:23:17
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Service(version = "1.0.0", retries = -1, timeout = 10000)
public class DubboSysEnterpriseExtAccountingServiceImpl implements DubboSysEnterpriseExtAccountingService {

	@Autowired
	private SysEnterpriseExtAccountingService sysEnterpriseExtAccountingService;


	/****************************************** extends BaseService 部分 start ******************************************/

	@Override
	public void addObj(SysEnterpriseExtAccountingParam param) {

		SysEnterpriseExtAccounting sysEnterpriseExtAccounting = AnBeanUtils.copy(param, SysEnterpriseExtAccounting.class);
		sysEnterpriseExtAccountingService.insertSelective(sysEnterpriseExtAccounting);

	}

	@Override
	public void updateObj(SysEnterpriseExtAccountingParam param) {

		SysEnterpriseExtAccounting sysEnterpriseExtAccounting = AnBeanUtils.copy(param, SysEnterpriseExtAccounting.class);
		sysEnterpriseExtAccountingService.updateByPrimaryKeySelective(sysEnterpriseExtAccounting);
	}

	@Override
	public void deleteObj(Long id) {
		sysEnterpriseExtAccountingService.deleteObj(id);
	}

	@Override
	public SysEnterpriseExtAccounting findById(Long id) {
		return sysEnterpriseExtAccountingService.findById(id);
	}

	@Override
	public PageInfo<SysEnterpriseExtAccounting> findByPaging(Map<String, Object> conditions, Integer pageNun, Integer pageSize) {
		return sysEnterpriseExtAccountingService.findByPaging(conditions, pageNun, pageSize);
	}

	@Override
	public List<SysEnterpriseExtAccounting> findAll(Map<String, Object> queryMap) {

		return sysEnterpriseExtAccountingService.findAll(queryMap);
	}

	/****************************************** extends BaseService 部分   end ******************************************/

	/**
	 * 初始化 全部企业 要先清理老数据
	 *
	 * @param param
	 */
	@Override
	public void initSysEnterpriseExtAccounting(SysEnterpriseExtAccountingParam param) {


	}


	@Override
	public void addSysEnterpriseExtAccounting(SysEnterpriseExtAccountingParam param) {

		SysEnterpriseExtAccounting sysEnterpriseExtAccounting = AnBeanUtils.copy(param, SysEnterpriseExtAccounting.class);
		sysEnterpriseExtAccounting.setId(param.getSysVirtId());

		sysEnterpriseExtAccountingService.addSysEnterpriseExtAccounting(sysEnterpriseExtAccounting);
	}

	@Override
	public void updateSysEnterpriseExtAccounting(SysEnterpriseExtAccountingParam param) {

		SysEnterpriseExtAccounting sysEnterpriseExtAccounting = AnBeanUtils.copy(param, SysEnterpriseExtAccounting.class);
		sysEnterpriseExtAccounting.setId(param.getSysVirtId());

		sysEnterpriseExtAccountingService.updateSysEnterpriseExtAccounting(sysEnterpriseExtAccounting);
	}

	@Override
	public void saveOrUpdateSysEnterpriseExtAccounting(SysEnterpriseExtAccountingParam param, LoginSysUser loginSysUser) {

		if (null == param.getId()) {

			param.setCreateTime(DateUtil.date());
			param.setCreateUserId(loginSysUser.getSysUserId());
			addSysEnterpriseExtAccounting(param);

		} else {

			SysEnterpriseExtAccounting check = findById(param.getId());

			if (null == check) {
				param.setCreateTime(DateUtil.date());
				param.setCreateUserId(loginSysUser.getSysUserId());
				addSysEnterpriseExtAccounting(param);
			} else {
				param.setUpdateTime(DateUtil.date());
				param.setUpdateUserId(loginSysUser.getSysUserId());
				updateSysEnterpriseExtAccounting(param);
			}
		}

	}

	@Override
	public void deleteSysEnterpriseExtAccounting(Long id) {
		sysEnterpriseExtAccountingService.deleteSysEnterpriseExtAccounting(id);
	}

	@Override
	public SysEnterpriseExtAccounting findSysEnterpriseExtAccountingById(Long id) {
		return sysEnterpriseExtAccountingService.findSysEnterpriseExtAccountingById(id);
	}

	@Override
	public R<List<SysEnterpriseExtAccounting>> pageQuery(Map<String, Object> conditions, int pageNun, int pageSize) {
		return sysEnterpriseExtAccountingService.pageQuery(conditions, pageNun, pageSize);

	}
}
