cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java
@@ -14,10 +14,13 @@
import com.dsh.activity.feignclient.account.model.TStoreStaff;
import com.dsh.activity.feignclient.model.CouponExamineListSearch;
import com.dsh.activity.feignclient.model.CouponListOfSearch;
import com.dsh.activity.feignclient.other.RegionClient;
import com.dsh.activity.feignclient.other.StoreClient;
import com.dsh.activity.feignclient.other.model.CityDataAndProvinceDataVo;
import com.dsh.activity.feignclient.other.model.Store;
import com.dsh.activity.model.CouponListVo;
import com.dsh.activity.model.request.CommodityRequest;
import com.dsh.activity.model.request.CouponDataVo;
import com.dsh.activity.model.request.CouponPackageReq;
import com.dsh.activity.model.response.CouponPackageResp;
import com.dsh.activity.service.CouponCityService;
@@ -35,6 +38,7 @@
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -68,6 +72,10 @@
    @Resource
    private StoreClient stoClient;
    @Resource
    private RegionClient regionClient;
    @Resource
    private CouponStoreService couStoreService;
@@ -147,8 +155,12 @@
    @PostMapping("/base/coupon/getAllCoupons")
    public List<Coupon> getAllCoupons(@RequestBody CommodityRequest request){
        List<Coupon> couponList = new ArrayList<>();
        String provinceCode = "";
        String cityCode = "";
        if (ToolUtil.isEmpty(request.getLat()) && ToolUtil.isEmpty(request.getLon())){
            return couponList;
        }
        try {
            Map<String, String> geocode = gdMapGeocodingUtil.geocode(request.getLon(), request.getLat());
            provinceCode = geocode.get("provinceCode");
@@ -157,10 +169,7 @@
            e.printStackTrace();
        }
        try {
            Integer userAppId = tokenUtil.getUserIdFormRedis();
            List<UserCoupon> list = ucService.list(new QueryWrapper<UserCoupon>()
                    .eq("userId",userAppId ));
            List<Coupon> couponList = couponService.list(new QueryWrapper<Coupon>()
            couponList = couponService.list(new QueryWrapper<Coupon>()
                    .eq("auditStatus",2)
                    .eq("state",1)
                    .eq("status",2));
@@ -263,14 +272,15 @@
            JSONObject jsonObject = JSON.parseObject(coupon.getContent());
            switch (coupon.getType()){
                case 1:
                    couponInfo.put("num1",jsonObject.getDouble("num1"));
                    couponInfo.put("num2",jsonObject.getDouble("num2"));
//                {"conditionalAmount":50,"deductionAmount":10,"experienceName":""}
                    couponInfo.put("num1",jsonObject.getDouble("conditionalAmount"));
                    couponInfo.put("num2",jsonObject.getDouble("deductionAmount"));
                    break;
                case 2:
                    couponInfo.put("num1",jsonObject.getDouble("num1"));
                    couponInfo.put("num1",jsonObject.getDouble("conditionalAmount"));
                    break;
                case 3:
                    couponInfo.put("num1",jsonObject.getString("num1"));
                    couponInfo.put("num1",jsonObject.getString("experienceName"));
                    break;
                default:
                    break;
@@ -365,4 +375,90 @@
        }
    }
    @ResponseBody
    @PostMapping("/base/coupon/insertIntoCouponData")
    public boolean saveCouponData(@RequestBody CouponDataVo dataVo){
        try {
            System.out.println(dataVo);
            Coupon coupon = new Coupon();
            coupon.setName(dataVo.getCouponName());
            coupon.setType(dataVo.getPrescription());
            HashMap<String, Object> stringObjectHashMap = new HashMap<>();
            switch (dataVo.getPrescription()){
//                {"conditionalAmount":50,"deductionAmount":10,"experienceName":""}
                case 1:
                    stringObjectHashMap.put("conditionalAmount",dataVo.getCondition());
                    stringObjectHashMap.put("deductionAmount",dataVo.getSubtraction());
                    coupon.setContent(stringObjectHashMap.toString());
                    break;
                case 2:
                    stringObjectHashMap.put("conditionalAmount",dataVo.getDiscount());
                    coupon.setContent(stringObjectHashMap.toString());
                    break;
                case 3:
                    stringObjectHashMap.put("experienceName",dataVo.getExperience());
                    coupon.setContent(stringObjectHashMap.toString());
                    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()));
            coupon.setQuantityIssued(dataVo.getQuantityIssued());
            coupon.setPickUpQuantity(dataVo.getPickUpQuantity());
            coupon.setUseScope(dataVo.getCompany());
            coupon.setAuditStatus(1);
            coupon.setStatus(1);
            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));
                }else {
                    for (String goodImg : goodImgs) {
                        builder.append(goodImg).append(",");
                    }
                    builder.deleteCharAt(builder.lastIndexOf(","));
                    coupon.setProductImages(builder.toString());
                }
            }
            coupon.setPublisherType(dataVo.getUserType());
            if (dataVo.getUserType() == 1){
                coupon.setCityManagerId(dataVo.getCityManagerId());
            }
            boolean save = couponService.save(coupon);
            if (save){
                if (dataVo.getCompany() == 2){
                    for (Integer storeId : dataVo.getStoreIds()) {
                        CouponStore couponStore = new CouponStore();
                        couponStore.setCouponId(coupon.getId());
                        couponStore.setStoreId(storeId);
                        couStoreService.save(couponStore);
                    }
                }
                List<Integer> cityIds = dataVo.getCityIds();
                if (dataVo.getCompany() == 3 && cityIds.size() > 0 ){
                    List<CityDataAndProvinceDataVo> cityAndProvince = regionClient.getCityAndProvince(cityIds);
                    for (CityDataAndProvinceDataVo cityId : cityAndProvince) {
                        CouponCity couponCity = new CouponCity();
                        couponCity.setCouponId(coupon.getId());
                        couponCity.setCityCode(cityId.getCityCode());
                        couponCity.setCity(cityId.getCityName());
                        couponCity.setProvinceCode(cityId.getProvinceCode());
                        couponCity.setProvince(cityId.getProvinceName());
                        cityService.save(couponCity);
                    }
                }
            }
            return true;
        }catch (Exception e){
            return false;
        }
    }
}