【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
client项目
接受查询结果的实体:
public class TIvrDataCountGroupByPressKeyBo {
private String pressKey;
private int count;
Dao层
@ResultType(value = com.xiaoju.kefu.jazz.base.entity.TIvrDataCountGroupByPressKeyBo.class )
@Select("select presskey,count(presskey) count from T_Ivr_Data where inIvrTime between #{beginDate} and #{endDate} group by presskey")
List<TIvrDataCountGroupByPressKeyBo> findTIvrDataCountByHour(@Param("beginDate")
Service层:
/**
* 定时发送话务数据监控的业务线总数
*
* @return
*/
public void executeCountByPressKey(){
try {
logger.info("executeCountByPressKey");
executeCountByPressKey.lock();
Date date = DateUtils.addHour(new Date(), -1);
String beginDate = DateUtils.format(date, "yyyy-MM-dd HH:00:00");
String endDate = DateUtils.format(date, "yyyy-MM-dd HH:59:59");
List<TIvrDataCountGroupByPressKeyBo> list = tIvrDataMapper.findTIvrDataCountByHour(beginDate, endDate);
Map<String,String> dataMaps = Maps.newHashMap();
dataMaps.put("type", Constants.GENESYS_PressKey_Count);
dataMaps.put("Date", beginDate + " To "+endDate);
dataMaps.put("list", JSON.toJSONString(list));
dataHttpRemoteService.sendData(Constants.HTTP_PressKey_PerHour, dataMaps);
} catch (Exception e) {
logger.error("GenesysDataTask类executeCountByPressKey方法异常:", e);
} finally {
executeCountByPressKey.unlock();
}
logger.info("executeCountByPressKey() Online program starts normal");
}
sendData添加代码:
else if(Constants.HTTP_PressKey_PerHour.equals(sendType)){
url=propertiesLoader.getProperty(Constants.HTTP_PressKey_PerHour);
Contants:
//定时发送话务数据监控的业务线总数
public static final String HTTP_PressKey_PerHour = "http.prehour.send.data";
//定时发送话务数据监控的业务线总数常量
public static final String GENESYS_PressKey_Count = "genesys_presskey_count";
application.properties
#定时发送话务数据监控的业务线总数
http.prehour.send.data=http://kefu-dc.xiaojukeji.com/genesys/acceptgenesysdatabypresskey
web项目:
/**
* 接受Genesys定时发送的话务数据监控的业务线总数,放到redis中
*
* @param data
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping("/acceptgenesysdatabypresskey")
@ResponseBody
public KResponse acceptGenesysDataByPressKey(HttpServletRequest request) {
Map<String, String[]> data = request.getParameterMap();
KResponse result = new KResponse();
try {
Map<String, String> dataMaps = MapUtils.toMap(data);
String type = dataMaps.get("type");
String Date = dataMaps.get("Date");
String list = dataMaps.get("list");
setHRedis(type,Date,list,24*60*60);
} catch (Exception ex) {
result.setSysFail();
logger.error("GenesysControl类的acceptGenesysDataByPressKey方法异常", ex);
}
return result;
}
/**
* 获取上一个小时的话务数据监控的业务线总数
*
* @return
*/
public String getIvrDataByHour() {
Date date = addHour(new Date(), -1);
String beginDate = format(date, "yyyy-MM-dd HH:00:00");
String endDate = format(date, "yyyy-MM-dd HH:59:59");
String Date = beginDate + " To "+ endDate;
String result = getHRedis(Constants.GENESYS_PressKey_Count,Date);
if (result != null) {
return result;
} else {
return "上一小时没有数据";
}
}
/**
* 将key,field和value对应的值存入redis
*
* @param typeKey
* @param typeValue
*/
public void setHRedis(String typeKey, String typefield, String typeValue, Integer timeout) {
RedisUtils jedis = RedisUtils.getInstance();
try {
jedis.hset(typeKey, typefield, typeValue);
// 过期时间如果不为空,需要设置过期时间
if (timeout != null) {
jedis.expire(typeKey, timeout);
}
} catch (Exception ex) {
logger.error("GenesysControl类的setHRedis失败");
}
}
/**
* 从redis中获取key,field对应的value值
*
* @param typeKey
* @param typeValue
*/
public String getHRedis(String typeKey, String typefield) {
RedisUtils jedis = RedisUtils.getInstance();
String result = null;
try {
result = jedis.hget(typeKey, typefield);
} catch (Exception ex) {
logger.error("GenesysControl类的getHRedis失败");
}
return result;
}
public static final String format(Date date, String pattern){
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
}
public static final Date addHour(Date date, int hour) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.HOUR_OF_DAY, hour);
return cal.getTime();
}