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);
}
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);
}
}
}
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;
}
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;
}
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";
}
Aggregations