package com.yc.open.yejibao.schedule;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
import com.yc.exception.ApplicationException;
|
import com.yc.exception.CallBackMessage;
|
import com.yc.factory.FactoryBean;
|
import com.yc.multiData.SpObserver;
|
import com.yc.open.deli.entity.T110565Entity;
|
import com.yc.open.deli.service.PostDataBaseService;
|
import com.yc.open.init.BaseGate;
|
import com.yc.open.init.Task;
|
import com.yc.open.mutual.schedule.GateEntity;
|
import com.yc.open.yejibao.controller.YeJiBaoController;
|
import com.yc.open.yejibao.entry.CancelEntry;
|
import com.yc.open.yejibao.service.YeJiBaoIfc;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
|
import java.util.Map;
|
|
/**
|
* 取消确认,向业绩宝推送删除操作
|
*/
|
public class Cancel150181Thread extends BaseGate {
|
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
private static String TASKID = "OP0079";
|
private GateEntity entity;
|
YeJiBaoIfc yeJiBaoIfc;
|
YeJiBaoController yeJiBaoController;
|
|
public Cancel150181Thread(GateEntity entity, YeJiBaoIfc yeJiBaoIfc, YeJiBaoController yeJiBaoController) {
|
this.entity = entity;
|
this.yeJiBaoIfc = yeJiBaoIfc;
|
this.yeJiBaoController = yeJiBaoController;
|
}
|
|
public void run() {
|
try {
|
SpObserver.setDBtoInstance("_" + entity.getDbid());
|
Task task = checkPoint(entity, TASKID);
|
//满足条件才执行
|
if (task != null && task.getResult() == 1) {
|
CancelEntry result = this.yeJiBaoIfc.cancelInfo(entity.getDocCode(), task);
|
if (result != null) {
|
String data = JSON.toJSONString(result, SerializerFeature.SortField);
|
CallBackMessage callBackMessage = yeJiBaoController.doPost(task.getApiUrl(), result.getCompanyID(), data);
|
if(callBackMessage.getState()==0){
|
Map<String,String> map= JSON.parseObject(callBackMessage.getData(),Map.class);
|
if(String.valueOf(map.get("code")).equals("1")) {
|
//成功
|
callBackMessage.sendSuccessMessage("业绩宝接收取消确认成功");
|
updateState(result, callBackMessage);
|
}else {
|
throw new ApplicationException("业绩宝:" + map.get("msg"));
|
}
|
}else {
|
throw new ApplicationException("业绩宝:" + callBackMessage.getError());
|
}
|
}
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
yeJiBaoController.sendErrorLog(entity.getFormid(), entity.getDocCode(), ex);
|
throw new ApplicationException("业绩宝:" + ex.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
private void updateState(CancelEntry cancelEntry, CallBackMessage callBackMessage){
|
PostDataBaseService mPostDataBaseService= (PostDataBaseService)FactoryBean.getBean("postDataBaseService");
|
try {
|
SpObserver.setDBtoInstance("_" + entity.getDbid());
|
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='" + cancelEntry.getDocCode()+"'",Integer.class);
|
}catch (Exception ex){
|
mPostDataBaseService.doLogBy110565(new T110565Entity(
|
150181,
|
cancelEntry.getDocCode(),
|
null,
|
"定金匹配销售订单150181",
|
"取消确认出错:"+ex.getMessage().replaceAll("'", "''")
|
));
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
}
|