Răsfoiți Sursa

修改手机号

qzy 6 luni în urmă
părinte
comite
bd5f0f5dbc

+ 7 - 4
sp-core/sp-api/src/main/java/com/pj/api/client/admin/AdminInterface.java

@@ -4,10 +4,7 @@ import com.pj.api.FeignInterceptor;
 import com.pj.api.consts.FeignConsts;
 import com.pj.api.dto.*;
 import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -99,4 +96,10 @@ public interface AdminInterface {
 
     @PostMapping("AppUser/rpc/changeBindShopStatus")
     public void changeBindShopStatus(@RequestBody BindShopDTO bindShopDTO);
+
+    @RequestMapping("AppUser/rpc/findUserByPhone")
+    AppUserDto findUserByPhone(@RequestParam("phone") String phone);
+
+    @PostMapping("AppUser/rpc/updateAccount")
+    int updateAccount(UpdateAccountDTO updateAccountDTO);
 }

+ 10 - 0
sp-core/sp-api/src/main/java/com/pj/api/client/admin/AdminInterfaceFallback.java

@@ -95,6 +95,16 @@ public class AdminInterfaceFallback implements FallbackFactory<AdminInterface> {
 
             }
 
+            @Override
+            public AppUserDto findUserByPhone(String phone) {
+                return null;
+            }
+
+            @Override
+            public int updateAccount(UpdateAccountDTO updateAccountDTO) {
+                return 0;
+            }
+
         };
     }
 

+ 25 - 0
sp-core/sp-api/src/main/java/com/pj/api/dto/UpdateAccountDTO.java

@@ -0,0 +1,25 @@
+package com.pj.api.dto;
+
+import java.io.Serializable;
+
+public class UpdateAccountDTO implements Serializable {
+
+    private Long id;
+    private String phone;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+}

+ 1 - 1
sp-core/sp-nacos/src/main/resources/bootstrap.properties

@@ -1,6 +1,6 @@
 # --------------------- nacos注册中心 --------------------- 
 ### nacos注册中心 - 地址
-spring.cloud.nacos.discovery.server-addr=106.15.1.216:4048
+spring.cloud.nacos.discovery.server-addr=127.0.0.1:4048
 ### nacos注册中心 - 用户
 spring.cloud.nacos.discovery.username=nacos
 ### nacos注册中心 - 密码

+ 8 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_people/TbPeopleController.java

@@ -12,6 +12,7 @@ import com.pj.api.dto.PeopleDto;
 import com.pj.tb_people.dto.LeaveGroupDto;
 import com.pj.tb_people.dto.StartStopDto;
 import com.pj.tb_people.vo.BindShopVO;
+import com.pj.tb_people.vo.EditPhoneVO;
 import com.pj.utils.so.SoMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
@@ -81,6 +82,13 @@ public class TbPeopleController {
         return AjaxJson.getSuccess();
     }
 
