package cn.hmsoft.skill.control.std;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.hmsoft.application.web.Ajax;

import cn.hmsoft.skill.data.dao.std.StdMaterialDao;
import cn.hmsoft.skill.data.model.cf.enrol.CfEnrolMaterial;
import cn.hmsoft.skill.service.std.StdMaterialService;
import cn.hmsoft.frame.constants.FrameStatus;
import cn.hmsoft.frame.control.FrameControl;
import cn.hmsoft.jdbc.entity.QueryOrder;

@RestController
public class StdMaterialControl extends FrameControl {

	@Autowired
	private StdMaterialDao daoMaterial;
	@Autowired
	private StdMaterialService sMaterial;

	@RequestMapping("std/material/refuse/all")
	public Ajax allRefuse() {
		//return new Ajax(this.daoMaterial.all(CfEnrolMaterialRefuse.class, new QueryOrder("refuse_id")));
		return new Ajax();
	}

	@RequestMapping("std/material/verify/random")
	public Ajax random(String material_type, String query) {
		return new Ajax(this.sMaterial.getRandomStd(material_type, query));
	}

	@RequestMapping("std/material/accept")
	public Ajax accept(int material_id) {
		this.sMaterial.accept(this.daoMaterial.find(material_id), FrameStatus.Active.toString(), this.getFrameOptr());
		return new Ajax();
	}
	@RequestMapping("std/material/accept/all")
	public Ajax accept(Integer[] material_ids) {
		this.sMaterial.acceptAll(material_ids, this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("std/material/refuse")
	public Ajax refuse(int material_id, String refuse_msg, String msg_flag) {
		this.sMaterial.refuse(this.daoMaterial.find(material_id), refuse_msg, msg_flag, this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("std/material/all")
	public Ajax allMaterial() {
		return new Ajax(this.daoMaterial.list(CfEnrolMaterial.class, "material_status", FrameStatus.Active.toString(),
				new QueryOrder("material_order")));
	}
}
