package com.ssj.sys.controller;

import com.ssj.framework.basic.common.bean.Page;
import com.ssj.framework.basic.common.bean.SplitPage;
import com.ssj.framework.core.common.controller.BaseController;
import com.ssj.framework.core.util.Constant;
import com.ssj.framework.core.util.ResponseEntity;
import com.ssj.service.conch.curator.service.v1.CuratorV1Service;
import com.ssj.service.weixin.library.service.LibManagerAuditService;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

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

@Controller
@RequestMapping("/sys/curator")
public class CuratorV1Controller extends BaseController {

	@Autowired
	private LibManagerAuditService libManagerAuditService;
	@Autowired
	private CuratorV1Service curatorV1Service;

	/**
	 * 审核列表列表
	 * @param pageSize 每页记录数
	 * @param pageNo 页码
	 */
	@RequestMapping("/auditList")
	public String TeacherAuditList(Model model,
			@RequestParam(required = false, defaultValue = "10") int pageSize,
			@RequestParam(required = false, defaultValue = "1") int pageNo) {

		Map<String, Object> params = new HashMap<String, Object>();
		String curatorName = Optional.ofNullable(request.getParameter("LIKE_curatorName")).orElse("");
		params.put("LIKE_curatorName", curatorName);
		SplitPage sp = new SplitPage();
        sp.setAction(request.getRequestURI());
        sp.setPageNo(pageNo);
        sp.setPageSize(pageSize);
        sp.setParams(params);
		Page page = libManagerAuditService.findPageByTypeAndName(pageNo, pageSize, Constant.CURATOR, curatorName);
		sp.setRowCnt((int) page.getRowCnt());
		model.addAttribute("list", page.getList());
		model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
		model.addAttribute("page", sp);
		model.addAttribute("search", params);

		return "sys/audit/curatorAuditList";
	}

	/**
	 * 审核
	 *
	 * @param auditResultType 审核的操作类型，1通过，2不通过
	 * @param reason          页码
	 */
	@RequestMapping("/audit")
	@ResponseBody
	public ResponseEntity audit(@RequestParam int auditResultType,
								@RequestParam String libManagerAuditId,
								String reason) {

		return curatorV1Service.audit(auditResultType, libManagerAuditId, reason);
	}

}
