Search in sources :

Example 26 with BussinessException

use of com.ikoori.vip.common.exception.BussinessException in project vip by guangdada.

the class CouponServiceImpl method saveCoupon.

/**
 * 优惠券保存
 * @Title: saveCoupon
 * @param coupon
 * @date:   2017年9月18日 下午2:34:36
 * @author: chengxg
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void saveCoupon(Coupon coupon, String storeIds) {
    if (coupon.getValue() != null) {
        coupon.setOriginValue(coupon.getValue() * 100);
    }
    if (!coupon.isIsAtLeast()) {
        coupon.setAtLeast(null);
        coupon.setOriginAtLeast(null);
        coupon.setUseCondition("不限制");
    }
    if (coupon.getAtLeast() != null) {
        coupon.setOriginAtLeast(coupon.getAtLeast() * 100);
        coupon.setUseCondition("满" + coupon.getAtLeast() + "元使用");
    }
    coupon.setStartTime(coupon.getStartAt().getTime());
    coupon.setEndTime(coupon.getEndAt().getTime());
    coupon.setLimitStore(StringUtils.isBlank(storeIds) ? false : true);
    if (coupon.getId() != null) {
        Coupon couponDb = couponMapper.selectById(coupon.getId());
        if (coupon.getTotal() < couponDb.getGetCount()) {
            throw new BussinessException(500, "发放总量不能小于领取数量" + couponDb.getGetCount());
        }
        int stock = coupon.getTotal() - couponDb.getTotal();
        couponDb.setStock(couponDb.getStock() + stock);
        couponDb.setName(coupon.getName());
        couponDb.setTotal(coupon.getTotal());
        couponDb.setValue(coupon.getValue());
        couponDb.setType(coupon.getType());
        couponDb.setIsAtLeast(coupon.isIsAtLeast());
        couponDb.setIsShare(coupon.isIsShare());
        couponDb.setAtLeast(coupon.getAtLeast());
        couponDb.setCardId(coupon.getCardId());
        couponDb.setQuota(coupon.getQuota());
        couponDb.setDescription(coupon.getDescription());
        couponDb.setServicePhone(coupon.getServicePhone());
        couponDb.setStartAt(coupon.getStartAt());
        couponDb.setEndAt(coupon.getEndAt());
        couponDb.setUpdateTime(new Date());
        couponMapper.updateAllColumnById(couponDb);
    } else {
        // 优惠券别名,用于领取的时候替代ID
        coupon.setAlias(UUID.randomUUID().toString().replaceAll("-", ""));
        coupon.setUrl(gunsProperties.getClientUrl() + "/coupon/tofetch/" + coupon.getAlias());
        couponMapper.insert(coupon);
    }
    // 保存优惠券可用店铺
    storeCouponService.saveStoreCoupon(coupon.getId(), storeIds);
}
Also used : Coupon(com.ikoori.vip.common.persistence.model.Coupon) BussinessException(com.ikoori.vip.common.exception.BussinessException) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with BussinessException

use of com.ikoori.vip.common.exception.BussinessException in project vip by guangdada.

the class FileUtil method toByteArray.

/**
 * NIO way
 */
public static byte[] toByteArray(String filename) {
    File f = new File(filename);
    if (!f.exists()) {
        log.error("文件未找到!" + filename);
        throw new BussinessException(BizExceptionEnum.FILE_NOT_FOUND);
    }
    FileChannel channel = null;
    FileInputStream fs = null;
    try {
        fs = new FileInputStream(f);
        channel = fs.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate((int) channel.size());
        while ((channel.read(byteBuffer)) > 0) {
        // do nothing
        // System.out.println("reading");
        }
        return byteBuffer.array();
    } catch (IOException e) {
        throw new BussinessException(BizExceptionEnum.FILE_READING_ERROR);
    } finally {
        try {
            channel.close();
        } catch (IOException e) {
            throw new BussinessException(BizExceptionEnum.FILE_READING_ERROR);
        }
        try {
            fs.close();
        } catch (IOException e) {
            throw new BussinessException(BizExceptionEnum.FILE_READING_ERROR);
        }
    }
}
Also used : FileChannel(java.nio.channels.FileChannel) IOException(java.io.IOException) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) BussinessException(com.ikoori.vip.common.exception.BussinessException) FileInputStream(java.io.FileInputStream)

