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.DictEquipmentMapper;
import cn.tsy.data.idsse.dsds.model.dict.DictEquipment;
import cn.tsy.idsse.dsds.helper.DSDSWebHelper;
import cn.tsy.idsse.dsds.service.dict.DictEquipmentService;

@RestController
@RequestMapping("dict/equipment")
public class DictEquipmentControl  extends AjaxControl{

	@Autowired
	private DictEquipmentMapper mEquipment;

	@Autowired
	private DictEquipmentService sEquipment;

	@RequestMapping("page.htm")
	public Ajax page(Integer group, Integer limit, Integer start, String query, String order, String type) {
		order = StringHelper.hasValue(order) ? order : "equipment_order";
		type = StringHelper.hasValue(type) ? type : "DESC";
		Pageable page = this.mEquipment.equipmentWithPage(group, start, limit, query, order, type);
		return new Ajax(page);
	}
	@RequestMapping("all.htm")
	public Ajax all() {
		return new Ajax(this.mEquipment.allByOrder(OrderBuilder.create().addOrderBy("equipment_order",DirectionEnum.DESC)));
	}
	
	@RequestMapping("edit.htm")
	public Ajax edit(DictEquipment equipment) {
		DSDSWebHelper.getFrameOptr(true);
		this.sEquipment.editEquipment(equipment);
		return new Ajax(equipment);
	}
	
	@RequestMapping("delete.htm")
	public Ajax delete(int tsy_id) {
		DSDSWebHelper.getFrameOptr(true);
		this.sEquipment.deleteEquipment(tsy_id);
		return new Ajax();
	}
	
	
	

}
