CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
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
package com.ld.igds.phone.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.ld.igds.verb.dto.VerbParam;
import com.ld.igds.constant.RespCodeEnum;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.request.ExeDevice;
import com.ld.igds.io.response.DeviceControlResponse;
import com.ld.igds.phone.constant.PhoneConstant;
import com.ld.igds.phone.dto.*;
import com.ld.igds.phone.param.ParamExeDevice;
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.verb.manager.VerbManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
 
/**
 * 设备控制-设备操作接口实现
 *
 * @author chen
 */
@Service
public class ServiceImpl5403 implements PhoneService {
 
    @Autowired
    private VerbManager verbManager;
 
    @Override
    public String getInterfaceId() {
        return PhoneConstant.API_PHONE_5403;
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public PhoneResponse<Object> execute(PhoneRequest<JSONObject> req, AuthUser authUser)
            throws Exception {
 
        VerbParam param = new VerbParam();
        List<ExeDevice> list = new ArrayList<>();
        ExeDevice device;
        //转化请求的设备参数
        for (JSONObject jsonObject : req.getData1()) {
            ParamExeDevice paramExeDevice = JSONObject.parseObject(jsonObject.toString(), ParamExeDevice.class);
            device = new ExeDevice();
            device.setId(paramExeDevice.getId());
            device.setCompanyId(authUser.getCompanyId());
            device.setDepotId(paramExeDevice.getDepotId());
            device.setPassCode(paramExeDevice.getPassCode());
            device.setName(paramExeDevice.getName());
            device.setSerId(paramExeDevice.getSerId());
            device.setType(paramExeDevice.getType());
            device.setLink(paramExeDevice.getLink());
            device.setTargetStatus(paramExeDevice.getTargetStatus());
            list.add(device);
        }
        param.setDeviceList(list);
        param.setDepotId(list.get(0).getDepotId());
        param.setCompanyId(authUser.getCompanyId());
        DeviceControlResponse response = verbManager.controlDevice(param);
 
        if (OrderRespEnum.ORDER_ERROR.getCode().equals(response.getCode())) {
            return PhoneRespUtil.error(RespCodeEnum.CODE_1111, response.getMsg());
        } else {
            return PhoneRespUtil.success(response.getMsg(), req);
        }
    }
}