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
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
package com.ld.igds.phone35.manager;
 
import com.alibaba.fastjson.JSONObject;
import com.ld.igds.basic.manager.FileManager;
import com.ld.igds.constant.RespCodeEnum;
import com.ld.igds.data.PageResponse;
import com.ld.igds.phone35.dto.Phone35AuthUser;
import com.ld.igds.phone35.dto.DtoUpload;
import com.ld.igds.phone35.dto.PhoneResponse;
import com.ld.igds.phone35.param.Phone35Request;
import com.ld.igds.phone35.service.Phone35Service;
import com.ld.igds.phone35.util.PhoneRespUtil;
import com.ld.igds.phone35.util.Phone35Util;
import com.ld.igds.util.RedisUtil;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 接口业务分发
 * @author chen
 */
@Component(Phone35Manager.BEAN_ID)
public class Phone35Manager implements ApplicationContextAware {
    public static final String BEAN_ID = "phone35.phoneManager";
 
    private static Map<String, Phone35Service> serviceMap;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private FileManager fileManager;
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, Phone35Service> map = applicationContext
                .getBeansOfType(Phone35Service.class);
        serviceMap = new HashMap<>();
        for (String key : map.keySet()) {
            serviceMap.put(map.get(key).getInterfaceId(), map.get(key));
        }
    }
 
    /**
     * 业务执行入口
     * @param req
     * @param phone35AuthUser
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    public PhoneResponse<Object> execute(Phone35Request<JSONObject> req, Phone35AuthUser phone35AuthUser) throws Exception{
 
        Phone35Service service = serviceMap.get(req.getInterfaceId());
        if(null == service){
            return PhoneRespUtil.error(RespCodeEnum.CODE_1111,
                    "当前接口没有找到实现类,无法执行处理");
        }
 
        return service.execute(req, phone35AuthUser);
    }
 
    /**
     * 根据tokenAuth获取缓存中的tokenUser
     * @param req
     * @return
     */
    public Phone35AuthUser checkTokenAuth(Phone35Request<JSONObject> req){
        String tokenAuth = req.getTokenAuth();
        return (Phone35AuthUser) redisUtil.get(Phone35Util.createKey(tokenAuth));
    }
 
    /**
     * 值仓图片上传
     * @param file
     * @param req
     * @return
     * @throws IOException
     */
    @SuppressWarnings("unchecked")
    public PhoneResponse<Object> phoneUploadImg(MultipartFile file,
                                                HttpServletRequest req) throws IOException {
        String plateNum = req.getParameter("plateNum");
 
        PageResponse<String> result = fileManager.upLoadInoutImg(file, plateNum);
 
        if(result.getCode().equals(RespCodeEnum.CODE_0000.getCode())){
            //上传成功
            DtoUpload dtoUpload = new DtoUpload();
            dtoUpload.setStatus("success");
            dtoUpload.setMsg("上传成功!");
            dtoUpload.setFileName(result.getMsg());
            return PhoneRespUtil.success(dtoUpload);
        }else {
            //上传失败
            return PhoneRespUtil.error(RespCodeEnum.CODE_1111,"上传失败");
        }
    }
 
}