Example 28 with BussinessException

use of com.ikoori.vip.common.exception.BussinessException in project vip by guangdada.

the class CouponController method batchImport.

/**
 * 上传excel文件到临时目录后并开始解析
 * @Title: batchImport
 * @param fileName
 * @param mfile
 * @param coupon
 * @return
 * @date:   2017年9月15日 下午5:30:57
 * @author: chengxg
 * @throws Exception
 */
public String batchImport(String fileName, MultipartFile mfile, Coupon coupon) throws Exception {
    // 初始化输入流
    InputStream is = null;
    String msg = "";
    try {
        String filename = UUID.randomUUID().toString() + ".xlsx";
        // 新建一个文件
        String fileSavePath = gunsProperties.getFileUploadPath() + filename;
        File tempFile = new File(fileSavePath);
        mfile.transferTo(tempFile);
        // 根据新建的文件实例化输入流
        is = new FileInputStream(tempFile);
        // 根据版本选择创建Workbook的方式
        Workbook wb = null;
        // 根据文件名判断文件是2003版本还是2007版本
        if (ExcelImportUtils.isExcel2007(fileName)) {
            wb = new XSSFWorkbook(is);
        } else {
            wb = new HSSFWorkbook(is);
        }
        // 根据excel里面的内容读取信息
        msg = couponFetchService.batchImportCode(wb, coupon, tempFile);
    } catch (BussinessException e) {
        throw e;
    } catch (Exception e) {
        throw e;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                is = null;
                e.printStackTrace();
            }
        }
    }
    return msg;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) FileInputStream(java.io.FileInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) BussinessException(com.ikoori.vip.common.exception.BussinessException) BussinessException(com.ikoori.vip.common.exception.BussinessException) IOException(java.io.IOException)

Example 29 with BussinessException

use of com.ikoori.vip.common.exception.BussinessException in project vip by guangdada.

the class CouponCodeController method add.

/**
 * 批量生成券号
 */
@RequestMapping(value = "/add")
@Permission
@ResponseBody
public Object add(Integer num) {
    Long userId = Long.valueOf(ShiroKit.getUser().getId());
    Merchant merchant = merchantService.getMerchantUserId(userId);
    String batchNo = couponCodeService.genarateCode(merchant.getId(), num);
    if (batchNo == null) {
        throw new BussinessException(500, "生成券号失败");
    }
    return batchNo;
}
Also used : Merchant(com.ikoori.vip.common.persistence.model.Merchant) BussinessException(com.ikoori.vip.common.exception.BussinessException) Permission(com.ikoori.vip.common.annotion.Permission) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 30 with BussinessException

use of com.ikoori.vip.common.exception.BussinessException in project vip by guangdada.

the class RedpackController method redpackUpdate.

/**
 * 跳转到修改红包
 */
@RequestMapping("/redpack_update/{redpackId}")
public String redpackUpdate(@PathVariable Long redpackId, Model model) {
    Redpack redpack = redpackService.selectById(redpackId);
    if (redpack == null) {
        throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
    }
    // model.addAttribute("amount", redpack.getAmount() == null ? "" : redpack.getAmount() / 100);
    // model.addAttribute("minAmount", redpack.getMinAmount() == null ? "" : redpack.getMinAmount() / 100);
    // model.addAttribute("maxAmount", redpack.getMaxAmount() == null ? "" : redpack.getMaxAmount() / 100);
    model.addAttribute("packType", RedpackType.values());
    model.addAttribute(redpack);
    return PREFIX + "redpack_edit.html";
}
Also used : Redpack(com.ikoori.vip.common.persistence.model.Redpack) BussinessException(com.ikoori.vip.common.exception.BussinessException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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