package com.fkzy.warn.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fkzy.warn.common.constants.EntityConstants;
import com.fkzy.warn.common.request.RequestParameter;
import com.fkzy.warn.common.response.ApiResponse;
import com.fkzy.warn.mapper.EnterpriseAlarmInfoMapper;
import com.fkzy.warn.model.EnterpriseAlarmInfo;
import com.fkzy.warn.service.EnterpriseAlarmInfoService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhangjing
 * @date 2023/10/16 18:17
 * @description
 */
@Service
public class EnterpriseAlarmInfoServiceImpl extends ServiceImpl<EnterpriseAlarmInfoMapper, EnterpriseAlarmInfo> implements
    EnterpriseAlarmInfoService {


    @Override
    public ApiResponse saveModel(EnterpriseAlarmInfo entity, String ticket) {
        save(entity);
        return new ApiResponse();
    }

    @Override
    public ApiResponse updateModel(EnterpriseAlarmInfo entity,String ticket) {
        this.updateById(entity);
        return new ApiResponse();
    }

    @Override
    public ApiResponse deleteModel(List<String> ids) {
        EnterpriseAlarmInfo entity = new EnterpriseAlarmInfo();
        entity.setIsDel(EntityConstants.DEL);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.in("id", ids);
        update(entity, wrapper);
        return new ApiResponse();
    }

    @Override
    public Page<EnterpriseAlarmInfo> queryPage(RequestParameter parameter) {
        EnterpriseAlarmInfo entity = parameter.getParameter().toJavaObject(EnterpriseAlarmInfo.class);
        Page<EnterpriseAlarmInfo> page = new Page<EnterpriseAlarmInfo>(parameter.getCurrent(), parameter.getSize());
        page.setSearchCount(true);
        page.setOptimizeCountSql(true);
        QueryWrapper<EnterpriseAlarmInfo> eWrapper = new QueryWrapper<EnterpriseAlarmInfo>(entity);
        Page<EnterpriseAlarmInfo> result = this.page(page, eWrapper);
        return result;
    }
}
