use of com.ikoori.vip.common.persistence.model.Merchant in project vip by guangdada.
the class UploadController method upload.
private JSONObject upload(MultipartFile picture, PicType picType) {
JSONObject obj = new JSONObject();
String pictureName = UUID.randomUUID().toString() + ".jpg";
try {
Long userId = Long.valueOf(ShiroKit.getUser().getId());
String fileSavePath = gunsProperties.getFileUploadPath() + pictureName;
picture.transferTo(new File(fileSavePath));
Picture pic = new Picture();
if (ShiroKit.hasRole(Const.MERCHANT_NAME)) {
Merchant merchant = merchantService.getMerchantUserId(userId);
pic.setMerchantId(merchant.getId());
}
pic.setPictypeId(picType.getCode());
pic.setRealName(picture.getOriginalFilename());
pic.setAbsUrl(gunsProperties.getImageUrl() + "/" + pictureName);
pic.setName(pictureName);
pictureMapper.insert(pic);
obj.put("pictureName", pic.getAbsUrl());
obj.put("pictureId", pic.getId());
} catch (Exception e) {
throw new BussinessException(BizExceptionEnum.UPLOAD_ERROR);
}
return obj;
}
Aggregations