فهرست منبع

供应商、用友客户、服务客户:添加编辑等绑定登录账号

shasha 2 هفته پیش
والد
کامیت
33f22006fc

+ 85 - 2
snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/bizservicecustomer/service/impl/BizServiceCustomerAccountServiceImpl.java

@@ -19,16 +19,29 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import jakarta.annotation.Resource;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import vip.xiaonuo.biz.modular.bizservicecustomer.entity.BizServiceCustomer;
 import vip.xiaonuo.biz.modular.bizservicecustomer.enums.BizServiceCustomerAccountEnum;
+import vip.xiaonuo.biz.modular.bizservicecustomer.enums.BizServiceCustomerEnum;
 import vip.xiaonuo.biz.modular.bizservicecustomer.param.*;
+import vip.xiaonuo.biz.modular.customer.entity.BizCustomerAccount;
+import vip.xiaonuo.biz.modular.customer.param.BizCustomerAccountIdParam;
+import vip.xiaonuo.biz.modular.user.entity.BizUser;
+import vip.xiaonuo.biz.modular.user.enums.BizUserStatusEnum;
+import vip.xiaonuo.biz.modular.user.mapper.BizUserMapper;
+import vip.xiaonuo.biz.modular.user.service.BizUserService;
 import vip.xiaonuo.common.enums.CommonSortOrderEnum;
 import vip.xiaonuo.common.exception.CommonException;
 import vip.xiaonuo.common.page.CommonPageRequest;
 import vip.xiaonuo.biz.modular.bizservicecustomer.entity.BizServiceCustomerAccount;
 import vip.xiaonuo.biz.modular.bizservicecustomer.mapper.BizServiceCustomerAccountMapper;
 import vip.xiaonuo.biz.modular.bizservicecustomer.service.BizServiceCustomerAccountService;
+import vip.xiaonuo.common.util.CommonCryptogramUtil;
+import vip.xiaonuo.dev.api.DevConfigApi;
+import vip.xiaonuo.sys.api.SysUserApi;
 
 import java.math.BigDecimal;
 import java.util.List;
@@ -42,6 +55,20 @@ import java.util.List;
 @Service
 public class BizServiceCustomerAccountServiceImpl extends ServiceImpl<BizServiceCustomerAccountMapper, BizServiceCustomerAccount> implements BizServiceCustomerAccountService {
 
+    private static final String SNOWY_SYS_DEFAULT_PASSWORD_KEY = "SNOWY_SYS_DEFAULT_PASSWORD";
+
+    @Resource
+    private BizUserService bizUserService;
+
+    @Resource
+    private BizUserMapper bizUserMapper;
+
+    @Resource
+    private DevConfigApi devConfigApi;
+
+    @Resource
+    private SysUserApi sysUserApi;
+
     @Override
     public Page<BizServiceCustomerAccount> page(BizServiceCustomerAccountPageParam bizServiceCustomerAccountPageParam) {
         QueryWrapper<BizServiceCustomerAccount> queryWrapper = new QueryWrapper<BizServiceCustomerAccount>().checkSqlInjection();
@@ -64,7 +91,11 @@ public class BizServiceCustomerAccountServiceImpl extends ServiceImpl<BizService
         //查询名称是否添加过
         long countName = this.count(new QueryWrapper<BizServiceCustomerAccount>().lambda().eq(BizServiceCustomerAccount::getLoginAccount, bizServiceCustomerAccountAddParam.getLoginAccount())
                                                                                 .eq(BizServiceCustomerAccount::getDeleteFlag, BizServiceCustomerAccountEnum.NOT_DELETE.getValue()));
+        if(countName>0){
+            throw new CommonException("服务客户账号已存在!");
+        }
         BizServiceCustomerAccount bizServiceCustomerAccount = BeanUtil.toBean(bizServiceCustomerAccountAddParam, BizServiceCustomerAccount.class);
+        addUserAccount(bizServiceCustomerAccount);
         this.save(bizServiceCustomerAccount);
     }
 
@@ -75,16 +106,68 @@ public class BizServiceCustomerAccountServiceImpl extends ServiceImpl<BizService
         long countName = this.count(new QueryWrapper<BizServiceCustomerAccount>().lambda().eq(BizServiceCustomerAccount::getLoginAccount, bizServiceCustomerAccountEditParam.getLoginAccount())
                                                                                 .ne(BizServiceCustomerAccount::getId, bizServiceCustomerAccountEditParam.getId())
                                                                                 .eq(BizServiceCustomerAccount::getDeleteFlag, BizServiceCustomerAccountEnum.NOT_DELETE.getValue()));
+        if(countName>0){
+            throw new CommonException("服务客户账号已存在!");
+        }
         BizServiceCustomerAccount bizServiceCustomerAccount = this.queryEntity(bizServiceCustomerAccountEditParam.getId());
+
+        if(!StringUtils.equals(bizServiceCustomerAccount.getLoginAccount(),bizServiceCustomerAccountEditParam.getLoginAccount())){
+            // 删除原本登录账号
+            BizUser userOld = bizUserService.getOne(new QueryWrapper<BizUser>().lambda().
+                    eq(BizUser::getAccount, bizServiceCustomerAccountEditParam.getLoginAccount()).
+                    last("limit 1"));
+            if(null != userOld){
+                this.bizUserService.removeById(userOld);
+            }
+
+            bizServiceCustomerAccount.setLoginAccount(bizServiceCustomerAccountEditParam.getLoginAccount());
+            addUserAccount(bizServiceCustomerAccount);
+        }
         BeanUtil.copyProperties(bizServiceCustomerAccountEditParam, bizServiceCustomerAccount);
         this.updateById(bizServiceCustomerAccount);
     }
 
