package com.engine.htsc.cooperation;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.htsc.collaboration.service.TaskLogService;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.interfaces.htsc.GlobatTools.MessageDetailLog;
import weaver.interfaces.htsc.GlobatTools.Smstools;
import weaver.interfaces.htsc.comInfo.PropBean;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.text.SimpleDateFormat;
import java.util.*;

public class TaskToLog {

    @POST
    @Path("/TaskToUser")
    @Produces({MediaType.TEXT_PLAIN})
    public String TaskToUser(@Context HttpServletRequest request, @Context HttpServletResponse response){
        PropBean propBean = new PropBean();
        Smstools smstools=new Smstools();
        RecordSet rs = new RecordSet();
        ModeRightInfo mode=new ModeRightInfo();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        SimpleDateFormat sd= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        MessageDetailLog meslog=new MessageDetailLog("uf_xzsy_dt1");
        String datetime=sd.format(new Date());
        String billid="";
      //  String sjlx="0";//1是评论，0是反馈
     //   String jllx="1";//1是任务，0是协作
        try{
            User user = HrmUserVarify.getUser(request, response);
            billid = Util.null2String(request.getParameter("billid"));
            String title= Util.null2String(request.getParameter("title"));
            String context  = Util.null2String(request.getParameter("context"));
            String sjlx= Util.null2String(request.getParameter("sjlx"));
            String jllx= Util.null2String(request.getParameter("jllx"));
            if("".equals(sjlx)){
                sjlx="0";
            }
            if("".equals(jllx)){
                jllx="1";
            }
            if("".equals(billid)||"".equals(title)||"".equals(context)){
                apidatas.put("status", false);
                apidatas.put("errormsg", "传递参数为空");
            }
            TaskLogService taskLogService=new TaskLogService();
            taskLogService.createTaskLog(user,billid,"",jllx,sjlx,context,title);
            apidatas.put("status", "true");

        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("status", false);
            apidatas.put("errormsg", "catch exception : " + e.getMessage());
          //  meslog.writLogsnotretrun(billid,e.getMessage(),"0",meslog.error);

        }
        return JSON.toJSONString(apidatas);
    }
}
