package com.dsh.guns.modular.system.controller.code; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.dsh.course.feignClient.account.AppUserClient; import com.dsh.course.feignClient.account.CityManagerClient; import com.dsh.course.feignClient.account.model.CityManager; import com.dsh.course.feignClient.account.model.QueryByNamePhone; import com.dsh.course.feignClient.account.model.TAppUser; 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.CouponListOfSearch; import com.dsh.course.feignClient.activity.model.CouponRecordQuery; import com.dsh.guns.config.UserExt; import com.dsh.guns.core.base.tips.SuccessTip; import com.dsh.guns.core.common.constant.factory.PageFactory; import com.dsh.guns.core.util.ToolUtil; import com.dsh.guns.modular.system.model.*; import com.dsh.guns.modular.system.service.*; import com.dsh.guns.modular.system.util.OBSUploadUtil; import com.dsh.guns.modular.system.util.OssUploadUtil; import com.dsh.guns.modular.system.util.ResultUtil; import org.apache.commons.beanutils.ConvertUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; /** * 优惠券管理 控制器 */ @Controller @RequestMapping("/tCouponManage") public class TCouponController { private String PREFIX = "/system/tCoupon/"; @Resource private IRegionService regiService; @Resource private IStoreService storeService; @Resource private CouponClient client; @Resource private CityManagerClient cmgrClient; @Autowired private AppUserClient appUserClient; @Autowired private IUserService userService; @Autowired private TOperatorService operatorService; @Autowired private TOperatorCityService operatorCityService; /** * 跳转到优惠券管理首页 */ @RequestMapping("") public String index(Model model) { return PREFIX + "TCoupon.html"; } /** * 跳转到添加 */ @RequestMapping("/coupon_add") public String memberCouponAdd(Model model) { Integer objectType = UserExt.getUser().getObjectType(); System.out.println(objectType); model.addAttribute("userType",objectType); return PREFIX + "TCouponAdd.html"; } @RequestMapping("/coupon_record/{id}") public String memberCouponAdd(@PathVariable Integer id,Model model) { Coupon coupon = client.queryCouponById(id); model.addAttribute("id",id); model.addAttribute("type",coupon.getType()); return PREFIX + "TCouponRecord.html"; } @RequestMapping("/coupon_detail/{id}") public String memberCouponDetail(@PathVariable Integer id,Model model) { Coupon coupon = client.queryCouponById(id); String content = coupon.getContent(); JSONObject jsonObject = JSONObject.parseObject(content); String one =""; String two =""; String three =""; if(coupon.getType()==1){ one = jsonObject.get("conditionalAmount").toString(); two = jsonObject.get("deductionAmount").toString(); } if(coupon.getType()==2){ one = jsonObject.get("conditionalAmount").toString(); } if(coupon.getType()==3){ three = jsonObject.get("experienceName").toString(); } List list = new ArrayList<>(); List list1=null; List list2=new ArrayList<>(); if(coupon.getUseScope()==2){ list = client.queryCity(coupon.getId()); } if(coupon.getUseScope()==3){ list1 = client.queryStore(coupon.getId()); list2 = storeService.list(new LambdaQueryWrapper().in(TStore::getId, list1)); for (TStore tStore : list2) { CityManager cityManager = cmgrClient.queryCityManagerById(tStore.getCityManagerId()); if (ToolUtil.isNotEmpty(cityManager)){ tStore.setProvince(tStore.getProvince()+tStore.getCity()); tStore.setPhone(cityManager.getName()+"-"+cityManager.getPhone()); } } } model.addAttribute("city",list); model.addAttribute("store",list2); model.addAttribute("s",new SimpleDateFormat("yyyy-MM-dd").format(coupon.getStartTime())); model.addAttribute("e",new SimpleDateFormat("yyyy-MM-dd").format(coupon.getEndTime())); model.addAttribute("one",one); model.addAttribute("two",two); model.addAttribute("three",three); ArrayList strings = new ArrayList<>(); String productImages = coupon.getProductImages(); for (String s : productImages.split(",")) { strings.add(s); } model.addAttribute("img",strings); Integer objectType = UserExt.getUser().getObjectType(); System.out.println(objectType); model.addAttribute("item",coupon); return PREFIX + "TCouponInfo.html"; } /** * 跳转到门店管理列表页 */ @RequestMapping("/storeList") public String storePage(Model model) { return PREFIX + "TStoreList.html"; } @RequestMapping("/updateType") @ResponseBody public Object updateType(Long id) { client.updateType(id); return new SuccessTip<>(); } @RequestMapping("/storeDetailsOfSearch") @ResponseBody public Object listOfStore(String provinceId,String cityId,Integer operatorId,String storeName){ Page> page = new PageFactory>().defaultPage(); List> storeList = storeService.queryListOfpage(provinceId,cityId,operatorId,storeName,page); if (storeList.size() > 0 ){ for (Map stringObjectMap : storeList) { String provinceName = (String) stringObjectMap.get("province"); String cityName = (String) stringObjectMap.get("city"); stringObjectMap.put("provinceCity",provinceName+cityName); Integer managerId = (Integer) stringObjectMap.get("operatorId"); if (managerId==0){ stringObjectMap.put("accountName","平台"); }else{ TOperator operator = operatorService.getOne(new QueryWrapper().eq("id", managerId)); if (ToolUtil.isNotEmpty(operator)){ stringObjectMap.put("accountName",operator.getName()); }else{ stringObjectMap.put("accountName","平台"); } } } } return storeList; } /** * 获取 优惠券管理 */ @RequestMapping(value = "/list") @ResponseBody public Object listOfDatas(String name, Integer type, Integer distributionMethod , Integer userPopulation, Integer status, Integer state) { Page> page = new PageFactory>().defaultPage(); CouponListOfSearch ofSearch = new CouponListOfSearch(); ofSearch.setPage(page); ofSearch.setName(name); ofSearch.setType(type); ofSearch.setDistributionMethod(distributionMethod); ofSearch.setUserPopulation(userPopulation); ofSearch.setStatus(status); ofSearch.setState(state); return client.getCouponListOfSearch(ofSearch); } /** * 获取 优惠券管理 */ @RequestMapping(value = "/list1") @ResponseBody public Object listOfDatas1(String name, Integer type, Integer distributionMethod , Integer userPopulation, Integer status, Integer state,String cityCode,Integer storeId) { Page> page = new PageFactory>().defaultPage(); CouponListOfSearch ofSearch = new CouponListOfSearch(); ofSearch.setPage(page); ofSearch.setName(name); ofSearch.setType(type); ofSearch.setDistributionMethod(distributionMethod); ofSearch.setUserPopulation(userPopulation); ofSearch.setStatus(status); ofSearch.setState(state); ofSearch.setCityCode(cityCode); ofSearch.setStoreId(storeId); return client.getCouponListOfSearch1(ofSearch); } @RequestMapping(value = "/listRecord") @ResponseBody public Object listRecord(Integer id,String name, Integer type, String phone) { Page> page = new PageFactory>().defaultPage(); List tAppUsers = appUserClient.queryByNamePhone(new QueryByNamePhone(name, phone)); if(tAppUsers.size()==0){ return new ArrayList<>(); } CouponRecordQuery ofSearch = new CouponRecordQuery(); ofSearch.setId(id); ofSearch.setLimit(page.getSize()); ofSearch.setOffset(page.getCurrent()); ofSearch.setIds(tAppUsers.stream().map(TAppUser::getId).collect(Collectors.toList())); ofSearch.setType(type); List> maps = client.listRecord(ofSearch); for (Map map : maps) { map.put("id",map.get("id").toString()); for (TAppUser tAppUser : tAppUsers) { if(map.get("userId").equals(tAppUser.getId())){ map.put("name",tAppUser.getName()); map.put("phone",tAppUser.getPhone()); } } } return maps; } @RequestMapping(value = "/getProvince") @ResponseBody public Object getProvince(){ return regiService.list(new LambdaQueryWrapper() .eq(Region::getParentId,0)); } @RequestMapping(value = "/onShelf") @ResponseBody public Object onShelf(Integer id,Integer type){ Coupon coupon = client.queryCouponById(id); coupon.setState(type); client.updateCouponData(coupon); return new SuccessTip<>(); } @RequestMapping(value = "/getCity") @ResponseBody public Object getCity(Integer province){ return regiService.list(new LambdaQueryWrapper() .eq(Region::getParentId,province)); } // 通过市 获取运营商 @RequestMapping(value = "/getOperator") @ResponseBody public Object getOperator(String city){ List name = operatorCityService.list(new QueryWrapper().eq("name", city)); List collect = name.stream().map(TOperatorCity::getOperatorId) .collect(Collectors.toList()); if (collect.size()==0){ return new ArrayList<>(); } return operatorService.list(new QueryWrapper().in("id",collect)); } @RequestMapping(value = "/uploadPic") @ResponseBody public Object add(@RequestParam("file") MultipartFile imgFile) throws IOException { if (imgFile != null){ String originalFilename = imgFile.getOriginalFilename(); String newName = originalFilename.substring(imgFile.getOriginalFilename().lastIndexOf(".")); String url = OssUploadUtil.ossUpload("img/",imgFile); Map map = new HashMap(); //是否上传成功 map.put("state", "SUCCESS"); //现在文件名称 map.put("title", newName); //文件原名称 map.put("original", originalFilename); //文件类型 .+后缀名 map.put("type", originalFilename.substring(imgFile.getOriginalFilename().lastIndexOf("."))); //文件路径 map.put("url", url); //文件大小(字节数) map.put("size", imgFile.getSize() + ""); System.out.println(map); return url; } return ResultUtil.success(); } /** * 提交添加 */ @PostMapping(value = "/commitData") @ResponseBody public Object commitData( CouponDataVo dataVo){ System.out.println(dataVo); Integer objectType = UserExt.getUser().getObjectType(); dataVo.setUserType(objectType); client.insertIntoData(dataVo); return new SuccessTip<>(); } @PostMapping(value = "/update") @ResponseBody public Object update( Integer id,Integer num,Integer num1,String text){ Coupon coupon = client.queryCouponById(id); coupon.setQuantityIssued(num); coupon.setPickUpQuantity(num1); coupon.setIllustrate(text); client.updateCouponData(coupon); return new SuccessTip<>(); } }