package com.api.custom.homePageDialog; import com.alibaba.fastjson.JSONObject; import weaver.conn.RecordSet; import weaver.general.StringUtil; import weaver.general.Util; import weaver.hrm.HrmUserVarify; import weaver.hrm.User; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.Map; @Path("/custom/homePageDialog") public class HomePageDialogApi { @GET @Path("/getHomePageDialog") @Produces(MediaType.TEXT_PLAIN) public String getVersionInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) { User user = HrmUserVarify.getUser(request, response); RecordSet rs = new RecordSet(); JSONObject result = new JSONObject(); JSONObject record = new JSONObject(); try { String currentDate = getCurrentDate(); String sql = " select * from uf_homePageDialo " + " where id = (" + " select max(id) from uf_homePageDialo" + " where startDate <= ? and endDate >= ?" + " ) "; rs.executeQuery(sql,currentDate,currentDate); String id = ""; String imgUrl = ""; String openUrl = ""; boolean isdialog = true; if (rs.next()){ id = Util.null2String(rs.getString("id")); imgUrl = Util.null2String(rs.getString("imgUrl")); openUrl = Util.null2String(rs.getString("openUrl")); } if(!"".equals(id)){ sql = "select count(1) as sl from uf_homePageDialo_dt1 where mainid = ? and userid = ? "; rs.executeQuery(sql,id,user.getUID()); while (rs.next()){ if(Util.getIntValue(rs.getString("sl"))>0){ isdialog = false; } } }else{ isdialog = false; } record.put("isdialog",isdialog); record.put("id",id); record.put("imgUrl",imgUrl); record.put("openUrl",openUrl); result.put("data", record); result.put("api_status", true); }catch (Exception e){ e.printStackTrace(); result.put("api_status", false); result.put("api_errormsg", "getVersionInfo catch exception : " + e.getMessage()); } return (JSONObject.toJSONString(result)); } @GET @Path("/addDialogUser") @Produces(MediaType.TEXT_PLAIN) public String addDialogUser(@Context HttpServletRequest request, @Context HttpServletResponse response) { Map apidatas = new HashMap(); try { //获取当前用户 User user = HrmUserVarify.getUser(request, response); String userid = user.getUID()+""; String mainid = Util.null2String(request.getParameter("id")); String sql = "insert into uf_homePageDialo_dt1 (mainid,userid) values ('"+mainid+"','"+userid+"')"; RecordSet rs = new RecordSet(); boolean status = rs.executeUpdate(sql); //删除其它版本用户查看记录 sql = "delete uf_homePageDialo_dt1 where mainid != '"+ mainid +"'"; rs.execute(sql); rs.next(); apidatas.put("status", status); apidatas.put("api_status", true); } catch (Exception e) { e.printStackTrace(); apidatas.put("api_status", false); apidatas.put("api_errormsg", "addDialogUser catch exception : " + e.getMessage()); } return (JSONObject.toJSONString(apidatas)); } /** * 获取当前日期,格式为 yyyy-MM-dd * @return 当前日期的字符串 */ public static String getCurrentDate() { // 获取当前日期 LocalDate currentDate = LocalDate.now(); // 定义日期格式 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // 格式化日期为 yyyy-MM-dd 格式的字符串 return currentDate.format(formatter); } }