package cn.tsy.idsse.dsds.control.sar;

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

import cn.hme.framework.helper.lang.StringHelper;
import cn.hme.framework.jdbc.provider.page.Pageable;
import cn.hme.framework.web.control.Ajax;
import cn.tsy.data.idsse.dsds.mapper.sar.SarRegMapper;
import cn.tsy.data.idsse.dsds.model.sar.SarReg;
import cn.tsy.idsse.dsds.control.DSDSControl;
import cn.tsy.idsse.dsds.service.sar.SarRegService;

@RestController
@RequestMapping("sar/reg")
@CrossOrigin
public class SarRegControl extends DSDSControl{

	@Autowired
	private SarRegMapper mSar;

	@Autowired
	private SarRegService sSar;

	@RequestMapping("page.htm")
	public Ajax page(Integer group, Integer limit, Integer start, String query, String order, String type) {
		order = StringHelper.hasValue(order) ? order : "create_time";
		type = StringHelper.hasValue(type) ? type : "DESC";
		Pageable page = this.mSar.sarWithPage(group, start, limit, query, order, type);
		return new Ajax(page);
	}
	
	@RequestMapping("edit.htm")
	public Ajax edit(SarReg sar) {
		this.sSar.editSar(sar, getFrameOptr());
		return new Ajax(sar);
	}

	@RequestMapping("delete.htm")
	public Ajax delete(int tsy_id) {
		this.sSar.deleteSar(tsy_id);
		return new Ajax();
	}
	
	@RequestMapping("start.htm")
	public Ajax start(int tsy_id) {
		this.sSar.startSar(tsy_id,this.getFrameOptr());
		return new Ajax();
	}

	@RequestMapping("complete.htm")
	public Ajax complete(int tsy_id) {
		this.sSar.completeSar(tsy_id,this.getFrameOptr());
		return new Ajax();
	}
	
	@RequestMapping("cancel.htm")
	public Ajax cancel(int tsy_id) {
		this.sSar.cancelSar(tsy_id,this.getFrameOptr());
		return new Ajax();
	}
}
