//服务器代码
public HashMap saveservice(Long driverid, String userkey, Long mlon,
Long mlat, String telephone, Long coopid,Long time,String clientcreatetime,int distime) {
System.out.println(time+"11111111111111111111111111111111111111111111111");
HashMap map = new HashMap();
String sql1 = "select * from edj_customer where user_key =?";
List<EdjCustomer> list = DBUtil.getHgjDao().findBySQL(sql1,
new Object[] { userkey }, 0, 1, new EdjCustomer());
Long customerId = null;
if (list == null || list.size() < 1) {
// 设置用户名
// 创建用户 userKey creatTime city
// userName=userKey;
EdjCustomer c = new EdjCustomer();
c.setUserKey(userkey);
c.setCreateTime(new Date());
DBUtil.getHgjDao().save(c);
customerId = c.getId();
} else {
EdjCustomer cc = list.get(0);
if (cc != null) {
customerId = cc.getId();
}
}
Date orderTime = null;
//--保存创建时间
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if(clientcreatetime!=null&&!"".equals(clientcreatetime)){
try {
orderTime=format.parse(clientcreatetime);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
String newsql="select * from edj_service t where t.customer_id=? and t.order_time=?";
//有过一次上传
List<EdjService> oldlist=DBUtil.getDao().findBySQL(newsql,new Object[]{customerId,orderTime}, 0, 1,new EdjService());
if(!(oldlist.size() == 1 && "".equals(oldlist.get(0)) || oldlist.size() == 0
|| oldlist == null || oldlist.get(0) == null)){
EdjService service=oldlist.get(0);
Long oldcalltime =0l;
if(service.getCallTime()!=null){
oldcalltime=service.getCallTime();
}
if(time>0&&time>oldcalltime){
service.setCallTime(time);
try {
DBUtil.getDao().update(service);
map.put("code",1);
map.put("msg","更新成功");
map.put("id",service.getId());
} catch (Exception e) {
map.put("code",0);
map.put("msg","更新失败");
}
}else {
map.put("code",2);
map.put("msg","已经添加");
}
}
//第一次上传数据
else{
EdjService s = new EdjService();
// 所属平台 1000 代表北京 根据城市查平台ID
// 提前预加载 存到map中 根据请求调用 等待...明天完成
s.setCustomerMobile(telephone);
s.setCoopId(coopid);
EdjTools edj=new EdjTools();
//正确的开始时间
if(distime!=0){
Date start=edj.MakeTime(distime);
System.out.println(start.toString()+"..........时间");
s.setCreateTime(start);
}
else {
s.setCreateTime(new Date());
}
s.setDriverId(driverid);
s.setCustomerId(customerId);
s.setLongitude(mlon);
s.setLatitude(mlat);
// 订单来源 2表示客户端
s.setOrderSource((short) 2);
if(orderTime!=null&&!"".equals(orderTime)){
s.setOrderTime(orderTime);
}
// if(time>0){
s.setCallTime(time);
// }
// int count=DBUtil.getDao().countBySQL(newsql, new Object[]{customerId,orderTime});
// if(count>0){
// map.put("code",2);
// map.put("msg","已经添加");
// }
// else{
try{
DBUtil.getHgjDao().save(s);
map.put("code",1);
map.put("msg","添加成功");
map.put("id",s.getId());
}catch(Exception ex){
map.put("code",0);
map.put("msg","添加失败");
}
// }
}
return map;
}
//客户端保存
点击呼叫 --保存本地 url ------1 code=0 2 成功 删除本地文件 2code=1 或空 等待上传
通话结束 --保存本地 url+通话时间time ------1 code=0 2 成功 删除本地文件 2code=1 或空 等待上传