+    public void addUserAccount(BizServiceCustomerAccount bizServiceCustomerAccount){
+        //根据账号是否存在
+        BizUser user = bizUserService.getOne(new QueryWrapper<BizUser>().lambda().
+                eq(BizUser::getAccount, bizServiceCustomerAccount.getLoginAccount()).
+                last("limit 1"));
+        if(ObjectUtil.isNotNull(user)){
+            throw new CommonException("服务客户手机号已经存在!");
+        }
+
+        // 添加供应商登录账号
+        BizUser bizUser = new BizUser();
+        bizUser.setCustomerId(bizServiceCustomerAccount.getId());
+        bizUser.setName(bizServiceCustomerAccount.getLoginAccount());
+        bizUser.setAccount(bizServiceCustomerAccount.getLoginAccount());
+        bizUser.setUserType("4");
+        // 设置密码
+        bizUser.setPassword(CommonCryptogramUtil.doHashValue(devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_PASSWORD_KEY)));
+        // 设置状态
+        bizUser.setUserStatus(BizUserStatusEnum.ENABLE.getValue());
+        this.bizUserMapper.insert(bizUser);
+    }
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void delete(List<BizServiceCustomerAccountIdParam> bizServiceCustomerAccountIdParamList) {
-        // 执行删除
-        this.removeByIds(CollStreamUtil.toList(bizServiceCustomerAccountIdParamList, BizServiceCustomerAccountIdParam::getId));
+        if(null != bizServiceCustomerAccountIdParamList && 0 < bizServiceCustomerAccountIdParamList.size()){
+            for (BizServiceCustomerAccountIdParam accountIdParam : bizServiceCustomerAccountIdParamList){
+                BizServiceCustomerAccount account = this.queryEntity(accountIdParam.getId());
+
+                // 删除原本登录账号
+                BizUser userOld = bizUserService.getOne(new QueryWrapper<BizUser>().lambda().
+                        eq(BizUser::getAccount, account.getLoginAccount()).
+                        last("limit 1"));
+                if(null != userOld){
+                    this.bizUserService.removeById(userOld);
+                }
+
+                // 执行删除
+                this.removeById(account.getId());
+            }
+        }
     }
 
     @Override

+ 94 - 0
snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/bizservicecustomer/service/impl/BizServiceCustomerServiceImpl.java

@@ -20,13 +20,22 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import jakarta.annotation.Resource;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import vip.xiaonuo.biz.modular.bizservicecustomer.entity.BizServiceCustomerAccount;
 import vip.xiaonuo.biz.modular.bizservicecustomer.entity.BizServiceCustomerFlow;
 import vip.xiaonuo.biz.modular.bizservicecustomer.enums.BizServiceCustomerEnum;
+import vip.xiaonuo.biz.modular.bizservicecustomer.service.BizServiceCustomerAccountService;
+import vip.xiaonuo.biz.modular.bizsupplier.entity.BizSupplier;
 import vip.xiaonuo.biz.modular.bizsupplier.entity.BizSupplierAccount;
 import vip.xiaonuo.biz.modular.bizsupplier.enums.BizSupplierAccountEnum;
+import vip.xiaonuo.biz.modular.bizsupplier.param.BizSupplierIdParam;
+import vip.xiaonuo.biz.modular.user.entity.BizUser;
+import vip.xiaonuo.biz.modular.user.enums.BizUserStatusEnum;
+import vip.xiaonuo.biz.modular.user.mapper.BizUserMapper;
+import vip.xiaonuo.biz.modular.user.service.BizUserService;
 import vip.xiaonuo.common.enums.CommonSortOrderEnum;
 import vip.xiaonuo.common.exception.CommonException;
 import vip.xiaonuo.common.page.CommonPageRequest;
