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
package com.ld.igds.phone.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.bstek.bdf2.core.model.DefaultUser;
import com.ld.igds.constant.OrderStatus;
import com.ld.igds.constant.OrderType;
import com.ld.igds.constant.RespCodeEnum;
import com.ld.igds.door.dto.DoorAccessParam;
import com.ld.igds.door.service.CoreDoorService;
import com.ld.igds.models.ApplyOrder;
import com.ld.igds.phone.constant.PhoneConstant;
import com.ld.igds.phone.dto.AuthUser;
import com.ld.igds.phone.dto.PhoneResponse;
import com.ld.igds.phone.mapper.PhoneCommonMapper;
import com.ld.igds.phone.param.ParamOrder;
import com.ld.igds.phone.param.PhoneRequest;
import com.ld.igds.phone.service.PhoneService;
import com.ld.igds.phone.util.PhoneRespUtil;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.warn.service.CoreWarnService;
import com.ld.igds.work.CoreApplyOrderService;
import com.ld.igds.work.dto.ApplyOrderData;
import com.ld.igds.work.dto.ApplyOrderParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Date;
 
/**
 * 工单模块-工单审核
 *
 * @author chen
 */
@Slf4j
@Service
public class ServiceImpl5704 implements PhoneService {
 
    @Autowired
    private CoreApplyOrderService applyOrderService;
    @Autowired
    private CoreDoorService coreDoorService;
    @Autowired
    private PhoneCommonMapper phoneCommonMapper;
    @Autowired
    private CoreWarnService warnSendService;
 
    @Override
    public String getInterfaceId() {
        return PhoneConstant.API_PHONE_5704;
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public PhoneResponse<Object> execute(PhoneRequest<JSONObject> req, AuthUser authUser)
            throws Exception {
 
        //转化为对象
        ParamOrder param = JSONObject.parseObject(req.getData().toString(), ParamOrder.class);
 
        if(param ==null || StringUtils.isEmpty(param.getId()) || StringUtils.isEmpty(param.getStatus())){
            return PhoneRespUtil.error(RespCodeEnum.CODE_1007, "参数有误,请重试!");
        }
 
        //审核工单更新
        ApplyOrderData data = new ApplyOrderData();
        data.setId(param.getId());
        data.setStatus(param.getStatus());
        data.setAuditTime(new Date());
        data.setAuditUser(authUser.getUsername());
        data.setAuditUserName(authUser.getCname());
        applyOrderService.updateApplyOrder(data);
 
        //判断审核状态,通过或者拒绝需要进行下一步操作
        if(OrderStatus.Status_20.getCode().equals(param.getStatus()) ||
                OrderStatus.Status_30.getCode().equals(param.getStatus())){
            //查询工单信息,判断是否是门禁类型
            ApplyOrderParam orderParam = new ApplyOrderParam();
            orderParam.setId(param.getId());
 
            ApplyOrderData orderData = applyOrderService.getApplyOrder(orderParam);
            if(OrderType.Type_10.getCode().equals(orderData.getType())){
                DoorAccessParam param1;
                if(OrderStatus.Status_20.getCode().equals(orderData.getStatus())){
                    //通过,进行门禁权限码生成并推送
                    param1 = new DoorAccessParam();
                    param1.setId(ContextUtil.getTimeId());
                    param1.setCompanyId(orderData.getCompanyId());
                    param1.setDeptId(orderData.getDeptId());
                    param1.setDepotId(orderData.getDepotId());
                    param1.setUser(orderData.getApplyUser());
                    String newToken = coreDoorService.getNewToken(null);
                    param1.setToken(newToken);
                    param1.setStart(orderData.getStart());
                    param1.setEnd(orderData.getEnd());
                    coreDoorService.addDoorAccess(param1);
 
                    //审核推送微信
                    this.pushAudit(orderData, param1.getToken());
                }
 
                if(OrderStatus.Status_30.getCode().equals(orderData.getStatus())){
                    //拒绝,门禁权限码记录进行删除
                    param1 = new DoorAccessParam();
                    param1.setCompanyId(orderData.getCompanyId());
                    param1.setDeptId(orderData.getDeptId());
                    param1.setDepotId(orderData.getDepotId());
                    param1.setUser(orderData.getApplyUserName());
                    coreDoorService.delDoorAccess(param1);
                }
            }
        }
 
        return PhoneRespUtil.success(null, req);
    }
 
    /**
     * 门禁审核推送
     * @param data
     */
    private void pushAudit(ApplyOrder data, String token){
 
        try{
            //推送微信
            DefaultUser user = phoneCommonMapper.phoneGetUser(data.getApplyUser());
            if(null == user || StringUtils.isEmpty(user.getMobile())){
                return;
            }
            ApplyOrderParam applyOrderParam = new ApplyOrderParam();
            applyOrderParam.setPhone(user.getMobile());
            applyOrderParam.setRecord("您的工单审核已通过");
            applyOrderParam.setId(data.getId());
            applyOrderParam.setType(OrderType.getMsg(data.getType()) + "权限码=" + token);
            String info = "您申请的工单已通过,注意查看!" ;
            applyOrderParam.setInfo(info);
 
            //调用推送接口
            warnSendService.noticeOrder(applyOrderParam);
        }catch (Exception e){
            log.error("-----后台异常:{}-----", e);
        }
    }
}