package com.ylx.massage.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ylx.massage.enums.ComplaintEnum;
import com.ylx.massage.mapper.ComplaintMapper;
import com.ylx.massage.domain.Complaint;
import com.ylx.massage.service.ComplaintService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 投诉(Complaint)表服务实现类
 *
 * @author makejava
 * @since 2024-07-30 11:06:59
 */
@Service("complaintService")
public class ComplaintServiceImpl extends ServiceImpl<ComplaintMapper, Complaint> implements ComplaintService {

    @Override
    public Page<Complaint> selectAll(Page<Complaint> page, Complaint complaint) {
        LambdaQueryWrapper<Complaint> complaintLambdaQueryWrapper = new LambdaQueryWrapper<>();
        complaintLambdaQueryWrapper
                .eq(StringUtils.isNotBlank(complaint.getPhone()),Complaint::getPhone, complaint.getPhone())
                .eq(StringUtils.isNotBlank(complaint.getDeptId()),Complaint::getDeptId, complaint.getDeptId())
                .eq(StringUtils.isNotBlank(complaint.getComplaintType()),Complaint::getComplaintType, complaint.getComplaintType())
                .like(StringUtils.isNotBlank(complaint.getJsName()),Complaint::getJsName, complaint.getJsName())
                .eq(StringUtils.isNotBlank(complaint.getDeptId()), Complaint::getDeptId, complaint.getDeptId())
                .orderByDesc(Complaint::getCreateTime);

        Page<Complaint> pageComplaint = this.page(page, complaintLambdaQueryWrapper);

        List<Complaint> records = pageComplaint.getRecords();

        if (CollectionUtil.isEmpty(records)) {
            return pageComplaint;
        }
        records.forEach(i -> {
            i.setComplaintType(ComplaintEnum.getDescByCode(i.getComplaintType()));
        });
        return pageComplaint;
    }
}