@@ -37,6 +46,9 @@ import vip.xiaonuo.biz.modular.bizservicecustomer.param.BizServiceCustomerEditPa
 import vip.xiaonuo.biz.modular.bizservicecustomer.param.BizServiceCustomerIdParam;
 import vip.xiaonuo.biz.modular.bizservicecustomer.param.BizServiceCustomerPageParam;
 import vip.xiaonuo.biz.modular.bizservicecustomer.service.BizServiceCustomerService;
+import vip.xiaonuo.common.util.CommonCryptogramUtil;
+import vip.xiaonuo.dev.api.DevConfigApi;
+import vip.xiaonuo.sys.api.SysUserApi;
 
 import java.util.List;
 
@@ -49,6 +61,23 @@ import java.util.List;
 @Service
 public class BizServiceCustomerServiceImpl extends ServiceImpl<BizServiceCustomerMapper, BizServiceCustomer> implements BizServiceCustomerService {
 
+    private static final String SNOWY_SYS_DEFAULT_PASSWORD_KEY = "SNOWY_SYS_DEFAULT_PASSWORD";
+
+    @Resource
+    private BizServiceCustomerAccountService bizServiceCustomerAccountService;
+
+    @Resource
+    private BizUserService bizUserService;
+
+    @Resource
+    private BizUserMapper bizUserMapper;
+
+    @Resource
+    private DevConfigApi devConfigApi;
+
+    @Resource
+    private SysUserApi sysUserApi;
+
     @Override
     public Page<BizServiceCustomer> page(BizServiceCustomerPageParam bizServiceCustomerPageParam) {
         QueryWrapper<BizServiceCustomer> queryWrapper = new QueryWrapper<BizServiceCustomer>().checkSqlInjection();
@@ -80,7 +109,18 @@ public class BizServiceCustomerServiceImpl extends ServiceImpl<BizServiceCustome
         if(countName>0){
             throw new CommonException("服务客户名称已存在!");
         }
+        //查询手机号是否添加过
+        long countPhone = this.count(new QueryWrapper<BizServiceCustomer>().lambda().eq(BizServiceCustomer::getPhone, bizServiceCustomerAddParam.getPhone())
+                .eq(BizServiceCustomer::getDeleteFlag, BizServiceCustomerEnum.NOT_DELETE.getValue()));
+        if(countPhone>0){
+            throw new CommonException("服务客户手机号已存在!");
+        }
         BizServiceCustomer bizServiceCustomer = BeanUtil.toBean(bizServiceCustomerAddParam, BizServiceCustomer.class);
+
+        //查询账号是否添加过
+        if(ObjectUtil.isNotEmpty(bizServiceCustomer.getPhone())){
+            addUserAccount(bizServiceCustomer);
+        }
         this.save(bizServiceCustomer);
     }
 
@@ -101,15 +141,69 @@ public class BizServiceCustomerServiceImpl extends ServiceImpl<BizServiceCustome
             throw new CommonException("服务客户名称已存在!");
         }
         BizServiceCustomer bizServiceCustomer = this.queryEntity(bizServiceCustomerEditParam.getId());
+        if(!StringUtils.equals(bizServiceCustomer.getPhone(),bizServiceCustomerEditParam.getPhone())){
+            deleteUserAccount(bizServiceCustomer.getId());
+            bizServiceCustomer.setPhone(bizServiceCustomerEditParam.getPhone());
+            addUserAccount(bizServiceCustomer);
+        }
         BeanUtil.copyProperties(bizServiceCustomerEditParam, bizServiceCustomer);
         this.updateById(bizServiceCustomer);
     }
 
