package com.cnd3b.restcontroller.singleagent.webclient.complaint;

import com.alibaba.fastjson.JSONObject;
import com.cnd3b.common.Controller;
import com.cnd3b.common.D3bException;
import com.cnd3b.common.data.Rows;
import p2.pao.PaoRemote;
import p2.pao.PaoSetRemote;
import p2.util.P2Exception;

/**
 * 投诉
 */
public class complaint extends Controller {
    public complaint(JSONObject content) {
        super(content);
    }

    /**
     * 投诉提交
     *
     * @return
     */
    public String insert() throws D3bException, P2Exception {
        String ftype = content.getString("ftype");//公告类型
        String ftitle = content.getString("ftitle", "tcomplaint.ftitle", "标题");//标题
        String fcontent = content.getString("fcontent", "tcomplaint.fcontent", "投诉内容");//公告内容

        PaoSetRemote tcomplaintSet = getP2ServerSystemPaoSet("tcomplaint");
        PaoRemote tcomplaint = tcomplaintSet.addAtEnd();
        tcomplaint.setValue("siteid", siteid, 11L);//企业ID
        tcomplaint.setValue("createby", username, 11L);//录入人
        tcomplaint.setValue("createdate", sysdate, 11L);//录入时间
        tcomplaint.setValue("fstatus", "待处理", 11L);

        tcomplaint.setValue("tenterprise_userid", userid, 11L);//录入人ID

        tcomplaint.setValue("ftype", ftype, 11L);//公告类型
        tcomplaint.setValue("fphonenumber", fphonenumber, 11L);
        tcomplaint.setValue("ftitle", ftitle, 11L);//标题
        tcomplaint.setValue("fcontent", fcontent, 11L);//公告内容

        tcomplaint.setValue("changeby", username, 11L);//修改人
        tcomplaint.setValue("changedate", sysdate, 11L);//修改时间
        long tcomplaintid = tcomplaint.getUniqueIDValue();
        saveDataLog(tcomplaint);
        tcomplaintSet.save();

        Rows rows = dbConnect.runSqlQuery("select tcomplaintid,createby,createdate,fcontent,fphonenumber,fstatus,ftitle,ftype,tenterprise_userid from tcomplaint where siteid='" + siteid + "' and tcomplaintid=" + tcomplaintid);
        return getSucReturnObject().setData(rows).toString();
    }

}
