package  com.zcloud.modules.invoicing.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zcloud.common.utils.PageUtils;
 import com.zcloud.datasource.annotation.DataSource;
 import com.zcloud.modules.invoicing.dao.BusInvoicingReturnDao;
 import com.zcloud.modules.invoicing.entity.BusInvoicingReturnEntity;
 import com.zcloud.modules.invoicing.service.BusInvoicingReturnService;
 import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

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

/**
 * @Author lizenan
 * @Desc 开票管理回传发票(BusInvoicingReturn)表服务实现类
 * @Date 2024-04-08 08:56:18
 */
@Service("busInvoicingReturnService")
public class BusInvoicingReturnServiceImpl extends ServiceImpl<BusInvoicingReturnDao, BusInvoicingReturnEntity> implements BusInvoicingReturnService {

    @Override
	@DataSource("slave1")
	public BusInvoicingReturnEntity queryByFlexibleParams(String paramName, Object paramValue) {
		QueryWrapper<BusInvoicingReturnEntity> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq(paramName, paramValue); // 根据传入的参数名和参数值动态构建查询条件

		return baseMapper.selectOne(queryWrapper);
	}

	@Override
	@DataSource("slave1")
	public List<BusInvoicingReturnEntity> queryListByFlexibleParams(String paramName, Object paramValue) {
		QueryWrapper<BusInvoicingReturnEntity> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq(paramName, paramValue); // 根据传入的参数名和参数值动态构建查询条件

		return baseMapper.selectList(queryWrapper);
	}

    @Override
	@DataSource("slave1")
    public PageUtils listPage(Map<String, Object> params) {
        Page<Map<String,Object>> page = new Page<>(Integer.parseInt(params.get("curPage").toString()),Integer.parseInt(params.get("limit").toString()));
        params.put("isDelete",0);
        IPage<BusInvoicingReturnEntity> ipage = baseMapper.listPage(page,params);
        return new PageUtils(ipage);
    }


	@Override
	@DataSource("slave1")
	public List<BusInvoicingReturnEntity> listByInvoicingId(String invoicingId) {
		LambdaQueryWrapper<BusInvoicingReturnEntity> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(BusInvoicingReturnEntity::getIsDelete,0);
		wrapper.eq(BusInvoicingReturnEntity::getInvoicingId,invoicingId);
		return baseMapper.selectList(wrapper);
	}


	@Override
	public void delete(String invoicingReturnId,String userId){
		UpdateWrapper<BusInvoicingReturnEntity> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("invoicing_return_id",invoicingReturnId);

		BusInvoicingReturnEntity busInvoicingReturn = new BusInvoicingReturnEntity();
		busInvoicingReturn.setOperator(userId);
		busInvoicingReturn.setIsDelete(1);

		this.update(busInvoicingReturn, updateWrapper);
	}

	@Override
	@DataSource("slave1")
	public BusInvoicingReturnEntity info(String invoicingReturnId) {
		return baseMapper.selectById(invoicingReturnId);
	}
}