+    public void addUserAccount(BizServiceCustomer bizServiceCustomer){
+        //根据账号是否存在
+        BizUser user = bizUserService.getOne(new QueryWrapper<BizUser>().lambda().
+                eq(BizUser::getAccount, bizServiceCustomer.getPhone()).
+                last("limit 1"));
+        if(ObjectUtil.isNotNull(user)){
+            throw new CommonException("服务客户手机号已经存在!");
+        }
+
+        // 添加供应商登录账号
+        BizUser bizUser = new BizUser();
+        bizUser.setCustomerId(bizServiceCustomer.getId());
+        bizUser.setName(bizServiceCustomer.getPhone());
+        bizUser.setAccount(bizServiceCustomer.getPhone());
+        bizUser.setUserType("4");
+        // 设置密码
+        bizUser.setPassword(CommonCryptogramUtil.doHashValue(devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_PASSWORD_KEY)));
+        // 设置状态
+        bizUser.setUserStatus(BizUserStatusEnum.ENABLE.getValue());
+        this.bizUserMapper.insert(bizUser);
+
+        // 添加供应商角色
+        this.sysUserApi.grantRoleType(bizUser.getId(), "供应商");
+
+        BizServiceCustomerAccount bizServiceCustomerAccount = new BizServiceCustomerAccount();
+        bizServiceCustomerAccount.setServiceCustomerId(bizServiceCustomer.getId());
+        bizServiceCustomerAccount.setLoginAccount(bizServiceCustomer.getPhone());
+        bizServiceCustomerAccountService.save(bizServiceCustomerAccount);
+    }
+
+    public void deleteUserAccount(String bizServiceCustomerId){
+        if(null != bizServiceCustomerId) {
+            // 删除供应商对应的子账号
+            List<BizServiceCustomerAccount> list = bizServiceCustomerAccountService.list(new QueryWrapper<BizServiceCustomerAccount>().lambda().eq(BizServiceCustomerAccount::getServiceCustomerId, bizServiceCustomerId));
+            for (BizServiceCustomerAccount bizServiceCustomerAccount : list) {
+                bizServiceCustomerAccountService.removeById(bizServiceCustomerAccount);
+
+                // 删除用户账号
+                List<BizUser> userList = bizUserService.list(new QueryWrapper<BizUser>().lambda()
+                        .eq(BizUser::getAccount, bizServiceCustomerAccount.getLoginAccount()));
+                bizUserService.removeByIds(CollStreamUtil.toList(userList, BizUser::getId));
+            }
+        }
+    }
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void delete(List<BizServiceCustomerIdParam> bizServiceCustomerIdParamList) {
         // 执行删除
         this.removeByIds(CollStreamUtil.toList(bizServiceCustomerIdParamList, BizServiceCustomerIdParam::getId));
+        // 删除登录账号
+        for(BizServiceCustomerIdParam bizServiceCustomerIdParam : bizServiceCustomerIdParamList){
+            deleteUserAccount(bizServiceCustomerIdParam.getId());
+        }
     }
 
     @Override

+ 77 - 2
snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/bizsupplier/service/impl/BizSupplierAccountServiceImpl.java

@@ -19,6 +19,8 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import jakarta.annotation.Resource;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import vip.xiaonuo.biz.modular.bizloadpoint.entity.BizLoadPoint;
@@ -29,12 +31,19 @@ import vip.xiaonuo.biz.modular.bizsupplier.param.*;
 import vip.xiaonuo.biz.modular.customer.entity.BizCustomer;
 import vip.xiaonuo.biz.modular.customer.entity.BizCustomerAccount;
 import vip.xiaonuo.biz.modular.customer.enums.BizCustomerAccountEnum;
+import vip.xiaonuo.biz.modular.customer.param.BizCustomerAccountIdParam;
+import vip.xiaonuo.biz.modular.user.entity.BizUser;
+import vip.xiaonuo.biz.modular.user.enums.BizUserStatusEnum;
+import vip.xiaonuo.biz.modular.user.mapper.BizUserMapper;
+import vip.xiaonuo.biz.modular.user.service.BizUserService;
 import vip.xiaonuo.common.enums.CommonSortOrderEnum;
 import vip.xiaonuo.common.exception.CommonException;
 import vip.xiaonuo.common.page.CommonPageRequest;
 import vip.xiaonuo.biz.modular.bizsupplier.entity.BizSupplierAccount;
 import vip.xiaonuo.biz.modular.bizsupplier.mapper.BizSupplierAccountMapper;
 import vip.xiaonuo.biz.modular.bizsupplier.service.BizSupplierAccountService;
+import vip.xiaonuo.common.util.CommonCryptogramUtil;
+import vip.xiaonuo.dev.api.DevConfigApi;
 
 import java.util.List;
 
@@ -47,6 +56,17 @@ import java.util.List;
 @Service
 public class BizSupplierAccountServiceImpl extends ServiceImpl<BizSupplierAccountMapper, BizSupplierAccount> implements BizSupplierAccountService {
 
+    @Resource
+    private BizUserService bizUserService;
+
+    @Resource
+    private BizUserMapper bizUserMapper;
+
+    @Resource
+    private DevConfigApi devConfigApi;
+
+    private static final String SNOWY_SYS_DEFAULT_PASSWORD_KEY = "SNOWY_SYS_DEFAULT_PASSWORD";
+
     @Override
     public Page<BizSupplierAccount> page(BizSupplierAccountPageParam bizSupplierAccountPageParam) {
         QueryWrapper<BizSupplierAccount> queryWrapper = new QueryWrapper<BizSupplierAccount>().checkSqlInjection();
@@ -74,6 +94,13 @@ public class BizSupplierAccountServiceImpl extends ServiceImpl<BizSupplierAccoun
             throw new CommonException("供应商账号已存在!");
         }
         BizSupplierAccount bizSupplierAccount = BeanUtil.toBean(bizSupplierAccountAddParam, BizSupplierAccount.class);
+
+        //查询账号是否添加过
+        if(ObjectUtil.isNotEmpty(bizSupplierAccount.getSupplierAccount())){
+            addAccount(bizSupplierAccount);
+        }
+
+        //添加供应商账号
         this.save(bizSupplierAccount);
     }
 
