package com.zcloud.modules.custormerInfo.service.impl;

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.modules.custormerInfo.dao.BusAlifacoryCustomerDao;
import com.zcloud.modules.custormerInfo.entity.BusAlifacoryCustomerEntity;
import com.zcloud.modules.custormerInfo.service.BusAlifacoryCustomerService;
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 zhangyue
 * @Desc 客户-阿里云转码模板关联表(BusAlifacoryCustomer)表服务实现类
 * @Date 2024-05-06 10:47:31
 */
@Service("busAlifacoryCustomerService")
public class BusAlifacoryCustomerServiceImpl extends ServiceImpl<BusAlifacoryCustomerDao, BusAlifacoryCustomerEntity> implements BusAlifacoryCustomerService {

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

        return baseMapper.selectOne(queryWrapper);
    }

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

        return baseMapper.selectList(queryWrapper);
    }

    @Override
    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<BusAlifacoryCustomerEntity> ipage = baseMapper.listPage(page, params);
        return new PageUtils(ipage);
    }


    @Override
    public void delete(String alifacoryCustomerId, String userId) {
        UpdateWrapper<BusAlifacoryCustomerEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("alifacory_customer_id", alifacoryCustomerId);

        BusAlifacoryCustomerEntity busAlifacoryCustomer = new BusAlifacoryCustomerEntity();
        busAlifacoryCustomer.setOperator(userId);
        busAlifacoryCustomer.setIsDelete("1");

        this.update(busAlifacoryCustomer, updateWrapper);
    }
}
