package com.nantian.cloud.ggjg.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.ggjg.entity.DoubleControl;
import com.nantian.cloud.ggjg.entity.Quota;
import com.nantian.cloud.ggjg.service.DoubleControlService;
import com.nantian.sc.cloud.common.core.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/doubleControl")
@Api(value = "doubleControl", tags = "双控")
public class DoubleControlController {

    private DoubleControlService doubleControlService;


    /**
     * 分页查询
     *
     * @param page             分页对象
     * @param doubleControl
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页获取双控", notes = "分页获取双控")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
            @ApiImplicitParam(name = "doubleControl", value = "双控对象", required = false, dataType = "json", paramType = "path")
    })
    public R getAdvancedMaterialPage(Page page, DoubleControl doubleControl) {
        return R.ok(doubleControlService.page(page, Wrappers.query(doubleControl)));
    }


    /**
     * 信息
     *
     * @param doubleControlId
     * @return R
     */
    @GetMapping("/{doubleControlId}")
    @ApiOperation(value = "根据id获取双控", notes = "根据id获取双控")
    @ApiImplicitParam(name = "doubleControlId", value = "doubleControlId", required = true, dataType = "String", paramType = "path")
    public R getById(@PathVariable("doubleControlId") String doubleControlId) {
        return R.ok(doubleControlService.getById(doubleControlId));
    }

    /**
     * 保存
     *
     * @param doubleControl
     * @return R
     */
    @PostMapping
    @ApiOperation(value = "新增双控", notes = "新增双控")
    @ApiImplicitParam(name = "doubleControl", value = "双控对象", required = true, dataType = "json", paramType = "path")
    public R save(@RequestBody DoubleControl doubleControl) {
        DoubleControl n = new DoubleControl();
        n.setAreaCode(doubleControl.getAreaCode());
        if(doubleControlService.getOne(Wrappers.query(n))!=null){
            return R.failed("记录已经存在不能重复添加！");
        }
        return R.ok(doubleControlService.save(doubleControl));
    }

    /**
     * 修改
     *
     * @param doubleControl
     * @return R
     */
    @PutMapping
    @ApiOperation(value = "修改双控", notes = "修改双控")
    @ApiImplicitParam(name = "doubleControl", value = "双控对象", required = true, dataType = "json", paramType = "path")
    public R updateById(@RequestBody DoubleControl doubleControl) {
        return R.ok(doubleControlService.updateById(doubleControl));
    }

    /**
     * 删除
     *
     * @param doubleControlId
     * @return R
     */
    @DeleteMapping("/{doubleControlId}")
    @ApiOperation(value = "根据id删除双控", notes = "根据id双控")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "String", paramType = "path")
    public R removeById(@PathVariable String doubleControlId) {
        return R.ok(doubleControlService.removeById(doubleControlId));
    }

    @GetMapping("/queryList")
    @ApiOperation(value = "双控目标列表", notes = "双控目标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doubleControl", value = "双控对象", required = false, dataType = "json", paramType = "path")
    })
    public R queryList(DoubleControl doubleControl) {
        HashMap<String,String> map =new HashMap<String,String>();
        return R.ok(doubleControlService.queryList(map));
    }

    @GetMapping("/decompose")
    @ApiOperation(value = "双控目标分解", notes = "双控目标分解")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doubleControl", value = "双控对象", required = false, dataType = "json", paramType = "path")
    })
    public R getDecompose(DoubleControl doubleControl) {
        HashMap<String,String> map =new HashMap<String,String>();
        return R.ok(doubleControlService.queryDecompose(map));
    }

}