@@ -88,15 +115,63 @@ public class BizSupplierAccountServiceImpl extends ServiceImpl<BizSupplierAccoun
             throw new CommonException("供应商账号已存在!");
         }
         BizSupplierAccount bizSupplierAccount = this.queryEntity(bizSupplierAccountEditParam.getId());
+
+        if(!StringUtils.equals(bizSupplierAccount.getSupplierAccount(),bizSupplierAccountEditParam.getSupplierAccount())){
+            deleteAccount(bizSupplierAccount);
+            bizSupplierAccount.setSupplierAccount(bizSupplierAccountEditParam.getSupplierAccount());
+            addAccount(bizSupplierAccount);
+        }
+
         BeanUtil.copyProperties(bizSupplierAccountEditParam, bizSupplierAccount);
         this.updateById(bizSupplierAccount);
     }
 
+    public void addAccount(BizSupplierAccount bizSupplierAccount){
+        //根据账号是否存在
+        BizUser user = bizUserService.getOne(new QueryWrapper<BizUser>().lambda().
+                eq(BizUser::getAccount, bizSupplierAccount.getSupplierAccount()).
+                last("limit 1"));
+        if(ObjectUtil.isNotNull(user)){
+            throw new CommonException("供应商账号已经存在!");
+        }
+
+        // 添加供应商登录账号
+        BizUser bizUser = new BizUser();
+        bizUser.setCustomerId(bizSupplierAccount.getSupplierId());
+        bizUser.setName(bizSupplierAccount.getSupplierAccount());
+        bizUser.setAccount(bizSupplierAccount.getSupplierAccount());
+        bizUser.setUserType("4");
+        // 设置密码
+        bizUser.setPassword(CommonCryptogramUtil.doHashValue(devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_PASSWORD_KEY)));
+        // 设置状态
+        bizUser.setUserStatus(BizUserStatusEnum.ENABLE.getValue());
+        this.bizUserMapper.insert(bizUser);
+    }
+
+    public void deleteAccount(BizSupplierAccount bizSupplierAccount){
+        if(null != bizSupplierAccount){
+            // 删除原本登录账号
+            BizUser userOld = bizUserService.getOne(new QueryWrapper<BizUser>().lambda().
+                    eq(BizUser::getAccount, bizSupplierAccount.getSupplierAccount()).
+                    last("limit 1"));
+            if(null != userOld){
+                this.bizUserMapper.updateById(userOld);
+            }
+        }
+    }
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void delete(List<BizSupplierAccountIdParam> bizSupplierAccountIdParamList) {
-        // 执行删除
-        this.removeByIds(CollStreamUtil.toList(bizSupplierAccountIdParamList, BizSupplierAccountIdParam::getId));
+        if(null != bizSupplierAccountIdParamList && 0 < bizSupplierAccountIdParamList.size()){
+            for (BizSupplierAccountIdParam accountIdParam : bizSupplierAccountIdParamList){
+                BizSupplierAccount account = this.queryEntity(accountIdParam.getId());
+                deleteAccount(account);
+
+                // 执行删除
+                this.removeById(account.getId());
+            }
+        }
     }
 
     @Override

+ 55 - 28
snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/bizsupplier/service/impl/BizSupplierServiceImpl.java

@@ -30,6 +30,7 @@ import vip.xiaonuo.biz.modular.bizsupplier.enums.BizSupplierEnum;
 import vip.xiaonuo.biz.modular.bizsupplier.service.BizSupplierAccountService;
 import vip.xiaonuo.biz.modular.customer.entity.BizCustomer;
 import vip.xiaonuo.biz.modular.customer.entity.BizCustomerAccount;
+import vip.xiaonuo.biz.modular.customer.param.BizCustomerIdParam;
 import vip.xiaonuo.biz.modular.user.entity.BizUser;
 import vip.xiaonuo.biz.modular.user.enums.BizUserStatusEnum;
 import vip.xiaonuo.biz.modular.user.mapper.BizUserMapper;
@@ -105,19 +106,53 @@ public class BizSupplierServiceImpl extends ServiceImpl<BizSupplierMapper, BizSu
             throw new CommonException("供货商已存在!");
         }
         BizSupplier bizSupplier = BeanUtil.toBean(bizSupplierAddParam, BizSupplier.class);
-        this.save(bizSupplier);
-
 
         //查询账号是否添加过
         if(ObjectUtil.isNotEmpty(bizSupplierAddParam.getSupplierPhone())){
-            addAccount(bizSupplier);
+            addUserAccount(bizSupplier);
         }
 
-
+        this.save(bizSupplier);
     }
 
