package com.ag.dynamicmodule.basecode.controller;

import com.ag.dynamicmodule.basecode.dao.CClientLinkmanDao;
import com.ag.dynamicmodule.basecode.pojo.CClientLinkman;
import com.ag.util.CommonUtil;
import com.alibaba.fastjson.JSON;
import com.wb.util.WebUtil;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2019/9/23 0023.
 */
@Controller
public class CClientLinkmanController {
    @Autowired
    CClientLinkmanDao cClientLinkmanDao;
    /**
     * 保存数据
     * @param object
     * @param response
     * @param request
     */
    public  void  saveMethod(JSONObject object, HttpServletResponse response, HttpServletRequest request){
        CClientLinkman cClientLinkman = JSON.parseObject(object.getString("cClientLinkmanData"),CClientLinkman.class);
        /*cClientLinkman.setId(SysUtil.getId());
        String username = (String) request.getSession().getAttribute("sys.username");
        cClientLinkman.setCreatedBy(username);
        cClientLinkman.setCreatedOn(CommonUtil.getNowDate());
        cClientLinkman.setUpdatedBy(username);
        cClientLinkman.setUpdatedOn(CommonUtil.getNowDate());*/
        cClientLinkmanDao.insert(cClientLinkman);
        String datajson = JSON.toJSONString(cClientLinkman);
        try {
            WebUtil.send(response, CommonUtil.upJson("["+datajson+"]"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public  void  saveUPMethod(JSONObject object, HttpServletResponse response, HttpServletRequest request){
        CClientLinkman cClientLinkman = JSON.parseObject(object.getString("cClientLinkmanData"),CClientLinkman.class);
        String username = (String) request.getSession().getAttribute("sys.username");
        cClientLinkman.setUpdatedBy(username);
        cClientLinkman.setUpdatedOn(CommonUtil.getNowDate());
        cClientLinkmanDao.update(cClientLinkman);
        String datajson = JSON.toJSONString(cClientLinkman);
        try {
            WebUtil.send(response, CommonUtil.upJson("["+datajson+"]"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 删除记录
     * @param object
     * @param response
     * @param request
     */
    public void delCClient(JSONObject object, HttpServletResponse response, HttpServletRequest request) {
        String ids = request.getParameter("ids");
        cClientLinkmanDao.delete(ids);
    }
}
