/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.base.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.base.dto.ApplyForReviewDTO;
import com.tofly.base.dto.ResetUserDTO;
import com.tofly.base.em.Constant;
import com.tofly.base.entity.System;
import com.tofly.base.entity.*;
import com.tofly.base.service.*;
import com.tofly.base.service.messge.MessagepushService;
import com.tofly.base.service.messge.MessagerecipientService;
import com.tofly.base.service.messge.UsertaskService;
import com.tofly.common.core.constant.CommonConstants;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.core.util.DateUtil;
import com.tofly.common.core.util.JSONUtil;
import com.tofly.common.core.util.PasswordUtil;
import com.tofly.common.core.util.StringUtil;
import com.tofly.common.ftp.config.FtpUtil;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.common.oauth.auth.ToflyUser;
import com.tofly.common.oauth.auth.innerCall;
import com.tofly.common.oauth.util.SecurityUtils;
import com.tofly.pojo.message.Messagepush;
import com.tofly.pojo.message.Messagerecipient;
import com.tofly.pojo.message.Usertask;
import io.swagger.annotations.*;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;

import static com.baomidou.mybatisplus.core.toolkit.Wrappers.update;

/**
 * 用户表
 *
 * @author admin
 * @date Thu Oct 10 00:00:00 CST 2019
 */
@RestController
@RequestMapping("/company")
@Api(tags = "公司管理")
@Slf4j
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    /**
     * 分页查询
     *
     * @param page       分页对象
     * @param company 部门表
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone getDepartmentPage(Page page, @ModelAttribute Company company) {
        return ResultRespone.success(companyService.page(page, Wrappers.query(company)));
    }


    /**
     * 通过id查询部门表
     *
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id") Long id) {
        return ResultRespone.success(companyService.getById(id));
    }

    /**
     * 新增部门表
     *
     * @param company 部门表
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "新增部门表")
    @ApiOperation(value = "新增部门表")
    @PostMapping
    public ResultRespone save(@RequestBody Company company) {

         return ResultRespone.success(companyService.save(company));

    }

    /**
     * 修改部门表
     *
     * @param company 部门表
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "修改部门表")
    @ApiOperation(value = "修改部门表")
    @PutMapping
    public ResultRespone updateById(@RequestBody Company company) {
        //先判断新增得部门名称是否重复
     return ResultRespone.success(companyService.updateById(company));
    }

}

