| 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,"上传失败"); | 
|         } | 
|     } | 
|   | 
| } |