package cn.palmte.work.controller.backend;

import cn.palmte.work.bean.SettleBean;
import cn.palmte.work.model.Admin;
import cn.palmte.work.pojo.MonthlySettleCount;
import cn.palmte.work.service.MonthlySettleStatisticsService;
import cn.palmte.work.utils.DateKit;
import cn.palmte.work.utils.InterfaceUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Controller
@RequestMapping("/monthlySettleStatistics")
public class MonthlySettleStatisticsController extends BaseController {

    @Autowired
    private MonthlySettleStatisticsService monthlySettleStatisticsService;

    /**
     * 开卡订单图表
     *
     * @param keywords
     * @param pageNumber
     * @param pageSize
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(@RequestParam(value = "keywords", required = false) String keywords,
                       @RequestParam(value = "pageNumber", defaultValue = "1") int pageNumber,
                       @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                       Map<String, Object> model) {
        //当前登录人的角色类型
        Admin admin = getAdmin();
        model.put("keywords",keywords);
        ConcurrentHashMap<String, String> searchInfo = getSearchInfo(keywords,model);
        String time;
        if (!searchInfo.containsKey("time")) {
            Calendar instance = Calendar.getInstance();
            instance.setTime(new Date());
            instance.set(Calendar.MONTH, instance.get(Calendar.MONTH));
            Date current = instance.getTime();
            time = DateKit.toStr(current, DateKit.DATE_FORMAT_YEAR_MONTH2);
            model.put("time", time);
        }
        return "/admin/monthly_settle_statistics";
    }

    @RequestMapping("/listData")
    @ResponseBody
    public String listData(@RequestParam(value = "time", required = false) String time,
                           Map<String, Object> model) {
        // 初始化参数
        List<MonthlySettleCount> countList = monthlySettleStatisticsService.getListData(time);
        return JSONObject.toJSONString(countList);
    }
}
