
package com.huimv.eartag2.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.eartag2.admin.entity.SysOrg;
import com.huimv.eartag2.admin.service.SysOrgService;
import com.huimv.eartag2.common.common.token.TokenSign;
import com.huimv.eartag2.common.utils.Result;
import com.huimv.eartag2.common.utils.ResultCode;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 系统组织机构控制器
 *
 * @author xuyuxiang
 * @date 2020/3/20 19:47
 */
@RestController
public class SysOrgController {

    @Resource
    private SysOrgService sysOrgService;

    /**
     * 查询系统机构
     *
     * @author xuyuxiang
     * @date 2020/5/11 15:49
     */
    @PostMapping("/sysOrg/page")
    public Result page(@RequestBody Map<String,String> map, HttpServletRequest request) {
        Integer userId = TokenSign.getMemberIdByJwtToken(request);
        return sysOrgService.page(map,userId);
    }

    @PostMapping("/sysOrg/page1")
    public Result page1(@RequestBody Map<String,String> map, HttpServletRequest request) {
        Integer userId = TokenSign.getMemberIdByJwtToken(request);
        return sysOrgService.page1(map,userId);
    }

    /**
     * 系统组织机构列表
     *
     * @author xuyuxiang
     * @date 2020/3/26 10:20
     */
    @GetMapping("/sysOrg/list")
    public Result list(HttpServletRequest request) {
        return sysOrgService.list(request);
    }

    /**
     * 添加系统组织机构
     *
     * @author xuyuxiang
     * @date 2020/3/25 14:44
     */
    @PostMapping("/sysOrg/add")
    public Result add(@RequestBody SysOrg sysOrgParam ) {
        sysOrgService.add(sysOrgParam);
        return new Result(ResultCode.SUCCESS);
    }

    @PostMapping("/sysOrg/update")
    public Result update(@RequestBody SysOrg sysOrgParam ) {
        sysOrgService.update(sysOrgParam);
        return new Result(ResultCode.SUCCESS);
    }
    @PostMapping("/sysOrg/approval")
    public Result approval(@RequestBody Map map, HttpServletRequest request ) {

        sysOrgService.approval(map,request);
        return new Result(ResultCode.SUCCESS);
    }



    @GetMapping("/sysOrg/remove")
    public Result remove(String orgIds ) {
        return  sysOrgService.remove(orgIds);

    }

    @GetMapping("/sysOrg/getFarm")
    public Result getFarm(HttpServletRequest request ) {
        String orgId = TokenSign.getOrgId(request);

        return new Result(ResultCode.SUCCESS,sysOrgService.list(new QueryWrapper<SysOrg>().like("pids",orgId).eq("is_farm",1).eq("audit",0)));
    }




}
