package com.project.zcustom.service.service.smart.impl;

import com.project.zcustom.domain.smart.PlatGreenSmartDegree;
import com.project.zcustom.mapper.service.smart.PlatGreenSmartDegreeMapper;
import com.project.zcustom.service.service.smart.IPlatGreenSmartDegreeService;
import com.project.common.core.domain.search.PageParamVo;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.common.utils.StringUtils;

import java.util.List;

/**
 * 食堂服务满意度Service业务层处理
 *
 * @author change
 * @date 2024-10-21
 */
@Service
public class PlatGreenSmartDegreeServiceImpl extends ServiceImpl<PlatGreenSmartDegreeMapper, PlatGreenSmartDegree> implements IPlatGreenSmartDegreeService {

    /**
     * 组装查询条件
     */
    private LambdaQueryWrapper<PlatGreenSmartDegree> getLambdaQueryWrapper(PlatGreenSmartDegree platGreenSmartDegree) {
        LambdaQueryWrapper<PlatGreenSmartDegree> lqw = new LambdaQueryWrapper<PlatGreenSmartDegree>();
        if (StringUtils.isNotBlank(platGreenSmartDegree.getAppOrg())) {
            lqw.eq(PlatGreenSmartDegree::getAppOrg, platGreenSmartDegree.getAppOrg());
        }
        if (StringUtils.isNotNull(platGreenSmartDegree.getVeryNum())) {
            lqw.eq(PlatGreenSmartDegree::getVeryNum, platGreenSmartDegree.getVeryNum());
        }
        if (StringUtils.isNotNull(platGreenSmartDegree.getSatisfyNum())) {
            lqw.eq(PlatGreenSmartDegree::getSatisfyNum, platGreenSmartDegree.getSatisfyNum());
        }
        if (StringUtils.isNotNull(platGreenSmartDegree.getSameNum())) {
            lqw.eq(PlatGreenSmartDegree::getSameNum, platGreenSmartDegree.getSameNum());
        }
        if (StringUtils.isNotNull(platGreenSmartDegree.getUnsatisfiedNum())) {
            lqw.eq(PlatGreenSmartDegree::getUnsatisfiedNum, platGreenSmartDegree.getUnsatisfiedNum());
        }
        if (StringUtils.isNotNull(platGreenSmartDegree.getType())) {
            lqw.eq(PlatGreenSmartDegree::getType, platGreenSmartDegree.getType());
        }
        return lqw;
    }

    /**
     * 分页查询食堂服务满意度列表
     *
     * @param platGreenSmartDegree 食堂服务满意度
     * @return 食堂服务满意度集合
     */
    @Override
    public IPage<PlatGreenSmartDegree> pagingPlatGreenSmartDegreeList(PlatGreenSmartDegree platGreenSmartDegree) {
        IPage<PlatGreenSmartDegree> page = new Page<>(platGreenSmartDegree.getPageNum(), platGreenSmartDegree.getPageSize());
        LambdaQueryWrapper<PlatGreenSmartDegree> lqw = getLambdaQueryWrapper(platGreenSmartDegree);
        // 排序 默认时间倒序
        lqw.orderByDesc(PlatGreenSmartDegree::getCreateTime);
        return baseMapper.selectPage(page, lqw);
    }

    /**
     * 分页查询食堂服务满意度列表
     *
     * @param lqw
     * @return 食堂服务满意度集合
     */
    @Override
    public IPage<PlatGreenSmartDegree> pagingPlatGreenSmartDegreeList(PageParamVo pageParamVo, LambdaQueryWrapper<PlatGreenSmartDegree> lqw) {
        IPage<PlatGreenSmartDegree> page = new Page<>(pageParamVo.getPageNum(), pageParamVo.getPageSize());
        // 排序 默认时间倒序
        lqw.orderByDesc(PlatGreenSmartDegree::getCreateTime);
        return baseMapper.selectPage(page, lqw);
    }

    /**
     * 查询食堂服务满意度列表
     *
     * @param platGreenSmartDegree 食堂服务满意度
     * @return 食堂服务满意度
     */
    @Override
    public List<PlatGreenSmartDegree> selectPlatGreenSmartDegreeList(PlatGreenSmartDegree platGreenSmartDegree) {
        LambdaQueryWrapper<PlatGreenSmartDegree> lqw = getLambdaQueryWrapper(platGreenSmartDegree);
        // 排序 默认时间倒序
        lqw.orderByDesc(PlatGreenSmartDegree::getCreateTime);
        return baseMapper.selectList(lqw);
    }

    /**
     * 查询食堂服务满意度列表
     *
     * @param platGreenSmartDegree 食堂服务满意度
     * @return 食堂服务满意度
     */
    @Override
    public List<PlatGreenSmartDegree> selectPlatGreenSmartDegreeList(PlatGreenSmartDegree platGreenSmartDegree, Long limitNum) {
        LambdaQueryWrapper<PlatGreenSmartDegree> lqw = getLambdaQueryWrapper(platGreenSmartDegree);
        // 排序 默认时间倒序
        lqw.orderByDesc(PlatGreenSmartDegree::getCreateTime);
        lqw.last("limit " + limitNum);
        return baseMapper.selectList(lqw);
    }

    /**
     * 根据指定字段查询信息
     *
     * @param field      字段名称
     * @param filedValue 字段值
     * @return 食堂服务满意度
     */
    @Override
    public PlatGreenSmartDegree getPlatGreenSmartDegreeByField(String field, String filedValue) {
        QueryWrapper<PlatGreenSmartDegree> lqw = new QueryWrapper<PlatGreenSmartDegree>();
        lqw.eq(field, filedValue);
        lqw.last("limit 1");
        return this.getOne(lqw, false);
    }

    /**
     * 根据指定字段查询信息列表
     *
     * @param field      字段名称
     * @param filedValue 字段值
     * @return 食堂服务满意度
     */
    @Override
    public List<PlatGreenSmartDegree> selectPlatGreenSmartDegreeListByField(String field, String filedValue, Long limitNum) {
        QueryWrapper<PlatGreenSmartDegree> lqw = new QueryWrapper<PlatGreenSmartDegree>();
        lqw.eq(field, filedValue);
        lqw.last("limit " + limitNum);
        return this.list(lqw);
    }

    /**
     * 根据指定字段查询信息列表
     *
     * @param field      字段名称
     * @param filedValue 字段值
     * @return 食堂服务满意度
     */
    @Override
    public List<PlatGreenSmartDegree> selectPlatGreenSmartDegreeListByField(String field, String filedValue) {
        QueryWrapper<PlatGreenSmartDegree> lqw = new QueryWrapper<PlatGreenSmartDegree>();
        lqw.eq(field, filedValue);
        return this.list(lqw);
    }

    /**
     * 判断指定字段值是否存在
     *
     * @param field      字段名称
     * @param filedValue 字段值
     */
    @Override
    public void checkFieldExist(String field, String filedValue, String tips, Long id) {
        QueryWrapper<PlatGreenSmartDegree> lqw = new QueryWrapper<PlatGreenSmartDegree>();
        lqw.eq(field, filedValue);
        lqw.ne("id", id);
        if (this.getOne(lqw, false) != null) {
            throw new RuntimeException(tips + "已存在");
        }
    }
}
