| @@ -126,16 +126,22 @@ public class WxCouponController extends BaseController { | |||
| } | |||
| return false; | |||
| } | |||
| private boolean hasMerchantCouponFlow() { | |||
| return hasFlow(EnumFlowKey.B_COUPON_MERCHANT_CREATE,getTenantInfo()); | |||
| } | |||
| @ApiOperation("查询是否有审批流程") | |||
| @PostMapping("hasFlow") | |||
| public ResultData hasFlow() { | |||
| if (hasFlow(EnumFlowKey.B_COUPON_MERCHANT_CREATE,getTenantInfo())) { | |||
| if (hasMerchantCouponFlow()) { | |||
| return new ResultData(1); | |||
| }else { | |||
| return new ResultData(0); | |||
| } | |||
| } | |||
| @ApiOperation("提交审批") | |||
| @PostMapping("apply") | |||
| @@ -150,7 +156,7 @@ public class WxCouponController extends BaseController { | |||
| return new ResultData(Result.ERROR,"非B端券,不能进行此操作"); | |||
| } | |||
| if (!hasFlow(EnumFlowKey.B_COUPON_MERCHANT_CREATE,coupon)) { | |||
| if (!hasMerchantCouponFlow()) { | |||
| return new ResultData(Result.ERROR,EnumFlowKey.B_COUPON_MERCHANT_CREATE.getMessage()+"未配置审批流程"); | |||
| } | |||
| wxFlowService.start(generateFlowParams(EnumFlowKey.B_COUPON_MERCHANT_CREATE,EnumCouponAppType.PUT,wxCoupon.getId(),wxCoupon.getRemark()), getBuserId(), getUser().getName(), wxCoupon); | |||
| @@ -162,6 +168,9 @@ public class WxCouponController extends BaseController { | |||
| @ApiOperation("新增接口") | |||
| @PostMapping("add") | |||
| public ResultData add(@RequestBody WxCoupon wxCoupon) { | |||
| if (!hasMerchantCouponFlow()) { | |||
| return new ResultData(Result.ERROR,EnumFlowKey.B_COUPON_MERCHANT_CREATE.getMessage()+"未配置审批流程"); | |||
| } | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::add"); | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| wxCoupon.updateTenantInfo(tenantEntity); | |||
| @@ -193,6 +202,9 @@ public class WxCouponController extends BaseController { | |||
| @ApiOperation("根据id更新接口") | |||
| @PostMapping("update") | |||
| public ResultData update(@RequestBody WxCoupon wxCoupon) { | |||
| if (!hasMerchantCouponFlow()) { | |||
| return new ResultData(Result.ERROR,EnumFlowKey.B_COUPON_MERCHANT_CREATE.getMessage()+"未配置审批流程"); | |||
| } | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::update"); | |||
| if (wxCoupon.getId() == null) { | |||
| return new ResultData(ResultData.ERROR, "缺少id"); | |||
| @@ -219,27 +231,15 @@ public class WxCouponController extends BaseController { | |||
| return new ResultData(ResultData.ERROR, "券未查询到。"+wxCoupon.getId()); | |||
| } | |||
| redisLock.setCouponStock(wxCoupon.getId(), coupon.getRemainInventory()); | |||
| //启动审批流 | |||
| if (wxCoupon.getFlowParams() != null && wxCoupon.getFlowParams().size() > 0) { | |||
| logger.info("------coupon.update().businessType:"+wxCoupon.getFlowParams().get("businessType")); | |||
| wxCoupon.getFlowParams().put("businessId",wxCoupon.getId()); | |||
| wxFlowService.start(wxCoupon.getFlowParams(), getBuserId(), getUser().getName(), getTenantInfo()); | |||
| //作废审批 | |||
| if (EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(wxCoupon.getStatus())) { | |||
| wxCoupon.setCancleApplyStatus(EnumRentContractAppStatus.APPLYING.getCode()); | |||
| return new ResultData(wxCoupon); | |||
| } else { | |||
| //投放审批 | |||
| wxCoupon.setPutApplyStatus(EnumRentContractAppStatus.APPLYING.getCode()); | |||
| } | |||
| } | |||
| return wxCouponService.saveOrUpdate(wxCoupon); | |||
| } | |||
| @ApiOperation("根据id更新库存及有效期接口") | |||
| @PostMapping("updateStokeAndValidDate") | |||
| public ResultData updateStokeAndValidDate(@RequestBody WxCoupon wxCoupon) { | |||
| if (!hasMerchantCouponFlow()) { | |||
| return new ResultData(Result.ERROR,EnumFlowKey.B_COUPON_MERCHANT_CREATE.getMessage()+"未配置审批流程"); | |||
| } | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::updateStokeAndValidDate"); | |||
| if (wxCoupon.getId() == null) { | |||
| logger.error("缺少id"); | |||
| @@ -301,58 +301,17 @@ public class WxCouponController extends BaseController { | |||
| return new ResultData(ErrorCode.COUPON_STOCK_ENDTIME_ERR); | |||
| } | |||
| } | |||
| //启动审批流 | |||
| if (wxCoupon.getFlowParams() != null && wxCoupon.getFlowParams().size() > 0) { | |||
| List<Map<String, Object>> variables = (List) wxCoupon.getFlowParams().get("variables"); | |||
| Map<String, Object> map = new HashedMap(); | |||
| map.put("key", "inventory"); | |||
| map.put("value", wxCoupon.getInventory()); | |||
| variables.add(map); | |||
| map = new HashedMap(); | |||
| map.put("key", "remainInventory"); | |||
| map.put("value", wxCoupon.getRemainInventory()); | |||
| variables.add(map); | |||
| map = new HashedMap(); | |||
| map.put("key", "type"); | |||
| map.put("value", wxCoupon.getType()); | |||
| variables.add(map); | |||
| map = new HashedMap(); | |||
| map.put("key", "validEndDate"); | |||
| map.put("value", wxCoupon.getValidEndDate()); | |||
| map = new HashedMap(); | |||
| map.put("key", "validStartDate"); | |||
| map.put("value", wxCoupon.getValidStartDate()); | |||
| map = new HashedMap(); | |||
| map.put("key", "validType"); | |||
| map.put("value", wxCoupon.getValidType()); | |||
| variables.add(map); | |||
| map = new HashedMap(); | |||
| map.put("key", "validDays"); | |||
| map.put("value", wxCoupon.getValidDays()); | |||
| variables.add(map); | |||
| wxCoupon.getFlowParams().put("businessId",wxCoupon.getId()); | |||
| wxFlowService.start(wxCoupon.getFlowParams(), getBuserId(), getUser().getName(), wxCoupon); | |||
| //更新状态 | |||
| WxCoupon updateCoupon = new WxCoupon(); | |||
| updateCoupon.updateTenantInfo(wxCoupon); | |||
| updateCoupon.setId(wxCoupon.getId()); | |||
| updateCoupon.setStockApplyStatus(EnumRentContractAppStatus.APPLYING.getCode()); | |||
| updateCoupon.setUpdateDate(new Date()); | |||
| wxCouponService.update(updateCoupon); | |||
| redisLock.setCouponStock(wxCoupon.getId(), wxCoupon.getRemainInventory()); | |||
| } else { | |||
| redisLock.setCouponStock(wxCoupon.getId(), wxCoupon.getRemainInventory()); | |||
| return wxCouponService.updateCouponStockAndEndTime(wxCoupon); | |||
| } | |||
| return new ResultData(); | |||
| redisLock.setCouponStock(wxCoupon.getId(), wxCoupon.getRemainInventory()); | |||
| return wxCouponService.updateCouponStockAndEndTime(wxCoupon); | |||
| } | |||
| @ApiOperation("根据id删除接口") | |||
| @GetMapping("/del") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData delete(Long id) { | |||
| if (!hasMerchantCouponFlow()) { | |||
| return new ResultData(Result.ERROR,EnumFlowKey.B_COUPON_MERCHANT_CREATE.getMessage()+"未配置审批流程"); | |||
| } | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::delete"); | |||
| wxCouponService.deleteById(id); | |||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||