package com.fdkankan.platform.user.controller.manager;

import com.fdkankan.common.controller.BaseController;
import com.fdkankan.common.util.PasswordUtils;
import com.fdkankan.platform.common.HttpHelper;
import com.fdkankan.platform.order.service.IOrderService;
import com.fdkankan.platform.order.service.IVirtualOrderService;
import com.fdkankan.platform.user.entity.Manager;
import com.fdkankan.platform.user.request.RequestTrade;
import com.fdkankan.platform.user.service.IManagerService;
import com.fdkankan.platform.user.vo.ResponseManager;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@Log4j2
@RestController
@RequestMapping("/service/platform/manager")
public class ManagerController extends BaseController {

    @Autowired
    private IManagerService managerService;
    @Autowired
    private IOrderService orderService;
    @Autowired
    private IVirtualOrderService virtualOrderService;

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add(){
        Manager managerEntity = new Manager("admin", PasswordUtils.encrypt("admin", "123456", PasswordUtils.getStaticSalt()));
        managerService.save(managerEntity);
        return "sdk";
    }

    @RequestMapping(value = "/detail/{userName}", method = RequestMethod.GET)
    public ResponseManager detail(@PathVariable String userName) throws Exception {
        Manager managerEntity = managerService.getByUserName(userName);
        ResponseManager responseManager = new ResponseManager();
        BeanUtils.copyProperties(managerEntity, responseManager);
        return responseManager;
    }

    @RequestMapping(value = "/home", method = RequestMethod.POST)
    public HashMap<String,Object> home() throws Exception {
        return managerService.getHome();
    }

    /**
     * 查看增值记录-汇总
     * @return
     */
    @RequestMapping(value = {"/getAllTrades"}, method = RequestMethod.POST)
    public String getAllTrades(@RequestBody RequestTrade base){
        return null;
    }

    @RequestMapping(value = {"/statistics"}, method = RequestMethod.POST)
    public String statistics(@RequestBody String param){
        try {
            String urlStr = "https://api.baidu.com/json/tongji/v1/ReportService/getData";
            String charset = "utf-8";
            byte[] res = HttpHelper.post(urlStr, param, charset);
            String s = new String(res);
            System.out.println(s);
            return  s;

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return null;
    }

}
