From dd91a28bdbf8a97531618415c2174aae0ce70ceb Mon Sep 17 00:00:00 2001 From: zhibing.pu <393733352@qq.com> Date: 星期六, 17 八月 2024 16:03:49 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile --- ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java | 171 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 144 insertions(+), 27 deletions(-) diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java index 217799e..bff645a 100644 --- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java +++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java @@ -1,6 +1,7 @@ package com.ruoyi.account.controller; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; @@ -14,6 +15,7 @@ import com.ruoyi.account.wx.body.resq.Code2SessionResqBody; import com.ruoyi.account.wx.model.WeixinProperties; import com.ruoyi.account.wx.tools.WxAppletTools; +import com.ruoyi.account.util.GiveVipUtil; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.bean.BeanUtils; import com.ruoyi.common.core.web.domain.AjaxResult; @@ -27,6 +29,7 @@ import com.ruoyi.order.api.model.TChargingOrder; import com.ruoyi.order.api.model.TExchangeOrder; import com.ruoyi.other.api.domain.TCompany; +import com.ruoyi.other.api.domain.TCoupon; import com.ruoyi.other.api.domain.TUserTag; import com.ruoyi.other.api.feignClient.OtherClient; import com.ruoyi.system.api.domain.SysRole; @@ -34,13 +37,16 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.apache.poi.ss.formula.functions.T; import lombok.extern.slf4j.Slf4j; +import org.aspectj.weaver.loadtime.Aj; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; import java.time.Duration; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -78,12 +84,70 @@ @Resource private ExchangeOrderClient exchangeOrderClient; + @Autowired + private TokenService tokenService; + @Autowired + private RedisService redisService; + @Autowired + private WeixinProperties wxConfig; + @Autowired + private RestTemplate wxRestTemplate; + + @Resource + private TAppUserSignService signService; + @Resource + private TAppCouponService appCouponService; + @Resource + private TAppUserCarService carService; + + + @ApiOperation(value = "查询当前用户是否为会员 0否1是", tags = {"小程序--查询当前用户是否为会员"}) + @PostMapping(value = "/getUserInfo") + public AjaxResult<Integer> getUserInfo() { + TAppUser byId = appUserService.getById(tokenService.getLoginUserApplet().getUserId()); + if (byId.getVipEndTime() == null){ + return AjaxResult.ok(0); + }else if (byId.getVipEndTime().isAfter(LocalDateTime.now())){ + return AjaxResult.ok(1); + }else{ + return AjaxResult.ok(0); + } + } + @ApiOperation(value = "通过code获得openid, 1 --->对应的appid:wx4c405fa42539fc21 2---->对应的appid:wx02d9f6c92e6d3c86") + @GetMapping("openId-by-jscode2session/{code}") + public AjaxResult<Map<String, Object>> jscode2session(@PathVariable String code) { + log.info("<<<<<<<<换取openid开始<<<<<<<<:{}", code); + WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig); + Code2SessionRespBody body = appletTools.getOpenIdByJscode2session(new Code2SessionResqBody().build(code)); + String openid = body.getOpenid(); + String sessionKey = body.getSessionKey(); + TAppUser appUser = appUserService.getOne(Wrappers.lambdaQuery(TAppUser.class).eq(TAppUser::getWxOpenid, openid).last("limit 1")); + if (Objects.isNull(appUser)) { + appUser = new TAppUser(); + appUser.setWxOpenid(openid); + appUserService.save(appUser); + } + // 提前对sessionKey进行删除 + log.info("换取sessionKey:{}", sessionKey); + // 将sessionKey进行存储,后续获取信息需要 + redisService.setCacheObject(openid, sessionKey); + LoginUserApplet loginUserApplet = new LoginUserApplet(); + if(ObjectUtils.isNotNull(appUser)){ + loginUserApplet.setUserId(appUser.getId()); + } + HashMap<String, Object> tokenInfos = new HashMap<>(); + tokenInfos.put("token",tokenService.createTokenApplet(loginUserApplet)); + tokenInfos.put("info",loginUserApplet); + return AjaxResult.ok(tokenInfos); + } @ApiOperation(value = "管理后台-根据手机号查询用户ids", tags = {"管理后台-活动费用统计"}) @PostMapping(value = "/user/getUserIdsByPhone") public R<List<Long>> getUserIdsByPhone(@RequestParam("phone") String phone) { return R.ok(appUserService.list(new QueryWrapper<TAppUser>().like("phone",phone)).stream().map(TAppUser::getId).collect(Collectors.toList())); } + @Resource + private GiveVipUtil giveVipUtil; @ApiOperation(value = "单位管理列表", tags = {"用户管理-单位管理"}) @PostMapping(value = "/unit/page") public R<Page<TCompany>> unitPage(@RequestBody UnitListQueryDto unitListQueryDto) { @@ -96,6 +160,20 @@ } return R.ok(data); } + + + @ApiOperation(value = "单位下拉框", tags = {"用户管理-单位管理"}) + @PostMapping(value = "/unit/select") + public R<List<TCompany>> unitSelect() { + UnitListQueryDto unitListQueryDto = new UnitListQueryDto(); + unitListQueryDto.setPageCurr(1); + unitListQueryDto.setPageSize(9999); + //拿到单位列表 + R<Page<TCompany>> pageR = otherClient.queryUnitPage(unitListQueryDto); + + return R.ok(pageR.getData().getRecords()); + } + @ApiOperation(value = "单位管理添加或编辑", tags = {"用户管理-单位管理"}) @PostMapping(value = "/unit/addOrUpdate") @@ -267,7 +345,7 @@ return R.ok(userDetailDto); } - @ApiOperation(value = "用户详情积分明细", tags = {"用户管理-用户列表"}) + @ApiOperation(value = "用户详情积分明细", tags = {"后台-用户管理-用户列表","小程序-个人中心"}) @PostMapping(value = "/user/points/page") public R<Page<TAppUserIntegralChange>> pointsDetail(@RequestBody PointsQueryDto pointsQueryDto) { List<Integer> types = new ArrayList<>(); @@ -303,7 +381,7 @@ } - @ApiOperation(value = "用户详情积分明细", tags = {"用户管理-用户列表"}) + @ApiOperation(value = "冻结解冻用户", tags = {"后台-用户管理-用户列表"}) @PostMapping(value = "/user/status/change") public R pointsDetail(@RequestBody UserChangeDto userChangeDto) { TAppUser appUser = appUserService.getById(userChangeDto.getUserId()); @@ -312,37 +390,76 @@ return R.ok(); } + @ApiOperation(value = "个人中心信息", tags = {"小程序-个人中心"}) + @PostMapping(value = "/user/info") + public R<AppUserInfoDto> info() { + Long userId = 1L; + TAppUser byId = appUserService.getById(userId); + AppUserInfoDto appUserInfoDto = new AppUserInfoDto(); + + //判断会员 + if (byId.getVipEndTime()==null||byId.getVipEndTime().isBefore(LocalDateTime.now())){ + appUserInfoDto.setIsVip(0); + }else { + appUserInfoDto.setIsVip(1); + appUserInfoDto.setVipExpireTime(byId.getVipEndTime()); + } + //判断当天是否签到 + Long count = signService.lambdaQuery().eq(TAppUserSign::getSignDay, LocalDate.now()).count(); + appUserInfoDto.setIsSign(count>0?1:0); + //获取当前拥有的优惠卷数量 + Long coupons = appCouponService.lambdaQuery().eq(TAppCoupon::getAppUserId, userId).eq(TAppCoupon::getStatus, 1).count(); + appUserInfoDto.setCouponNum(Math.toIntExact(coupons)); + //当前绑定的车辆 + List<TAppUserCar> list = carService.lambdaQuery().eq(TAppUserCar::getAppUserId, userId).list(); + appUserInfoDto.setUserCars(list); + return R.ok(appUserInfoDto); + + + } + + @ApiOperation(value = "优惠卷列表不分页(1可使用2不可用)", tags = {"小程序-个人中心"}) + @PostMapping(value = "/user/coupon") + public R<List<InfoCouponDto>> userCoupon(@RequestParam("type") Integer type) { + LocalDateTime now = LocalDateTime.now(); + + List<InfoCouponDto> couponDtos = new ArrayList<>(); + List<TAppCoupon> list = appCouponService.lambdaQuery().le(TAppCoupon::getStartTime, now).ge(TAppCoupon::getEndTime, now).eq(TAppCoupon::getStatus, type).list(); + for (TAppCoupon tAppCoupon : list) { + TCoupon coupon = JSON.toJavaObject(JSON.parseObject(tAppCoupon.getCouponJson()), TCoupon.class); + InfoCouponDto infoCouponDto = new InfoCouponDto(); + BeanUtils.copyProperties(coupon,infoCouponDto); + couponDtos.add(infoCouponDto); + + } + + + return R.ok(couponDtos); + + + } + + @ApiOperation(value = "赠送会员", tags = {"用户管理-用户列表"}) @PostMapping(value = "/user/give/vip") public R giveVip(@RequestBody GiveVipDto giveVipDto) { TAppUser nowUser = appUserService.getById(giveVipDto.getUserId()); - - //如果vipEndTime为空或已过期,直接增加 - if (nowUser.getVipEndTime()==null||nowUser.getVipEndTime().isBefore(LocalDateTime.now())) { - if (giveVipDto.getType() == 1) { - nowUser.setVipEndTime(LocalDateTime.now().plusDays(31)); - //直接增加vipDetail - } else if (giveVipDto.getType() == 2) { - nowUser.setVipEndTime(LocalDateTime.now().plusDays(93)); - } else if (giveVipDto.getType() == 3) { - nowUser.setVipEndTime(LocalDateTime.now().plusDays(365)); - } - //直接赠送优惠卷 - }else { - if (giveVipDto.getType() == 1) { - nowUser.setVipEndTime(nowUser.getVipEndTime().plusDays(31)); - //如果有这个类型的vip,累加,没有的话,从entTime新增 - } else if (giveVipDto.getType() == 2) { - nowUser.setVipEndTime(nowUser.getVipEndTime().plusDays(93)); - } else if (giveVipDto.getType() == 3) { - nowUser.setVipEndTime(nowUser.getVipEndTime().plusDays(365)); - } + int plusDay = 0; + if (giveVipDto.getType() == 1) { + plusDay = 1; + } else if (giveVipDto.getType() == 2) { + plusDay = 3; + } else if (giveVipDto.getType() == 3) { + plusDay = 12; } + //增加vipDetail + giveVipUtil.sendVip(nowUser, giveVipDto.getVipId(),plusDay); - + appUserService.updateById(nowUser); + //执行一次赠送优惠卷的定时任务 return R.ok(); } @@ -357,7 +474,7 @@ return R.ok(appUserService.list(Wrappers.<TAppUser>lambdaQuery().in(TAppUser::getId,appUserIds))); } - + /** * 根据用户id获取用户 * @param id @@ -368,8 +485,8 @@ TAppUser appUser = appUserService.getById(id); return R.ok(appUser); } - - + + /** * 修改用户信息 * @param appUser -- Gitblit v1.7.1