|  |  |  | 
|---|
|  |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
|---|
|  |  |  | import com.doumee.config.annotation.LoginNoRequired; | 
|---|
|  |  |  | import com.doumee.core.annotation.trace.Trace; | 
|---|
|  |  |  | import com.doumee.core.constants.ResponseStatus; | 
|---|
|  |  |  | import com.doumee.core.exception.BusinessException; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.HKConstants; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.BaseResponse; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.request.FacePictureCheckRequest; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.respose.FacePictureCheckResponse; | 
|---|
|  |  |  | import com.doumee.core.haikang.service.HKService; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.DateUtil; | 
|---|
|  |  |  | import com.doumee.core.utils.FtpUtil; | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.awt.*; | 
|---|
|  |  |  | import java.awt.image.BufferedImage; | 
|---|
|  |  |  | import java.io.*; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.Iterator; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.UUID; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Eva.Caesar Liu | 
|---|
|  |  |  | 
|---|
|  |  |  | @Trace(exclude = true) | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @LoginNoRequired | 
|---|
|  |  |  | @RequestMapping(Constants.CLOUD_SERVICE_URL_INDEX+"/web/visit/public") | 
|---|
|  |  |  | @RequestMapping(Constants.CLOUD_SERVICE_URL_INDEX+"/web/public") | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | public class WebPublicController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemDictDataBiz systemDictDataBiz; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "上传", notes = "上传", httpMethod = "POST", position = 6) | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "folder", value = "文件夹", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class), | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(value = "/upload", headers = "content-type=multipart/form-data") | 
|---|
|  |  |  | public void uploadMobile(String folder, HttpServletRequest request, HttpServletResponse response) throws Exception { | 
|---|
|  |  |  | public void uploadMobile(String folder, HttpServletRequest request, HttpServletResponse response,Integer isFace) throws Exception { | 
|---|
|  |  |  | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; | 
|---|
|  |  |  | upload(multipartRequest, response, folder + "/", | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.BUCKETNAME).getCode(), | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_ID).getCode(), | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_KEY).getCode(), | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode(), | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode()); | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode(),isFace); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(name = "folder", value = "文件夹", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class), | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(value = "/uploadPicture", headers = "content-type=multipart/form-data") | 
|---|
|  |  |  | public void uploadPicture(String folder, HttpServletRequest request, HttpServletResponse response) throws Exception { | 
|---|
|  |  |  | public void uploadPicture(String folder, HttpServletRequest request, HttpServletResponse response,Integer isFace) throws Exception { | 
|---|
|  |  |  | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; | 
|---|
|  |  |  | Iterator<String> fileNames = multipartRequest.getFileNames(); | 
|---|
|  |  |  | Map<String, Object> context = new HashMap<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_ID).getCode(), | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_KEY).getCode(), | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode(), | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode()); | 
|---|
|  |  |  | systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode(),isFace); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "上传文件到FTP") | 
|---|
|  |  |  | @RequestMapping(method= RequestMethod.POST,value="uploadFtp.do",headers = "content-type=multipart/form-data") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public void uploadFtp(HttpServletRequest request, HttpServletResponse response, String folderCode) throws Exception { | 
|---|
|  |  |  | public void uploadFtp(HttpServletRequest request, HttpServletResponse response, String folderCode,Integer isFace) throws Exception { | 
|---|
|  |  |  | System.out.println("上传中"); | 
|---|
|  |  |  | String folder = systemDictDataBiz.queryByCode(Constants.FTP,folderCode).getCode(); | 
|---|
|  |  |  | String prefixPath = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode(); | 
|---|
|  |  |  | 
|---|
|  |  |  | //                    boolean r = ftp.uploadInputstream(compressImg(is),fileName); | 
|---|
|  |  |  | boolean r = ftp.uploadInputstream(is,fileName); | 
|---|
|  |  |  | if(r){ | 
|---|
|  |  |  | if(Objects.nonNull(isFace) && Constants.equalsInteger(isFace,Constants.ZERO)){ | 
|---|
|  |  |  | //验证人脸评分 | 
|---|
|  |  |  | //人脸评分 | 
|---|
|  |  |  | FacePictureCheckRequest param = new FacePictureCheckRequest(); | 
|---|
|  |  |  | String prefixUrl = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_LOCAL_RESOURCE_PATH).getCode(); | 
|---|
|  |  |  | param.setFacePicUrl(prefixUrl + fileName); | 
|---|
|  |  |  | BaseResponse<FacePictureCheckResponse> responseBaseResponse = HKService.facePictureCheck(param); | 
|---|
|  |  |  | if(responseBaseResponse == null || !StringUtils.equals(responseBaseResponse.getCode(), HKConstants.RESPONSE_SUCCEE)){ | 
|---|
|  |  |  | //                                throw  new BusinessException(com.doumee.core.constants.ResponseStatus.SERVER_ERROR.getCode(), "对不起,人脸评分获取数据失败~"); | 
|---|
|  |  |  | context.put("code", 0); | 
|---|
|  |  |  | context.put("message", "对不起,人脸评分获取数据失败~"); | 
|---|
|  |  |  | context.put("errno",0); | 
|---|
|  |  |  | writerJson(response, context); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | FacePictureCheckResponse facePictureCheckResponse = responseBaseResponse.getData(); | 
|---|
|  |  |  | if(Objects.isNull(facePictureCheckResponse) || Objects.isNull(facePictureCheckResponse.getCheckResult())){ | 
|---|
|  |  |  | //                                throw  new BusinessException(com.doumee.core.constants.ResponseStatus.SERVER_ERROR.getCode(), "对不起,人脸评分获取数据失败~"); | 
|---|
|  |  |  | context.put("code", 0); | 
|---|
|  |  |  | context.put("message", "对不起,人脸评分获取数据失败~"); | 
|---|
|  |  |  | context.put("errno",0); | 
|---|
|  |  |  | writerJson(response, context); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!facePictureCheckResponse.getCheckResult()){ | 
|---|
|  |  |  | //                                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), facePictureCheckResponse.getStatusMessage()); | 
|---|
|  |  |  | context.put("code", 0); | 
|---|
|  |  |  | context.put("message", facePictureCheckResponse.getStatusMessage()); | 
|---|
|  |  |  | context.put("errno",0); | 
|---|
|  |  |  | writerJson(response, context); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | context.put("success", true); | 
|---|
|  |  |  | context.put("code", 200); | 
|---|
|  |  |  | context.put("errno",0); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void upload(HttpServletRequest request, HttpServletResponse response, String folder, String bucketName, | 
|---|
|  |  |  | String access_id, String access_key, String resourcePath, String endpoint) throws Exception { | 
|---|
|  |  |  | String access_id, String access_key, String resourcePath, String endpoint,Integer isFace) throws Exception { | 
|---|
|  |  |  | response.setCharacterEncoding("UTF-8"); | 
|---|
|  |  |  | response.setContentType("text/html;charset=UTF-8"); | 
|---|
|  |  |  | Map<String, Object> context = new HashMap<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | ALiYunUtil obs = new ALiYunUtil(endpoint,access_id, access_key); | 
|---|
|  |  |  | if (obs.uploadOnlineObject(file.getInputStream(),bucketName, key,null)) { | 
|---|
|  |  |  | // 移动成功,返回文件名 | 
|---|
|  |  |  | // sendSuccessMessage(response, resourcePath+key); | 
|---|
|  |  |  | if(Objects.nonNull(isFace) && Constants.equalsInteger(isFace,Constants.ZERO)){ | 
|---|
|  |  |  | //验证人脸评分 | 
|---|
|  |  |  | //人脸评分 | 
|---|
|  |  |  | FacePictureCheckRequest param = new FacePictureCheckRequest(); | 
|---|
|  |  |  | String prefixUrl = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_LOCAL_RESOURCE_PATH).getCode(); | 
|---|
|  |  |  | param.setFacePicUrl(prefixUrl + key); | 
|---|
|  |  |  | BaseResponse<FacePictureCheckResponse> responseBaseResponse = HKService.facePictureCheck(param); | 
|---|
|  |  |  | if(responseBaseResponse == null || !StringUtils.equals(responseBaseResponse.getCode(), HKConstants.RESPONSE_SUCCEE)){ | 
|---|
|  |  |  | context.put("code", 0); | 
|---|
|  |  |  | context.put("message", "对不起,人脸评分获取数据失败~"); | 
|---|
|  |  |  | context.put("errno",0); | 
|---|
|  |  |  | writerJson(response, context); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | FacePictureCheckResponse facePictureCheckResponse = responseBaseResponse.getData(); | 
|---|
|  |  |  | if(Objects.isNull(facePictureCheckResponse) || Objects.isNull(facePictureCheckResponse.getCheckResult())){ | 
|---|
|  |  |  | context.put("code", 0); | 
|---|
|  |  |  | context.put("message", "对不起,人脸评分获取数据失败~"); | 
|---|
|  |  |  | context.put("errno",0); | 
|---|
|  |  |  | writerJson(response, context); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!facePictureCheckResponse.getCheckResult()){ | 
|---|
|  |  |  | context.put("code", 0); | 
|---|
|  |  |  | context.put("message", facePictureCheckResponse.getStatusMessage()); | 
|---|
|  |  |  | context.put("errno",0); | 
|---|
|  |  |  | writerJson(response, context); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | context.put("success", true); | 
|---|
|  |  |  | context.put("code", 200); | 
|---|
|  |  |  | context.put("errno",0); | 
|---|