|
@@ -27,13 +27,16 @@ import org.apache.commons.compress.utils.Lists;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import vip.xiaonuo.biz.modular.customer.entity.BizCustomerAccount;
|
|
|
import vip.xiaonuo.biz.modular.customer.enums.BizCustomerEnum;
|
|
|
import vip.xiaonuo.biz.modular.customer.param.*;
|
|
|
+import vip.xiaonuo.biz.modular.customer.service.BizCustomerAccountService;
|
|
|
import vip.xiaonuo.biz.modular.goodsConf.entity.BizGoodsConf;
|
|
|
import vip.xiaonuo.biz.modular.goodsConf.enums.BizGoodsConfEnum;
|
|
|
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;
|
|
@@ -57,6 +60,23 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class BizCustomerServiceImpl extends ServiceImpl<BizCustomerMapper, BizCustomer> implements BizCustomerService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SysUserApi sysUserApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BizUserMapper bizUserMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DevConfigApi devConfigApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BizUserService bizUserService;
|
|
|
+
|
|
|
+ private static final String SNOWY_SYS_DEFAULT_PASSWORD_KEY = "SNOWY_SYS_DEFAULT_PASSWORD";
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BizCustomerAccountService bizCustomerAccountService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<BizCustomer> page(BizCustomerPageParam bizCustomerPageParam) {
|
|
|
QueryWrapper<BizCustomer> queryWrapper = new QueryWrapper<BizCustomer>().checkSqlInjection();
|
|
@@ -112,6 +132,41 @@ public class BizCustomerServiceImpl extends ServiceImpl<BizCustomerMapper, BizCu
|
|
|
}
|
|
|
BizCustomer bizCustomer = BeanUtil.toBean(bizCustomerAddParam, BizCustomer.class);
|
|
|
this.save(bizCustomer);
|
|
|
+
|
|
|
+ if(ObjectUtil.isNotEmpty(bizCustomerAddParam.getPhone())){
|
|
|
+ addAccount(bizCustomer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addAccount(BizCustomer bizCustomer){
|
|
|
+
|
|
|
+ //根据账号是否存在
|
|
|
+ BizUser user = bizUserService.getOne(new QueryWrapper<BizUser>().lambda().
|
|
|
+ eq(BizUser::getAccount, bizCustomer.getPhone()).
|
|
|
+ last("limit 1"));
|
|
|
+ if(ObjectUtil.isNotNull(user)){
|
|
|
+ throw new CommonException("客户手机号已经存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加客户登录账号
|
|
|
+ BizUser bizUser = new BizUser();
|
|
|
+ bizUser.setCustomerId(bizCustomer.getId());
|
|
|
+ bizUser.setName(bizCustomer.getPhone());
|
|
|
+ bizUser.setAccount(bizCustomer.getPhone());
|
|
|
+ bizUser.setUserType("1");
|
|
|
+ // 设置密码
|
|
|
+ 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(), "客户");
|
|
|
+
|
|
|
+ BizCustomerAccount bizCustomerAccount = new BizCustomerAccount();
|
|
|
+ bizCustomerAccount.setCustomerId(bizCustomer.getId());
|
|
|
+ bizCustomerAccount.setLoginAccount(bizCustomer.getPhone());
|
|
|
+ bizCustomerAccountService.save(bizCustomerAccount);
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -135,6 +190,10 @@ public class BizCustomerServiceImpl extends ServiceImpl<BizCustomerMapper, BizCu
|
|
|
}
|
|
|
BizCustomer bizCustomer = BeanUtil.toBean(bizCustomerYongAddParam, BizCustomer.class);
|
|
|
this.save(bizCustomer);
|
|
|
+
|
|
|
+ if(ObjectUtil.isNotEmpty(bizCustomerYongAddParam.getPhone())){
|
|
|
+ addAccount(bizCustomer);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|