package com.nantian.cloud.jljc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.jljc.entity.TSupervisionOrganization;
import com.nantian.cloud.jljc.service.TSupervisionOrganizationService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/TSupervisionOrganization")
@Api(value = "t_supervision_organization",tags = "监察机构")
public class TSupervisionOrganizationController {

    @Autowired
    TSupervisionOrganizationService tSupervisionOrganizationService;

    /**
     * 查询
     * @param page
     * @param tSupervisionOrganization
     * @return
     */
    @GetMapping("/selectall")
    @SysLog("分页获取监察机构")
    @ApiOperation(value = "分页获取监察机构", notes = "分页获取监察机构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tSupervisionOrganization", value = "tSupervisionOrganization", required = false, dataType = "json", paramType = "path"),
            @ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path")
    })
    public R selectall(Page page, TSupervisionOrganization tSupervisionOrganization) {
        tSupervisionOrganization.setDelFlag("1"); //筛选未删除项
        return R.ok(tSupervisionOrganizationService.selectall(page,tSupervisionOrganization));
    }

    /**
     * 获取所有监察机构
     * @return
     */
    @GetMapping("/getList")
    @SysLog("获取所有监察机构")
    @ApiOperation(value = "获取所有监察机构", notes = "获取所有监察机构")
    @ApiImplicitParam(name = "TSupervisionOrganization", value = "监察机构", required = false, dataType = "json", paramType = "path")
    public R getList(TSupervisionOrganization tSupervisionOrganization) {
        tSupervisionOrganization.setDelFlag("1"); //筛选未删除项
        return R.ok(tSupervisionOrganizationService.getList(tSupervisionOrganization));
    }

    /**
     * 获取区域、监察机构树形结构
     * @return
     */
    @GetMapping("/regionOrganizationTree")
    @SysLog("获取区域、监察机构树形结构")
    @ApiOperation(value = "获取区域、监察机构树形结构", notes = "获取区域、监察机构树形结构")
    @ApiImplicitParam(name = "TSupervisionOrganization", value = "监察机构", required = false, dataType = "json", paramType = "path")
    public R regionOrganizationTree(TSupervisionOrganization tSupervisionOrganization) {
        tSupervisionOrganization.setDelFlag("1"); //筛选未删除项
        return R.ok(tSupervisionOrganizationService.regionOrganizationTree(tSupervisionOrganization));
    }

    /**
     * 获取监察机构树形结构
     * @return
     */
    @GetMapping("/tree")
    @SysLog("获取监察机构树形结构")
    @ApiOperation(value = "获取监察机构树形结构", notes = "获取监察机构树形结构")
    public R getTree(String deptId) {
        return R.ok(tSupervisionOrganizationService.getTree(deptId));
    }

    /**
     * 新增
     * @param tSupervisionOrganization
     * @return
     */
    @PostMapping("/insertall")
    @SysLog("添加监察机构")
    @ApiOperation(value = "添加监察机构", notes = "添加监察机构")
    @ApiImplicitParam(name = "tStandardsRegulations", value = "tStandardsRegulations", required = true, dataType = "boolean", paramType = "path")
    public Boolean insertall(@RequestBody TSupervisionOrganization tSupervisionOrganization){

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        // System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
        try {
            tSupervisionOrganization.setUpdateTime(df.parse(df.format(new Date())));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        tSupervisionOrganization.setDelFlag("1");
        return tSupervisionOrganizationService.insertall(tSupervisionOrganization);
    }

    /**
     * 修改方法
     * @param tSupervisionOrganization
     * @return
     */
    @PutMapping("/updateall")
    @SysLog("修改监察机构")
    @ApiOperation(value = "修改监察机构", notes = "修改监察机构")
    @ApiImplicitParam(name = "TSupervisionOrganization", value = "TSupervisionOrganization", required = true, dataType = "boolean", paramType = "path")
    public Boolean updateall(@RequestBody TSupervisionOrganization tSupervisionOrganization){

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        // System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
        try {
            tSupervisionOrganization.setUpdateTime(df.parse(df.format(new Date())));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return tSupervisionOrganizationService.updateall(tSupervisionOrganization);
    }

    /**
     * 删除监察机构
     * @param tSupervisionOrganization
     * @return
     */
    @DeleteMapping("/deleteall")
    @SysLog("删除监察机构")
    @ApiOperation(value = "删除监察机构", notes = "删除监察机构")
    @ApiImplicitParam(name = "tSupervisionOrganization", value = "tSupervisionOrganization", required = true, dataType = "boolean", paramType = "path")
    public Boolean deleteall(@RequestBody TSupervisionOrganization tSupervisionOrganization){

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        // System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
        try {
            tSupervisionOrganization.setUpdateTime(df.parse(df.format(new Date())));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        tSupervisionOrganization.setDelFlag("4");
        return tSupervisionOrganizationService.updateById(tSupervisionOrganization);
    }
}
