xinyb
2024-01-19 d92c57be4019f59482244e03830d15656dfc2967
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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();
        }
    }
}