+    @RequestMapping("editPhone")
+    @SaCheckPermission(TbPeople.PERMISSION_CODE_EDIT)
+    public AjaxJson editPhone(EditPhoneVO editPhoneVO) {
+        tbPeopleService.editPhone(editPhoneVO);
+        return AjaxJson.getSuccess();
+    }
+
     @RequestMapping("bindShop")
     @SaCheckPermission(TbPeople.PERMISSION_CODE_BIND_SHOP)
     public AjaxJson bindShop(BindShopVO shopVO) {

+ 45 - 5
sp-service/level-one-server/src/main/java/com/pj/tb_people/TbPeopleService.java

@@ -2,6 +2,7 @@ package com.pj.tb_people;
 
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.cglib.CglibUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -24,6 +25,7 @@ import com.pj.tb_people.dto.LeaveGroupDto;
 import com.pj.tb_people.dto.StartStopDto;
 import com.pj.tb_people.vo.ApplyPeopleVo;
 import com.pj.tb_people.vo.BindShopVO;
+import com.pj.tb_people.vo.EditPhoneVO;
 import com.pj.tb_shop.TbShop;
 import com.pj.tb_shop.TbShopMapper;
 import com.pj.tb_shop.TbShopService;
@@ -33,6 +35,7 @@ import com.pj.utils.sg.AjaxError;
 import com.pj.utils.sg.AjaxJson;
 import com.pj.utils.so.SoMap;
 import com.tencentcloudapi.live.v20180801.models.PublishTime;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
@@ -58,6 +61,7 @@ import java.util.*;
  */
 @Service
 @Transactional(rollbackFor = Exception.class)
+@Slf4j
 public class TbPeopleService extends ServiceImpl<TbPeopleMapper, TbPeople> implements IService<TbPeople> {
 
     /**
@@ -573,11 +577,11 @@ public class TbPeopleService extends ServiceImpl<TbPeopleMapper, TbPeople> imple
         tbPeople.setTradeAreaName(tbTradeArea.getName());
         /**备案编号,如果为新增备案,传空值;如果为变更备案,必须传值;*/
 
-        if (isNew){
+        if (isNew) {
             tbPeople.setCreateTime(new Date()); // 创建时间
             tbPeople.setCreateName("航通"); // 创建人
             this.save(tbPeople);
-        }else {
+        } else {
             tbPeople.setUpdateTime(new Date()); // 修改时间
             tbPeople.setUpdateName("航通"); // 修改人
             this.updateById(tbPeople);
@@ -597,7 +601,7 @@ public class TbPeopleService extends ServiceImpl<TbPeopleMapper, TbPeople> imple
             return true;
         } else {
             AppUserDto appUserDto = adminInterface.getByFkId(tbPeople.getId());
-            if(appUserDto == null) {
+            if (appUserDto == null) {
                 //给边民生成账号
                 AppUserCreateDTO createDTO = new AppUserCreateDTO();
                 createDTO.setAuth("1");
@@ -745,7 +749,7 @@ public class TbPeopleService extends ServiceImpl<TbPeopleMapper, TbPeople> imple
                     }
                 });
         this.updateBatchById(list);
-        BindShopDTO bindShopDTO=new BindShopDTO();
+        BindShopDTO bindShopDTO = new BindShopDTO();
         bindShopDTO.setBindShop(2);
         bindShopDTO.setIds(t.getIds());
         FeignFactory.adminInterface.changeBindShopStatus(bindShopDTO);
@@ -757,9 +761,45 @@ public class TbPeopleService extends ServiceImpl<TbPeopleMapper, TbPeople> imple
         wrapper.set(TbPeople::getShopName, null);
         wrapper.eq(TbPeople::getId, id);
         this.update(wrapper);
-        BindShopDTO bindShopDTO=new BindShopDTO();
+        BindShopDTO bindShopDTO = new BindShopDTO();
         bindShopDTO.setBindShop(1);
         bindShopDTO.setIds(id);
         FeignFactory.adminInterface.changeBindShopStatus(bindShopDTO);
     }
+
+    public void editPhone(EditPhoneVO editPhoneVO) {
+        String phone=editPhoneVO.getPhone();
+        TbPeople tbPeople = getById(editPhoneVO.getId());
+        if (tbPeople == null) {
+            throw new ServiceException("该边民不存在");
+        }
+        AppUserDto oldUser  = FeignFactory.adminInterface.findUserByPhone(tbPeople.getPhone());
+        //账号不存在或者存在但不是自己的,则新增
+        if (oldUser == null||!StrUtil.equals(oldUser.getName(),tbPeople.getName())) {
+            AppUserCreateDTO appUserCreateDTO = new AppUserCreateDTO();
+            appUserCreateDTO.setAuth("1");
+            appUserCreateDTO.setPhone(phone);
+            appUserCreateDTO.setName(tbPeople.getName());
+            appUserCreateDTO.setFkId(tbPeople.getId());
+            appUserCreateDTO.setUserType(UserType.USER_TYPE_PEOPLE.getCode() + "");
+            log.info("create user :{}", JSONUtil.toJsonStr(appUserCreateDTO));
+            FeignFactory.adminInterface.createAccount(appUserCreateDTO);
+        }else{
+            //存在,检查下是否冲突
+            AppUserDto checkUser  = FeignFactory.adminInterface.findUserByPhone(editPhoneVO.getPhone());
+            if (checkUser!= null&&!Objects.equals(checkUser.getFkId(),tbPeople.getId()) ){
+                throw new AjaxError("手机已被【"+checkUser.getName()+"】占用");
+            }
+            UpdateAccountDTO updateAccountDTO = new UpdateAccountDTO();
+            updateAccountDTO.setPhone(phone);
+            updateAccountDTO.setId(oldUser.getId());
+            FeignFactory.adminInterface.updateAccount(updateAccountDTO);
+        }
+        tbPeople.setPhone(phone);
+        this.updateById(tbPeople);
+
+
+
+
+    }
 }

+ 10 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_people/vo/EditPhoneVO.java

@@ -0,0 +1,10 @@
+package com.pj.tb_people.vo;
+
+import lombok.Data;
+
+@Data
+public class EditPhoneVO {
+    private Long id;
+    private String phone;
+    private String name;
+}

+ 3 - 2
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserApiController.java

@@ -2,6 +2,7 @@ package com.pj.project.app_user;
 
 import com.pj.api.dto.AppUserCreateDTO;
 import com.pj.api.dto.AppUserDto;
+import com.pj.api.dto.UpdateAccountDTO;
 import com.pj.current.satoken.StpAPPUserUtil;
 import com.pj.project.app_user.dto.ForgetPasswordDto;
 import com.pj.project.app_user.dto.LoginDto;
@@ -148,11 +149,11 @@ public class AppUserApiController {
      */
     @PostMapping("rpc/getByPhoneAndUserType")
     public AppUserDto getByPhoneAndUserType(@RequestParam("phone") String phone,@RequestParam("userType")Integer userType) {
-        AppUserDto byPhoneAndUserType = appUserService.getByPhoneAndUserType(phone, userType);
-        return byPhoneAndUserType;
+        return appUserService.getByPhoneAndUserType(phone, userType);
     }
 
 
 
 
+
 }

+ 11 - 1
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserController.java

@@ -2,6 +2,8 @@ package com.pj.project.app_user;
 
 import java.util.List;
 
+import cn.hutool.json.JSONUtil;
+import cn.hutool.log.StaticLog;
 import com.pj.api.dto.*;
 
 import com.pj.api.dto.BindShopDTO;
@@ -68,7 +70,7 @@ public class AppUserController {
 	@RequestMapping("pass")
 	@SaCheckPermission( AppUser.PERMISSION_CODE_EDIT)
 	public AjaxJson pass(@Validated PassDto dto){
-		System.out.println("dto:"+dto.getPassword());
+		StaticLog.info("dto:", JSONUtil.toJsonStr(dto.getPassword()));
 		return AjaxJson.toAjax(appUserService.pass(dto));
 	}
 
@@ -168,4 +170,12 @@ public class AppUserController {
 		return appUserService.getAppUserByFkId(fkId);
 	}
 
+	@RequestMapping("rpc/findUserByPhone")
+	public AppUserDto findUserByPhone(@RequestParam("phone") String phone) {
+		return appUserService.findUserByPhone(phone);
+	}
+	@PostMapping("rpc/updateAccount")
+	public int updateAccount(@RequestBody UpdateAccountDTO phone) {
+		return appUserService.updateAccount(phone);
+	}
 }

+ 53 - 14
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserService.java

@@ -4,6 +4,7 @@ import cn.dev33.satoken.spring.SpringMVCUtil;
 import cn.hutool.core.codec.Base64;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.crypto.digest.DigestUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -14,6 +15,7 @@ import com.pj.api.client.level_two_server.LevelTwoServerInterface;
 import com.pj.api.client.transport.TransportInterface;
 import com.pj.api.dto.*;
 import com.pj.common.core.exception.ServiceException;
+import com.pj.common.core.utils.StringUtils;
 import com.pj.current.config.SystemObject;
 import com.pj.current.dto.APPLoginUserInfo;
 import com.pj.current.satoken.StpAPPUserUtil;
@@ -615,6 +617,12 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
     public void createUser(AppUserCreateDTO createDTO) {
         log.info("创建APP账号:{}", JSONUtil.toJsonStr(createDTO));
         String phone = createDTO.getPhone().trim();
+        boolean phoneStatus = true;
+        if (StringUtils.isEmpty(phone)) {
+            phoneStatus = false;
+            log.info("创建APP账号失败: 手机号不能为空");
+            phone = RandomUtil.randomNumbers(11);
+        }
         AppUser appUser = this.findByPhone(phone);
         if (appUser != null) {
             log.info("创建APP账号失败:当前账号的手机号码已存在!!!");
@@ -629,14 +637,17 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
                 .setUserType(Integer.parseInt(createDTO.getUserType()))
                 .setDeleteStatus(DeleteStatus.DELETE_STATUS_ON.getCode())
                 .setCreateTime(new Date());
-        boolean save = this.save(appUser);
-        String content = "您好,您的app账号已生成。账号:" + phone + ", 初始密码:" + phone + "。可前往app进行修改";
-        // todo 发送短信
-        SystemObject.smsFactory.handler().sendSMS(phone, content);
+        if (phoneStatus) {
+            boolean save = this.save(appUser);
+            String content = "您好,您的app账号已生成。账号:" + phone + ", 初始密码:" + phone + "。可前往app进行修改";
+            // todo 发送短信
+            SystemObject.smsFactory.handler().sendSMS(phone, content);
+        }
+
     }
 
 
-    public void authFace(Long loginId, MultipartFile file,Integer type) {
+    public void authFace(Long loginId, MultipartFile file, Integer type) {
         String img;
         try (InputStream is = file.getInputStream()) {
             img = Base64.encode(is);
@@ -644,20 +655,20 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         } catch (IOException e) {
             throw new AjaxError("识别失败");
         }
-        if (type==2){
+        if (type == 2) {
             List<String> faceId = faceFactory.handler().faceSearch(img);
             if (faceId.isEmpty()) {
-                throw  new AjaxError("人脸不匹配");
+                throw new AjaxError("人脸不匹配");
             }
-            AppUser appUser =null;
+            AppUser appUser = null;
             for (String id : faceId) {
-                AppUser  checkUser = findByFaceId(id);
-                if (checkUser!=null){
-                    appUser=checkUser;
+                AppUser checkUser = findByFaceId(id);
+                if (checkUser != null) {
+                    appUser = checkUser;
                 }
             }
             if (appUser == null) {
-                throw  new AjaxError("人员信息未找到");
+                throw new AjaxError("人员信息未找到");
             }
             return;
         }
@@ -689,7 +700,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
             img = Base64.encode(is);
             boolean isLive = faceFactory.handler().checkIsLive(img);
             if (!isLive) {
-               // throw new AjaxError("非活体人脸");
+                // throw new AjaxError("非活体人脸");
             }
         } catch (IOException e) {
             throw new AjaxError("识别失败");
@@ -760,9 +771,37 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
     }
 
     public void changeBindShopStatus(BindShopDTO bindShopDTO) {
-        log.info("修改绑定状态:{}", JSONUtil.toJsonStr(bindShopDTO));
+        log.info("修改商铺绑定状态:{}", JSONUtil.toJsonStr(bindShopDTO));
         StrUtil.split(bindShopDTO.getIds(), ",").forEach(id -> {
             appUserMapper.changeBindShopStatus(id, bindShopDTO.getBindShop());
         });
     }
+
+    public AppUserDto findUserByPhone(String phone) {
+        AppUser appUser = findByPhone(phone);
+        if (appUser == null) {
+            return null;
+        }
+        AppUserDto appUserDto = new AppUserDto();
+        BeanUtils.copyProperties(appUser, appUserDto);
+        return appUserDto;
+    }
+
+    /**
+     * 修改手机并且修改密码
+     * @param updateAccountDTO
+     * @return
+     */
+    public int updateAccount(UpdateAccountDTO updateAccountDTO) {
+        Long id = updateAccountDTO.getId();
+        AppUser appUser =  this.getById(id);
+        if (appUser==null) {
+            return 0;
+        }
+        String phone=updateAccountDTO.getPhone();
+        appUser.setId(id);
+        appUser.setUpdateTime(new Date()).setPhone(phone);
+        appUser.setPassword(passwordEncoder.encode(phone));
+        return updateById(appUser)?1:0;
+    }
 }