From 7d348d54c93e1333951c6d20f8ead81d389cd262 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期一, 19 八月 2024 17:52:11 +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 |  112 ++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 73 insertions(+), 39 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 8e3444d..92e2852 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
@@ -16,7 +16,9 @@
 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.constant.Constants;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.bean.BeanUtils;
 import com.ruoyi.common.core.web.domain.AjaxResult;
 import com.ruoyi.common.core.web.domain.BasePojo;
@@ -41,6 +43,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.weaver.loadtime.Aj;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.client.RestTemplate;
 
@@ -88,10 +91,6 @@
     private TokenService tokenService;
     @Autowired
     private RedisService redisService;
-    @Autowired
-    private WeixinProperties wxConfig;
-    @Autowired
-    private RestTemplate wxRestTemplate;
 
     @Resource
     private  TAppUserSignService signService;
@@ -112,33 +111,6 @@
         }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 = {"管理后台-活动费用统计"})
@@ -163,7 +135,7 @@
 
 
     @ApiOperation(value = "单位下拉框", tags = {"用户管理-单位管理"})
-    @PostMapping(value = "/unit/select")
+    @GetMapping(value = "/unit/select")
     public R<List<TCompany>> unitSelect() {
         UnitListQueryDto unitListQueryDto = new UnitListQueryDto();
         unitListQueryDto.setPageCurr(1);
@@ -182,6 +154,10 @@
        otherClient.unitAddorUpadate(tCompany);
         return R.ok();
     }
+
+
+
+
     @ApiOperation(value = "单位管理删除", tags = {"用户管理-单位管理"})
     @DeleteMapping(value = "/unit/delete")
     public R add(@RequestParam String ids) {
@@ -222,16 +198,19 @@
         for (TAppUser appUser : page.getRecords()) {
             //拿到最新的tagId
             TAppUserTag one = appUserTagService.lambdaQuery().eq(TAppUserTag::getAppUserId, appUser.getId()).orderByDesc(TAppUserTag::getCreateTime).last("limit 1").one();
-            //设置最新的tagName
-            R<TUserTag> byIdTag = otherClient.getByIdTag(one.getUserTagId());
-            if (byIdTag.getData()!=null) {
-                appUser.setTagName(byIdTag.getData().getName());
+            if (one!=null) {
+                //设置最新的tagName
+                R<TUserTag> byIdTag = otherClient.getByIdTag(one.getUserTagId());
+                if (byIdTag.getData() != null) {
+                    appUser.setTagName(byIdTag.getData().getName());
+                }
             }
             //匹配vipMap的值
             appUser.setVipName(vipMap.getData().get(appUser.getVipId()));
             //累计充电次数
             R<Long> useOrderCount = chargingOrderClient.useOrderCount(appUser.getId());
             appUser.setOrderCount(useOrderCount.getData());
+            appUser.setUid(appUser.getId().toString());
 
         }
         return R.ok(page);
@@ -323,7 +302,7 @@
     }
 
     @ApiOperation(value = "用户详情", tags = {"用户管理-用户列表"})
-    @PostMapping(value = "/user/detail/{id}")
+    @GetMapping(value = "/user/detail/{id}")
     public R<UserDetailDto> userDetail(@PathVariable Long id) {
         TAppUser user = appUserService.getById(id);
         UserDetailDto userDetailDto =  new UserDetailDto();
@@ -393,6 +372,28 @@
         return R.ok();
     }
 
+    @ApiOperation(value = "修改单位", tags = {"后台-用户管理-用户列表"})
+    @PostMapping(value = "/user/unit/change")
+    public R unitChange(@RequestBody UnitChangeDto unitChangeDto) {
+        for (String s : unitChangeDto.getIds().split(",")) {
+            TAppUser byId = appUserService.getById(s);
+            byId.setCompanyId(unitChangeDto.getUnitId());
+            appUserService.updateById(byId);
+        }
+    return R.ok();
+    }
+
+    @ApiOperation(value = "删除用户", tags = {"后台-用户管理-用户列表"})
+    @DeleteMapping(value = "/user/delete")
+    public R userDelete(String ids) {
+        String[] split = ids.split(",");
+        for (String s : split) {
+            appUserService.removeById(s);
+        }
+        return R.ok();
+
+    }
+
     @ApiOperation(value = "个人中心信息", tags = {"小程序-个人中心"})
     @PostMapping(value = "/user/info")
     public R<AppUserInfoDto> info() {
@@ -447,7 +448,11 @@
     @ApiOperation(value = "赠送会员", tags = {"用户管理-用户列表"})
     @PostMapping(value = "/user/give/vip")
     public R giveVip(@RequestBody GiveVipDto  giveVipDto) {
-        TAppUser nowUser = appUserService.getById(giveVipDto.getUserId());
+        String[] split = giveVipDto.getUserIds().split(",");
+        for (String s : split) {
+
+
+        TAppUser nowUser = appUserService.getById(s);
 
         int plusDay = 0;
         if (giveVipDto.getType() == 1) {
@@ -463,8 +468,26 @@
 
         appUserService.updateById(nowUser);
         //执行一次赠送优惠卷的定时任务
-
+        }
         return R.ok();
+    }
+
+    @ApiOperation(value = "更换手机号", tags = {"小程序-用户管理-更换手机号"})
+    @PostMapping(value = "/user/updatePhone")
+    public AjaxResult<String> updatePhone(@Validated @RequestBody UpdatePhoneDTO dto) {
+        String code = redisService.getCacheObject(dto.getPhone() + Constants.APPLET);
+        if(StringUtils.isEmpty(code)){
+            return AjaxResult.error("验证码已过期,请重新获取验证码!");
+        }
+        if(!code.equals(dto.getCode())){
+            return AjaxResult.error("验证码错误!");
+        }
+        // 获取当前用户信息
+        Long userId = tokenService.getLoginUserApplet().getUserId();
+        TAppUser appUser = appUserService.getById(userId);
+        appUser.setPhone(dto.getPhone());
+        appUserService.updateById(appUser);
+        return AjaxResult.success();
     }
 
     /**
@@ -502,6 +525,17 @@
         return R.ok();
     }
 
+    /**
+     * 通过手机号查询用户
+     * @param phone
+     * @return
+     */
+    @GetMapping("/user/selectByPhone")
+    public R<TAppUser> selectByPhone(@RequestParam("phone") String phone){
+        return R.ok(appUserService.getOne(Wrappers.lambdaQuery(TAppUser.class)
+                .eq(TAppUser::getPhone,phone)
+                .last("LIMIT 1")));
+    }
 
 //    @ApiOperation(value = "签到", tags = {"小程序-个人中心-签到"})
 //    @PostMapping(value = "/user/sign")

--
Gitblit v1.7.1