use of com.ikoori.vip.common.exception.BussinessException in project vip by guangdada.
the class CouponFetchServiceImpl method batchImportCode.
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public String batchImportCode(Workbook wb, Coupon coupon, File tempFile) {
// 错误信息接收器
StringBuilder errorMsg = new StringBuilder("");
// 得到第一个shell
Sheet sheet = wb.getSheetAt(0);
// 得到Excel的行数
int totalRows = sheet.getPhysicalNumberOfRows();
// 总列数
int totalCells = 0;
// 得到Excel的列数(前提是有行数),从第二行算起
if (totalRows >= 2 && sheet.getRow(1) != null) {
totalCells = sheet.getRow(1).getPhysicalNumberOfCells();
}
// 判断库存数量
int stock = coupon.getStock();
int rows = totalRows - 1;
if (rows == 0) {
throw new BussinessException(500, "数据为空!");
}
if (rows > stock) {
throw new BussinessException(500, "剩余张数为" + stock + ",小于当前导入数量" + rows + "");
}
List<CouponFetch> couponFetchs = new ArrayList<CouponFetch>();
String br = "<br/>";
// 循环Excel行数,从第二行开始。标题不入库
for (int r = 1; r < totalRows; r++) {
StringBuilder rowMessage = new StringBuilder("");
Row row = sheet.getRow(r);
if (row == null) {
errorMsg.append(br + "第" + (r + 1) + "行数据有问题,请仔细检查!");
continue;
}
CouponFetch couponFetch = new CouponFetch();
String verifyCode = "";
// 循环Excel的列
for (int c = 0; c < totalCells; c++) {
Cell cell = row.getCell(c);
if (null != cell) {
if (c == 0) {
verifyCode = cell.getStringCellValue();
if (StringUtils.isBlank(verifyCode)) {
rowMessage.append("券号不能为空;");
} else if (!verifyCode.matches(RandomUtil.coupon_code_matches)) {
rowMessage.append("券号必须是20位的大写字母或数子;");
} else if (checkVerifyCode(verifyCode)) {
rowMessage.append("券号已经存在;");
}
couponFetch.setVerifyCode(verifyCode);
}
} else {
rowMessage.append("第" + (c + 1) + "列数据有问题,请仔细检查;");
}
}
// 拼接每行的错误提示
if (StringUtils.isNotBlank(rowMessage.toString())) {
errorMsg.append(br + "第" + (r + 1) + "行," + rowMessage.toString());
} else {
couponFetchs.add(couponFetch);
}
}
// 删除上传的临时文件
if (tempFile.exists()) {
tempFile.delete();
}
// 全部验证通过才导入到数据库
if (StringUtils.isBlank(errorMsg.toString())) {
if (couponFetchs.size() == 0) {
throw new BussinessException(500, "数据为空!");
}
// 更新库存
if (couponDao.updateStock(coupon.getId(), couponFetchs.size()) == 0) {
throw new BussinessException(500, "剩余张数不够");
}
for (CouponFetch cf : couponFetchs) {
cf.setCouponId(coupon.getId());
cf.setAvailableValue(coupon.getOriginValue());
cf.setExpireTime(coupon.getEndAt());
cf.setValidTime(coupon.getStartAt());
cf.setIsInvalid(true);
cf.setIsUsed(CouponUseState.NO_USED.getCode());
cf.setMerchantId(coupon.getMerchantId());
cf.setMessage("谢谢关注!");
cf.setValue(coupon.getOriginValue());
// cf.setStoreId(coupon.getStoreId());
cf.setUsedValue(0);
couponFetchMapper.insert(cf);
}
errorMsg.append("导入成功,共" + couponFetchs.size() + "条数据!");
} else {
throw new BussinessException(500, errorMsg.toString());
}
return errorMsg.toString();
}
use of com.ikoori.vip.common.exception.BussinessException in project vip by guangdada.
the class CouponCodeServiceImpl method deleteByIds.
/**
* 批量删除
* @Title: deleteByIds
* @param ids
* @date: 2017年10月15日 下午8:10:04
* @author: chengxg
*/
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void deleteByIds(Long[] ids) {
for (Long id : ids) {
CouponCode code = couponCodeMapper.selectById(id);
if (code.getUseStatus().intValue() != CouponCodeStatus.create.getCode()) {
throw new BussinessException(500, code.getVerifyNo() + "已制卡,不能删除");
}
couponCodeMapper.deleteById(id);
}
}
use of com.ikoori.vip.common.exception.BussinessException in project vip by guangdada.
the class CouponServiceImpl method publishCoupon.
/**
* 批量发行现金券
* @Title: publish
* @param couponId
* @param num
*s * @date: 2017年10月16日 下午2:02:56
* @author: chengxg
*/
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void publishCoupon(Long couponId, Integer num) {
Coupon coupon = couponMapper.selectById(couponId);
if (coupon == null) {
throw new BussinessException(500, "现金券不存在");
}
List<CouponCode> codes = getCouponCode(coupon.getMerchantId(), num);
if (CollectionUtils.isEmpty(codes)) {
throw new BussinessException(500, "券码库券码数为0,请先制卡");
}
if (codes.size() < num) {
throw new BussinessException(500, "券码库剩余券码数:" + codes.size() + ",请先制卡");
}
// 已发行数量
Integer count = getPublishCount(couponId, coupon.getMerchantId());
Integer left = coupon.getTotal() - count;
if (left < num) {
throw new BussinessException(500, "已发行:" + count + ",剩余可发行数量:" + left);
}
for (CouponCode code : codes) {
code.setUseStatus(CouponCodeStatus.publish.getCode());
code.setCouponId(couponId);
code.updateById();
}
}
use of com.ikoori.vip.common.exception.BussinessException in project vip by guangdada.
the class MerchantServiceImpl method saveMerchant.
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void saveMerchant(Merchant merchant) {
if (merchant.getId() == null) {
User theUser = managerDao.getByAccount(merchant.getMobile());
if (theUser != null) {
throw new BussinessException(BizExceptionEnum.USER_ALREADY_REG);
}
User user = new User();
// 完善账号信息
user.setAccount(merchant.getMobile());
user.setName(merchant.getName());
user.setSalt(ShiroKit.getRandomSalt(5));
user.setPassword(ShiroKit.md5(ShiroKit.DEFAULTPWD, user.getSalt()));
user.setStatus(ManagerStatus.OK.getCode());
user.setPhone(merchant.getMobile());
user.setCreatetime(new Date());
user.setRoleid(gunsProperties.getMerchantRoleId());
// user.setAvatar(merchant.getHeadImg());
user.insert();
merchant.setUserId(Long.valueOf(user.getId()));
merchant.setState(MerchantState.YES.getCode());
merchantMapper.insert(merchant);
} else {
Merchant dbMerchant = merchantMapper.selectById(merchant.getId());
User dbUser = userMapper.selectById(dbMerchant.getUserId());
if (!checkMobile(dbUser.getId(), merchant.getMobile())) {
throw new BussinessException(BizExceptionEnum.USER_ALREADY_REG);
}
dbUser.setName(merchant.getName());
// dbUser.setAvatar(merchant.getHeadImg());
dbUser.updateById();
merchantMapper.updateById(merchant);
}
}
use of com.ikoori.vip.common.exception.BussinessException in project vip by guangdada.
the class GwOrderController method pay.
@ApiOperation("会员优惠券、积分结算接口")
@RequestMapping(value = "pay", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> pay(@ApiParam(value = "店铺编号", required = true) @RequestParam(required = true) String storeNo, @ApiParam(value = "openid", required = true) @RequestParam(required = true) String openid, @ApiParam(value = "订单号", required = true) @RequestParam(required = true) String orderNo, @ApiParam(value = "订单总额", required = true) @RequestParam(required = true) String balanceDue, @ApiParam(value = "支付金额", required = true) @RequestParam(required = true) String payment, @ApiParam(value = "使用积分", required = true) @RequestParam(required = true) String point, @ApiParam(value = "优惠金额", required = true) @RequestParam(required = true) String discount, @ApiParam(value = "优惠券明细", required = true) @RequestParam(required = true) String coupons, @ApiParam(value = "订单明细", required = true) @RequestParam(required = true) String orderItems, @ApiParam(value = "签名", required = true) @RequestParam(required = true) String sign) {
Map<String, Object> result = new HashMap<String, Object>();
result.put("code", "200");
result.put("msg", "请求成功");
try {
log.info(">>>>>>>>>>>>>>>>>>>>>>>会员优惠券、积分结算接口>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
boolean isSign = true;
if (gunsProperties.isCheckSign()) {
Map<String, String> data = new HashMap<String, String>();
data.put("storeNo", storeNo);
data.put("openid", openid);
data.put("mobile", orderNo);
data.put("balanceDue", balanceDue);
data.put("payment", payment);
data.put("point", point);
data.put("discount", discount);
data.put("coupons", coupons);
data.put("orderItems", orderItems);
data.put("sign", sign);
log.info("请求参数:" + data.toString());
isSign = WXPayUtil.isSignatureValid(data, gunsProperties.getSignKey());
if (isSign) {
log.info("签名失败");
result.put("code", "500");
result.put("msg", "签名失败");
}
}
if (isSign) {
OrderPayDo orderPayDo = new OrderPayDo();
orderPayDo.setStoreNo(storeNo);
orderPayDo.setOpenid(openid);
orderPayDo.setOrderNo(orderNo);
orderPayDo.setBalanceDue(Integer.valueOf(balanceDue));
orderPayDo.setPayment(Integer.valueOf(payment));
orderPayDo.setDiscount(StringUtils.isBlank(discount) ? null : Integer.valueOf(discount));
orderPayDo.setPoint(StringUtils.isBlank(point) ? null : Integer.valueOf(point));
orderPayDo.setCoupons(StringUtils.isBlank(coupons) ? null : JSONArray.parseArray(coupons, CouponPayDo.class));
orderPayDo.setOrderItems(JSONArray.parseArray(orderItems, OrderItemPayDo.class));
orderPayDo.setOrderSource(OrderSource.gw.getCode());
orderService.saveOrder(orderPayDo);
}
} catch (BussinessException e) {
log.error("", e);
result.put("code", e.getCode());
result.put("msg", e.getMessage());
} catch (Exception e) {
log.error("", e);
result.put("code", "500");
result.put("msg", "请求失败");
}
log.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<会员优惠券、积分结算接口<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
return result;
}
Aggregations