package com.changhu.module.securityManagement.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.Db;
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.securityManagement.pojo.params.ServiceProjectSaveOrUpdateParams;
import com.changhu.module.securityManagement.pojo.queryParams.ServiceProjectPagerQueryParams;
import com.changhu.module.securityManagement.pojo.vo.ServiceProjectPagerVo;
import com.changhu.module.securityManagement.service.Service_ProjectService;
import com.changhu.pojo.entity.ServiceProject;
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/11/22 上午10:19
 * @desc ServiceProjectController...
 */
@Tag(name = "保安后台-服务项目管理")
@JsonBody
@RequestMapping("/m3/sp")
@RestController("securityServiceProjectManagement")
@CheckUserType(userTypes = UserType.MANAGEMENT_SECURITY)
public class ServiceProjectController {

    @Autowired
    private Service_ProjectService service_projectService;

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

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

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