| | |
| | | import com.dsh.activity.util.ResultUtil; |
| | | import com.dsh.activity.util.TokenUtil; |
| | | import com.dsh.activity.util.ToolUtil; |
| | | import com.google.gson.Gson; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | @ResponseBody |
| | | @PostMapping("/base/coupon/insertIntoCouponData") |
| | | public boolean saveCouponData(@RequestBody CouponDataVo dataVo){ |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | try { |
| | | System.out.println(dataVo); |
| | | Coupon coupon = new Coupon(); |
| | | coupon.setName(dataVo.getCouponName()); |
| | | coupon.setType(dataVo.getPrescription()); |
| | | HashMap<String, Object> stringObjectHashMap = new HashMap<>(); |
| | | Gson gson = new Gson(); |
| | | switch (dataVo.getPrescription()){ |
| | | // {"conditionalAmount":50,"deductionAmount":10,"experienceName":""} |
| | | case 1: |
| | | stringObjectHashMap.put("conditionalAmount",dataVo.getCondition()); |
| | | stringObjectHashMap.put("deductionAmount",dataVo.getSubtraction()); |
| | | coupon.setContent(stringObjectHashMap.toString()); |
| | | coupon.setContent(gson.toJson(stringObjectHashMap)); |
| | | break; |
| | | case 2: |
| | | stringObjectHashMap.put("conditionalAmount",dataVo.getDiscount()); |
| | | coupon.setContent(stringObjectHashMap.toString()); |
| | | coupon.setContent(gson.toJson(stringObjectHashMap)); |
| | | break; |
| | | case 3: |
| | | stringObjectHashMap.put("experienceName",dataVo.getExperience()); |
| | | coupon.setContent(stringObjectHashMap.toString()); |
| | | coupon.setContent(gson.toJson(stringObjectHashMap)); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | coupon.setIllustrate(dataVo.getIllustrate()); |
| | | coupon.setDistributionMethod(dataVo.getDistributionMethod()); |
| | | coupon.setRedemptionMethod(dataVo.getExchangeMethod()); |
| | | coupon.setCash(dataVo.getRequiredCash()); |
| | | coupon.setIntegral(BigDecimal.valueOf(dataVo.getRequiredPoints())); |
| | | switch (dataVo.getExchangeMethod()){ |
| | | case 1: |
| | | coupon.setIntegral(BigDecimal.valueOf(dataVo.getRequiredPoints())); |
| | | break; |
| | | case 2: |
| | | coupon.setCash(dataVo.getRequiredCash()); |
| | | coupon.setIntegral(BigDecimal.valueOf(dataVo.getRequiredPoints())); |
| | | break; |
| | | case 3: |
| | | coupon.setCash(dataVo.getRequiredCash()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | coupon.setQuantityIssued(dataVo.getQuantityIssued()); |
| | | coupon.setPickUpQuantity(dataVo.getPickUpQuantity()); |
| | | coupon.setUseScope(dataVo.getCompany()); |
| | | coupon.setUserPopulation(dataVo.getUserGroup()); |
| | | String timeDeal = dataVo.getPeriodOfValidity(); |
| | | if (ToolUtil.isNotEmpty(timeDeal)){ |
| | | String[] split = timeDeal.split(" - "); |
| | | coupon.setStartTime(simpleDateFormat.parse(split[0])); |
| | | coupon.setEndTime(simpleDateFormat.parse(split[1])); |
| | | } |
| | | coupon.setAuditStatus(1); |
| | | coupon.setStatus(1); |
| | | coupon.setState(2); |
| | | coupon.setInsertTime(new Date()); |
| | | coupon.setCover(dataVo.getGoodImg()); |
| | | List<String> goodImgs = dataVo.getGoodImgs(); |
| | | StringBuilder builder = new StringBuilder(); |
| | | if (goodImgs.size() > 0){ |
| | | if (goodImgs.size() == 1){ |
| | | coupon.setProductImages(goodImgs.get(0)); |
| | | String goodImgs = dataVo.getGoodImgs(); |
| | | String[] imgsSplit = goodImgs.split(","); |
| | | if (imgsSplit.length > 0){ |
| | | if (imgsSplit.length == 1){ |
| | | coupon.setProductImages(imgsSplit[0]); |
| | | }else { |
| | | for (String goodImg : goodImgs) { |
| | | builder.append(goodImg).append(","); |
| | | } |
| | | builder.deleteCharAt(builder.lastIndexOf(",")); |
| | | coupon.setProductImages(builder.toString()); |
| | | coupon.setProductImages(goodImgs); |
| | | } |
| | | } |
| | | coupon.setPublisherType(dataVo.getUserType()); |
| | | if (dataVo.getUserType() == 1){ |
| | | coupon.setPublisherType(2); |
| | | } |
| | | if (dataVo.getUserType() == 2){ |
| | | coupon.setPublisherType(1); |
| | | coupon.setCityManagerId(dataVo.getCityManagerId()); |
| | | } |
| | | boolean save = couponService.save(coupon); |
| | | if (save){ |
| | | if (dataVo.getCompany() == 2){ |
| | | for (Integer storeId : dataVo.getStoreIds()) { |
| | | if (dataVo.getCompany() == 3){ |
| | | String[] split = dataVo.getStoreIds().split(","); |
| | | for (String storeId : split) { |
| | | CouponStore couponStore = new CouponStore(); |
| | | couponStore.setCouponId(coupon.getId()); |
| | | couponStore.setStoreId(storeId); |
| | | couponStore.setStoreId(Integer.parseInt(storeId)); |
| | | couStoreService.save(couponStore); |
| | | } |
| | | } |
| | | List<Integer> cityIds = dataVo.getCityIds(); |
| | | if (dataVo.getCompany() == 3 && cityIds.size() > 0 ){ |
| | | List<CityDataAndProvinceDataVo> cityAndProvince = regionClient.getCityAndProvince(cityIds); |
| | | String cityIds = dataVo.getCityIds(); |
| | | String[] split = cityIds.split(","); |
| | | List<Integer> cityIdss = new ArrayList<>(); |
| | | if (dataVo.getCompany() == 2 && split.length > 0 ){ |
| | | for (String s : split) { |
| | | int intValue = Integer.parseInt(s); |
| | | cityIdss.add(intValue); |
| | | } |
| | | List<CityDataAndProvinceDataVo> cityAndProvince = regionClient.getCityAndProvince(cityIdss); |
| | | for (CityDataAndProvinceDataVo cityId : cityAndProvince) { |
| | | CouponCity couponCity = new CouponCity(); |
| | | couponCity.setCouponId(coupon.getId()); |
| | |
| | | couponCity.setCity(cityId.getCityName()); |
| | | couponCity.setProvinceCode(cityId.getProvinceCode()); |
| | | couponCity.setProvince(cityId.getProvinceName()); |
| | | System.out.println(couponCity); |
| | | cityService.save(couponCity); |
| | | } |
| | | } |