|
@@ -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
|