package org.linlinjava.jz.admin.web.report;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.validation.constraints.NotNull;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.linlinjava.jz.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.jz.admin.service.AdminDmTicketConsultTypeService;
import org.linlinjava.jz.admin.service.AdminReportService;
import org.linlinjava.jz.admin.vo.Ticket_Consult_Type_Vo;
import org.linlinjava.jz.core.util.ResponseUtil;
import org.linlinjava.jz.db.dto.BuiltlistReportDto;
import org.linlinjava.jz.db.dto.ConsultTypeReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/ticketConsultReport")
@Validated
public class AdminTicketConsultReportController {

	@Autowired
	AdminDmTicketConsultTypeService adminDmTicketConsultTypeService;

	@Autowired
	AdminReportService adminReportService;

	@RequiresPermissions("admin:ticketConsultReport:list")
	@RequiresPermissionsDesc(menu = { "报表统计", "咨询类型报表" }, button = "查询")
	@GetMapping("/list")
	public Object list(@RequestParam(required = false) Integer campaignId,
			@NotNull @RequestParam(required = false) String startTime,
			@NotNull @RequestParam(required = false) String endTime) {

		List<Ticket_Consult_Type_Vo> consultTypeData = adminDmTicketConsultTypeService.getConsultTypeTree();
		Ticket_Consult_Type_Vo temp=new Ticket_Consult_Type_Vo();
		temp.setId(-1);
		temp.setName("空类型");
		temp.setChildren(new ArrayList<Ticket_Consult_Type_Vo>());
		consultTypeData.add(temp);
		
		List<ConsultTypeReport> ticketConsultTypeData = adminReportService.ticketConsultTypeReport(campaignId,
				startTime, endTime);

		Map<Object, Object> data = new HashMap<Object, Object>();
		data.put("consultTypeData", consultTypeData);
		data.put("ticketConsultTypeData", ticketConsultTypeData);

		return ResponseUtil.ok(data);
	}
}
