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

import org.springframework.beans.factory.annotation.Autowired;
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.builder.DirectionEnum;
import cn.hme.framework.jdbc.provider.builder.OrderBuilder;
import cn.hme.framework.jdbc.provider.page.Pageable;
import cn.hme.framework.web.control.Ajax;
import cn.hme.framework.web.control.AjaxControl;
import cn.tsy.data.idsse.dsds.mapper.dict.DictFundingMapper;
import cn.tsy.data.idsse.dsds.model.dict.DictFunding;
import cn.tsy.idsse.dsds.helper.DSDSWebHelper;
import cn.tsy.idsse.dsds.service.dict.DictFundingService;

@RestController
@RequestMapping("dict/funding")
public class DictFundingControl  extends AjaxControl{

	@Autowired
	private DictFundingMapper mFunding;

	@Autowired
	private DictFundingService sFunding;

	@RequestMapping("page.htm")
	public Ajax page(Integer group, Integer limit, Integer start, String query, String order, String type) {
		order = StringHelper.hasValue(order) ? order : "funding_order";
		type = StringHelper.hasValue(type) ? type : "DESC";
		Pageable page = this.mFunding.fundingWithPage(group, start, limit, query, order, type);
		return new Ajax(page);
	}
	@RequestMapping("all.htm")
	public Ajax all() {
		return new Ajax(this.mFunding.allByOrder(OrderBuilder.create().addOrderBy("funding_order",DirectionEnum.DESC)));
	}
	
	@RequestMapping("edit.htm")
	public Ajax edit(DictFunding funding) {
		DSDSWebHelper.getFrameOptr(true);
		this.sFunding.editFunding(funding);
		return new Ajax(funding);
	}
	
	@RequestMapping("delete.htm")
	public Ajax delete(int tsy_id) {
		DSDSWebHelper.getFrameOptr(true);
		this.sFunding.deleteFunding(tsy_id);
		return new Ajax();
	}
	
	
	

}
