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.DictDataMapper;
import cn.tsy.data.idsse.dsds.model.dict.DictData;
import cn.tsy.idsse.dsds.helper.DSDSWebHelper;
import cn.tsy.idsse.dsds.service.dict.DictDataService;

@RestController
@RequestMapping("dict/data")
public class DictDataControl extends AjaxControl {

	@Autowired
	private DictDataMapper mData;

	@Autowired
	private DictDataService sData;

	@RequestMapping("page.htm")
	public Ajax page(Integer group, Integer limit, Integer start, String query, String order, String type) {
		order = StringHelper.hasValue(order) ? order : "data_order";
		type = StringHelper.hasValue(type) ? type : "DESC";
		Pageable page = this.mData.dataWithPage(group, start, limit, query, order, type);
		return new Ajax(page);
	}

	@RequestMapping("all.htm")
	public Ajax all() {
		return new Ajax(this.mData.allByOrder(OrderBuilder.create().addOrderBy("data_order", DirectionEnum.DESC)));
	}

	@RequestMapping("edit.htm")
	public Ajax edit(DictData data) {
		DSDSWebHelper.getFrameOptr(true);
		this.sData.editData(data);
		return new Ajax(data);
	}

	@RequestMapping("delete.htm")
	public Ajax delete(int tsy_id) {
		DSDSWebHelper.getFrameOptr(true);
		this.sData.deleteData(tsy_id);
		return new Ajax();
	}

}
