From b38caa7012b8da89d5ca61d389258d4fd8d9172e Mon Sep 17 00:00:00 2001
From: liujie <liujie>
Date: 星期三, 09 八月 2023 17:51:07 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java |  317 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 307 insertions(+), 10 deletions(-)

diff --git a/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java b/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java
index ab641e5..e83e1c8 100644
--- a/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java
+++ b/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java
@@ -1,27 +1,47 @@
 package com.dsh.activity.controller;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.dsh.activity.entity.Coupon;
+import com.dsh.activity.entity.CouponCity;
+import com.dsh.activity.entity.CouponStore;
 import com.dsh.activity.entity.UserCoupon;
+import com.dsh.activity.feignclient.account.CityClient;
+import com.dsh.activity.feignclient.account.StoreStaffClient;
+import com.dsh.activity.feignclient.account.model.TCityManager;
+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;
+import com.dsh.activity.service.CouponStoreService;
 import com.dsh.activity.service.ICouponService;
 import com.dsh.activity.service.UserCouponService;
 import com.dsh.activity.util.GDMapGeocodingUtil;
 import com.dsh.activity.util.ResultUtil;
 import com.dsh.activity.util.TokenUtil;
+import com.dsh.activity.util.ToolUtil;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author zhibing.pu
@@ -43,6 +63,25 @@
     @Autowired
     private GDMapGeocodingUtil gdMapGeocodingUtil;
 
+    @Resource
+    private CityClient citClient;
+
+    @Resource
+    private StoreStaffClient stoStaClient;
+
+
+    @Resource
+    private StoreClient stoClient;
+
+
+    @Resource
+    private RegionClient regionClient;
+
+    @Resource
+    private CouponStoreService couStoreService;
+
+    @Resource
+    private CouponCityService cityService;
 
 
 
@@ -116,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");
@@ -126,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));
@@ -137,8 +177,17 @@
                 Iterator<Coupon> iterator = couponList.iterator();
                 while (iterator.hasNext()) {
                     Coupon merchandise = iterator.next();
-                    if (merchandise.getUseScope() == 2 && (!Objects.equals(merchandise.getCityCode(), cityCode) && !Objects.equals(merchandise.getProvinceCode(), provinceCode))) {
-                        iterator.remove(); // 移除符合条件的商品
+                    if (merchandise.getUseScope() == 2){
+                        List<CouponCity> couponCities = cityService.list(new LambdaQueryWrapper<CouponCity>()
+                                .eq(CouponCity::getCouponId,merchandise.getId()));
+                        if (couponCities.size() > 0){
+                            for (CouponCity couponCity : couponCities) {
+                                if (!Objects.equals(couponCity.getCityCode(), cityCode) && !Objects.equals(couponCity.getProvinceCode(), provinceCode)){
+                                    iterator.remove(); // 移除符合条件的商品
+                                    break;
+                                }
+                            }
+                        }
                     }
                 }
             }
@@ -158,11 +207,259 @@
 
     @PostMapping("/base/coupon/insertToAppuserCoupon")
     public void insertToAppuserCoupon(@RequestBody UserCoupon coupon){
+        coupon.setInsertTime(new Date());
         ucService.save(coupon);
     }
 
 
 
+    @ResponseBody
+    @PostMapping("/base/coupon/queryCouponListSearch")
+    public List<Map<String,Object>> getCouponListOfSearch(@RequestBody CouponListOfSearch ofSearch){
+        List<Map<String, Object>> mapList = couponService.queryCouponListOfSearch(ofSearch);
+        if (mapList.size() > 0){
+            for (Map<String, Object> stringObjectMap : mapList) {
+                Integer o = (Integer) stringObjectMap.get("id");
+                Object startTime = stringObjectMap.get("startTime");
+                Object endTime = stringObjectMap.get("endTime");
+                stringObjectMap.put("timeValue",startTime + "至"+endTime);
+                int count = ucService.count(new LambdaQueryWrapper<UserCoupon>()
+                        .eq(UserCoupon::getCouponId, o));
+                stringObjectMap.put("hasPickQty",count);
+            }
+        }
+        return mapList;
+    }
 
