jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
package com.ld.igds.phone.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.file.CoreFileService;
import com.ld.igds.phone.dto.DtoUpload;
import com.ld.igds.phone.util.PhoneRespUtil;
import com.ld.igds.phone.dto.AuthUser;
import com.ld.igds.phone.dto.PhoneResponse;
import com.ld.igds.phone.param.PhoneRequest;
import com.ld.igds.phone.service.PhoneService;
import com.ld.igds.phone.util.PhoneUtil;
import com.ld.igds.util.FfmpegUtil;
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.Date;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 接口业务分发
 * @author chen
 */
@Component
public class PhoneManager implements ApplicationContextAware {
 
    private static Map<String, PhoneService> serviceMap;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private FileManager fileManager;
    @Autowired
    private CoreFileService fileService;
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, PhoneService> map = applicationContext
                .getBeansOfType(PhoneService.class);
        serviceMap = new HashMap<>();
        for (String key : map.keySet()) {
            serviceMap.put(map.get(key).getInterfaceId(), map.get(key));
        }
    }
 
    /**
     * 业务执行入口
     * @param req
     * @param authUser
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    public PhoneResponse<Object> execute(PhoneRequest<JSONObject> req, AuthUser authUser) throws Exception{
 
        PhoneService service = serviceMap.get(req.getInterfaceId());
        if(null == service){
            return PhoneRespUtil.error(RespCodeEnum.CODE_1111,
                    "当前接口没有找到实现类,无法执行处理");
        }
 
        return service.execute(req,authUser);
    }
 
    /**
     * 根据tokenAuth获取缓存中的tokenUser
     * @param req
     * @return
     */
    public AuthUser checkTokenAuth(PhoneRequest<JSONObject> req){
        String tokenAuth = req.getTokenAuth();
        return (AuthUser) redisUtil.get(PhoneUtil.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,"上传失败");
        }
    }
 
}