package com.changhu.module.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.changhu.common.annotation.CheckUserType;
import com.changhu.common.annotation.JsonBody;
import com.changhu.common.db.enums.UserType;
import com.changhu.common.exception.MessageException;
import com.changhu.module.management.pojo.params.ServiceProjectSaveOrUpdateParams;
import com.changhu.module.management.pojo.queryParams.ServiceProjectPagerQueryParams;
import com.changhu.module.management.pojo.vo.ServiceProjectPagerVo;
import com.changhu.module.management.service.ServiceProjectService;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 20252
 * @createTime 2024/9/5 上午11:09
 * @desc ServiceProjectController...
 */
@Tag(name = "服务项目")
@JsonBody
@RequestMapping("/serviceProject")
@CheckUserType(userTypes = UserType.MANAGEMENT_SECURITY)
public class ServiceProjectController {

    @Autowired
    private ServiceProjectService serviceProjectService;

    @Operation(summary = "分页查询")
    @PostMapping("/pager")
    public Page<ServiceProjectPagerVo> pager(@RequestBody PageParams<ServiceProjectPagerQueryParams, ServiceProjectPagerVo> queryParams) {
        return serviceProjectService.pager(queryParams);
    }

    @Operation(summary = "新增或者保存")
    @PostMapping("/saveOrUpdate")
    public void saveOrUpdate(@RequestBody ServiceProjectSaveOrUpdateParams params) {
        serviceProjectService.saveOrUpdate(params);
    }

    @Operation(summary = "根据id删除")
    @DeleteMapping("/deleteById")
    public void deleteById(@RequestParam Long serviceProjectId) {
        boolean b = serviceProjectService.removeById(serviceProjectId);
        if (!b) {
            throw new MessageException();
        }
    }
}
