package com.casic.missiles.modular.dept.controller;

import com.casic.missiles.core.base.controller.BaseController;
import com.casic.missiles.core.base.response.ResponseData;
import com.casic.missiles.core.common.annotion.Permission;
import com.casic.missiles.core.util.ToolUtil;
import com.casic.missiles.modular.dept.dto.DeptUserView;
import com.casic.missiles.modular.dept.model.BusDeptUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import java.util.List;
import com.casic.missiles.core.common.constant.factory.PageFactory;

import com.casic.missiles.modular.dept.service.IBusDeptUserService;

/**
 * 控制器
 *
 * @author dev
 * @Date 2020-05-07 17:59:11
 */
@Controller
@RequestMapping("/config")
public class BusDeptUserController extends BaseController {

    @Autowired
    private IBusDeptUserService busDeptUserService;

    /**
     * 给某部门配置责任人,有则修改，无则新增
     * @param deptid 组织机构id
     * @param user 用户id
     * @return
     */
    @RequestMapping("/responsiblePersonConfig")
    @ResponseBody
    public Object responsiblePersonConfig(String deptid, String user){
        EntityWrapper<BusDeptUser> query = new EntityWrapper<>();
        query.eq("DEPTID",deptid);
        BusDeptUser busDeptUser = busDeptUserService.selectOne(query);
        if(ToolUtil.isEmpty(busDeptUser)){
            busDeptUser = new BusDeptUser();
            busDeptUser.setDeptid(Long.valueOf(deptid));
            busDeptUser.setUser(Long.valueOf(user));
            busDeptUserService.insert(busDeptUser);
        } else {
            busDeptUser.setUser(Long.valueOf(user));
            busDeptUserService.updateById(busDeptUser);
        }
        return ResponseData.success();
    }

    @RequestMapping("/deptResponsiblePersonList")
    @ResponseBody
    public Object deptResponsiblePersonList(String deptType, String deptName){
        List<DeptUserView> list = busDeptUserService.selectDeptUserList(deptType, deptName);
        return ResponseData.success(list);
    }

}
