提交 | 用户 | age
|
bfda87
|
1 |
package com.yc.open.yejibao.schedule; |
F |
2 |
|
|
3 |
import com.alibaba.fastjson.JSON; |
|
4 |
import com.alibaba.fastjson.serializer.SerializerFeature; |
|
5 |
import com.yc.exception.ApplicationException; |
|
6 |
import com.yc.exception.CallBackMessage; |
|
7 |
import com.yc.factory.FactoryBean; |
|
8 |
import com.yc.multiData.SpObserver; |
|
9 |
import com.yc.open.deli.entity.T110565Entity; |
|
10 |
import com.yc.open.deli.service.PostDataBaseService; |
|
11 |
import com.yc.open.init.BaseGate; |
|
12 |
import com.yc.open.init.Task; |
|
13 |
import com.yc.open.mutual.schedule.GateEntity; |
|
14 |
import com.yc.open.yejibao.controller.YeJiBaoController; |
|
15 |
import com.yc.open.yejibao.entry.T150181Entity; |
|
16 |
import com.yc.open.yejibao.service.YeJiBaoIfc; |
|
17 |
import org.slf4j.Logger; |
|
18 |
import org.slf4j.LoggerFactory; |
|
19 |
|
|
20 |
import java.util.Map; |
|
21 |
|
|
22 |
/** |
|
23 |
* 推送收款单 |
|
24 |
*/ |
|
25 |
public class T150181Thread extends BaseGate implements Runnable { |
|
26 |
protected final Logger log = LoggerFactory.getLogger(this.getClass()); |
|
27 |
private static String TASKID = "OP0074";//指定任务ID,其他功能号也有对应的taskid |
|
28 |
private GateEntity entity; |
|
29 |
YeJiBaoIfc yeJiBaoIfc; |
|
30 |
YeJiBaoController yeJiBaoController; |
|
31 |
|
|
32 |
public T150181Thread(GateEntity entity, YeJiBaoIfc yeJiBaoIfc, YeJiBaoController yeJiBaoController) { |
|
33 |
this.entity = entity; |
|
34 |
this.yeJiBaoIfc = yeJiBaoIfc; |
|
35 |
this.yeJiBaoController = yeJiBaoController; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public void run() { |
|
40 |
try { |
|
41 |
SpObserver.setDBtoInstance("_" + entity.getDbid()); |
|
42 |
Task task = checkPoint(entity, TASKID); |
|
43 |
//满足条件才执行 |
|
44 |
if (task != null && task.getResult() == 1) { |
|
45 |
T150181Entity result = this.yeJiBaoIfc.getT150181List(entity.getDocCode(), task); |
|
46 |
if (result != null) { |
|
47 |
String data = JSON.toJSONString(result, SerializerFeature.SortField); |
|
48 |
CallBackMessage callBackMessage = yeJiBaoController.doPost(task.getApiUrl(), result.getCompanyID(), data); |
|
49 |
if(callBackMessage.getState()==0){ |
|
50 |
Map<String,String> map= JSON.parseObject(callBackMessage.getData(),Map.class); |
|
51 |
if(String.valueOf(map.get("code")).equals("1")) { |
|
52 |
//成功 |
|
53 |
callBackMessage.sendSuccessMessage("推送成功"); |
|
54 |
updateState(result, callBackMessage); |
|
55 |
}else { |
|
56 |
throw new ApplicationException(map.get("msg")); |
|
57 |
} |
|
58 |
}else { |
|
59 |
throw new ApplicationException(callBackMessage.getError()); |
|
60 |
} |
|
61 |
} |
|
62 |
} |
|
63 |
} catch (Exception ex) { |
|
64 |
ex.printStackTrace(); |
|
65 |
yeJiBaoController.sendErrorLog(entity.getFormid(), entity.getDocCode(), ex); |
|
66 |
log.error(ex.getMessage()); |
|
67 |
} finally { |
|
68 |
SpObserver.setDBtoInstance(); |
|
69 |
} |
|
70 |
} |
|
71 |
private void updateState(T150181Entity t150181Entity,CallBackMessage callBackMessage){ |
|
72 |
PostDataBaseService mPostDataBaseService= (PostDataBaseService)FactoryBean.getBean("postDataBaseService"); |
|
73 |
try { |
|
74 |
SpObserver.setDBtoInstance("_" + entity.getDbid()); |
|
75 |
mPostDataBaseService.getSimpleJdbcTemplate().queryForObject("update a set a.YeJiBaoPushStatus=" +callBackMessage.getState() + ",a.YeJiBaoPushDate=getdate(),a.YeJiBaoPushTimes=isnull(a.YeJiBaoPushTimes,0)+1,a.YeJiBaoPushMsg='" + callBackMessage.getSuccess() + "' from t150181H a where a.doccode='" + t150181Entity.getDocCode()+"'",Integer.class); |
|
76 |
}catch (Exception ex){ |
|
77 |
mPostDataBaseService.doLogBy110565(new T110565Entity( |
|
78 |
150181, |
|
79 |
t150181Entity.getDocCode(), |
|
80 |
null, |
|
81 |
"定金匹配销售订单150181", |
|
82 |
ex.getMessage().replaceAll("'", "''") |
|
83 |
)); |
|
84 |
}finally { |
|
85 |
SpObserver.setDBtoInstance(); |
|
86 |
} |
|
87 |
} |
|
88 |
} |