提交 | 用户 | age
|
900851
|
1 |
package com.yc.open.deli.schedule.v2; |
F |
2 |
|
|
3 |
import com.alibaba.fastjson.JSON; |
|
4 |
import com.yc.action.grid.GridUtils; |
|
5 |
import com.yc.factory.FactoryBean; |
|
6 |
import com.yc.multiData.SpObserver; |
|
7 |
import com.yc.open.deli.controller.DeliController; |
|
8 |
import com.yc.open.deli.entity.DeliCallBackMessage; |
|
9 |
import com.yc.open.deli.entity.T110562Entity; |
|
10 |
import com.yc.open.deli.entity.T110565Entity; |
|
11 |
import com.yc.open.deli.entity.T170139Entity; |
|
12 |
import com.yc.open.deli.service.PostDataBaseService; |
|
13 |
import com.yc.open.deli.service.v2.DeLiIfc; |
|
14 |
import com.yc.open.init.BaseGate; |
|
15 |
import com.yc.open.init.Task; |
|
16 |
import com.yc.open.mutual.schedule.GateEntity; |
|
17 |
import org.slf4j.Logger; |
|
18 |
import org.slf4j.LoggerFactory; |
|
19 |
|
|
20 |
import java.util.ArrayList; |
|
21 |
import java.util.List; |
|
22 |
import java.util.stream.Collectors; |
|
23 |
|
|
24 |
/** |
|
25 |
* 推送客户跟进记录 |
|
26 |
*/ |
|
27 |
public class T170139Thread extends BaseGate implements Runnable { |
|
28 |
protected final Logger log = LoggerFactory.getLogger(this.getClass()); |
|
29 |
private static String TASKID = "OP0047";//指定任务ID,其他功能号也有对应的taskid |
|
30 |
private GateEntity entity; |
|
31 |
DeLiIfc deliIfc; |
|
32 |
DeliController deliController; |
|
33 |
|
|
34 |
public T170139Thread(GateEntity entity, DeLiIfc deliIfc, DeliController deliController) { |
|
35 |
this.entity = entity; |
|
36 |
this.deliIfc = deliIfc; |
|
37 |
this.deliController = deliController; |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public void run() { |
|
42 |
try { |
|
43 |
SpObserver.setDBtoInstance("_" + entity.getDbid()); |
|
44 |
Task task = checkPoint(entity, TASKID); |
|
45 |
//满足条件才执行 |
|
46 |
if (task != null && task.getResult() == 1) { |
671e86
|
47 |
this.deliIfc.getDeliCvent(entity); |
a557a9
|
48 |
List<T170139Entity> result = this.deliIfc.getT170139List(entity.getDocCode(),task,entity.getDbid()); |
900851
|
49 |
if (result != null && result.size() > 0) { |
F |
50 |
String data = GridUtils.toJson(result); |
ecf825
|
51 |
String url = task.getApiUrl()+ deliController.getSignByDeLi(task,data,entity); |
900851
|
52 |
String msg= deliController.doPostByParameter(url, data); |
F |
53 |
List<DeliCallBackMessage> callBackMessage=JSON.parseArray(msg,DeliCallBackMessage.class); |
|
54 |
callBackMessage= callBackMessage.stream().map(x->{ |
|
55 |
if(x.getState()==0) { |
|
56 |
x.setMsg("推送成功"); |
|
57 |
}else { |
|
58 |
x.setMsg(x.getMsg()); |
|
59 |
} |
|
60 |
return x; |
|
61 |
}).collect(Collectors.toList()); |
|
62 |
updateState(callBackMessage,result); |
|
63 |
} |
|
64 |
} |
|
65 |
} catch (Exception ex) { |
|
66 |
ex.printStackTrace(); |
|
67 |
deliController.sendErrorLog(entity.getFormid(), entity.getDocCode(), ex); |
|
68 |
log.error(ex.getMessage()); |
|
69 |
} finally { |
|
70 |
SpObserver.setDBtoInstance(); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
private void updateState(List<DeliCallBackMessage> callBackMessages, List<T170139Entity> data) { |
|
75 |
if (callBackMessages != null && callBackMessages.size() > 0) { |
|
76 |
List<T110562Entity> t110562Entities = new ArrayList<>(); |
|
77 |
StringBuilder sb=new StringBuilder(); |
|
78 |
for (DeliCallBackMessage deliCallBackMessage : callBackMessages) { |
|
79 |
for(T170139Entity t170139Entity:data) { |
|
80 |
if (deliCallBackMessage.getDoccode().equalsIgnoreCase(t170139Entity.getDocCode())){ |
|
81 |
t110562Entities.add(new T110562Entity(170139, |
|
82 |
t170139Entity.getDocCode(), |
|
83 |
0, |
|
84 |
"", |
|
85 |
"", |
|
86 |
"", |
|
87 |
"", |
|
88 |
"", |
|
89 |
0, |
|
90 |
0, |
|
91 |
0, |
|
92 |
"", |
|
93 |
"", |
|
94 |
"", |
|
95 |
deliCallBackMessage.getState(), |
|
96 |
1, |
|
97 |
deliCallBackMessage.getMsg() |
|
98 |
)); |
|
99 |
|
|
100 |
//更新到对应单据的明细表 |
fabb9b
|
101 |
sb.append(" set nocount on \n update a set a.DeLi_PushStatus="+(deliCallBackMessage.getState()==0?1:0)+",a.DeLi_PushDate=getdate(),a.DeLi_PushTimes=isnull(a.DeLi_PushTimes,0)+1,a.DeLi_PushMsg='"+deliCallBackMessage.getMsg()+"' from t170139H a where a.doccode='"+t170139Entity.getDocCode()+"'\n"); |
900851
|
102 |
break; |
F |
103 |
} |
|
104 |
|
|
105 |
} |
|
106 |
} |
|
107 |
try { |
|
108 |
SpObserver.setDBtoInstance("_"+entity.getDbid()); |
|
109 |
PostDataBaseService mPostDataBaseService= (PostDataBaseService)FactoryBean.getBean("postDataBaseService"); |
|
110 |
int updateCount = mPostDataBaseService.getSimpleJdbcTemplate().queryForObject(sb.toString() + " \n select @@rowcount;", Integer.class); |
|
111 |
if(updateCount<=0){ |
|
112 |
log.error("德立销售订单-->更新出错【"+sb.toString()+"】"); |
|
113 |
} |
|
114 |
mPostDataBaseService.doLogBy110562(t110562Entities); |
|
115 |
if(data!=null&&data.size()>0) { |
|
116 |
T170139Entity t170139Entity=data.get(0); |
|
117 |
String docCode=t170139Entity.getDocCode(); |
|
118 |
mPostDataBaseService.doLogBy110565(new T110565Entity( |
|
119 |
170139, |
|
120 |
docCode, |
|
121 |
null, |
|
122 |
"推送客户跟进单170139", |
|
123 |
GridUtils.toJson(data) |
|
124 |
)); |
|
125 |
} |
|
126 |
}catch (Exception ex){ |
|
127 |
log.error("德立客户跟进单-->"+ex.getMessage()); |
|
128 |
}finally { |
|
129 |
SpObserver.setDBtoInstance(); |
|
130 |
} |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
} |