From 63cc713ca321f9fb520a0c9b9796085ed31efb29 Mon Sep 17 00:00:00 2001
From: 101captain <237651143@qq.com>
Date: 星期四, 06 一月 2022 16:32:46 +0800
Subject: [PATCH] Merge branch 'phs' of http://gitlab.nhys.cdnhxx.com/root/zhihuishequ into phs

---
 springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java |  101 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
index 34d571b..1ac82ba 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
@@ -2,6 +2,7 @@
 
 import static java.util.Objects.isNull;
 import static java.util.Objects.nonNull;
+import static org.apache.commons.lang3.StringUtils.isNotBlank;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -13,7 +14,9 @@
 import java.util.stream.Collectors;
 
 import javax.annotation.Resource;
+import javax.validation.constraints.NotBlank;
 
+import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO;
 import org.apache.commons.lang.time.DateFormatUtils;
 import org.apache.commons.lang.time.DateUtils;
 import org.springframework.beans.BeanUtils;
@@ -2799,4 +2802,102 @@
         BeanUtils.copyProperties(sysUserDO, loginUserInfoVO);
         return R.ok(loginUserInfoVO);
     }
+
+    /**
+     * 微商业街新增商家账号
+     * @param mcsMerchantDTO
+     * @return 商家用户id
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R addMcsMerchantUser(McsMerchantDTO mcsMerchantDTO) {
+        SysUserDO sysUserDO;
+        sysUserDO = userDao.selectOne(new QueryWrapper<SysUserDO>().lambda()
+                .eq(SysUserDO::getAccount, mcsMerchantDTO.getAccount()).eq(SysUserDO::getType, 11));
+        if (nonNull(sysUserDO)) {
+            return R.fail("账户已经存在");
+        }
+        // sys_user 表
+        sysUserDO = new SysUserDO();
+        String encode = new BCryptPasswordEncoder().encode(mcsMerchantDTO.getPassword());
+        BeanUtils.copyProperties(mcsMerchantDTO, sysUserDO);
+        sysUserDO.setAccount(mcsMerchantDTO.getAccount());
+        sysUserDO.setType(11);
+        sysUserDO.setAreaId(null);
+        sysUserDO.setStatus(mcsMerchantDTO.getAccountStatus());
+        sysUserDO.setPhone(mcsMerchantDTO.getPhone());
+        sysUserDO.setPassword(encode);
+        try {
+            userDao.insert(sysUserDO);
+            return R.ok(sysUserDO.getUserId());
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("修改数字商业街商家用户报错【{}】", e.getMessage());
+            if (e.getMessage().contains("union_phone_type")) {
+                return R.fail("手机号已存在");
+            } else if (e.getMessage().contains("union_account_type")) {
+                return R.fail("账户已经存在");
+            }else if(e.getMessage().contains("23000")){
+                return R.fail("手机号已存在");
+            } else {
+                return R.fail("账户或手机号已存在,请重新填写尝试");
+            }
+        }
+    }
+
+    /**
+     * 微商业街修改商家账号
+     * @param mcsMerchantDTO
+     * @return
+     */
+    @Override
+    public R putMcsMerchantUser(McsMerchantDTO mcsMerchantDTO) {
+        SysUserDO sysUserDO = userDao.selectById(mcsMerchantDTO.getUserId());
+        if (isNull(sysUserDO)) {
+            return R.fail("用户不存在");
+        }
+        String account = mcsMerchantDTO.getAccount();
+        String phone = mcsMerchantDTO.getPhone();
+        Integer accountStatus = mcsMerchantDTO.getAccountStatus();
+        if (isNotBlank(account)) {
+            sysUserDO.setAccount(account);
+        }
+        if (isNotBlank(phone)) {
+            sysUserDO.setPhone(phone);
+        }
+        if (nonNull(accountStatus)) {
+            sysUserDO.setStatus(accountStatus);
+        }
+        try {
+            userDao.updateById(sysUserDO);
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("修改数字商业街商家用户报错【{}】", e.getMessage());
+            if (e.getMessage().contains("union_phone_type")) {
+                return R.fail("手机号已存在");
+            } else if (e.getMessage().contains("union_account_type")) {
+                return R.fail("账户已经存在");
+            }else if(e.getMessage().contains("23000")){
+                return R.fail("手机号已存在");
+            } else {
+                return R.fail("账户或手机号已存在,请重新填写尝试");
+            }
+        }
+        return R.ok();
+    }
+
+    /**
+     * 检查用户是否有效
+     * @param userId
+     * @param type
+     * @return
+     */
+    @Override
+    public Boolean checkUserIsValid(Long userId, Integer type) {
+        SysUserDO sysUserDO = userDao.selectById(userId);
+        if (isNull(sysUserDO) || sysUserDO.getStatus() != 1 || !sysUserDO.getType().equals(type)) {
+            return false;
+        }
+        return true;
+    }
 }

--
Gitblit v1.7.1