-    public void addAccount(BizSupplier bizSupplier){
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void edit(BizSupplierEditParam bizSupplierEditParam) {
+        //校验手机号格式
+        if(ObjectUtil.isNotEmpty(bizSupplierEditParam.getSupplierPhone())){
+            if(!PhoneUtil.isMobile(bizSupplierEditParam.getSupplierPhone())) {
+                throw new CommonException("手机号码:{}格式错误", bizSupplierEditParam.getSupplierPhone());
+            }
+        }
+        BizSupplier bizSupplier = this.queryEntity(bizSupplierEditParam.getId());
+        if(!StringUtils.equals(bizSupplier.getSupplierName(),bizSupplierEditParam.getSupplierName())){
+            //修改过供货商名称,判断供货商是否存在
+            long count = this.count(new QueryWrapper<BizSupplier>().lambda().eq(BizSupplier::getSupplierName, bizSupplierEditParam.getSupplierName())
+                                                                    .ne(BizSupplier::getId, bizSupplierEditParam.getId())
+                                                                    .eq(BizSupplier::getDeleteFlag, BizSupplierEnum.NOT_DELETE.getValue()));
+            if(count>0){
+                throw new CommonException("供货商名称已存在!");
+            }
+        }
+        if(!StringUtils.equals(bizSupplier.getSupplierPhone(),bizSupplierEditParam.getSupplierPhone())){
+            //修改过供货商名称,判断供货商是否存在
+            long count = this.count(new QueryWrapper<BizSupplier>().lambda().eq(BizSupplier::getSupplierPhone, bizSupplierEditParam.getSupplierPhone())
+                    .ne(BizSupplier::getId, bizSupplierEditParam.getId())
+                    .eq(BizSupplier::getDeleteFlag, BizSupplierEnum.NOT_DELETE.getValue()));
+            if(count>0){
+                throw new CommonException("供货商手机号已存在!");
+            }
+        }
+        if(!StringUtils.equals(bizSupplier.getSupplierPhone(),bizSupplierEditParam.getSupplierPhone())){
+            deleteUserAccount(bizSupplier.getId());
+            bizSupplier.setSupplierPhone(bizSupplierEditParam.getSupplierPhone());
+            addUserAccount(bizSupplier);
+        }
+        BeanUtil.copyProperties(bizSupplierEditParam, bizSupplier);
+        this.updateById(bizSupplier);
+    }
 
+    public void addUserAccount(BizSupplier bizSupplier){
         //根据账号是否存在
         BizUser user = bizUserService.getOne(new QueryWrapper<BizUser>().lambda().
                 eq(BizUser::getAccount, bizSupplier.getSupplierPhone()).
@@ -147,31 +182,19 @@ public class BizSupplierServiceImpl extends ServiceImpl<BizSupplierMapper, BizSu
         bizSupplierAccountService.save(bizSupplierAccount);
     }
 
-    @Transactional(rollbackFor = Exception.class)
-    @Override
-    public void edit(BizSupplierEditParam bizSupplierEditParam) {
-        //校验手机号格式
-        if(ObjectUtil.isNotEmpty(bizSupplierEditParam.getSupplierPhone())){
-            if(!PhoneUtil.isMobile(bizSupplierEditParam.getSupplierPhone())) {
-                throw new CommonException("手机号码:{}格式错误", bizSupplierEditParam.getSupplierPhone());
-            }
-        }
-        BizSupplier bizSupplier = this.queryEntity(bizSupplierEditParam.getId());
-        if(!StringUtils.equals(bizSupplier.getSupplierName(),bizSupplierEditParam.getSupplierName())){
-            //修改过供货商名称,判断供货商是否存在
-            long count = this.count(new QueryWrapper<BizSupplier>().lambda().eq(BizSupplier::getSupplierName, bizSupplierEditParam.getSupplierName())
-                                                                    .ne(BizSupplier::getId, bizSupplierEditParam.getId())
-                                                                    .eq(BizSupplier::getDeleteFlag, BizSupplierEnum.NOT_DELETE.getValue()));
-            if(count>0){
-                throw new CommonException("供货商已存在!");
+    public void deleteUserAccount(String bizSupplierId){
+        if(null != bizSupplierId) {
+            // 删除供应商对应的子账号
+            List<BizSupplierAccount> list = bizSupplierAccountService.list(new QueryWrapper<BizSupplierAccount>().lambda().eq(BizSupplierAccount::getSupplierId, bizSupplierId));
+            for (BizSupplierAccount bizSupplierAccount : list) {
+                bizSupplierAccountService.removeById(bizSupplierAccount);
+
+                // 删除用户账号
+                List<BizUser> userList = bizUserService.list(new QueryWrapper<BizUser>().lambda()
+                        .eq(BizUser::getAccount, bizSupplierAccount.getSupplierAccount()));
+                bizUserService.removeByIds(CollStreamUtil.toList(userList, BizUser::getId));
             }
         }
-        if(!StringUtils.equals(bizSupplier.getSupplierPhone(),bizSupplierEditParam.getSupplierPhone())){
-            bizSupplier.setSupplierPhone(bizSupplierEditParam.getSupplierPhone());
-            addAccount(bizSupplier);
-        }
-        BeanUtil.copyProperties(bizSupplierEditParam, bizSupplier);
-        this.updateById(bizSupplier);
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -179,6 +202,10 @@ public class BizSupplierServiceImpl extends ServiceImpl<BizSupplierMapper, BizSu
     public void delete(List<BizSupplierIdParam> bizSupplierIdParamList) {
         // 执行删除
         this.removeByIds(CollStreamUtil.toList(bizSupplierIdParamList, BizSupplierIdParam::getId));
+
+        for(BizSupplierIdParam bizSupplierIdParam : bizSupplierIdParamList){
+            deleteUserAccount(bizSupplierIdParam.getId());
+        }
     }
 
     @Override

+ 21 - 3
snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/customer/service/impl/BizCustomerAccountServiceImpl.java

@@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import vip.xiaonuo.biz.modular.bizsupplier.entity.BizSupplierAccount;
 import vip.xiaonuo.biz.modular.customer.entity.BizCustomer;
 import vip.xiaonuo.biz.modular.customer.enums.BizCustomerAccountEnum;
 import vip.xiaonuo.biz.modular.customer.enums.BizCustomerEnum;
@@ -30,6 +31,7 @@ import vip.xiaonuo.biz.modular.goods.entity.BizGoods;
 import vip.xiaonuo.biz.modular.user.entity.BizUser;
 import vip.xiaonuo.biz.modular.user.enums.BizUserStatusEnum;
 import vip.xiaonuo.biz.modular.user.mapper.BizUserMapper;
+import vip.xiaonuo.biz.modular.user.service.BizUserService;
 import vip.xiaonuo.common.enums.CommonSortOrderEnum;
 import vip.xiaonuo.common.exception.CommonException;
 import vip.xiaonuo.common.page.CommonPageRequest;
@@ -58,6 +60,8 @@ public class BizCustomerAccountServiceImpl extends ServiceImpl<BizCustomerAccoun
 
     @Resource
     private BizUserMapper bizUserMapper;
+    @Resource
+    private BizUserService bizUserService;
 
     @Resource
     private SysUserApi sysUserApi;
@@ -110,14 +114,28 @@ public class BizCustomerAccountServiceImpl extends ServiceImpl<BizCustomerAccoun
         this.bizUserMapper.insert(bizUser);
 
         // 添加客户角色
-        this.sysUserApi.grantRoleType(bizUser.getId(), "客户");
+        this.sysUserApi.grantRoleType(bizUser.getId(), "服务客户");
     }
 
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void delete(List<BizCustomerAccountIdParam> bizCustomerAccountIdParamList) {
-        // 执行删除
-        this.removeByIds(CollStreamUtil.toList(bizCustomerAccountIdParamList, BizCustomerAccountIdParam::getId));
+        if(null != bizCustomerAccountIdParamList && 0 < bizCustomerAccountIdParamList.size()){
+            for (BizCustomerAccountIdParam accountIdParam : bizCustomerAccountIdParamList){
+                BizCustomerAccount account = this.queryEntity(accountIdParam.getId());
+
+                // 删除原本登录账号
+                BizUser userOld = bizUserService.getOne(new QueryWrapper<BizUser>().lambda().
+                        eq(BizUser::getAccount, account.getLoginAccount()).
+                        last("limit 1"));
+                if(null != userOld){
+                    this.bizUserService.removeById(userOld);
+                }
+
+                // 执行删除
+                this.removeById(account.getId());
+            }
+        }
     }
 
     @Override

+ 35 - 10
snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/customer/service/impl/BizCustomerServiceImpl.java

@@ -29,6 +29,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import vip.xiaonuo.biz.core.sign.utils.MD5;
+import vip.xiaonuo.biz.modular.bizsupplier.entity.BizSupplier;
+import vip.xiaonuo.biz.modular.bizsupplier.entity.BizSupplierAccount;
 import vip.xiaonuo.biz.modular.customer.entity.BizCustomerAccount;
 import vip.xiaonuo.biz.modular.customer.enums.BizCustomerEnum;
 import vip.xiaonuo.biz.modular.customer.param.*;
@@ -134,15 +136,17 @@ public class BizCustomerServiceImpl extends ServiceImpl<BizCustomerMapper, BizCu
             throw new CommonException("客户名称已存在!");
         }
         BizCustomer bizCustomer = BeanUtil.toBean(bizCustomerAddParam, BizCustomer.class);
-        this.save(bizCustomer);
 
         if(ObjectUtil.isNotEmpty(bizCustomerAddParam.getPhone())){
-            addAccount(bizCustomer);
+            // 添加用户账号
+            addUserAccount(bizCustomer);
         }
-    }
 
-    public void addAccount(BizCustomer bizCustomer){
+        // 添加用友客户
+        this.save(bizCustomer);
+    }
 
+    public void addUserAccount(BizCustomer bizCustomer){
         //根据账号是否存在
         BizUser user = bizUserService.getOne(new QueryWrapper<BizUser>().lambda().
                 eq(BizUser::getAccount, bizCustomer.getPhone()).
@@ -164,7 +168,7 @@ public class BizCustomerServiceImpl extends ServiceImpl<BizCustomerMapper, BizCu
         this.bizUserMapper.insert(bizUser);
 
         // 添加客户角色
-        this.sysUserApi.grantRoleType(bizUser.getId(), "客户");
+        this.sysUserApi.grantRoleType(bizUser.getId(), "服务客户");
 
         BizCustomerAccount bizCustomerAccount = new BizCustomerAccount();
         bizCustomerAccount.setCustomerId(bizCustomer.getId());
@@ -173,6 +177,21 @@ public class BizCustomerServiceImpl extends ServiceImpl<BizCustomerMapper, BizCu
         log.info("用友推送客户信息结束");
     }
 
+    public void deleteUserAccount(String bizCustomerId){
+        if(null != bizCustomerId) {
+            // 删除供应商对应的子账号
+            List<BizCustomerAccount> list = bizCustomerAccountService.list(new QueryWrapper<BizCustomerAccount>().lambda().eq(BizCustomerAccount::getCustomerId, bizCustomerId));
+            for (BizCustomerAccount bizCustomerAccount : list) {
+                bizCustomerAccountService.removeById(bizCustomerAccount);
+
+                // 删除用户账号
+                List<BizUser> userList = bizUserService.list(new QueryWrapper<BizUser>().lambda()
+                        .eq(BizUser::getAccount, bizCustomerAccount.getLoginAccount()));
+                bizUserService.removeByIds(CollStreamUtil.toList(userList, BizUser::getId));
+            }
+        }
+    }
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void addYong(BizCustomerYongAddParam bizCustomerYongAddParam) {
@@ -197,7 +216,7 @@ public class BizCustomerServiceImpl extends ServiceImpl<BizCustomerMapper, BizCu
         this.save(bizCustomer);
 
         if(ObjectUtil.isNotEmpty(bizCustomerYongAddParam.getPhone())){
-            addAccount(bizCustomer);
+            addUserAccount(bizCustomer);
         }
     }
 
@@ -218,13 +237,18 @@ public class BizCustomerServiceImpl extends ServiceImpl<BizCustomerMapper, BizCu
                 throw new CommonException("客户关联的用友平台ID已存在!");
             }
         }
-        if(!StringUtils.equals(bizCustomer.getName(),bizCustomerEditParam.getName())){
+        if(!StringUtils.equals(bizCustomer.getName(),bizCustomerEditParam.getName())) {
             //查询客户名称是否添加过
             long count = this.count(new QueryWrapper<BizCustomer>().lambda().eq(BizCustomer::getName, bizCustomerEditParam.getName()));
-            if(count>0){
+            if (count > 0) {
                 throw new CommonException("客户名称已存在!");
             }
         }
+        if(!StringUtils.equals(bizCustomer.getPhone(), bizCustomerEditParam.getPhone())){
+            deleteUserAccount(bizCustomer.getId());
+            bizCustomer.setPhone(bizCustomerEditParam.getPhone());
+            addUserAccount(bizCustomer);
+        }
         BeanUtil.copyProperties(bizCustomerEditParam, bizCustomer);
         this.updateById(bizCustomer);
     }
@@ -236,13 +260,14 @@ public class BizCustomerServiceImpl extends ServiceImpl<BizCustomerMapper, BizCu
         this.removeByIds(CollStreamUtil.toList(bizCustomerIdParamList, BizCustomerIdParam::getId));
 
         for(BizCustomerIdParam bizCustomerIdParam:bizCustomerIdParamList ){
-            //删除客户账号
+            // 删除客户对应的子账号
             List<BizCustomerAccount> list = bizCustomerAccountService.list(new QueryWrapper<BizCustomerAccount>().lambda().eq(BizCustomerAccount::getCustomerId, bizCustomerIdParam.getId()));
             for(BizCustomerAccount bizCustomerAccount : list){
                 bizCustomerAccountService.removeById(bizCustomerAccount);
 
+                // 删除用户账号
                 List<BizUser> userList = bizUserService.list(new QueryWrapper<BizUser>().lambda()
-                        .eq(BizUser::getAccount, bizCustomerAccount.getLoginAccount()));
+                                                .eq(BizUser::getAccount, bizCustomerAccount.getLoginAccount()));
                 bizUserService.removeByIds(CollStreamUtil.toList(userList, BizUser::getId));
             }
         }