package com.ag.secp.platform.spring;

import com.ag.web.demo.BeanpojoDemo;
import com.alibaba.fastjson.JSON;
import org.json.JSONObject;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by shaoqiang on 2017/8/17.
 */
@Component
public class SpringService {
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    @Transactional
    public void sendat(JSONObject object, HttpServletResponse response, HttpServletRequest request) {
        try {


            BeanpojoDemo beanpojoDemoarr = JSON.parseObject(object.getString("paneldata"), BeanpojoDemo.class);//获取表单数据
            //DaoUtil.insert("agCommon.demoinsert",beanpojoDemoarr);//数据插入,借助mybatis,亦可独立抽出dao层

            Map datamap=new HashMap();

            datamap.put("containerid","contaiid");
            sqlSessionTemplate.insert("agCommon.insertdockerlog",datamap);
            sqlSessionTemplate.update("agCommon.updatecontainer",datamap);

          /*    String datarec2 = CommonUtil.parseJson(object, "datatable2", "create");//获取表格2数据
            List beanpojoDemoList= CommonUtil.getBeanlist(object, "datatable1", "create",BeanpojoDemo.class);//返回表格1bean list
            BeanpojoDemo beanpojoDemo = (BeanpojoDemo) beanpojoDemoList.get(0);
            beanpojoDemo.setEMPLOYEE_ID("aaaaaaaaaaaaaaaaaaa");
            String datajson1 = JSON.toJSONString(beanpojoDemo);
            datajson1 = "[" + datajson1 + "]";
            String data = "[" + datajson1 + "," + datarec2 + "]";



            BeanpojoDemo beanpojoDemoarr = JSON.parseObject(object.getString("paneldata"), BeanpojoDemo.class);//获取表单数据

            beanpojoDemoarr.setDEPT_ID("bafdsap");

            String data=JSON.toJSONString(beanpojoDemoarr);



            WebUtil.send(response, data);//将修改数据同步返回表格*/
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
