package com.kiisoo.ic.wx.controller;

import com.alibaba.fastjson.JSON;
import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.employee.entity.EmployeeDO;
import com.kiisoo.ic.employee.service.EmployeeService;
import com.kiisoo.ic.wx.entity.CreateWXDO;
import com.kiisoo.ic.wx.service.AddWXService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

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

@Controller
@RequestMapping("/wechat")
@Slf4j
public class CreateWechatController extends BaseController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/create")
    public void createWechat(@RequestParam("code") String code,@RequestParam("name") String name){
        //查看此人是否已经创建过企业微信
        EmployeeDO employeeDO = new EmployeeDO();
        employeeDO.setMobile(code);
        employeeDO.setName(name);
        employeeDO.setUserId(code);
        try {
            employeeService.addUser(employeeDO);
        } catch (Exception e) {
            log.error("新增店铺创建店长微信失败",e);
        }
    }

    @Autowired
    private AddWXService addWXService;
    /**
     * 登录账号
     * @return 成功/失败
     */
    @RequestMapping(value = "/test",method = RequestMethod.POST)
    @ResponseBody
    public String loginAccount(@RequestBody CreateWXDO createWXDO){
        Map<String, Object> m = new HashMap<>();
        m.put("errcode",0);
        return JSON.toJSONString(m);
    }

//    @Scheduled(cron = "59 05 17 * * ?")
    public void a(){
        addWXService.addWX("a","b");
    }
}
