|
@@ -0,0 +1,377 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.modules.api.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.common.cache.DictBizCache;
|
|
|
+import org.springblade.common.cache.DictCache;
|
|
|
+import org.springblade.common.cache.SysCache;
|
|
|
+import org.springblade.common.constant.CommonConstant;
|
|
|
+import org.springblade.common.enums.DictBizEnum;
|
|
|
+import org.springblade.common.enums.DictEnum;
|
|
|
+import org.springblade.core.boot.ctrl.BladeController;
|
|
|
+import org.springblade.core.mp.support.Condition;
|
|
|
+import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.redis.cache.BladeRedis;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.support.Kv;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.core.tool.utils.DateUtil;
|
|
|
+import org.springblade.modules.api.request.*;
|
|
|
+import org.springblade.modules.platform.entity.*;
|
|
|
+import org.springblade.modules.platform.service.*;
|
|
|
+import org.springblade.modules.platform.vo.UserBankCardsVO;
|
|
|
+import org.springblade.modules.platform.vo.UserRecomVO;
|
|
|
+import org.springblade.modules.platform.wrapper.UserBankCardsWrapper;
|
|
|
+import org.springblade.modules.platform.wrapper.UserRecomWrapper;
|
|
|
+import org.springblade.modules.system.entity.User;
|
|
|
+import org.springblade.modules.system.entity.UserApp;
|
|
|
+import org.springblade.modules.system.mapper.UserAppMapper;
|
|
|
+import org.springblade.modules.system.service.IUserService;
|
|
|
+import org.springblade.modules.system.vo.UserAppVO;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 控制器
|
|
|
+ *
|
|
|
+ * @author xuwei
|
|
|
+ * @since 2022-02-12
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping(CommonConstant.API_URL)
|
|
|
+@Api(value = "3", tags = "平台模块")
|
|
|
+public class Api03Controller extends BladeController {
|
|
|
+
|
|
|
+ private final IUserAddressService userAddressService;
|
|
|
+
|
|
|
+ private final IAdsService adsService;
|
|
|
+
|
|
|
+ private final IPaymentsService paymentsService;
|
|
|
+
|
|
|
+ private final IUserFeedbacksService userFeedbacksService;
|
|
|
+
|
|
|
+ private final IUserService userService;
|
|
|
+
|
|
|
+ private final IUserRecomService userRecomService;
|
|
|
+
|
|
|
+ private final UserAppMapper userAppMapper;
|
|
|
+
|
|
|
+ private final IUserBankCardsService userBankCardsService;
|
|
|
+
|
|
|
+ private final BladeRedis bladeRedis;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户信息
|
|
|
+ */
|
|
|
+ @GetMapping("/userApp-detailById")
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "获取用户信息", notes = "传入用户ID")
|
|
|
+ public R<UserAppVO> userDetailById(@ApiParam(value = "用户ID", required = true) @RequestParam Long id) {
|
|
|
+ UserAppVO redisVo = bladeRedis.get(String.valueOf(id));
|
|
|
+ if (redisVo != null){
|
|
|
+ return R.data(redisVo);
|
|
|
+ }
|
|
|
+ UserApp userApp = new UserApp();
|
|
|
+ UserApp query = userApp.selectOne(Wrappers.<UserApp>lambdaQuery().eq(UserApp::getUserId, id));
|
|
|
+ if (query == null){
|
|
|
+ return R.fail("用户不存在!");
|
|
|
+ }
|
|
|
+ UserAppVO vo = Objects.requireNonNull(BeanUtil.copy(query,UserAppVO.class));
|
|
|
+ User user = userService.getById(id);
|
|
|
+ if (user == null){
|
|
|
+ return R.fail("用户不存在!");
|
|
|
+ }
|
|
|
+ vo.setCode(user.getCode());
|
|
|
+ vo.setAvatar(user.getAvatar());
|
|
|
+ vo.setRealName(user.getRealName());
|
|
|
+ vo.setName(user.getName());
|
|
|
+ vo.setSexDisplayName(DictCache.getValue(DictEnum.SEX,user.getSex()));
|
|
|
+ vo.setStateDisplayName(DictBizCache.getValue(DictBizEnum.USER_STATE,query.getState()));
|
|
|
+ bladeRedis.setEx(String.valueOf(id),vo, 60L);
|
|
|
+ return R.data(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改昵称和头像
|
|
|
+ */
|
|
|
+ @PostMapping("/user-updateById")
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "修改昵称和头像", notes = "传入用户ID")
|
|
|
+ public R userUpdateById(@Valid @RequestBody UserAppUpdateRequest request) {
|
|
|
+ User user = new User();
|
|
|
+ user.setId(request.getUserId());
|
|
|
+ user.setName(request.getName());
|
|
|
+ user.setAvatar(request.getAvatar());
|
|
|
+ boolean flg = userService.updateById(user);
|
|
|
+ if (flg){
|
|
|
+ //清除缓存
|
|
|
+ bladeRedis.del(String.valueOf(request.getUserId()));
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改简介说明
|
|
|
+ */
|
|
|
+ @PostMapping("/userApp-updateByUserId")
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "修改简介说明", notes = "传入用户ID")
|
|
|
+ public R userAppUpdateByUserId(@ApiParam(value = "用户ID", required = true) @RequestParam Long userId,
|
|
|
+ @ApiParam(value = "简介说明", required = true) @RequestParam String userExplain) {
|
|
|
+ UserApp userApp = new UserApp();
|
|
|
+ userApp.setUserExplain(userExplain);
|
|
|
+ boolean flg = userApp.update(Wrappers.<UserApp>lambdaQuery().eq(UserApp::getUserId,userId));
|
|
|
+ if (flg){
|
|
|
+ //清除缓存
|
|
|
+ bladeRedis.del(String.valueOf(userId));
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户地址分页查询
|
|
|
+ */
|
|
|
+ @GetMapping("/userAddress-page")
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "用户地址分页查询", notes = "传入用户ID")
|
|
|
+ public R<IPage<UserAddress>> userAddressPage(@ApiParam(value = "用户ID", required = true) @RequestParam Long userId, Query query) {
|
|
|
+ UserAddress userAddress = new UserAddress();
|
|
|
+ userAddress.setUserId(userId);
|
|
|
+ IPage<UserAddress> list = userAddressService.page(Condition.getPage(query), Condition.getQueryWrapper(userAddress));
|
|
|
+ return R.data(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户地址详情
|
|
|
+ */
|
|
|
+ @GetMapping("/userAddress-detailById")
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
+ @ApiOperation(value = "用户地址详情", notes = "传入地址ID")
|
|
|
+ public R<UserAddress> userAddressDetailById(@ApiParam(value = "地址ID", required = true) @RequestParam String id) {
|
|
|
+ return R.data(userAddressService.getById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户默认地址
|
|
|
+ */
|
|
|
+ @GetMapping("/userAddress-detailByUserId")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "用户默认地址", notes = "传入用户ID")
|
|
|
+ public R<UserAddress> userAddressDetailByUserId(@ApiParam(value = "用户ID", required = true) @RequestParam Long userId) {
|
|
|
+ UserAddress userAddress = new UserAddress();
|
|
|
+ userAddress.setUserId(userId);
|
|
|
+ userAddress.setDefaultState(2);//默认标识
|
|
|
+ return R.data(userAddressService.getOne(Condition.getQueryWrapper(userAddress)));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加用户地址
|
|
|
+ */
|
|
|
+ @PostMapping("/userAddress-save")
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
+ @ApiOperation(value = "添加用户地址", notes = "添加用户地址")
|
|
|
+ public R userAddressSave(@Valid @RequestBody AddressSaveRequest request) {
|
|
|
+ UserAddress userAddress = Objects.requireNonNull(BeanUtil.copy(request, UserAddress.class));
|
|
|
+ userAddress.setCreateTime(DateUtil.now());
|
|
|
+ //设置默认地址
|
|
|
+ if (userAddress.getDefaultState() == 2){
|
|
|
+ //用户所有的改为不默认
|
|
|
+ UserAddress param = new UserAddress();
|
|
|
+ param.setUserId(request.getUserId());
|
|
|
+ UserAddress entity= new UserAddress();
|
|
|
+ entity.setDefaultState(1);
|
|
|
+ userAddressService.update(entity, Condition.getQueryWrapper(param));
|
|
|
+ }
|
|
|
+ return R.status(userAddressService.save(userAddress));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改用户地址
|
|
|
+ */
|
|
|
+ @PostMapping("/userAddress-update")
|
|
|
+ @ApiOperationSupport(order = 5)
|
|
|
+ @ApiOperation(value = "修改用户收货地址", notes = "修改用户地址")
|
|
|
+ public R userAddressUpdate(@Valid @RequestBody AddressUpdateRequest request) {
|
|
|
+ UserAddress userAddress = Objects.requireNonNull(BeanUtil.copy(request, UserAddress.class));
|
|
|
+ userAddress.setUpdateTime(DateUtil.now());
|
|
|
+ if (userAddress.getDefaultState() == 2){
|
|
|
+ UserAddress entity= new UserAddress();
|
|
|
+ entity.setDefaultState(1);
|
|
|
+ UserAddress param = new UserAddress();
|
|
|
+ param.setUserId(request.getUserId());
|
|
|
+ userAddressService.update(entity, Condition.getQueryWrapper(param));
|
|
|
+ }
|
|
|
+ return R.status(userAddressService.updateById(userAddress));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取广告列表数据
|
|
|
+ */
|
|
|
+ @GetMapping("/ads-list")
|
|
|
+ @ApiOperationSupport(order = 6)
|
|
|
+ @ApiOperation(value = "获取广告列表数据", notes = "传入类型和条数")
|
|
|
+ public R<List<Ads>> adsList(@ApiParam(value = "类型", required = true) @RequestParam Integer type,
|
|
|
+ @ApiParam(value = "条数", required = true) @RequestParam Integer limit) {
|
|
|
+ return R.data(adsService.selectAdsList(type, limit));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取支付方式数据
|
|
|
+ */
|
|
|
+ @GetMapping("/payments-list")
|
|
|
+ @ApiOperationSupport(order = 7)
|
|
|
+ @ApiOperation(value = "获取支付方式数据", notes = "无参")
|
|
|
+ public R<List<Payments>> paymentsList() {
|
|
|
+ Payments payments = new Payments();
|
|
|
+ payments.setIsEnabled(2);
|
|
|
+ payments.setPayFor(4);//APP端
|
|
|
+ return R.data(paymentsService.list(Condition.getQueryWrapper(payments).lambda().orderByAsc(Payments::getSort)));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 反馈意见分页查询
|
|
|
+ */
|
|
|
+ @GetMapping("/userFeedbacks-page")
|
|
|
+ @ApiOperationSupport(order = 8)
|
|
|
+ @ApiOperation(value = "反馈意见分页查询", notes = "传入用户ID")
|
|
|
+ public R<IPage<UserFeedbacks>> userFeedbacksPage(@ApiParam(value = "用户ID", required = true) @RequestParam Long userId, Query query) {
|
|
|
+ UserFeedbacks userFeedbacks = new UserFeedbacks();
|
|
|
+ userFeedbacks.setUserId(userId);
|
|
|
+ IPage<UserFeedbacks> list = userFeedbacksService.page(Condition.getPage(query),
|
|
|
+ Condition.getQueryWrapper(userFeedbacks).lambda().orderByAsc(UserFeedbacks::getCreateTime));
|
|
|
+ return R.data(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 反馈意见详情
|
|
|
+ */
|
|
|
+ @GetMapping("/userFeedbacks-detailById")
|
|
|
+ @ApiOperationSupport(order = 9)
|
|
|
+ @ApiOperation(value = "反馈意见详情", notes = "传入意见ID")
|
|
|
+ public R<UserFeedbacks> userFeedbacksDetailById(@ApiParam(value = "意见ID", required = true) @RequestParam String id) {
|
|
|
+ return R.data(userFeedbacksService.getById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加反馈意见
|
|
|
+ */
|
|
|
+ @PostMapping("/userFeedbacks-save")
|
|
|
+ @ApiOperationSupport(order = 10)
|
|
|
+ @ApiOperation(value = "添加反馈意见", notes = "添加反馈意见")
|
|
|
+ public R userFeedbacksSave(@Valid @RequestBody UserFeedbacksSaveRequest request) {
|
|
|
+ UserFeedbacks userFeedbacks = Objects.requireNonNull(BeanUtil.copy(request, UserFeedbacks.class));
|
|
|
+ userFeedbacks.setCreateTime(DateUtil.now());
|
|
|
+ return R.status(userFeedbacksService.save(userFeedbacks));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户推荐记录分页查询
|
|
|
+ */
|
|
|
+ @GetMapping("/userRecom-page")
|
|
|
+ @ApiOperationSupport(order = 11)
|
|
|
+ @ApiOperation(value = "用户推荐记录分页查询", notes = "传入用户ID")
|
|
|
+ public R<IPage<UserRecomVO>> userRecomPage(@ApiParam(value = "用户ID", required = true) @RequestParam Long userId, Query query) {
|
|
|
+ UserRecom userRecom = new UserRecom();
|
|
|
+ userRecom.setUserId(userId);
|
|
|
+ IPage<UserRecom> list = userRecomService.page(Condition.getPage(query),
|
|
|
+ Condition.getQueryWrapper(userRecom).lambda().orderByAsc(UserRecom::getCreateTime));
|
|
|
+ return R.data(UserRecomWrapper.build().pageVO(list));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户团队人数和直荐人员数据
|
|
|
+ */
|
|
|
+ @GetMapping("/user-teamAndRecomById")
|
|
|
+ @ApiOperationSupport(order = 12)
|
|
|
+ @ApiOperation(value = "获取用户团队人数和直荐人员数据", notes = "传入用户ID")
|
|
|
+ public R<Kv> userTeamAndRecomById(@ApiParam(value = "用户ID", required = true) @RequestParam Long userId) {
|
|
|
+ Kv kv = Kv.create();
|
|
|
+ UserApp userApp = new UserApp();
|
|
|
+ Integer teamNum = userAppMapper.selectCount(Condition.getQueryWrapper(userApp).lambda().like(UserApp::getParentPath, userId));
|
|
|
+ userApp.setParentId(userId);
|
|
|
+ Integer recomNum = userAppMapper.selectCount(Condition.getQueryWrapper(userApp).lambda().eq(UserApp::getParentId, userId));
|
|
|
+ kv.set("teamNum",teamNum);
|
|
|
+ kv.set("recomNum", recomNum);
|
|
|
+ return R.data(kv);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户银行卡分页查询
|
|
|
+ */
|
|
|
+ @GetMapping("/userBankCards-page")
|
|
|
+ @ApiOperationSupport(order = 13)
|
|
|
+ @ApiOperation(value = "用户银行卡分页查询", notes = "传入用户ID")
|
|
|
+ public R<IPage<UserBankCardsVO>> userBankCardsPage(@ApiParam(value = "用户ID", required = true) @RequestParam Long userId, Query query) {
|
|
|
+ UserBankCards userBankCards = new UserBankCards();
|
|
|
+ userBankCards.setUserId(userId);
|
|
|
+ IPage<UserBankCards> list = userBankCardsService.page(Condition.getPage(query),
|
|
|
+ Condition.getQueryWrapper(userBankCards).lambda().orderByAsc(UserBankCards::getSort));
|
|
|
+ return R.data(UserBankCardsWrapper.build().pageVO(list));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绑定银行卡
|
|
|
+ */
|
|
|
+ @PostMapping("/userBankCards-save")
|
|
|
+ @ApiOperationSupport(order = 14)
|
|
|
+ @ApiOperation(value = "绑定银行卡", notes = "绑定银行卡")
|
|
|
+ public R userBankCardsSave(@Valid @RequestBody UserBankCardsSaveRequest request) {
|
|
|
+ UserBankCards userBankCards = Objects.requireNonNull(BeanUtil.copy(request, UserBankCards.class));
|
|
|
+ userBankCards.setCreateTime(DateUtil.now());
|
|
|
+ userBankCards.setUpdateTime(DateUtil.now());
|
|
|
+ userBankCards.setSort(100);
|
|
|
+ return R.status(userBankCardsService.save(userBankCards));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绑定银行卡
|
|
|
+ */
|
|
|
+ @PostMapping("/userBankCards-update")
|
|
|
+ @ApiOperationSupport(order = 15)
|
|
|
+ @ApiOperation(value = "修改银行卡", notes = "传入主键ID")
|
|
|
+ public R userBankCardsUpdate(@Valid @RequestBody UserBankCardsUpdateRequest request) {
|
|
|
+ UserBankCards userBankCards = Objects.requireNonNull(BeanUtil.copy(request, UserBankCards.class));
|
|
|
+ userBankCards.setUpdateTime(DateUtil.now());
|
|
|
+ return R.status(userBankCardsService.updateById(userBankCards));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 银行卡详情
|
|
|
+ */
|
|
|
+ @GetMapping("/userBankCards-detailById")
|
|
|
+ @ApiOperationSupport(order = 16)
|
|
|
+ @ApiOperation(value = "银行卡详情", notes = "传入主键ID")
|
|
|
+ public R<UserBankCardsVO> userBankCardsDetailById(@ApiParam(value = "用户银行卡主键ID", required = true) @RequestParam String id) {
|
|
|
+ UserBankCards userBankCards = userBankCardsService.getById(id);
|
|
|
+ return R.data(UserBankCardsWrapper.build().entityVO(userBankCards));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|