package com.mosty.yszx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.dto.yszx.TbYsGajgAndGlbmDto;
import com.mosty.base.model.dto.yszx.TbYsGajgByJwdDto;
import com.mosty.base.model.dto.yszx.TbYsGajgDto;
import com.mosty.base.model.dto.yszx.TbYsGajgGlbmDto;
import com.mosty.base.model.vo.yszx.TbYsGajgGlbmVo;
import com.mosty.base.model.vo.yszx.TbYsGajgQuery;
import com.mosty.base.model.vo.yszx.TbYsGajgVo;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.entity.log.BusinessType;
import com.mosty.common.base.entity.log.Log;
import com.mosty.common.core.business.entity.vo.Base64Str;
import com.mosty.common.token.JwtSysUser;
import com.mosty.yszx.service.TbYsGajgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author dw
 * @since 2022/7/18
 * 要素中心--公安机关要素
 **/
@Api(tags = "要素中心--公安机关要素")
@RestController
@AllArgsConstructor
@RequestMapping("/tbYsGajg")
public class TbYsGajgController {

    private final TbYsGajgService tbYsGajgService;

    @ApiOperation("公安机关要素新增")
    @JwtSysUser
    @Log(title = "公安机关要素新增", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public ResponseResult<Integer> insertEntity(@RequestBody TbYsGajgDto dto) {
        return ResponseResult.success(this.tbYsGajgService.insertEntity(dto));
    }

    @ApiOperation("公安机关要素新增--添加关联部门")
    @JwtSysUser
    @Log(title = "公安机关要素新增--添加关联部门", businessType = BusinessType.INSERT)
    @PostMapping("addGajg")
    public ResponseResult<Integer> addGajg(@RequestBody TbYsGajgAndGlbmDto dto) {
        return ResponseResult.success(this.tbYsGajgService.addGajg(dto));
    }

    @ApiOperation("公安机关要素修改--修改关联部门")
    @JwtSysUser
    @Log(title = "公安机关要素修改--修改关联部门", businessType = BusinessType.INSERT)
    @PostMapping("editGajg")
    public ResponseResult<Void> editGajg(@RequestBody TbYsGajgAndGlbmDto dto) {
        this.tbYsGajgService.editGajg(dto);
        return ResponseResult.success();
    }

    @ApiOperation("公安机关要素修改")
    @JwtSysUser
    @Log(title = "公安机关要素修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseResult<Void> updateEntity(@RequestBody TbYsGajgDto dto) {
        this.tbYsGajgService.updateEntity(dto);
        return ResponseResult.success();
    }

    @ApiOperation("根据来源id 和来源表名修改 公安机关要素")
    @JwtSysUser
    @Log(title = "根据来源id 和来源表名 修改 公安机关要素", businessType = BusinessType.UPDATE)
    @PutMapping("update")
    public ResponseResult<Void> updateEntityByLY(@RequestBody TbYsGajgDto dto) {
        this.tbYsGajgService.updateEntityByLY(dto);
        return ResponseResult.success();
    }

    @ApiOperation("公安机关要素详情查询")
    @JwtSysUser
    @GetMapping("{id}")
    public ResponseResult<TbYsGajgVo> getInfo(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbYsGajgService.getInfo(id));
    }

    @ApiOperation("公安机关要素查询列表，pageNum参数不传查询所有列表")
    @JwtSysUser
    @PostMapping("getList")
    public ResponseResult<IPage<TbYsGajgVo>> getPageList(@RequestBody TbYsGajgQuery dto) {
        return ResponseResult.success(this.tbYsGajgService.getPageList(dto));
    }

    @ApiOperation("查询公安机关列表（包含关联部门ID）")
    @JwtSysUser
    @PostMapping("getGajgList")
    public ResponseResult<List<TbYsGajgGlbmVo>> getGajgList(@RequestBody TbYsGajgQuery dto) {
        return ResponseResult.success(this.tbYsGajgService.getGajgList(dto));
    }

    @ApiOperation("删除公安机关要素")
    @JwtSysUser
    @DeleteMapping("{id}")
    public ResponseResult<Void> delEntity(@PathVariable("id") String id) {
        this.tbYsGajgService.delEntity(id);
        return ResponseResult.success();
    }

    @ApiOperation("根据来源id 和来源表名 删除公安机关要素")
    @JwtSysUser
    @Log(title = "根据来源id 和来源表名 删除公安机关要素", businessType = BusinessType.DELETE)
    @DeleteMapping
    public ResponseResult<Void> delEntity(@RequestBody TbYsGajgDto dto) {
        this.tbYsGajgService.delEntity(dto);
        return ResponseResult.success();
    }

    @ApiOperation("根据经纬度判断所属公安机关")
    @JwtSysUser
    @PostMapping("getGajgByJwd")
    public ResponseResult<TbYsGajgVo> getGajgByJwd(@RequestBody TbYsGajgByJwdDto dto) {
        return ResponseResult.success(this.tbYsGajgService.getGajgByJwd(dto));
    }

    @ApiOperation("查询关联部门")
    @JwtSysUser
    @PostMapping("getGlbmList/{id}")
    public ResponseResult<List<TbYsGajgGlbmDto>> getGlbmList(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbYsGajgService.getGlbmList(id));
    }
}
