#E10-23# 群聊数量接口优化
parent
6bf69c4b7c
commit
6171563d31
@ -0,0 +1,211 @@
|
||||
package com.weaver.seconddev.jcldoor.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.common.distribution.genid.IdGenerator;
|
||||
import com.weaver.ebuilder.datasource.api.entity.SqlParamEntity;
|
||||
import com.weaver.ebuilder.datasource.api.enums.SqlParamType;
|
||||
import com.weaver.em.msg.api.entity.Request;
|
||||
import com.weaver.em.msg.api.entity.Response;
|
||||
import com.weaver.framework.rpc.annotation.RpcReference;
|
||||
import com.weaver.teams.domain.user.SimpleEmployee;
|
||||
import com.weaver.teams.security.context.UserContext;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class ChatDayUtils {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(ChatDayUtils.class);
|
||||
|
||||
@RpcReference
|
||||
private com.weaver.em.msg.api.rest.OaRest oaRest;
|
||||
|
||||
@Autowired
|
||||
private DatabaseUtils databaseUtils;
|
||||
|
||||
|
||||
public Map<String,Object> getChatDay(String tenant_key, String tablename,String pageSize,String pageNum){
|
||||
Map<String,Object> dataMap = new HashMap<String,Object>();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
String sourceType = "LOGIC";
|
||||
|
||||
try {
|
||||
SimpleEmployee employee = UserContext.getCurrentUser();
|
||||
|
||||
String startDate = "2001-01-01";
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
//设置当前时间
|
||||
cal.setTime(new Date());
|
||||
//同理增加一天的方法:
|
||||
cal.add(Calendar.DATE, -1);
|
||||
String endDate = format.format(cal.getTime());
|
||||
|
||||
log.error("startDate:"+startDate);
|
||||
log.error("endDate:"+endDate);
|
||||
Long cid = employee.getCid();
|
||||
log.error("getChatGroup--cid:"+cid);
|
||||
Long employeeId = employee.getEmployeeId();
|
||||
|
||||
Map<String, Object> json = new HashMap<String, Object>();
|
||||
json.put("cid",cid);
|
||||
json.put("pageNum",pageNum);
|
||||
json.put("pageSize",pageSize);
|
||||
json.put("startDate",startDate);
|
||||
json.put("endDate",endDate);
|
||||
|
||||
log.error("json:"+ JSON.toJSONString(json));
|
||||
|
||||
Request request = new Request();
|
||||
request.setUrl("/user-profile/dailySingleSession");
|
||||
request.setParamsMap(json);
|
||||
request.setAsync(false);
|
||||
|
||||
log.error("request:"+ request.toString());
|
||||
Response response = oaRest.executeIm(request);
|
||||
log.error("getChatGroup--isSuccess"+response.isSuccess());
|
||||
if (response.isSuccess()){
|
||||
String data = response.getData();
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
JSONObject dataJson = JSONObject.parseObject(data);
|
||||
JSONObject actionMsg = dataJson.getJSONObject("actionMsg");
|
||||
if(actionMsg.containsKey("code")){
|
||||
String code = actionMsg.getString("code");
|
||||
if("0".equals(code)){
|
||||
JSONObject dataObject = dataJson.getJSONObject("data");
|
||||
if(dataObject.containsKey("data")){
|
||||
JSONArray dataArray = dataObject.getJSONArray("data");
|
||||
for(int i=0;i<dataArray.size();i++){
|
||||
JSONObject dataInfo = dataArray.getJSONObject(i);
|
||||
String userid = dataInfo.getString("userid");
|
||||
String amount = dataInfo.getString("amount");
|
||||
|
||||
String sql = " select id from "+tablename+" where ry=? and tenant_key=? and delete_type=0 ";
|
||||
List<SqlParamEntity> sqlparam = new ArrayList<SqlParamEntity>();
|
||||
SqlParamEntity sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(userid+"");
|
||||
sqlparam.add(sqlParamEntity);
|
||||
|
||||
sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(tenant_key+"");
|
||||
sqlparam.add(sqlParamEntity);
|
||||
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, sql,sqlparam);
|
||||
List<Map<String,Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
if(!recordList.isEmpty()){
|
||||
updateChatDayDate(userid,amount,sourceType,groupId,tenant_key,tablename);
|
||||
}else{
|
||||
insertChatDayDate(userid,amount,employeeId,sourceType,groupId,tenant_key,tablename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("testSapi13:"+e);
|
||||
}
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param userid
|
||||
* @param amount
|
||||
* @param employeeId
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param tenant_key
|
||||
*/
|
||||
public void insertChatDayDate(String userid,String amount,long employeeId,String sourceType,String groupId,String tenant_key,String tablename){
|
||||
|
||||
try {
|
||||
long generate = IdGenerator.generate();
|
||||
String sql =" insert into "+tablename+"(id,ry,amount,form_data_id,data_index,create_time,update_time,tenant_key,is_delete,creator,delete_type) " +
|
||||
" values (" + generate + "," + userid + ",'"+amount+"'," + generate + ",0,now(),now(),'"+tenant_key+"',0," + employeeId + ",0)";
|
||||
log.error("insertChatDayDate-sql:"+sql);
|
||||
Map<String, Object> result = databaseUtils.execute(sourceType, groupId, sql);
|
||||
|
||||
Iterator<Map.Entry<String, Object>> iterator = result.entrySet().iterator();
|
||||
while (iterator.hasNext()){
|
||||
Map.Entry<String, Object> next = iterator.next();
|
||||
log.error("insertChatDayDate--key="+next.getKey()+" value="+String.valueOf(next.getValue()));
|
||||
}
|
||||
|
||||
List<Map<String,Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
for(int i=0;i<recordList.size();i++){
|
||||
Map<String,Object> map = recordList.get(i);
|
||||
for (String key:map.keySet()){
|
||||
System.out.println("insertChatDayDate222--key= "+key+" and value= "+String.valueOf(map.get(key)));
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("insertChatDayDate:"+e);
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param userid
|
||||
* @param amount
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param tenant_key
|
||||
*/
|
||||
public void updateChatDayDate(String userid,String amount,String sourceType,String groupId,String tenant_key,String tablename){
|
||||
try {
|
||||
String sql =" update "+tablename+" set amount=?,update_time=now() where ry = ? and tenant_key= ? and delete_type=0 ";
|
||||
log.error("insertChatDayDate-sql:"+sql);
|
||||
|
||||
List<SqlParamEntity> sqlparam = new ArrayList<SqlParamEntity>();
|
||||
SqlParamEntity sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(amount+"");
|
||||
sqlparam.add(sqlParamEntity);
|
||||
|
||||
sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(userid+"");
|
||||
sqlparam.add(sqlParamEntity);
|
||||
|
||||
sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(tenant_key);
|
||||
sqlparam.add(sqlParamEntity);
|
||||
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, sql,sqlparam);
|
||||
Iterator<Map.Entry<String, Object>> iterator = result.entrySet().iterator();
|
||||
while (iterator.hasNext()){
|
||||
Map.Entry<String, Object> next = iterator.next();
|
||||
log.error("insertChatDayDate--key="+next.getKey()+" value="+String.valueOf(next.getValue()));
|
||||
}
|
||||
|
||||
List<Map<String,Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
for(int i=0;i<recordList.size();i++){
|
||||
Map<String,Object> map = recordList.get(i);
|
||||
for (String key:map.keySet()){
|
||||
System.out.println("insertChatDayDate222--key= "+key+" and value= "+String.valueOf(map.get(key)));
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("insertChatDayDate:"+e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,219 @@
|
||||
package com.weaver.seconddev.jcldoor.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.common.distribution.genid.IdGenerator;
|
||||
import com.weaver.ebuilder.datasource.api.entity.SqlParamEntity;
|
||||
import com.weaver.ebuilder.datasource.api.enums.SqlParamType;
|
||||
import com.weaver.em.msg.api.entity.Request;
|
||||
import com.weaver.em.msg.api.entity.Response;
|
||||
import com.weaver.framework.rpc.annotation.RpcReference;
|
||||
import com.weaver.teams.domain.user.SimpleEmployee;
|
||||
import com.weaver.teams.security.context.UserContext;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.weaver.em.msg.api.rest.OaRest;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class ChatGroupUtils {
|
||||
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(ChatGroupUtils.class);
|
||||
|
||||
@RpcReference
|
||||
private OaRest oaRest;
|
||||
|
||||
@Autowired
|
||||
private DatabaseUtils databaseUtils;
|
||||
|
||||
/***
|
||||
*
|
||||
*
|
||||
*/
|
||||
public Map<String,Object> getChatGroup(String tenant_key, String tablename,String pageSize,String pageNum){
|
||||
Map<String,Object> dataMap = new HashMap<String,Object>();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
String groupId = "weaver-ebuilder-form-service";
|
||||
String sourceType = "LOGIC";
|
||||
|
||||
try {
|
||||
|
||||
String startDate = "2001-01-01";
|
||||
//设置当前时间
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
//同理增加一天的方法:
|
||||
cal.add(Calendar.DATE, -1);
|
||||
String endDate = format.format(cal.getTime());
|
||||
|
||||
log.error("startDate:"+startDate);
|
||||
log.error("endDate:"+endDate);
|
||||
|
||||
SimpleEmployee employee = UserContext.getCurrentUser();
|
||||
Long cid = employee.getCid();
|
||||
long employeeId = employee.getEmployeeId();
|
||||
log.error("getChatGroup--cid:"+cid);
|
||||
|
||||
Map<String, Object> json = new HashMap<String, Object>();
|
||||
json.put("cid",cid);
|
||||
json.put("pageNum",pageNum);
|
||||
json.put("pageSize",pageSize);
|
||||
json.put("startDate",startDate);
|
||||
json.put("endDate",endDate);
|
||||
|
||||
log.error("json:"+ JSON.toJSONString(json));
|
||||
|
||||
Request request = new Request();
|
||||
request.setUrl("/user-profile/groupSession");
|
||||
request.setParamsMap(json);
|
||||
request.setAsync(false);
|
||||
|
||||
Response response = oaRest.executeIm(request);
|
||||
log.error("getChatGroup--isSuccess"+response.isSuccess());
|
||||
if(response.isSuccess()){
|
||||
String data = response.getData();
|
||||
if(StringUtils.isNotBlank(data)){
|
||||
JSONObject dataJson = JSONObject.parseObject(data);
|
||||
JSONObject actionMsg = dataJson.getJSONObject("actionMsg");
|
||||
if(actionMsg.containsKey("code")){
|
||||
String code = actionMsg.getString("code");
|
||||
log.error("getChatGroup--code"+code);
|
||||
if("0".equals(code)){
|
||||
JSONObject dataObject = dataJson.getJSONObject("data");
|
||||
if(dataObject.containsKey("data")){
|
||||
JSONArray dataArray = dataObject.getJSONArray("data");
|
||||
for(int i=0;i<dataArray.size();i++){
|
||||
JSONObject dataInfo = dataArray.getJSONObject(i);
|
||||
String userid = dataInfo.getString("userid");
|
||||
String amount = dataInfo.getString("amount");
|
||||
|
||||
String sql = " select id from "+tablename+" where ry=? and tenant_key=? and delete_type=0 ";
|
||||
log.error("getChatGroup--sql"+sql);
|
||||
|
||||
List<SqlParamEntity> sqlparam = new ArrayList<SqlParamEntity>();
|
||||
SqlParamEntity sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(userid+"");
|
||||
sqlparam.add(sqlParamEntity);
|
||||
|
||||
sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(tenant_key+"");
|
||||
sqlparam.add(sqlParamEntity);
|
||||
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, sql,sqlparam);
|
||||
List<Map<String,Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
if(!recordList.isEmpty()){
|
||||
|
||||
log.error("getChatGroup--!isEmpty");
|
||||
updateChatGroupDate(userid,amount,sourceType,groupId,tenant_key,tablename);
|
||||
}else{
|
||||
log.error("getChatGroup--isEmpty");
|
||||
insertChatGroupDate(userid,amount,employeeId,sourceType,groupId,tenant_key,tablename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("getChatGroup:"+e);
|
||||
}
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param userid
|
||||
* @param amount
|
||||
* @param employeeId
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param tenant_key
|
||||
*/
|
||||
public void insertChatGroupDate(String userid,String amount,long employeeId,String sourceType,String groupId,String tenant_key,String tablename){
|
||||
|
||||
try {
|
||||
long generate = IdGenerator.generate();
|
||||
String sql =" insert into "+tablename+"(id,ry,amount,form_data_id,data_index,create_time,update_time,tenant_key,is_delete,creator,delete_type) " +
|
||||
" values(" + generate + "," + userid + ",'"+amount+"'," + generate + ",0,now(),now(),'"+tenant_key+"',0," + employeeId + ",0)";
|
||||
log.error("insertChatGroupDate-sql:"+sql);
|
||||
Map<String, Object> result = databaseUtils.execute(sourceType, groupId, sql);
|
||||
Iterator<Map.Entry<String, Object>> iterator = result.entrySet().iterator();
|
||||
while (iterator.hasNext()){
|
||||
Map.Entry<String, Object> next = iterator.next();
|
||||
log.error("insertChatGroupDate--key="+next.getKey()+" value="+String.valueOf(next.getValue()));
|
||||
}
|
||||
|
||||
List<Map<String,Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
for(int i=0;i<recordList.size();i++){
|
||||
Map<String,Object> map = recordList.get(i);
|
||||
for (String key:map.keySet()){
|
||||
System.out.println("insertChatGroupDate--key= "+key+" and value= "+String.valueOf(map.get(key)));
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("insertChatGroupDate:"+e);
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
*
|
||||
* @param userid
|
||||
* @param amount
|
||||
* @param sourceType
|
||||
* @param groupId
|
||||
* @param tenant_key
|
||||
*/
|
||||
public void updateChatGroupDate(String userid,String amount,String sourceType,String groupId,String tenant_key,String tablename){
|
||||
try {
|
||||
String sql =" update "+tablename+" set amount=?,update_time=now() where ry = ? and tenant_key= ? and delete_type=0 ";
|
||||
List<SqlParamEntity> sqlparam = new ArrayList<SqlParamEntity>();
|
||||
SqlParamEntity sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(amount+"");
|
||||
sqlparam.add(sqlParamEntity);
|
||||
|
||||
sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(userid+"");
|
||||
sqlparam.add(sqlParamEntity);
|
||||
|
||||
sqlParamEntity = new SqlParamEntity();
|
||||
sqlParamEntity.setParamType(SqlParamType.VARCHAR);
|
||||
sqlParamEntity.setValue(tenant_key);
|
||||
sqlparam.add(sqlParamEntity);
|
||||
|
||||
Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, sql,sqlparam);
|
||||
Iterator<Map.Entry<String, Object>> iterator = result.entrySet().iterator();
|
||||
while (iterator.hasNext()){
|
||||
Map.Entry<String, Object> next = iterator.next();
|
||||
log.error("updateChatGroupDate--key="+next.getKey()+" value="+String.valueOf(next.getValue()));
|
||||
}
|
||||
|
||||
List<Map<String,Object>> recordList = databaseUtils.getDataSourceList(result);
|
||||
for(int i=0;i<recordList.size();i++){
|
||||
Map<String,Object> map = recordList.get(i);
|
||||
for (String key:map.keySet()){
|
||||
System.out.println("updateChatGroupDate--key= "+key+" and value= "+String.valueOf(map.get(key)));
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("updateChatGroupDate:"+e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue