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.mapper.ContractMapper;
import com.fkzy.warn.model.Contract;
import com.fkzy.warn.service.ContractService;
import com.fkzy.warn.common.constants.EntityConstants;
import com.fkzy.warn.common.request.RequestParameter;
import com.fkzy.warn.common.response.ApiResponse;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhangjing
 * @date 2023/10/16 18:17
 * @description
 */
@Service
public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> implements
    ContractService {


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

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

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

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