package com.sifang.modules.sunshine.SystemSetting.controller;

import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.sunshine.SystemSetting.dao.SiteInformationDao;
import com.sifang.modules.sunshine.SystemSetting.service.FittingAmountService;
import com.sifang.modules.sunshine.SystemSetting.utils.Result;
import com.sifang.modules.sunshine.financialManagement.dao.SiteAssetDao;
import com.sifang.modules.sunshine.financialManagement.entity.CrmSiteAsset;
import com.sifang.modules.sunshine.fittingManager.dao.FittingApplyDao;
import com.sifang.modules.sunshine.fittingManager.entity.CrmPlantformFittingApply;
import com.sifang.modules.sys.common.UserUtils;
import com.sifang.modules.sys.common.entity.User;
import com.sifang.modules.sys.util.CrmUtils;
import com.sifang.modules.sys.util.LayuiPage;
import com.sifang.modules.sys.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "${adminPath}/fittingAmount")
public class FittingAmountController extends BaseController {
    @Autowired
    FittingAmountService fittingAmountService;
    @Autowired
    SiteInformationDao siteInformationDao;


    @RequestMapping(value = "recharge")
    public String recharge(HttpServletRequest request, Model model){
        List<Record> siteList =siteInformationDao.getNotSiteCUstomerList();
        model.addAttribute("siteList", siteList);
        return "modules/yangguang/systemSetting/siteManage/rechargeList";
    }

    /**
     * 服务商查看充值记录
    */
    @RequestMapping(value = "getSiteFittingAmount")
    public String getSiteFittingAmount(HttpServletRequest request){

        return "modules/yangguang/systemSetting/siteManage/siteRechargeList";
    }

    /**
     * 获取充值记录信息列表
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "rechargeList")
    public Object getRechargeList(HttpServletRequest request){
        LayuiPage page = new LayuiPage(request);
        User user = UserUtils.getUser();
        Map<String, String> map= getParams(request);
        if(User.USER_TYPE_XXY.equals(user.getUserType()) || User.USER_TYPE_FWSRY.equals(user.getUserType())){
            map.put("siteId", CrmUtils.getSiteId(user));
        }
        fittingAmountService.getRechargeList(page,map);
        return page.renderJson();
    }

    /**
     * 跳转充值页面
     * @param request
     * @return
     */
    @RequestMapping(value = "addRecharge")
    public String addRecharge(HttpServletRequest request, Model model){
        List<Record> siteList =siteInformationDao.getSiteList();
        model.addAttribute("siteList", siteList);
        return "modules/yangguang/systemSetting/siteManage/addRecharge";
    }

    /**
     * 添加保存充值
     * @param request
     * @return
     */
    @RequestMapping(value = "save")
    @ResponseBody
    public Object siteSave(HttpServletRequest request){
        Map<String,String> map = getParams(request);
        return fittingAmountService.save(map);
    }


    @RequestMapping(value = "cost")
    public String cost(HttpServletRequest request, Model model){
        List<Record> siteList =siteInformationDao.getSiteList();
        model.addAttribute("siteList", siteList);
        return "modules/yangguang/systemSetting/siteManage/costList";
    }

    /**
     * 服务商查看扣款记录
    */
    @RequestMapping(value = "sitecost")
    public String getSitecost(HttpServletRequest request, Model model){
        return "modules/yangguang/systemSetting/siteManage/siteCostList";
    }

    /**
     * 获取额度扣款记录信息列表
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getcostList")
    public Object getCostList(HttpServletRequest request){
        LayuiPage page = new LayuiPage(request);
        User user = UserUtils.getUser();
        Map<String, String> map= getParams(request);
        if(User.USER_TYPE_XXY.equals(user.getUserType()) || User.USER_TYPE_FWSRY.equals(user.getUserType())){
            map.put("siteId", CrmUtils.getSiteId(user));
        }
        fittingAmountService.getCostList(page,map);
        return page.renderJson();
    }

}
