package com.cnd3b.restcontroller.customer.wechatapplet; import com.alibaba.fastjson.JSONObject; import com.cnd3b.common.Controller; import com.cnd3b.common.data.Row; import com.cnd3b.common.data.Rows; import com.cnd3b.common.data.RowsMap; import com.cnd3b.common.data.SQLFactory; import com.cnd3b.common.parameter.parameter; import com.cnd3b.utility.WebRequest; import com.cnd3b.utility.wechatdock.WechatDock_Enterprise; import org.apache.commons.codec.digest.DigestUtils; import p2.pao.PaoRemote; import p2.pao.PaoSetRemote; import p2.util.P2Exception; import java.text.SimpleDateFormat; import java.util.Calendar; public class wechatapplet extends Controller { /** * 构造函数 * * @param content */ public wechatapplet(JSONObject content) { super(content); } /** * 获取培训学习列表 * * @return */ public String getCoursewareList() throws P2Exception { String ttypedetailid = content.getString("ttypedetailid"); String keywords = ""; if (content.containsKey("keywords")) { keywords = content.getString("keywords"); } SQLFactory sqlFactory = new SQLFactory(this, "查询课件列表", pageSize, pageNumber, " t1.createdate desc"); sqlFactory.addParameter("ttypedetailid", ttypedetailid); sqlFactory.addParameter("keywords", "%" + keywords + "%"); Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL()); // RowsMap rowsMap = getAttachmentUrl("tarchives_sc", rows.toArrayList("tarchives_scid"), "video"); //查询封面 RowsMap rowsMapCover = getAttachmentUrl("tarchives_sc", rows.toArrayList("tarchives_scid"), "cover"); for (Row row : rows) { // row.put("attinfos", rowsMap.get(row.getString("tarchives_scid"))); Rows coverRows = rowsMapCover.get(row.getString("tarchives_scid")); if (!coverRows.isEmpty()) { row.put("cover", coverRows.get(0).getString("fobsurl")); } else { row.put("cover", ""); } } createRequestLog(); return getSucReturnObject().setDataByPaging(rows).preloading(1).toString(); } /** * 获取课件详情 * * @return */ public String getCoursewareDetail() throws P2Exception { String tarchives_scid = content.getString("tarchives_scid"); //已学习人数加一 String sql = "UPDATE tarchives_sc SET fvisitors= CASE WHEN fvisitors IS NULL THEN 1 else fvisitors + 1 END where tarchives_scid='" + tarchives_scid + "'"; dbConnect.runSqlUpdate(sql); SQLFactory sqlFactory = new SQLFactory(this, "查询课件详细"); sqlFactory.addParameter("tarchives_scid", tarchives_scid); Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL()); RowsMap rowsMap = getAttachmentUrl("tarchives_sc", rows.toArrayList("tarchives_scid"), "video"); //查询封面 RowsMap rowsMapCover = getAttachmentUrl("tarchives_sc", rows.toArrayList("tarchives_scid"), "cover"); for (Row row : rows) { row.put("attinfos", rowsMap.get(row.getString("tarchives_scid"))); Rows coverRows = rowsMapCover.get(row.getString("tarchives_scid")); if (!coverRows.isEmpty()) { row.put("cover", coverRows.get(0).getString("fobsurl")); } } if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("未找到当前课件").toString(); } createRequestLog(); return getSucReturnObject().setData(rows.get(0)).toString(); } /** * 获取分类 * * @return * @throws P2Exception */ public String getTypeList() throws P2Exception { String fusertype = content.getString("fusertype"); String where = ""; //1表示业务员 if (fusertype.equals("1")) { where = "t1.fissaler ='1'"; } else { where = "t1.fisagent ='1'"; } String fparentid = content.getString("fparentid"); SQLFactory sqlFactory = new SQLFactory(this, "分类"); sqlFactory.addParameter_SQL("fparentid", fparentid); sqlFactory.addParameter_SQL("where", where); String sql = sqlFactory.getSQL(); Rows rows = dbConnect.runSqlQuery(sql); createRequestLog(); return getSucReturnObject().setData(rows).toString(); } /** * 新增日志 */ private void createRequestLog() { new Thread() { @Override public void run() { String sql = "SELECT*FROM tuserrequestlog WHERE fdate='" + getDate_Str() + "' AND tuserid='" + parameter.tuserid + "'"; Rows rows = dbConnect.runSqlQuery(sql); if (rows.isEmpty()) { SQLFactory sqlFactory = new SQLFactory(this, "新增日志"); sqlFactory.addParameter("tuserrequestlogid", createTableID("tuserrequestlog", "tuserrequestlogid")); sqlFactory.addParameter("siteid", parameter.defaultsiteid); sqlFactory.addParameter("fdate", getDate_Str()); sqlFactory.addParameter("flastrequestdate", getDateTime_Str()); sqlFactory.addParameter("tuserid", parameter.tuserid); dbConnect.runSqlUpdate(sqlFactory.getSQL()); } else { String id = rows.get(0).getString("tuserrequestlogid"); String sqlUpdate = "UPDATE tuserrequestlog SET frequesttimes=frequesttimes+1,flastrequestdate = '" + getDateTime_Str() + "' WHERE tuserrequestlogid = '" + id + "'"; dbConnect.runSqlUpdate(sqlUpdate); } } }.start(); } }