/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.bank.sealhandover.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import org.springblade.bank.sealhandover.entity.SealHandover;
import org.springblade.bank.sealhandover.vo.SealHandoverVO;
import org.springblade.bank.sealhandover.mapper.SealHandoverMapper;
import org.springblade.bank.sealhandover.service.ISealHandoverService;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

/**
 * 業務印章交接登記表 服务实现类
 *
 * @author BladeX
 * @since 2021-08-13
 */
@Service
public class SealHandoverServiceImpl extends BaseServiceImpl<SealHandoverMapper, SealHandover> implements ISealHandoverService {

	@Override
	public IPage<SealHandoverVO> selectSealHandoverPage(IPage<SealHandoverVO> page, SealHandoverVO sealHandover) {
		sealHandover.setStatus(1);
		return page.setRecords(baseMapper.selectSealHandoverPage(page, sealHandover));
	}

	@Override
	public List<SealHandover> getMyInitialted() {
		List<SealHandover> list = this.list(new QueryWrapper<>(new SealHandover()).lambda().eq(SealHandover::getCreateUser, AuthUtil.getUser().getUserId()));
		return list;
	}

	@Override
	public List<SealHandoverVO> getKeepList(SealHandoverVO sealHandover) {
		sealHandover.setStatus(2);
		sealHandover.setProcess(3);
		sealHandover.setIsTurnIn(0);
		return baseMapper.selectSealHandoverPage(sealHandover);
	}

	@Override
	public List<SealHandover> getTurnInList() {
		return this.list(new QueryWrapper<>(new SealHandover()).lambda().eq(SealHandover::getIsTurnIn, 1).eq(SealHandover::getProcess, 3));
	}

	@Override
	public SealHandover getKeyOneByOrgNoSealTypeNo(String bankNo, String orgNo, String sealType, String sealNo) {
		LambdaQueryWrapper<SealHandover> eq = new QueryWrapper<>(new SealHandover()).lambda().eq(SealHandover::getBankNo, bankNo).eq(SealHandover::getOrgNo, orgNo)
			.eq(SealHandover::getSealType, sealType).eq(SealHandover::getSealNo, sealNo).eq(SealHandover::getStatus, 2).eq(SealHandover::getProcess, 3);
		return baseMapper.selectOne(eq);
	}

	@Override
	public List<SealHandoverVO> getList(SealHandoverVO sealHandover) {
		return baseMapper.selectSealHandoverPage(sealHandover);
	}

	@Override
	public boolean checkTodoByOrgNoSealTypeNo(SealHandover sealHandover) {
		LambdaQueryWrapper<SealHandover> eq = new QueryWrapper<>(new SealHandover()).lambda().eq(SealHandover::getBankNo, sealHandover.getBankNo())
			.eq(SealHandover::getOrgNo, sealHandover.getOrgNo()).eq(SealHandover::getSealType, sealHandover.getSealType()).eq(SealHandover::getSealNo, sealHandover.getSealNo())
			.eq(SealHandover::getProcess, 2).eq(SealHandover::getStatus, 1);
		SealHandover one = baseMapper.selectOne(eq);
		return one != null;
	}
}
