package com.dsh.guns.modular.system.controller.code; import com.dsh.course.feignClient.account.AppUserClient; 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.guns.config.UserExt; import com.dsh.guns.core.base.controller.BaseController; import com.dsh.guns.modular.system.model.TOperator; import com.dsh.guns.modular.system.model.TSite; import com.dsh.guns.modular.system.model.TStore; import com.dsh.guns.modular.system.model.Vip; import com.dsh.guns.modular.system.model.dto.VipDetailDto; import com.dsh.guns.modular.system.model.dto.VipPaymentDto; import com.dsh.guns.modular.system.model.vo.VipDetailVO; import com.dsh.guns.modular.system.model.vo.VipPaymentListVO; import com.dsh.guns.modular.system.service.IStoreService; import com.dsh.guns.modular.system.service.ITSiteService; import com.dsh.guns.modular.system.service.IVipService; import com.dsh.guns.modular.system.service.TOperatorService; import com.dsh.guns.modular.system.util.DateUtil; import com.dsh.guns.modular.system.util.ExcelUtil; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; import java.util.List; import java.util.stream.Collectors; /** * @author zhibing.pu * @Date 2023/8/1 14:02 */ @Controller @RequestMapping("/vipPayment") public class TVipPaymentController extends BaseController { @Autowired private IVipService vipService; @Autowired private CouponClient couponClient; @Autowired private IStoreService storeService; @Autowired private AppUserClient appUserClient; @Autowired private ITSiteService siteService; @Autowired private TOperatorService operatorService; private String PREFIX = "/system/vipDetail/"; /** * 跳转到优惠券管理首页 */ @RequestMapping("") public String index(Model model) { Integer objectType = UserExt.getUser().getObjectType(); Integer objectId = UserExt.getUser().getObjectId(); if (objectType!=1){ List list = operatorService.lambdaQuery().eq(TOperator::getId, objectId).list(); model.addAttribute("list",list); }else{ List list = operatorService.lambdaQuery().ne(TOperator::getState,3).list(); model.addAttribute("list",list); } model.addAttribute("objectType",objectType); return PREFIX + "vip_detail.html"; } /** * 获取 会员权益使用明细列表 */ @RequestMapping(value = "/list") @ResponseBody public List list(String vipName, Integer type , String phone, String storeName , Integer operatorId, Integer status , String time , String useTime) { Integer objectType = UserExt.getUser().getObjectType(); Integer objectId = UserExt.getUser().getObjectId(); VipDetailDto vipDetailDto = new VipDetailDto(); vipDetailDto.setOperatorId(operatorId); vipDetailDto.setStatus(status); vipDetailDto.setType(type); vipDetailDto.setObjectType(objectType); if (objectType == 2){ vipDetailDto.setStatus(2); } if (StringUtils.hasLength(vipName)){ List vipIds = vipService.lambdaQuery().like(Vip::getVipName, vipName) .list().stream().map(Vip::getId).collect(Collectors.toList()); if (vipIds.isEmpty()){ vipIds.add(-1); } vipDetailDto.setVipIds(vipIds); } if (StringUtils.hasLength(phone)){ QueryByNamePhone queryByNamePhone = new QueryByNamePhone(); queryByNamePhone.setPhone( phone); List userIds = appUserClient.queryByNamePhone(queryByNamePhone).stream().map(TAppUser::getId) .collect(Collectors.toList()); if (userIds.isEmpty()){ userIds.add(-1); } vipDetailDto.setUserIds(userIds); } if (StringUtils.hasLength(storeName)){ List storeIds = storeService.lambdaQuery().like(TStore::getName, storeName) .eq(objectType!=1,TStore::getOperatorId,objectId ).list() .stream().map(TStore::getId).collect(Collectors.toList()); if (storeIds.isEmpty()){ storeIds.add(-1); } vipDetailDto.setStoreIds(storeIds); } if (StringUtils.hasLength(time)){ String stareTime = null; String endTime = null; stareTime = time.split(" - ")[0] + " 00:00:00"; endTime = time.split(" - ")[1] + " 23:59:59"; vipDetailDto.setStartTime(stareTime); vipDetailDto.setEndTime(endTime); } if (StringUtils.hasLength(useTime)){ String stareTime = null; String endTime = null; stareTime = time.split(" - ")[0] + " 00:00:00"; endTime = time.split(" - ")[1] + " 23:59:59"; vipDetailDto.setUseStartTime(stareTime); vipDetailDto.setUseEndTime(endTime); } List res = couponClient.vipDetail(vipDetailDto); QueryByNamePhone queryByNamePhone = new QueryByNamePhone(); List tAppUsers = appUserClient.queryByNamePhone(queryByNamePhone); List vipList = vipService.list(); List storeList = storeService.list(); List siteList = siteService.list(); List operatorList = operatorService.list(); for (VipDetailVO re : res) { TAppUser tAppUser = tAppUsers.stream().filter(e -> e.getId().equals(re.getAppUserId())).findFirst().orElse(null); if (tAppUser!=null){ re.setAppUserName(tAppUser.getName()); re.setAppUserPhone(tAppUser.getPhone()); } Vip vip = vipList.stream().filter(e -> e.getId().equals(re.getVipId())).findFirst().orElse(null); if (vip!=null){ re.setVipName(vip.getVipName()); } if (re.getUseSiteId()!=null){ TSite site = siteList.stream().filter(e -> e.getId().equals(re.getUseSiteId())).findFirst().orElse(null); if (site!=null){ re.setGoodsName(site.getName()); } } if (re.getUseStoreId()!=null){ TStore store = storeList.stream().filter(e -> e.getId().equals(re.getUseStoreId())).findFirst().orElse(null); if (store!=null){ re.setStoreName(store.getName()); } } if (re.getOperatorId()!=null){ if (re.getOperatorId()==0){ re.setOperatorName("总平台"); }else{ TOperator operator = operatorList.stream().filter(e -> e.getId().equals(re.getOperatorId())).findFirst().orElse(null); if (operator!=null){ re.setOperatorName(operator.getName()); } } } } return res; } /** * 导出会员权益明细 * @param */ @GetMapping("/export") public void exportData(String vipName, Integer type , String phone, String storeName , Integer operatorId, Integer status , String time , String useTime, HttpServletResponse response) { Integer objectType = UserExt.getUser().getObjectType(); Integer objectId = UserExt.getUser().getObjectId(); VipDetailDto vipDetailDto = new VipDetailDto(); vipDetailDto.setOperatorId(operatorId); vipDetailDto.setStatus(status); vipDetailDto.setType(type); vipDetailDto.setObjectType(objectType); if (objectType == 2){ vipDetailDto.setStatus(2); } if (StringUtils.hasLength(vipName)){ List vipIds = vipService.lambdaQuery().like(Vip::getVipName, vipName) .list().stream().map(Vip::getId).collect(Collectors.toList()); if (vipIds.isEmpty()){ vipIds.add(-1); } vipDetailDto.setVipIds(vipIds); } if (StringUtils.hasLength(phone)){ QueryByNamePhone queryByNamePhone = new QueryByNamePhone(); queryByNamePhone.setPhone( phone); List userIds = appUserClient.queryByNamePhone(queryByNamePhone).stream().map(TAppUser::getId) .collect(Collectors.toList()); if (userIds.isEmpty()){ userIds.add(-1); } vipDetailDto.setUserIds(userIds); } if (StringUtils.hasLength(storeName)){ List storeIds = storeService.lambdaQuery().like(TStore::getName, storeName) .eq(objectType!=1,TStore::getOperatorId,objectId ).list() .stream().map(TStore::getId).collect(Collectors.toList()); if (storeIds.isEmpty()){ storeIds.add(-1); } vipDetailDto.setStoreIds(storeIds); } if (StringUtils.hasLength(time)){ String stareTime = null; String endTime = null; stareTime = time.split(" - ")[0] + " 00:00:00"; endTime = time.split(" - ")[1] + " 23:59:59"; vipDetailDto.setStartTime(stareTime); vipDetailDto.setEndTime(endTime); } if (StringUtils.hasLength(useTime)){ String stareTime = null; String endTime = null; stareTime = time.split(" - ")[0] + " 00:00:00"; endTime = time.split(" - ")[1] + " 23:59:59"; vipDetailDto.setUseStartTime(stareTime); vipDetailDto.setUseEndTime(endTime); } List res = couponClient.vipDetail(vipDetailDto); QueryByNamePhone queryByNamePhone = new QueryByNamePhone(); List tAppUsers = appUserClient.queryByNamePhone(queryByNamePhone); List vipList = vipService.list(); List storeList = storeService.list(); List siteList = siteService.list(); List operatorList = operatorService.list(); for (VipDetailVO re : res) { TAppUser tAppUser = tAppUsers.stream().filter(e -> e.getId().equals(re.getAppUserId())).findFirst().orElse(null); if (tAppUser!=null){ re.setAppUserName(tAppUser.getName()); re.setAppUserPhone(tAppUser.getPhone()); } Vip vip = vipList.stream().filter(e -> e.getId().equals(re.getVipId())).findFirst().orElse(null); if (vip!=null){ re.setVipName(vip.getVipName()); } if (re.getUseSiteId()!=null){ TSite site = siteList.stream().filter(e -> e.getId().equals(re.getUseSiteId())).findFirst().orElse(null); if (site!=null){ re.setGoodsName(site.getName()); } } if (re.getUseStoreId()!=null){ TStore store = storeList.stream().filter(e -> e.getId().equals(re.getUseStoreId())).findFirst().orElse(null); if (store!=null){ re.setStoreName(store.getName()); } } if (re.getOperatorId()!=null){ if (re.getOperatorId()==0){ re.setOperatorName("总平台"); }else{ TOperator operator = operatorList.stream().filter(e -> e.getId().equals(re.getOperatorId())).findFirst().orElse(null); if (operator!=null){ re.setOperatorName(operator.getName()); } } } } String[] titleArr = {"权益名称", "权益类型", "关联会员类型", "购买会员姓名", "联系电话", "使用状态", "使用场地/商品名称", "使用门店", "归属运营商", "获得时间", "使用时间"}; String[][] values = new String[res.size()][]; for (int i = 0; i < res.size(); i++) { VipDetailVO vipDetailVO = res.get(i); values[i] = new String[titleArr.length]; values[i][0] = vipDetailVO.getTicketName(); values[i][1] = vipDetailVO.getType()==1 ? "优惠券" : "门票"; values[i][2] = vipDetailVO.getVipName(); values[i][3] = vipDetailVO.getAppUserName(); values[i][4] = vipDetailVO.getAppUserPhone(); values[i][5] = vipDetailVO.getStatus() == 1 ? "未使用" : vipDetailVO.getStatus()==2 ? "已使用" : "已过期"; values[i][6] = vipDetailVO.getGoodsName(); values[i][7] = vipDetailVO.getStoreName(); values[i][8] = vipDetailVO.getOperatorName(); values[i][9] = DateUtil.format(vipDetailVO.getInsertTime(), "yyyy-MM-dd HH:mm:ss"); values[i][10] = vipDetailVO.getUseTime()!=null?DateUtil.format(vipDetailVO.getUseTime(), "yyyy-MM-dd HH:mm:ss"):""; } try { HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("会员权益使用明细", titleArr, values, null); ExcelUtil.setResponseHeader(response, "会员权益使用明细.xls"); OutputStream os = response.getOutputStream(); wb.write(os); os.flush(); os.close(); } catch (IOException e) { throw new RuntimeException(e); } } }