Search in sources :

Example 41 with BussinessException

use of com.ikoori.vip.common.exception.BussinessException 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;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Merchant(com.ikoori.vip.common.persistence.model.Merchant) Picture(com.ikoori.vip.common.persistence.model.Picture) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) BussinessException(com.ikoori.vip.common.exception.BussinessException) BussinessException(com.ikoori.vip.common.exception.BussinessException)

Aggregations

BussinessException (com.ikoori.vip.common.exception.BussinessException)41 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)25 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)19 Permission (com.ikoori.vip.common.annotion.Permission)17 Transactional (org.springframework.transaction.annotation.Transactional)9 User (com.ikoori.vip.common.persistence.model.User)8 Merchant (com.ikoori.vip.common.persistence.model.Merchant)7 Date (java.util.Date)7 Coupon (com.ikoori.vip.common.persistence.model.Coupon)6 ShiroUser (com.ikoori.vip.server.core.shiro.ShiroUser)6 BussinessLog (com.ikoori.vip.common.annotion.log.BussinessLog)5 File (java.io.File)4 HashMap (java.util.HashMap)4 EntityWrapper (com.baomidou.mybatisplus.mapper.EntityWrapper)3 OrderItemPayDo (com.ikoori.vip.common.dto.OrderItemPayDo)3 Card (com.ikoori.vip.common.persistence.model.Card)3 Member (com.ikoori.vip.common.persistence.model.Member)3 Menu (com.ikoori.vip.common.persistence.model.Menu)3 StoreCoupon (com.ikoori.vip.common.persistence.model.StoreCoupon)3 ApiOperation (io.swagger.annotations.ApiOperation)3