package com.tuoheng.service.information.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tuoheng.enums.MarkTypeEnum;
import com.tuoheng.mapper.information.WorkorderMapper;
import com.tuoheng.model.entity.Workorder;
import com.tuoheng.model.query.WorkorderQuery;
import com.tuoheng.service.information.WorkorderService;
import com.tuoheng.until.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 小影
 * @description 针对表【t_workorder(全民/河长问题工单表)】的数据库操作Service实现
 * @createDate 2023-04-24 09:14:32
 */
@Service
public class WorkorderServiceImpl extends ServiceImpl<WorkorderMapper, Workorder>
        implements WorkorderService {

    @Autowired
    private WorkorderMapper workorderMapper;
    /**
     * 查询工单列表
     *
     * @param query
     * @return
     */
    @Override
    public JsonResult index(WorkorderQuery query) {

        //分页校验
        query.checkParam();
        //分页
        IPage<Workorder> page = new Page<>(query.getPage(), query.getLimit());

        IPage<Workorder> pageDate = workorderMapper.selectPage(page, Wrappers.<Workorder>lambdaQuery()
                .like(ObjectUtil.isNotEmpty(query.getCode()), Workorder::getCode, query.getCode())
                .eq(ObjectUtil.isNotNull(query.getStatus()), Workorder::getStatus, query.getStatus())
                .eq(ObjectUtil.isNotEmpty(query.getClientId()), Workorder::getClientId, query.getClientId())
                .eq(Workorder::getMark, MarkTypeEnum.VALID.getCode())
                .orderByDesc(Workorder::getCreateTime));
        return JsonResult.success(pageDate);
    }
}




