package com.lz.modules.third.controller;


import com.alibaba.fastjson.JSONObject;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.common.utils.StringUtil;
import com.lz.modules.job.business.DingtalkBusiness;
import com.lz.modules.third.entity.ThirdAppConfig;
import com.lz.modules.third.service.ThirdAppConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/thirdAppConfig")
public class ThirdAppConfigController {


    @Autowired
    private ThirdAppConfigService thirdAppConfigservice;

    @Autowired
    private DingtalkBusiness dingtalkBusiness;


    @RequestMapping("/list")
     public R list(@RequestBody String body) {
        Map<String,Object> params = new HashMap<>();
        if(StringUtil.isNotBlank(body)){
            params = JSONObject.parseObject(body,Map.class);
        }
        PageUtils page = thirdAppConfigservice.queryPage(params);
        return R.ok().put("page", page);
     }

    @GetMapping("/syn")
    public R syn(@RequestParam String appid) {
        dingtalkBusiness.getDingTalkepartmentsIntoData(appid);
        return R.ok();
    }




     @RequestMapping("/getById")
     public R getById(@RequestBody ThirdAppConfig thirdAppConfig) {
        thirdAppConfig = thirdAppConfigservice.selectThirdAppConfigById(thirdAppConfig.getId());
        return R.ok().put("thirdAppConfig",thirdAppConfig);
     }


     @RequestMapping("/update")
     public R update(@RequestBody ThirdAppConfig thirdAppConfig) {
        thirdAppConfigservice.updateThirdAppConfigById(thirdAppConfig);
        return R.ok();
     }


     @RequestMapping("/save")
        public R save(@RequestBody ThirdAppConfig thirdAppConfig) {
        thirdAppConfigservice.insertThirdAppConfig(thirdAppConfig);
        return R.ok();
     }


    @RequestMapping("/delete")
    public R list(@RequestBody Long id) {
        thirdAppConfigservice.deleteThirdAppConfigById(id);
        return R.ok();
     }
}
