package com.changhu.module.policeManagement.controller;

import com.baomidou.mybatisplus.core.toolkit.Assert;
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.enums.ResultCode;
import com.changhu.module.miniProgram.pojo.params.SecurityUserSaveOrUpdateParams;
import com.changhu.module.miniProgram.pojo.queryParams.ServiceProjectSecurityUserPagerQueryParams;
import com.changhu.module.miniProgram.pojo.vo.ServiceProjectSecurityUserPagerVo;
import com.changhu.module.policeManagement.pojo.params.ServiceProjectSaveOrUpdateParams;
import com.changhu.module.policeManagement.pojo.vo.ServiceProjectListVo;
import com.changhu.module.policeManagement.service.PoliceEnterprisesUnitService;
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.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 20252
 * @createTime 2024/11/27 下午2:37
 * @desc EnterprisesUnitController...
 */
@Tag(name = "公安后台-企事业单位")
@JsonBody
@RequestMapping("/m2/eu")
@RestController("policeManagementEnterprisesUnit")
@CheckUserType(userTypes = UserType.MANAGEMENT_POLICE)
public class EnterprisesUnitController {

    @Autowired
    private PoliceEnterprisesUnitService policeEnterprisesUnitService;

    @Operation(summary = "事业单位下服务项目列表")
    @GetMapping("/listSp")
    public List<ServiceProjectListVo> listSp(@RequestParam @Schema(description = "事业单位id") Long enterprisesUnitId) {
        return policeEnterprisesUnitService.listSp(enterprisesUnitId);
    }

    @Operation(summary = "新增或保存服务项目")
    @PostMapping("/add_upd_sp")
    public void saveOrUpdateSp(@RequestBody @Valid ServiceProjectSaveOrUpdateParams params) {
        policeEnterprisesUnitService.saveOrUpdateSp(params);
    }

    @Operation(summary = "根据id删除服务项目")
    @DeleteMapping("/deleteSpById")
    public void deleteSpById(@RequestParam Long serviceProjectId) {
        Assert.isTrue(Db.removeById(serviceProjectId, ServiceProject.class), ResultCode.ERROR.getMessage());
    }

    @Operation(summary = "新增或修改保安人员")
    @PostMapping("/add_upd_sec_user")
    public void saveOrUpdateSecurityUser(@RequestBody @Valid SecurityUserSaveOrUpdateParams params) {
        policeEnterprisesUnitService.saveOrUpdateSecurityUser(params);
    }

    @Operation(summary = "服务项目保安人员分页")
    @PostMapping("/sec_user_pager")
    public Page<ServiceProjectSecurityUserPagerVo> securityUserPager(@RequestBody PageParams<ServiceProjectSecurityUserPagerQueryParams, ServiceProjectSecurityUserPagerVo> queryParams) {
        return policeEnterprisesUnitService.securityUserPager(queryParams);
    }

    @Operation(summary = "根据id删除保安人员")
    @DeleteMapping("/del_security_user_id")
    public void deleteSecurityUserById(@RequestParam @Schema(description = "保安人员id") Long securityUserId) {
        policeEnterprisesUnitService.deleteSecurityUserById(securityUserId);
    }


}
