///*
// * Author: wangjian
// * 生成controller
// */
//package com.tofly.base.controller;
//
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.tofly.base.api.entity.MemberUser;
//import com.tofly.base.entity.Position;
//import com.tofly.base.service.PositionService;
//import com.tofly.base.service.UserService;
//import com.tofly.common.core.entity.ResultRespone;
//import com.tofly.common.core.util.SpringContextHolder;
//import com.tofly.common.log.annotation.ToFlyAppLog;
//import com.tofly.common.oauth.feign.FlowableAddUserToGroupEvent;
//import com.tofly.common.oauth.feign.FlowableDeleteUserToGroupEvent;
//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.Map;
//
///**
// * 职位表
// *
// * @author wangjian
// * @date Tue Dec 03 00:00:00 CST 2019
// */
//@RestController
//@AllArgsConstructor
//@RequestMapping("/position")
//@Api(tags="用户绑定职位")
//public class PositionController {
//
//    private final PositionService positionService;
//    private final UserService userService;
//
//    /**
//    * 分页查询
//    * @param page 分页对象
//    * @return
//    */
//    @GetMapping("/page" )
//    @ApiOperation(value = "分页查询")
//    public ResultRespone getPositionPage(Page page,@RequestParam Map map) {
//        page.setRecords(positionService.getPosition(map,page));
//        return ResultRespone.success(page);
//    }
//
//
//    /**
//     * 分页查询
//     * @param page 分页对象
//     * @return
//     */
//    @GetMapping("/pageAllUser" )
//    @ApiOperation(value = "分页查询所有用户")
//    public ResultRespone getAllUserPosition(Page page) {
//        page.setRecords(positionService.getAllUserPosition(page));
//        return ResultRespone.success(page);
//    }
//
//
//    /**
//     * 通过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(positionService.getById(id));
//    }
//
//    /**
//     * 新增职位表
//     * @param position 职位表
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="新增用户职位" )
//    @ApiOperation(value = "新增用户职位")
//    @PostMapping
//    public ResultRespone save(@RequestBody Position position) {
//        boolean save = positionService.save(position);
//        if(save){
//            MemberUser memberUser=new MemberUser();
//            memberUser.setGroupId(position.getCategory());
//            memberUser.setUser(userService.getById(position.getUserId()));
//            //调用工作流接口
//            SpringContextHolder.publishEvent(new FlowableAddUserToGroupEvent(memberUser));
//        }
//        return ResultRespone.success(save);
//    }
//
//    /**
//     * 修改职位表
//     * @param position 职位表
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="修改用户职位" )
//    @ApiOperation(value = "修改用户职位")
//    @PutMapping
//    public ResultRespone updateById(@RequestBody Position position) {
//        Position positionOld=positionService.getById(position.getId());
//        boolean b = positionService.updateById(position);
//        if(b){
//            //先删除再增加
//            MemberUser memberUser=new MemberUser();
//            memberUser.setGroupId(positionOld.getCategory());
//            memberUser.setUser(userService.getById(positionOld.getUserId()));
//            //调用工作流接口
//            SpringContextHolder.publishEvent(new FlowableDeleteUserToGroupEvent(memberUser));
//            memberUser=new MemberUser();
//            memberUser.setGroupId(position.getCategory());
//            memberUser.setUser(userService.getById(position.getUserId()));
//            //调用工作流接口
//            SpringContextHolder.publishEvent(new FlowableAddUserToGroupEvent(memberUser));
//        }
//        return ResultRespone.success();
//    }
//
//    /**
//     * 通过id删除职位表
//     * @param id id
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="通过id删除用户职位" )
//    @ApiOperation(value = "通过ID删除用户职位")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
//    })
//    @DeleteMapping("/{id}" )
//    public ResultRespone removeById(@PathVariable Long id) {
//        Position position=positionService.getById(id);
//        boolean b = positionService.removeById(id);
//        if(b){
//            MemberUser memberUser=new MemberUser();
//            memberUser.setGroupId(position.getCategory());
//            memberUser.setUser(userService.getById(position.getUserId()));
//            //调用工作流接口
//            SpringContextHolder.publishEvent(new FlowableDeleteUserToGroupEvent(memberUser));
//        }
//        return ResultRespone.success(b);
//    }
//}
