|
|
@@ -0,0 +1,153 @@
|
|
|
+package com.xingxi.web.controller.master.merchant.service.impl;
|
|
|
+
|
|
|
+import com.xingxi.common.constant.Constants;
|
|
|
+import com.xingxi.common.core.domain.entity.SysDept;
|
|
|
+import com.xingxi.common.core.domain.entity.SysUser;
|
|
|
+import com.xingxi.common.core.text.Convert;
|
|
|
+import com.xingxi.common.enums.*;
|
|
|
+import com.xingxi.common.exception.BusinessException;
|
|
|
+import com.xingxi.common.utils.DateUtils;
|
|
|
+import com.xingxi.common.utils.ShiroUtils;
|
|
|
+import com.xingxi.common.utils.StringUtils;
|
|
|
+import com.xingxi.framework.shiro.service.SysPasswordService;
|
|
|
+import com.xingxi.framework.web.service.ConfigService;
|
|
|
+import com.xingxi.master.merchant.domain.MerchantProd;
|
|
|
+import com.xingxi.system.domain.SysUserRole;
|
|
|
+import com.xingxi.system.mapper.SysDeptMapper;
|
|
|
+import com.xingxi.system.mapper.SysRoleMapper;
|
|
|
+import com.xingxi.system.mapper.SysUserMapper;
|
|
|
+import com.xingxi.system.mapper.SysUserRoleMapper;
|
|
|
+import com.xingxi.web.controller.master.merchant.domain.MerchantProdVo;
|
|
|
+import com.xingxi.web.controller.master.merchant.domain.MerchantVo;
|
|
|
+import com.xingxi.web.controller.master.merchant.mapper.MerchantProdVoMapper;
|
|
|
+import com.xingxi.web.controller.master.merchant.mapper.MerchantVoMapper;
|
|
|
+import com.xingxi.web.controller.master.merchant.service.IMerchantVoService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 店铺商品Service业务层处理
|
|
|
+ *
|
|
|
+ * @author xingxi
|
|
|
+ * @date 2025-03-06
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class MerchantVoServiceImpl implements IMerchantVoService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private MerchantVoMapper merchantVoMapper;
|
|
|
+ @Resource
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
+ @Resource
|
|
|
+ private SysDeptMapper deptMapper;
|
|
|
+ @Resource
|
|
|
+ private SysPasswordService passwordService;
|
|
|
+ @Resource
|
|
|
+ private ConfigService configService;
|
|
|
+ @Resource
|
|
|
+ private SysRoleMapper sysRoleMapper;
|
|
|
+ @Resource
|
|
|
+ private SysUserRoleMapper userRoleMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int insertMerchantVo(MerchantVo merchantVo) {
|
|
|
+
|
|
|
+ int rtn = 0;
|
|
|
+
|
|
|
+ // 创建部门
|
|
|
+ SysDept newDept = new SysDept();
|
|
|
+ newDept.setParentId(Constants.PLATFORM_ID);
|
|
|
+ newDept.setAncestors("0,100");
|
|
|
+ newDept.setDeptName(merchantVo.getMercName());
|
|
|
+ newDept.setDeptType(EDeptType.MERCHANT.getVal());
|
|
|
+ newDept.setOrderNum(999);
|
|
|
+ newDept.setLeader(merchantVo.getContact());
|
|
|
+ newDept.setPhone(merchantVo.getMobile());
|
|
|
+ newDept.setEmail(merchantVo.getMail());
|
|
|
+ newDept.setStatus(EYesNo.NO.getVal());
|
|
|
+ newDept.setDelFlag(EDelFlag.NO.getVal());
|
|
|
+ newDept.setCreateTime(merchantVo.getCreateTime());
|
|
|
+ newDept.setCreateUser(merchantVo.getCreateUser());
|
|
|
+ newDept.setUpdateTime(merchantVo.getUpdateTime());
|
|
|
+ newDept.setUpdateUser(merchantVo.getUpdateUser());
|
|
|
+ rtn = deptMapper.insertDept(newDept);
|
|
|
+
|
|
|
+ merchantVo.setMercId(newDept.getDeptId());
|
|
|
+
|
|
|
+ merchantVo.setDelFlag(EDelFlag.NO.getVal());
|
|
|
+ merchantVo.setCreateUser(ShiroUtils.getLoginName());
|
|
|
+ merchantVo.setCreateTime(DateUtils.getNowDate());
|
|
|
+
|
|
|
+ rtn = rtn + merchantVoMapper.insertMerchant(merchantVo);
|
|
|
+
|
|
|
+ // 创建登录用户
|
|
|
+ // 校验手机号是否已经作为登录名存在
|
|
|
+ if (sysUserMapper.selectUserByPhoneNumber(merchantVo.getMobile()) != null) {
|
|
|
+ throw new BusinessException("手机号已在平台注册过,请更换手机号!");
|
|
|
+ }
|
|
|
+ SysUser loginUser = new SysUser();
|
|
|
+ loginUser.setDelFlag(EDelFlag.NO.getVal());
|
|
|
+ loginUser.setDeptId(newDept.getDeptId());
|
|
|
+ loginUser.setLoginName(merchantVo.getMobile());
|
|
|
+ loginUser.setUserName(merchantVo.getMercName());
|
|
|
+ loginUser.setUserType(EUserType.ORDINARY.getVal());
|
|
|
+ loginUser.setEmail(merchantVo.getMail());
|
|
|
+ // 性别未知
|
|
|
+ loginUser.setSex("2");
|
|
|
+ loginUser.setPhonenumber(merchantVo.getMobile());
|
|
|
+ loginUser.setSalt(ShiroUtils.randomSalt());
|
|
|
+ loginUser.setPassword(passwordService.encryptPassword(loginUser.getLoginName(),
|
|
|
+ configService.getKey(EConfigKeys.USER_INIT_PWD.getVal()), loginUser.getSalt()));
|
|
|
+ loginUser.setStatus(UserStatus.DISABLE.getCode());
|
|
|
+ loginUser.setCreateUser(merchantVo.getCreateUser());
|
|
|
+ loginUser.setCreateTime(merchantVo.getCreateTime());
|
|
|
+ loginUser.setUpdateUser(merchantVo.getUpdateUser());
|
|
|
+ loginUser.setUpdateTime(merchantVo.getUpdateTime());
|
|
|
+ Long[] roleIds = new Long[1];
|
|
|
+ roleIds[0] = sysRoleMapper.checkRoleKeyUnique(ERoleKey.MERCHANT.getCode()).getRoleId();
|
|
|
+ loginUser.setRoleIds(roleIds);
|
|
|
+ // 新增用户信息
|
|
|
+ int userRows = sysUserMapper.insertUser(loginUser);
|
|
|
+ if (userRows < 1) {
|
|
|
+ throw new BusinessException("用户信息更新失败!");
|
|
|
+ } else {
|
|
|
+ rtn += userRows;
|
|
|
+ }
|
|
|
+ // 新增用户与角色管理
|
|
|
+ int roleRows = insertUserRole(loginUser.getUserId(), loginUser.getRoleIds());
|
|
|
+ if (roleRows < 1) {
|
|
|
+ throw new BusinessException("用户权限更新失败!");
|
|
|
+ } else {
|
|
|
+ rtn += roleRows;
|
|
|
+ }
|
|
|
+
|
|
|
+ return rtn;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增用户角色信息
|
|
|
+ *
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @param roleIds 角色组
|
|
|
+ */
|
|
|
+ private int insertUserRole(Long userId, Long[] roleIds) {
|
|
|
+ int ret = 0;
|
|
|
+ if (StringUtils.isNotNull(roleIds)) {
|
|
|
+ // 新增用户与角色管理
|
|
|
+ List<SysUserRole> list = new ArrayList<>();
|
|
|
+ for (Long roleId : roleIds) {
|
|
|
+ SysUserRole ur = new SysUserRole();
|
|
|
+ ur.setUserId(userId);
|
|
|
+ ur.setRoleId(roleId);
|
|
|
+ list.add(ur);
|
|
|
+ }
|
|
|
+ if (list.size() > 0) {
|
|
|
+ ret = userRoleMapper.batchUserRole(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+}
|