| | |
| | | package com.dsh.guns.modular.system.controller.code; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | 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.model.TAppUser; |
| | | import com.dsh.course.feignClient.activity.PayHuiminClient; |
| | | import com.dsh.course.feignClient.activity.model.HuiminPayQuery; |
| | | import com.dsh.course.feignClient.activity.model.TPayHuimin; |
| | | import com.dsh.guns.config.UserExt; |
| | | import com.dsh.guns.core.base.controller.BaseController; |
| | | import com.dsh.guns.core.common.constant.factory.PageFactory; |
| | | import com.dsh.guns.modular.system.model.AppUserByNameAndPhoneDTO; |
| | | import com.dsh.guns.modular.system.model.SalesDetailVO; |
| | | import com.dsh.guns.modular.system.model.TOperator; |
| | | import com.dsh.guns.modular.system.model.TStore; |
| | | import com.dsh.guns.modular.system.service.IStoreService; |
| | | 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 com.dsh.guns.modular.system.util.ResultUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | 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.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | 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.math.BigDecimal; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 惠民卡控制器 |
| | | * 玩湃惠民卡控制器 |
| | | * |
| | | * @author fengshuonan |
| | | * @Date 2025-03-29 17:41:48 |
| | |
| | | |
| | | @Autowired |
| | | private PayHuiminClient payHuiminClient; |
| | | @Autowired |
| | | private TOperatorService operatorService; |
| | | @Autowired |
| | | private IStoreService storeService; |
| | | @Autowired |
| | | private AppUserClient appUserClient; |
| | | |
| | | |
| | | /** |
| | | * 跳转到惠民卡首页 |
| | | * 跳转到玩湃惠民卡首页 |
| | | */ |
| | | @RequestMapping("") |
| | | public String index() { |
| | | public String index(Model model) { |
| | | Integer objectType = UserExt.getUser().getObjectType(); |
| | | Integer operatorId = null; |
| | | if (objectType.equals(2)){ |
| | | //查询运营商 |
| | | TOperator operator = operatorService.getOne(new QueryWrapper<TOperator>() |
| | | .eq("userId", UserExt.getUser().getId()) |
| | | .ne("state", 3) |
| | | .last("LIMIT 1")); |
| | | if (Objects.nonNull(operator)) { |
| | | operatorId = operator.getId(); |
| | | } |
| | | } |
| | | //查询运营商列表 |
| | | model.addAttribute("operatorList", operatorService.list(new QueryWrapper<TOperator>().eq(Objects.nonNull(operatorId), "id",operatorId).eq("state", 1))); |
| | | model.addAttribute("storeList", storeService.list(new QueryWrapper<TStore>().eq("state", 1))); |
| | | return PREFIX + "tPayHuimin.html"; |
| | | } |
| | | |
| | | /** |
| | | * 跳转到添加惠民卡 |
| | | * 跳转到添加玩湃惠民卡 |
| | | */ |
| | | @RequestMapping("/tPayHuimin_add") |
| | | public String tPayHuiminAdd() { |
| | | return PREFIX + "tPayHuimin_add.html"; |
| | | } |
| | | |
| | | /* *//** |
| | | * 跳转到修改惠民卡 |
| | | *//* |
| | | @RequestMapping("/tPayHuimin_update/{tPayHuiminId}") |
| | | public String tPayHuiminUpdate(@PathVariable Integer tPayHuiminId, Model model) { |
| | | TPayHuimin tPayHuimin = payHuiminClient.selectById(tPayHuiminId); |
| | | model.addAttribute("item",tPayHuimin); |
| | | LogObjectHolder.me().set(tPayHuimin); |
| | | return PREFIX + "tPayHuimin_edit.html"; |
| | | } |
| | | |
| | | *//** |
| | | * 获取惠民卡列表 |
| | | *//* |
| | | /** |
| | | * 获取玩湃惠民卡列表 |
| | | */ |
| | | @RequestMapping(value = "/list") |
| | | @ResponseBody |
| | | public Object list(String condition) { |
| | | return payHuiminClient.selectList(null); |
| | | public Object list(HuiminPayQuery query) { |
| | | Integer objectType = UserExt.getUser().getObjectType(); |
| | | if (objectType.equals(2)){ |
| | | //查询运营商 |
| | | TOperator operator = operatorService.getOne(new QueryWrapper<TOperator>() |
| | | .eq("userId", UserExt.getUser().getId()) |
| | | .ne("state", 3) |
| | | .last("LIMIT 1")); |
| | | if (Objects.nonNull(operator)) { |
| | | query.setOperatorId(Long.valueOf(operator.getId())); |
| | | } |
| | | } |
| | | Page<TPayHuimin> tPayHuiminPage = new PageFactory<TPayHuimin>().defaultPage(); |
| | | query.setCurrent(tPayHuiminPage.getCurrent()); |
| | | query.setSize(tPayHuiminPage.getSize()); |
| | | List<Integer> appUserIds = Collections.emptyList(); |
| | | if (StringUtils.isNotBlank(query.getUserName()) || StringUtils.isNotBlank(query.getPhone())){ |
| | | AppUserByNameAndPhoneDTO appUserByNameAndPhoneDTO = new AppUserByNameAndPhoneDTO(); |
| | | appUserByNameAndPhoneDTO.setUserName(query.getUserName()); |
| | | appUserByNameAndPhoneDTO.setPhone(query.getPhone()); |
| | | List<TAppUser> tAppUsers = appUserClient.queryAPPUserByNameAndPhone(appUserByNameAndPhoneDTO); |
| | | appUserIds = tAppUsers.stream() |
| | | .map(TAppUser::getId) |
| | | .collect(Collectors.toList()); |
| | | if (CollUtil.isEmpty(appUserIds)){ |
| | | return new Page<>(); |
| | | } |
| | | } |
| | | query.setAppUserIds(appUserIds); |
| | | Page<SalesDetailVO> salesDetailVOPage = payHuiminClient.selectPage(query); |
| | | List<SalesDetailVO> records = salesDetailVOPage.getRecords(); |
| | | if (CollUtil.isNotEmpty(records)) { |
| | | List<Integer> operatorIdList = records.stream() |
| | | .map(SalesDetailVO::getOperatorId) |
| | | .collect(Collectors.toList()); |
| | | Map<Integer, String> operatorMap = operatorService.listByIds(operatorIdList).stream() |
| | | .collect(Collectors.toMap(TOperator::getId, TOperator::getName)); |
| | | Map<Integer, String> storeMap = storeService.list().stream() |
| | | .collect(Collectors.toMap(TStore::getId, TStore::getName)); |
| | | records.forEach(item->{ |
| | | item.setOperatorName(operatorMap.getOrDefault(item.getOperatorId(),"")); |
| | | StringBuilder sb = new StringBuilder(); |
| | | System.err.println("==========="+item); |
| | | Arrays.stream(item.getStoreIds().split(",")).map(Integer::parseInt).forEach(s->{ |
| | | sb.append( storeMap.getOrDefault(s, "")); |
| | | sb.append(","); |
| | | }); |
| | | //sb去除最后一个逗号 |
| | | sb.deleteCharAt(sb.length() - 1); |
| | | item.setStoreName(sb.toString()); |
| | | }); |
| | | } |
| | | return super.packForBT(salesDetailVOPage); |
| | | } |
| | | |
| | | *//** |
| | | * 新增惠民卡 |
| | | *//* |
| | | @RequestMapping(value = "/add") |
| | | /** |
| | | * 获取统计数据 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @RequestMapping("/getStaticsData") |
| | | @ResponseBody |
| | | public Object add(TPayHuimin tPayHuimin) { |
| | | payHuiminClient.insert(tPayHuimin); |
| | | return SUCCESS_TIP; |
| | | public ResultUtil<Map<String, BigDecimal>> getStaticsData(HuiminPayQuery query) { |
| | | Map<String, BigDecimal> map = new HashMap<>(); |
| | | map.put("totalAmount",BigDecimal.ZERO); |
| | | map.put("refundAmount",BigDecimal.ZERO); |
| | | List<Integer> appUserIds = Collections.emptyList(); |
| | | if (StringUtils.isNotBlank(query.getUserName()) || StringUtils.isNotBlank(query.getPhone())){ |
| | | AppUserByNameAndPhoneDTO appUserByNameAndPhoneDTO = new AppUserByNameAndPhoneDTO(); |
| | | appUserByNameAndPhoneDTO.setUserName(query.getUserName()); |
| | | appUserByNameAndPhoneDTO.setPhone(query.getPhone()); |
| | | List<TAppUser> tAppUsers = appUserClient.queryAPPUserByNameAndPhone(appUserByNameAndPhoneDTO); |
| | | appUserIds = tAppUsers.stream() |
| | | .map(TAppUser::getId) |
| | | .collect(Collectors.toList()); |
| | | if (CollUtil.isEmpty(appUserIds)){ |
| | | return ResultUtil.success(map); |
| | | } |
| | | } |
| | | query.setAppUserIds(appUserIds); |
| | | map = payHuiminClient.getStaticsData(query); |
| | | return ResultUtil.success(map); |
| | | } |
| | | |
| | | *//** |
| | | * 删除惠民卡 |
| | | *//* |
| | | @RequestMapping(value = "/delete") |
| | | /** |
| | | * 退款 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @PostMapping("/refund") |
| | | @ResponseBody |
| | | public Object delete(@RequestParam Integer tPayHuiminId) { |
| | | payHuiminClient.deleteById(tPayHuiminId); |
| | | return SUCCESS_TIP; |
| | | public ResultUtil<?> refund(Integer id) { |
| | | payHuiminClient.refund(id); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | *//** |
| | | * 修改惠民卡 |
| | | *//* |
| | | @RequestMapping(value = "/update") |
| | | @ResponseBody |
| | | public Object update(TPayHuimin tPayHuimin) { |
| | | payHuiminClient.updateById(tPayHuimin); |
| | | return SUCCESS_TIP; |
| | | /** |
| | | * 导出售卖明细 |
| | | * @param query |
| | | */ |
| | | @GetMapping("/export") |
| | | public void exportData(HuiminPayQuery query, HttpServletResponse response) { |
| | | List<SalesDetailVO> records = payHuiminClient.exportData(query); |
| | | records = records.stream().filter(Objects::nonNull).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(records)) { |
| | | List<Integer> operatorIdList = records.stream() |
| | | .map(SalesDetailVO::getOperatorId) |
| | | .collect(Collectors.toList()); |
| | | Map<Integer, String> operatorMap = operatorService.listByIds(operatorIdList).stream() |
| | | .collect(Collectors.toMap(TOperator::getId, TOperator::getName)); |
| | | Map<Integer, String> storeMap = storeService.list().stream() |
| | | .collect(Collectors.toMap(TStore::getId, TStore::getName)); |
| | | records.forEach(item->{ |
| | | item.setOperatorName(operatorMap.getOrDefault(item.getOperatorId(),"")); |
| | | StringBuilder sb = new StringBuilder(); |
| | | Arrays.stream(item.getStoreIds().split(",")).map(Integer::parseInt).forEach(s->{ |
| | | sb.append( storeMap.getOrDefault(s, "")); |
| | | sb.append(","); |
| | | }); |
| | | //sb去除最后一个逗号 |
| | | sb.deleteCharAt(sb.length() - 1); |
| | | item.setStoreName(sb.toString()); |
| | | }); |
| | | } |
| | | String[] titleArr = {"玩湃惠民卡名称", "玩湃惠民卡类型", "售卖金额", "所属运营商", "可用门店", "购买用户", "联系电话", "购买时间", "绑定人员", "已用次数", "有效期", "状态"}; |
| | | String[][] values = new String[records.size()][]; |
| | | for (int i = 0; i < records.size(); i++) { |
| | | SalesDetailVO salesDetailVO = records.get(i); |
| | | values[i] = new String[titleArr.length]; |
| | | values[i][0] = salesDetailVO.getHuiMinName(); |
| | | values[i][1] = salesDetailVO.getHuiMinType() == 1 ? "年度卡" : "年内卡"; |
| | | values[i][2] = salesDetailVO.getSalesMoney().toString(); |
| | | values[i][3] = salesDetailVO.getOperatorName(); |
| | | values[i][4] = salesDetailVO.getStoreName(); |
| | | values[i][5] = salesDetailVO.getUserName(); |
| | | values[i][6] = salesDetailVO.getPhone(); |
| | | values[i][7] = DateUtil.format(salesDetailVO.getPaymentTime(), "yyyy-MM-dd HH:mm:ss"); |
| | | values[i][8] = salesDetailVO.getStudentName(); |
| | | values[i][9] = salesDetailVO.getUseTimes().toString(); |
| | | values[i][10] = DateUtil.format(salesDetailVO.getEndTime(), "yyyy-MM-dd HH:mm:ss"); |
| | | values[i][11] = salesDetailVO.getStatus() == 2 ? "使用中" : "已退款"; |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | *//** |
| | | * 惠民卡详情 |
| | | *//* |
| | | @RequestMapping(value = "/detail/{tPayHuiminId}") |
| | | @ResponseBody |
| | | public Object detail(@PathVariable("tPayHuiminId") Integer tPayHuiminId) { |
| | | return payHuiminClient.selectById(tPayHuiminId); |
| | | }*/ |
| | | } |