CZT
2023-09-06 71c4fa1e27f75ae4b765c95c67a3069c84dc72ba
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
package com.ld.igds.m.view;
 
import com.alibaba.fastjson.JSONObject;
import com.bstek.bdf2.core.model.DefaultDept;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.provider.Page;
import com.ld.igds.constant.Constant;
import com.ld.igds.constant.OrderStatus;
import com.ld.igds.constant.RespCodeEnum;
import com.ld.igds.m.dto.AppointParam;
import com.ld.igds.m.service.HAppointService;
import com.ld.igds.m.service.HInoutCustomerService;
import com.ld.igds.models.DicTrigger;
import com.ld.igds.models.InoutAppoint;
import com.ld.igds.models.InoutCustomer;
import com.ld.igds.sys.service.SysDeptService;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.DateUtil;
import com.ld.igds.warn.data.MsgResponse;
import com.ld.igds.wechat.WeChatUtils;
 
import lombok.extern.slf4j.Slf4j;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.*;
 
/**
 * 预约管理
 * 
 * @author: czt
 * @date 2023-04-12 17:45
 *
 */
@Slf4j
@Component
@SuppressWarnings("rawtypes")
public class AppointPR {
 
    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private HInoutCustomerService customerService;
    @Autowired
    private HAppointService inoutAppointService;
    @Autowired
    private WeChatUtils weChatUtils;
 
 
    /**
     * 状态类型
     * ${dorado.getDataProvider("appointPR#triggerStatusType").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<DicTrigger> triggerStatusType() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
 
        list.add(new DicTrigger(OrderStatus.Status_10.getCode(), "待审核"));
        list.add(new DicTrigger(OrderStatus.Status_20.getCode(), "通过"));
        list.add(new DicTrigger(OrderStatus.Status_30.getCode(), "拒绝"));
        list.add(new DicTrigger(OrderStatus.Status_40.getCode(), "退回"));
 
        return list;
    }
 
    /**
     * appointPR#pageInoutAppoint
     * @param page
     * @param param
     * @throws Exception
     */
    @DataProvider
    public void pageInoutAppoint(Page<InoutAppoint> page, Map<String, Object> param) throws Exception {
        if (null == param) {
            param = new HashMap<String, Object>();
        }
        inoutAppointService.pageInoutAppoint(page, param);
    }
 
 
    /**
     * 通过
     * appointPR#auditPass
     * @param data
     * @return
     */
    @Expose
    public void auditPass(InoutAppoint data) {
        data.setStatus(OrderStatus.Status_20.getCode());
        data.setAuditTime(new Date());
        data.setAuditUser(ContextUtil.getLoginUserCName());
        inoutAppointService.saveOrUpInoutAppoint(data);
    }
    /**
     * 拒绝
     * appointPR#auditReject
     * @param data
     * @return
     */
    @Expose
    public void auditReject(InoutAppoint data) {
        data.setStatus(OrderStatus.Status_30.getCode());
        data.setAuditTime(new Date());
        data.setAuditUser(ContextUtil.getLoginUserCName());
        inoutAppointService.saveOrUpInoutAppoint(data);
    }
 
    /**
     * 退回
     * appointPR#auditBack
     * @param data
     * @return
     */
    @Expose
    public void auditBack(InoutAppoint data) {
        data.setStatus(OrderStatus.Status_40.getCode());
        data.setAuditTime(new Date());
        data.setAuditUser(ContextUtil.getLoginUserCName());
        inoutAppointService.saveOrUpInoutAppoint(data);
    }
 
 
 
    /**
     * 同步出入库预约信息
     *
     * appointPR#syncInoutAppoint
     *
     * @return
     */
    @Expose
    public String syncInoutAppoint(AppointParam param) {
 
        AppointParam appointParam = new AppointParam();
        BeanUtils.copyProperties(param, appointParam);
 
        if(StringUtils.isEmpty(appointParam.getDeptId())){
            appointParam.setDeptId(ContextUtil.subDeptId(null));
        }
        if(StringUtils.isEmpty(appointParam.getCompanyId())){
            appointParam.setCompanyId(ContextUtil.getCompanyId());
        }
        if(null == appointParam.getStartTime()){
            appointParam.setStartTime(DateUtil.getCurZero(new Date()));
        }
 
        return syncInout(appointParam);
    }
 
