package com.sa.ibiz.demo.mob.controller;

import lombok.Data;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sa.ibiz.demo.ibizutil.domain.ActionResult;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sa.ibiz.demo.ibizutil.errors.BadRequestAlertException;
import org.springframework.validation.annotation.Validated;
import org.springframework.http.ResponseEntity;
import com.fasterxml.jackson.databind.JsonNode;
import com.sa.ibiz.demo.ibizutil.errors.BadRequestAlertException;
import java.io.InputStream;
import com.fasterxml.jackson.databind.ObjectMapper;

@RestController
@RequestMapping("/mob/app/mob")
public class MobController{

	@Data
	static protected class AppData{
		private String remotetag = null;
		private ObjectNode localdata = null;
	}
	
	@RequestMapping("getappdata")
    public ResponseEntity<AppData> getAppData(@Validated HttpServletRequest request){
    		AppData appData = new AppData();
    		fillAppData(appData);
    		return ResponseEntity.ok().body(appData);
    }
    
    protected void fillAppData(@Validated AppData appData){
    
    }

	@RequestMapping("/getdemodel/zjsy")
    public ResponseEntity<JsonNode> getZjsyDEModel(){
		return getDEModel("/demodel/ZJSY.json");
	}

	@RequestMapping("/getdemodel/kq")
    public ResponseEntity<JsonNode> getKqDEModel(){
		return getDEModel("/demodel/KQ.json");
	}

	@RequestMapping("/getdemodel/bgypsq")
    public ResponseEntity<JsonNode> getBgypsqDEModel(){
		return getDEModel("/demodel/BGYPSQ.json");
	}

	@RequestMapping("/getdemodel/bgypsqmx")
    public ResponseEntity<JsonNode> getBgypsqmxDEModel(){
		return getDEModel("/demodel/BGYPSQMX.json");
	}

	@RequestMapping("/getdemodel/wfworklist")
    public ResponseEntity<JsonNode> getWfworklistDEModel(){
		return getDEModel("/demodel/WFWorkList.json");
	}

	@RequestMapping("/getdemodel/ht")
    public ResponseEntity<JsonNode> getHtDEModel(){
		return getDEModel("/demodel/HT.json");
	}

	@RequestMapping("/getdemodel/zb")
    public ResponseEntity<JsonNode> getZbDEModel(){
		return getDEModel("/demodel/ZB.json");
	}

	@RequestMapping("/getdemodel/zcmx")
    public ResponseEntity<JsonNode> getZcmxDEModel(){
		return getDEModel("/demodel/ZCMX.json");
	}

	@RequestMapping("/getdemodel/df")
    public ResponseEntity<JsonNode> getDfDEModel(){
		return getDEModel("/demodel/DF.json");
	}

	@RequestMapping("/getdemodel/bgyp")
    public ResponseEntity<JsonNode> getBgypDEModel(){
		return getDEModel("/demodel/BGYP.json");
	}

	@RequestMapping("/getdemodel/orguser")
    public ResponseEntity<JsonNode> getOrguserDEModel(){
		return getDEModel("/demodel/OrgUser.json");
	}

	@RequestMapping("/getdemodel/qj")
    public ResponseEntity<JsonNode> getQjDEModel(){
		return getDEModel("/demodel/QJ.json");
	}

	@RequestMapping("/getdemodel/xm")
    public ResponseEntity<JsonNode> getXmDEModel(){
		return getDEModel("/demodel/XM.json");
	}

	@RequestMapping("/getdemodel/ycsq")
    public ResponseEntity<JsonNode> getYcsqDEModel(){
		return getDEModel("/demodel/YCSQ.json");
	}


    /**
    * 获取实体模型数据
    * @param filePath 模型文件路径
    * @return
    */
    public ResponseEntity<JsonNode> getDEModel(String filePath){
        JsonNode jsonNode;
        try{
			InputStream in = this.getClass().getResourceAsStream(filePath);
			jsonNode = new ObjectMapper().readTree(in);
        }
        catch(Exception ex){
        	throw new BadRequestAlertException("操作发生错误","","");
        }
        	return ResponseEntity.ok().body(jsonNode);
        }
}