New file |
| | |
| | | package com.dsh.guns.modular.system.controller.code; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.dsh.course.feignClient.activity.CouponClient; |
| | | import com.dsh.course.feignClient.activity.model.Coupon; |
| | | import com.dsh.course.feignClient.activity.model.CouponCity; |
| | | import com.dsh.course.feignClient.activity.model.TicketDetailVO; |
| | | import com.dsh.guns.core.base.controller.BaseController; |
| | | import com.dsh.guns.core.common.constant.factory.PageFactory; |
| | | import com.dsh.guns.modular.system.model.*; |
| | | import com.dsh.guns.modular.system.service.IProtocolService; |
| | | import com.dsh.guns.modular.system.service.IStoreService; |
| | | import com.dsh.guns.modular.system.service.IVipService; |
| | | import com.dsh.guns.modular.system.util.ResultUtil; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.ui.Model; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @Date 2023/8/1 14:02 |
| | | */ |
| | | @Controller |
| | | @RequestMapping("/vip") |
| | | public class TVipController extends BaseController { |
| | | |
| | | @Autowired |
| | | private IVipService vipService; |
| | | @Autowired |
| | | private CouponClient couponClient; |
| | | @Autowired |
| | | private IStoreService storeService; |
| | | private String PREFIX = "/system/vip/"; |
| | | |
| | | |
| | | /** |
| | | * 跳转到优惠券管理首页 |
| | | */ |
| | | @RequestMapping("") |
| | | public String index(Model model) { |
| | | |
| | | return PREFIX + "vip.html"; |
| | | } |
| | | @RequestMapping("/add") |
| | | public String add(Model model) { |
| | | |
| | | return PREFIX + "vip_add.html"; |
| | | } |
| | | @RequestMapping("/edit/{id}") |
| | | public String edit(@PathVariable("id")Integer id,Model model) { |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | Vip vip = vipService.getById(id); |
| | | model.addAttribute("vip",vip); |
| | | if (vip.getCouponJson() != null && !vip.getCouponJson().isEmpty()){ |
| | | String couponJson = vip.getCouponJson(); |
| | | // 转化为jsonArray |
| | | JSONArray couponJsonArray = JSONArray.parseArray(couponJson); |
| | | List<Integer> couponIds = new ArrayList<>(); |
| | | Map<Integer, Integer> integerIntegerHashMap = new HashMap<>(); |
| | | // 收集里面得id |
| | | for (Object o : couponJsonArray) { |
| | | JSONObject couponJsonObject = (JSONObject) o; |
| | | Integer couponId = couponJsonObject.getInteger("id"); |
| | | Integer count = couponJsonObject.getInteger("value"); |
| | | integerIntegerHashMap.put(couponId, count); |
| | | couponIds.add(couponId); |
| | | } |
| | | List<Coupon> coupons = couponClient.queryCouponList(); |
| | | |
| | | if (!couponIds.isEmpty()){ |
| | | coupons = coupons.stream().filter(coupon -> couponIds.contains(coupon.getId())).collect(Collectors.toList()); |
| | | for (Coupon coupon : coupons) { |
| | | Date startTime = coupon.getStartTime(); |
| | | Date endTime = coupon.getEndTime(); |
| | | coupon.setTimeValue(simpleDateFormat.format(startTime) + "至" + simpleDateFormat.format(endTime)); |
| | | Integer orDefault = integerIntegerHashMap.getOrDefault(coupon.getId(), 0); |
| | | coupon.setCount(orDefault); |
| | | switch (coupon.getUseScope()){ |
| | | case 1: |
| | | coupon.setUseScopeValue("全国"); |
| | | break; |
| | | case 2: |
| | | coupon.setUseScopeValue("指定城市"); |
| | | break; |
| | | case 3: |
| | | coupon.setUseScopeValue("指定门店"); |
| | | break; |
| | | } |
| | | switch (coupon.getType()){ |
| | | case 1: |
| | | coupon.setTypeValue("满减券"); |
| | | break; |
| | | case 2: |
| | | coupon.setTypeValue("代金券"); |
| | | break; |
| | | case 3: |
| | | coupon.setTypeValue("体验券"); |
| | | break; |
| | | } |
| | | switch (coupon.getUserPopulation()){ |
| | | case 1: |
| | | coupon.setUserPopulationValue("全部用户"); |
| | | break; |
| | | case 2: |
| | | coupon.setUserPopulationValue("会员"); |
| | | break; |
| | | case 3: |
| | | coupon.setUserPopulationValue("已有学员用户"); |
| | | break; |
| | | } |
| | | } |
| | | model.addAttribute("couponList", coupons); |
| | | }else{ |
| | | model.addAttribute("couponList", new ArrayList<Coupon>()); |
| | | } |
| | | } |
| | | if (vip.getTicketJson() != null && !vip.getTicketJson().isEmpty()){ |
| | | String ticketJson = vip.getTicketJson(); |
| | | // 转化为jsonArray |
| | | JSONArray ticketJsonArray = JSONArray.parseArray(ticketJson); |
| | | // 收集里面得id |
| | | List<TicketDetailVO> ticketDetailVOS = new ArrayList<>(); |
| | | |
| | | for (Object o : ticketJsonArray) { |
| | | JSONObject couponJsonObject = (JSONObject) o; |
| | | TicketDetailVO ticketDetailVO = new TicketDetailVO(); |
| | | ticketDetailVO.setName(couponJsonObject.getString("name")); |
| | | ticketDetailVO.setTime(couponJsonObject.getInteger("time")); |
| | | ticketDetailVO.setCount(couponJsonObject.getInteger("count")); |
| | | ticketDetailVOS.add(ticketDetailVO); |
| | | } |
| | | model.addAttribute("ticketList", ticketDetailVOS); |
| | | } |
| | | return PREFIX + "vip_edit.html"; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String temp = "[{\"id\":\"36\",\"value\":\"1\"}]"; |
| | | JSONArray couponJsonArray = JSONArray.parseArray(temp); |
| | | for (Object o : couponJsonArray) { |
| | | JSONObject couponJsonObject = (JSONObject) o; |
| | | Integer couponId = couponJsonObject.getInteger("id"); |
| | | } |
| | | } |
| | | @RequestMapping("/detail/{id}") |
| | | public String detail(@PathVariable("id")Integer id, Model model) { |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | Vip vip = vipService.getById(id); |
| | | model.addAttribute("vip",vip); |
| | | if (vip.getCouponJson() != null && !vip.getCouponJson().isEmpty()){ |
| | | String couponJson = vip.getCouponJson(); |
| | | // 转化为jsonArray |
| | | JSONArray couponJsonArray = JSONArray.parseArray(couponJson); |
| | | List<Integer> couponIds = new ArrayList<>(); |
| | | Map<Integer, Integer> integerIntegerHashMap = new HashMap<>(); |
| | | // 收集里面得id |
| | | for (Object o : couponJsonArray) { |
| | | JSONObject couponJsonObject = (JSONObject) o; |
| | | Integer couponId = couponJsonObject.getInteger("id"); |
| | | Integer count = couponJsonObject.getInteger("value"); |
| | | integerIntegerHashMap.put(couponId, count); |
| | | couponIds.add(couponId); |
| | | } |
| | | List<Coupon> coupons = couponClient.queryCouponList(); |
| | | |
| | | if (!couponIds.isEmpty()){ |
| | | coupons = coupons.stream().filter(coupon -> couponIds.contains(coupon.getId())).collect(Collectors.toList()); |
| | | for (Coupon coupon : coupons) { |
| | | Date startTime = coupon.getStartTime(); |
| | | Date endTime = coupon.getEndTime(); |
| | | coupon.setTimeValue(simpleDateFormat.format(startTime) + "至" + simpleDateFormat.format(endTime)); |
| | | Integer orDefault = integerIntegerHashMap.getOrDefault(coupon.getId(), 0); |
| | | coupon.setCount(orDefault); |
| | | switch (coupon.getUseScope()){ |
| | | case 1: |
| | | coupon.setUseScopeValue("全国"); |
| | | break; |
| | | case 2: |
| | | coupon.setUseScopeValue("指定城市"); |
| | | break; |
| | | case 3: |
| | | coupon.setUseScopeValue("指定门店"); |
| | | break; |
| | | } |
| | | switch (coupon.getType()){ |
| | | case 1: |
| | | coupon.setTypeValue("满减券"); |
| | | break; |
| | | case 2: |
| | | coupon.setTypeValue("代金券"); |
| | | break; |
| | | case 3: |
| | | coupon.setTypeValue("体验券"); |
| | | break; |
| | | } |
| | | switch (coupon.getUserPopulation()){ |
| | | case 1: |
| | | coupon.setUserPopulationValue("全部用户"); |
| | | break; |
| | | case 2: |
| | | coupon.setUserPopulationValue("会员"); |
| | | break; |
| | | case 3: |
| | | coupon.setUserPopulationValue("已有学员用户"); |
| | | break; |
| | | } |
| | | } |
| | | model.addAttribute("couponList", coupons); |
| | | }else{ |
| | | model.addAttribute("couponList", new ArrayList<Coupon>()); |
| | | } |
| | | } |
| | | if (vip.getTicketJson() != null && !vip.getTicketJson().isEmpty()){ |
| | | String ticketJson = vip.getTicketJson(); |
| | | // 转化为jsonArray |
| | | JSONArray ticketJsonArray = JSONArray.parseArray(ticketJson); |
| | | // 收集里面得id |
| | | List<TicketDetailVO> ticketDetailVOS = new ArrayList<>(); |
| | | |
| | | for (Object o : ticketJsonArray) { |
| | | JSONObject couponJsonObject = (JSONObject) o; |
| | | TicketDetailVO ticketDetailVO = new TicketDetailVO(); |
| | | ticketDetailVO.setName(couponJsonObject.getString("name")); |
| | | ticketDetailVO.setTime(couponJsonObject.getInteger("time")); |
| | | ticketDetailVO.setCount(couponJsonObject.getInteger("count")); |
| | | ticketDetailVOS.add(ticketDetailVO); |
| | | } |
| | | model.addAttribute("ticketList", ticketDetailVOS); |
| | | } |
| | | |
| | | return PREFIX + "vip_detail.html"; |
| | | } |
| | | /** |
| | | * 跳转到门店管理列表页 |
| | | */ |
| | | @RequestMapping("/couponList") |
| | | public String couponList(Model model) { |
| | | return PREFIX + "TCoupon.html"; |
| | | } |
| | | @RequestMapping(value = "/addVipInfo") |
| | | @ResponseBody |
| | | public ResultUtil addVipInfo(String vipName, Integer time, Integer timeType, String price,String couponJson, String ticketJson) { |
| | | Vip vip = new Vip(); |
| | | vip.setVipName(vipName); |
| | | vip.setTimeType(timeType); |
| | | vip.setTime(time); |
| | | vip.setPrice(new BigDecimal(price)); |
| | | vip.setStatus(1); |
| | | vip.setInsertTime(new Date()); |
| | | vip.setCouponJson(couponJson); |
| | | vip.setTicketJson(ticketJson); |
| | | vipService.save(vip); |
| | | return ResultUtil.success(); |
| | | } |
| | | @RequestMapping(value = "/editVipInfo") |
| | | @ResponseBody |
| | | public ResultUtil addVipInfo(Integer id,String vipName, Integer time, Integer timeType, String price,String couponJson, String ticketJson) { |
| | | Vip vip = vipService.getById(id); |
| | | vip.setVipName(vipName); |
| | | vip.setTimeType(timeType); |
| | | vip.setTime(time); |
| | | vip.setPrice(new BigDecimal(price)); |
| | | vip.setInsertTime(new Date()); |
| | | if (couponJson==null){ |
| | | couponJson = ""; |
| | | } |
| | | vip.setCouponJson(couponJson); |
| | | if (ticketJson==null){ |
| | | ticketJson = ""; |
| | | } |
| | | vip.setTicketJson(ticketJson); |
| | | vipService.updateById(vip); |
| | | return ResultUtil.success(); |
| | | } |
| | | @RequestMapping(value = "/offShelf") |
| | | @ResponseBody |
| | | public ResultUtil offShelf(Integer id) { |
| | | Vip vip = vipService.getById(id); |
| | | vip.setStatus(2); |
| | | vipService.updateById(vip); |
| | | return ResultUtil.success(); |
| | | } |
| | | @RequestMapping(value = "/onShelf") |
| | | @ResponseBody |
| | | public ResultUtil onShelf(Integer id) { |
| | | Vip vip = vipService.getById(id); |
| | | vip.setStatus(1); |
| | | vipService.updateById(vip); |
| | | return ResultUtil.success(); |
| | | } |
| | | /** |
| | | * 获取 会员卡列表 |
| | | */ |
| | | @RequestMapping(value = "/list") |
| | | @ResponseBody |
| | | public List<Map<String, Object>> list(String vipName, Integer status) { |
| | | Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(); |
| | | List<Map<String, Object>> maps = vipService.listOfPage(vipName, status, page); |
| | | for (Map<String, Object> map : maps) { |
| | | Object timeType = map.get("timeType"); |
| | | Object time = map.get("time"); |
| | | Integer timeTypeValue = Integer.valueOf(timeType.toString()); |
| | | Integer timeValue = Integer.valueOf(time.toString()); |
| | | switch (timeTypeValue) { |
| | | case 1: |
| | | map.put("time",timeValue+"天"); |
| | | break; |
| | | case 2: |
| | | map.put("time",timeValue+"月"); |
| | | break; |
| | | case 3: |
| | | map.put("time",timeValue+"年"); |
| | | break; |
| | | } |
| | | } |
| | | return maps; |
| | | } |
| | | |
| | | // APP查询所有上架的会员卡 |
| | | @ResponseBody |
| | | @PostMapping("/listAll") |
| | | public List<Vip> listAll() { |
| | | List<Vip> list = vipService.lambdaQuery().eq(Vip::getStatus, 1).list(); |
| | | List<Coupon> coupons = couponClient.queryCouponAll(); |
| | | List<CouponCity> couponCityList = couponClient.queryAllCity(); |
| | | List<CouponStore> storeList = couponClient.queryAllStore(); |
| | | List<TStore> shopList = storeService.list(); |
| | | // 封装会员权益 |
| | | for (Vip vip : list) { |
| | | List<CouponVipResp> couponVipRespList = new ArrayList<>(); |
| | | List<TicketVipResp> ticketVipRespList = new ArrayList<>(); |
| | | String couponJson = vip.getCouponJson(); |
| | | JSONArray couponJsonArray = JSONArray.parseArray(couponJson); |
| | | for (Object o : couponJsonArray) { |
| | | JSONObject couponJsonObject = (JSONObject) o; |
| | | // 优惠券id |
| | | Integer id = Integer.valueOf(couponJsonObject.getString("id")); |
| | | // 优惠券数量 |
| | | Integer value = Integer.valueOf(couponJsonObject.getString("value")); |
| | | Coupon coupon = coupons.stream().filter(e -> e.getId().equals(id)).findFirst().orElse(new Coupon()); |
| | | CouponVipResp couponVipResp = new CouponVipResp(); |
| | | couponVipResp.setId(coupon.getId()); |
| | | couponVipResp.setName(coupon.getName()); |
| | | couponVipResp.setType(coupon.getType()); |
| | | couponVipResp.setUseCondition(coupon.getUseScope()); |
| | | couponVipResp.setCount(value); |
| | | switch (coupon.getUseScope()) { |
| | | case 1: |
| | | couponVipResp.setAvailable("全国通用"); |
| | | break; |
| | | case 2: |
| | | couponVipResp.setAvailable("指定城市可用"); |
| | | List<CouponCity> couponId = couponCityList.stream().filter(e -> e.getCouponId().equals(id)) |
| | | .collect(Collectors.toList()); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | for (CouponCity couponCity : couponId) { |
| | | stringBuilder.append(couponCity.getCity()); |
| | | } |
| | | couponVipResp.setCityOrStore(String.valueOf(stringBuilder)); |
| | | break; |
| | | case 3: |
| | | couponVipResp.setAvailable("指定门店可用"); |
| | | // 门店ids |
| | | List<Integer> storeIds = storeList.stream().filter(e -> e.getCouponId().equals(id)) |
| | | .map(CouponStore::getStoreId).collect(Collectors.toList()); |
| | | StringBuilder storeNames = new StringBuilder(""); |
| | | |
| | | if (!storeIds.isEmpty()) { |
| | | List<TStore> stores = shopList.stream().filter(e -> storeIds.contains(e.getId())).collect(Collectors.toList()); |
| | | for (TStore store : stores) { |
| | | storeNames.append(store.getName()).append(","); |
| | | } |
| | | // 去除最后一位 |
| | | StringBuilder res = storeNames.deleteCharAt(storeNames.length() - 1); |
| | | couponVipResp.setCityOrStore(res.toString()); |
| | | } else { |
| | | couponVipResp.setCityOrStore("无可用门店"); |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | couponVipResp.setInstructionsForUse(coupon.getIllustrate()); |
| | | ConponJsonRuleModel ruleModel = new ConponJsonRuleModel(); |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | switch (coupon.getType()) { |
| | | case 1: |
| | | // 满减券 |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | Double num2 = jsonObject.getDouble("deductionAmount"); |
| | | ruleModel.setConditionalAmount("满" + num1 + "可用"); |
| | | ruleModel.setDeductionAmount("¥ " + num2); |
| | | ruleModel.setExperienceName(""); |
| | | break; |
| | | case 2: |
| | | // 代金券 |
| | | Double jsonObjectDouble = jsonObject.getDouble("conditionalAmount"); |
| | | ruleModel.setConditionalAmount(""); |
| | | ruleModel.setDeductionAmount("¥ " + jsonObjectDouble); |
| | | ruleModel.setExperienceName(""); |
| | | break; |
| | | case 3: |
| | | // 体验券 |
| | | ruleModel.setConditionalAmount(""); |
| | | ruleModel.setDeductionAmount(""); |
| | | ruleModel.setExperienceName(jsonObject.getString("experienceName")); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | couponVipResp.setRuleModel(ruleModel); |
| | | |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | couponVipResp.setEffectiveTime(simpleDateFormat.format(coupon.getEndTime())); |
| | | couponVipRespList.add(couponVipResp); |
| | | } |
| | | vip.setCouponList(couponVipRespList); |
| | | String ticketJson = vip.getTicketJson(); |
| | | JSONArray ticketJsonArray = JSONArray.parseArray(ticketJson); |
| | | for (Object o : ticketJsonArray) { |
| | | JSONObject ticketJsonObject = (JSONObject) o; |
| | | TicketVipResp ticketVipResp = new TicketVipResp(); |
| | | ticketVipResp.setName(ticketJsonObject.getString("name")); |
| | | ticketVipResp.setTime(ticketJsonObject.getInteger("time")); |
| | | ticketVipResp.setCount(ticketJsonObject.getInteger("count")); |
| | | ticketVipRespList.add(ticketVipResp); |
| | | } |
| | | vip.setTicketList(ticketVipRespList); |
| | | } |
| | | return list; |
| | | } |
| | | @Autowired |
| | | private IProtocolService protocolService; |
| | | @ResponseBody |
| | | @PostMapping("/getAgreement") |
| | | public String getAgreement() { |
| | | Protocol one = protocolService.lambdaQuery().eq(Protocol::getType, 6).one(); |
| | | if (one==null){ |
| | | Protocol protocol = new Protocol(); |
| | | protocol.setType(6); |
| | | protocol.setContent(""); |
| | | protocol.setInsertTime(new Date()); |
| | | protocolService.save( protocol); |
| | | return ""; |
| | | }else{ |
| | | return one.getContent(); |
| | | |
| | | } |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/getVipByIds") |
| | | public List<Vip> getVipByIds(@RequestBody String ids) { |
| | | List<Vip> list = vipService.lambdaQuery().in(Vip::getId, Arrays.asList(ids.split(","))).list(); |
| | | return list; |
| | | } |
| | | } |