    /**
     * 推送出入库客户信息到公众号服务
     *
     * appointPR#pushCustomer
     *
     * @return
     */
    
    @Expose
    public String pushCustomer() {
 
        //推送出入库客户信息到公众号服务
        List<InoutCustomer> list = customerService.queryList(null);
 
        if(null == list || list.isEmpty()){
            log.warn("----------未获取到单位信息,不推送---------");
            return "未获取到单位信息,不推送";
        }
        AppointParam param;
        List<AppointParam> listData = new ArrayList<>();
        for (InoutCustomer customer : list) {
            param = new AppointParam();
            param.setCustomerId(customer.getId());
            param.setCustomerName(customer.getName());
            param.setDeptId(customer.getDeptId());
            param.setType(customer.getType());
            listData.add(param);
        }
        MsgResponse response = weChatUtils.postToWeChat(listData, WeChatUtils.WECHAT_INTERFACEID_3002, ContextUtil.getCompanyId());
        if(null == response || StringUtils.isEmpty(response.getCode()) || !RespCodeEnum.CODE_0000.getCode().equals(response.getCode())){
            log.warn("----------单位{}信息推送失败,原因={}----------", listData, response);
            return "单位信息推送失败";
        }
        log.info("----------单位信息推送成功={}----------", listData);
        return "success";
    }
 
    /**
     * 推送库区信息到公众号服务
     *
     * appointPR#pushDept
     *
     * @return
     */
    @Expose
    public String pushDept() {
 
        List<DefaultDept> listDept = sysDeptService.getCacheDept(ContextUtil.getCompanyId());
        if(null == listDept || listDept.isEmpty()){
            return "未获取到库区信息,不推送!";
        }
        MsgResponse response;
        AppointParam param;
        List<AppointParam> listData = new ArrayList<>();
        for (DefaultDept dept : listDept) {
            if(Constant.DEPT_TYPE_20.equals(dept.getType())){
                param = new AppointParam();
                param.setDeptId(dept.getId());
                param.setDeptName(dept.getName());
                listData.add(param);
            }
        }
        response = weChatUtils.postToWeChat(listData, WeChatUtils.WECHAT_INTERFACEID_3001, ContextUtil.getCompanyId());
        if(null == response || StringUtils.isEmpty(response.getCode()) || !RespCodeEnum.CODE_0000.getCode().equals(response.getCode())){
            log.warn("----------库区{}信息推送失败,原因={}----------", listData, response);
            return "库区信息推送失败";
        }
        log.info("----------库区信息推送成功={}----------", listData);
        return "success";
    }
 
    /**
     * 同步出入库预约信息
     * @param param
     * @return
     */
    public String syncInout(AppointParam param) {
 
        MsgResponse response = weChatUtils.postToWeChat(param, WeChatUtils.WECHAT_INTERFACEID_3003, param.getCompanyId());
        if(null == response || StringUtils.isEmpty(response.getCode()) || !RespCodeEnum.CODE_0000.getCode().equals(response.getCode())){
            log.warn("----------出入库预约信息同步失败,原因={}----------", response);
            return "同步失败";
        }
        List<InoutAppoint> list = JSONObject.parseArray(JSONObject.toJSONString(response.getData()), InoutAppoint.class);
        if(null == list || list.isEmpty()){
            log.warn("----------同步出入库信息为空,不处理----------");
            return "同步数据为空";
        }
        InoutAppoint appoint;
        for (InoutAppoint inoutAppoint : list) {
            appoint = inoutAppointService.getInoutAppointById(inoutAppoint.getId(), inoutAppoint.getDeptId());
            if(null != appoint){
                log.warn("----------当前预约信息已存在,不更新={}---------", appoint);
                continue;
            }
 
            //新增,状态为待审核
            inoutAppoint.setStatus(OrderStatus.Status_10.getCode());
            inoutAppoint.setCompanyId(param.getCompanyId());
            inoutAppointService.saveOrUpInoutAppoint(inoutAppoint);
        }
        return "success";
    }
 
}