+    @ResponseBody
+    @PostMapping("/base/coupon/couponExamineListSearch")
+    public List<Map<String,Object>> getCouponExamineListOfSearch(@RequestBody CouponExamineListSearch ofSearch){
+        List<Map<String, Object>> mapList = couponService.queryCouponExamineList(ofSearch);
+        if (mapList.size() > 0){
+            for (Map<String, Object> stringObjectMap : mapList) {
+                Object startTime = stringObjectMap.get("startTime");
+                Object endTime = stringObjectMap.get("endTime");
+                stringObjectMap.put("timeValue",startTime + "至"+endTime);
+                Integer publisherType = (Integer) stringObjectMap.get("publisherType");
+                if ( publisherType == 1) {
+                    Integer cityManagerId = (Integer) stringObjectMap.get("cityManagerId");
+                    TCityManager byId = citClient.getById(cityManagerId);
+                    stringObjectMap.put("province", byId.getProvince());
+                    stringObjectMap.put("city", byId.getCity());
+                }
+            }
+        }
+        return mapList;
+    }
+
+
+    @ResponseBody
+    @PostMapping("/base/coupon/couponExamineDetail")
+    Map<String, Object> queryCouponExamineDetail(@RequestBody Integer id){
+        Map<String, Object> couponInfo = new HashMap<>();
+        Coupon coupon = couponService.getById(id);
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        if (ToolUtil.isNotEmpty(coupon)){
+            couponInfo.put("id",coupon.getId());
+            couponInfo.put("auditStatus",coupon.getAuditStatus());
+            couponInfo.put("publisherType",coupon.getPublisherType());
+            if (coupon.getPublisherType() == 1){
+                TCityManager byId = citClient.getById(coupon.getCityManagerId());
+                couponInfo.put("province",byId.getProvince());
+                couponInfo.put("city",byId.getCity());
+            }
+            couponInfo.put("name",coupon.getName());
+            couponInfo.put("type",coupon.getType());
+            JSONObject jsonObject = JSON.parseObject(coupon.getContent());
+            switch (coupon.getType()){
+                case 1:
+//                {"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("conditionalAmount"));
+                    break;
+                case 3:
+                    couponInfo.put("num1",jsonObject.getString("experienceName"));
+                    break;
+                default:
+                    break;
+            }
+            couponInfo.put("illustrate",coupon.getIllustrate());
+            switch (coupon.getDistributionMethod()){
+                case 1:
+                    couponInfo.put("distributionMethod","积分注册");
+                    break;
+                case 2:
+                    couponInfo.put("distributionMethod","注册赠送");
+                    break;
+                case 3:
+                    couponInfo.put("distributionMethod","自动发券");
+                    break;
+                default:
+                    break;
+            }
+            couponInfo.put("redemptionMethod",coupon.getRedemptionMethod());
+            couponInfo.put("integral",coupon.getIntegral());
+            couponInfo.put("cash",coupon.getCash());
+            switch (coupon.getUserPopulation()){
+                case 1:
+                    couponInfo.put("userPopulation","全部用户");
+                    break;
+                case 2:
+                    couponInfo.put("userPopulation","年度会员");
+                    break;
+                case 3:
+                    couponInfo.put("userPopulation","已有学员用户");
+                    break;
+                default:
+                    break;
+            }
+            couponInfo.put("quantityIssued",coupon.getQuantityIssued());
+            couponInfo.put("pickUpQuantity",coupon.getPickUpQuantity());
+            String startTime = simpleDateFormat.format(coupon.getStartTime());
+            String endTime = simpleDateFormat.format(coupon.getEndTime());
+            couponInfo.put("timeValue",startTime + "至"+endTime);
+            couponInfo.put("useScope",coupon.getUseScope());
+            ArrayList<Map<String, Object>> maps = new ArrayList<>();
+            switch (coupon.getUseScope()){
+                case 2:
+                    List<CouponCity> couponCities = cityService.list(new LambdaQueryWrapper<CouponCity>()
+                            .eq(CouponCity::getCouponId,coupon.getId()));
+                    if (couponCities.size() > 0){
+                        for (CouponCity couponCity : couponCities) {
+                            HashMap<String, Object> stringObjectHashMap = new HashMap<>();
+                            stringObjectHashMap.put("province",couponCity.getProvince());
+                            stringObjectHashMap.put("city",couponCity.getCity());
+                            maps.add(stringObjectHashMap);
+                        }
+                        couponInfo.put("rangeData",maps);
+                    }
+                    break;
+                case 3:
+                    List<CouponStore> list = couStoreService.list(new LambdaQueryWrapper<CouponStore>()
+                            .eq(CouponStore::getCouponId,coupon.getId()));
+                    if (list.size() > 0){
+                        List<Integer> collect = list.stream().map(CouponStore::getStoreId).collect(Collectors.toList());
+                        List<Store> storeList = stoClient.queryStoreByIds(collect);
+                        if (storeList.size() > 0){
+                            for (Store store : storeList) {
+                                TStoreStaff list1 = stoStaClient.baseInfo(store.getStoreStaffId());
+                                HashMap<String, Object> stringObjectHashMap = new HashMap<>();
+                                stringObjectHashMap.put("procity",store.getProvince()+store.getCity());
+                                stringObjectHashMap.put("storeAccount",list1.getName()+"+"+list1.getPhone());
+                                stringObjectHashMap.put("storeName",store.getName());
+                                maps.add(stringObjectHashMap);
+                            }
+                            couponInfo.put("rangeData",maps);
+                        }
+
+                    }
+                    break;
+                default:
+                    break;
+            }
+        }
+        return couponInfo;
+    }
+
+
+
+    @ResponseBody
+    @PostMapping("/base/coupon/updateCouponExamine")
+    public boolean updateCouponData(@RequestBody Coupon coupon){
+        try {
+            return couponService.updateById(coupon);
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    @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;
+        }
+    }
 
 }

--
Gitblit v1.7.1