Эх сурвалжийг харах

增加店铺时,生成对应的部门和用户

baolei 6 сар өмнө
parent
commit
8834c5c99f

+ 7 - 3
08.src/Xingxi/xingxi-admin/src/main/java/com/xingxi/web/controller/master/merchant/controller/MerchantController.java

@@ -10,6 +10,8 @@ import com.xingxi.common.exception.BusinessException;
 import com.xingxi.common.utils.poi.ExcelUtil;
 import com.xingxi.master.merchant.domain.Merchant;
 import com.xingxi.master.merchant.service.IMerchantService;
+import com.xingxi.web.controller.master.merchant.domain.MerchantVo;
+import com.xingxi.web.controller.master.merchant.service.IMerchantVoService;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
@@ -31,6 +33,8 @@ public class MerchantController extends BaseController {
 
     @Resource
     private IMerchantService merchantService;
+    @Resource
+    private IMerchantVoService merchantVoService;
 
     @RequiresPermissions("master:merchant:view")
     @GetMapping()
@@ -79,17 +83,17 @@ public class MerchantController extends BaseController {
     @Log(title = "商户", businessType = BusinessType.INSERT)
     @PostMapping("/add")
     @ResponseBody
-    public AjaxResult addSave(Merchant merchant) {
+    public AjaxResult addSave(MerchantVo merchantVo) {
         Merchant cond;
         List<Merchant> checkResult;
         cond = new Merchant();
-        cond.setMercName(merchant.getMercName());
+        cond.setMercName(merchantVo.getMercName());
         cond.setDelFlag(EDelFlag.NO.getVal());
         checkResult = merchantService.selectMerchantList(cond);
         if (checkResult.size() > 0) {
             throw new BusinessException("商户名已存在!");
         }
-        return toAjax(merchantService.insertMerchant(merchant));
+        return toAjax(merchantVoService.insertMerchantVo(merchantVo));
     }
 
     /**

+ 21 - 0
08.src/Xingxi/xingxi-admin/src/main/java/com/xingxi/web/controller/master/merchant/domain/MerchantVo.java

@@ -0,0 +1,21 @@
+package com.xingxi.web.controller.master.merchant.domain;
+
+import com.xingxi.master.merchant.domain.Merchant;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+
+/**
+ * 店铺对象 MerchantVo
+ *
+ * @author xingxi
+ * @date 2025-05-21
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString
+public class MerchantVo extends Merchant {
+    private static final long serialVersionUID = 1L;
+
+
+}

+ 15 - 0
08.src/Xingxi/xingxi-admin/src/main/java/com/xingxi/web/controller/master/merchant/mapper/MerchantVoMapper.java

@@ -0,0 +1,15 @@
+package com.xingxi.web.controller.master.merchant.mapper;
+
+import com.xingxi.master.merchant.mapper.MerchantMapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * 店铺商品Mapper接口
+ *
+ * @author xingxi
+ * @date 2025-03-06
+ */
+@Repository
+public interface MerchantVoMapper extends MerchantMapper {
+
+}

+ 21 - 0
08.src/Xingxi/xingxi-admin/src/main/java/com/xingxi/web/controller/master/merchant/service/IMerchantVoService.java

@@ -0,0 +1,21 @@
+package com.xingxi.web.controller.master.merchant.service;
+
+import com.xingxi.web.controller.master.merchant.domain.MerchantVo;
+
+/**
+ * 店铺Service接口
+ *
+ * @author xingxi
+ * @date 2025-03-06
+ */
+public interface IMerchantVoService {
+
+    /**
+     * 新增店铺
+     *
+     * @param merchantVo 店铺Vo
+     * @return 结果
+     */
+    int insertMerchantVo(MerchantVo merchantVo);
+
+}

+ 153 - 0
08.src/Xingxi/xingxi-admin/src/main/java/com/xingxi/web/controller/master/merchant/service/impl/MerchantVoServiceImpl.java

@@ -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;
+    }
+}

+ 9 - 0
08.src/Xingxi/xingxi-admin/src/main/resources/templates/system/dept/add.html

@@ -55,6 +55,15 @@
 					</div>
 				</div>
 			</div>
+			<div class="form-group">
+				<label class="col-sm-3 control-label">部门区分:</label>
+				<div class="col-sm-8">
+					<select class="form-control" name="deptType" th:with="depttype=${@dict.getType('dept_type')}" required>
+						<option value="">请选择</option>
+						<option th:each="dict : ${depttype}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
+					</select>
+				</div>
+			</div>
 		</form>
 	</div>
 	<th:block th:include="include :: footer" />

+ 15 - 0
08.src/Xingxi/xingxi-admin/src/main/resources/templates/system/dept/dept.html

@@ -20,6 +20,12 @@
 								</select>
 							</li>
 							<li>
+								部门区分:<select name="deptType" th:with="depttype=${@dict.getType('dept_type')}">
+								<option value="">所有</option>
+								<option th:each="dict : ${depttype}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
+							</select>
+							</li>
+							<li>
 								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
 								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
 							</li>
@@ -50,6 +56,7 @@
 		var editFlag = [[${@permission.hasPermi('system:dept:edit')}]];
 		var removeFlag = [[${@permission.hasPermi('system:dept:remove')}]];
 		var datas = [[${@dict.getType('sys_normal_disable')}]];
+		var typeDatas = [[${@dict.getType('dept_type')}]];
 		var prefix = ctx + "system/dept"
 
 		$(function() {
@@ -84,6 +91,14 @@
 		            	return $.table.selectDictLabel(datas, item.status);
 		            }
 		        },
+				{
+					field: 'deptType',
+					title: '部门区分',
+					align: "left",
+					formatter: function(value, item, index) {
+						return $.table.selectDictLabel(typeDatas, item.deptType);
+					}
+				},
 		        {
 		            field: 'createTime',
 		            title: '创建时间',

+ 9 - 0
08.src/Xingxi/xingxi-admin/src/main/resources/templates/system/dept/edit.html

@@ -56,6 +56,15 @@
 					</div>
 				</div>
 			</div>
+			<div class="form-group">
+				<label class="col-sm-3 control-label">部门区分:</label>
+				<div class="col-sm-8">
+					<select class="form-control" name="deptType" th:with="depttype=${@dict.getType('dept_type')}" required>
+						<option value="">请选择</option>
+						<option th:each="dict : ${depttype}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{deptType}"></option>
+					</select>
+				</div>
+			</div>
 		</form>
 	</div>
 	<th:block th:include="include :: footer" />

+ 4 - 0
08.src/Xingxi/xingxi-common/src/main/java/com/xingxi/common/constant/Constants.java

@@ -119,4 +119,8 @@ public class Constants
      */
     public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
             "org.springframework", "org.apache", "com.xingxi.common.utils.file", "com.xingxi.common.config", "com.xingxi.generator" };
+
+    /** 平台ID */
+    public static final Long PLATFORM_ID = 100L;
+
 }

+ 12 - 0
08.src/Xingxi/xingxi-common/src/main/java/com/xingxi/common/core/domain/entity/SysDept.java

@@ -30,6 +30,9 @@ public class SysDept extends BaseEntity
     /** 部门名称 */
     private String deptName;
 
+    /** 部门分类 */
+    private String deptType;
+
     /** 显示顺序 */
     private Integer orderNum;
 
@@ -96,6 +99,15 @@ public class SysDept extends BaseEntity
         this.deptName = deptName;
     }
 
+    public String getDeptType()
+    {
+        return deptType;
+    }
+    public void setDeptType(String deptType)
+    {
+        this.deptType = deptType;
+    }
+
     @NotNull(message = "显示顺序不能为空")
     public Integer getOrderNum()
     {

+ 27 - 0
08.src/Xingxi/xingxi-common/src/main/java/com/xingxi/common/enums/EConfigKeys.java

@@ -0,0 +1,27 @@
+package com.xingxi.common.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @program: biandan
+ * @description: 系统配置
+ * @author: dong
+ * @create: 2022-02-25 11:12
+ */
+@AllArgsConstructor
+@Getter
+public enum EConfigKeys {
+    USER_INIT_PWD("sys.user.initPassword", "用户管理-账号初始密码"),
+    PF_MERC_ID("pf.merc.id", "平台直属商户ID"),
+    PF_USER_ID("pf.user.id", "平台分润用户ID"),
+    INVOICE_SHDZFP_BMBBBH("invoice.shdzfp.bmbbbh","税收分类编码版本号"),
+    ORDER_CONFIRM_RECEIPT_PERIOD("order.comfirm.receipt.period","订单系统定时确认收货期限(天)"),
+    ORDER_FINISHED_PERIOD("order.finished.period","订单无理由售后期限期限(天)"),
+    MERC_APPLY_STATE_QUERY_PERIOD("merc.apply.state.query.period","商户进件结果查询期限(月)"),
+    INVOICE_PRIVATE_PERIOD("invoice.private.period","批量开具个人发票周期跨度(月)");
+
+    private String val;
+    private String desc;
+
+}

+ 32 - 0
08.src/Xingxi/xingxi-common/src/main/java/com/xingxi/common/enums/EDeptType.java

@@ -0,0 +1,32 @@
+package com.xingxi.common.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @program: biandan
+ * @description: 部门分类
+ * @author: bao
+ * @create: 2022-02-14
+ */
+@AllArgsConstructor
+@Getter
+public enum EDeptType {
+    PLATFORM("PLATFORM", "平台"),
+    MERCHANT("MERCHANT", "经销商"),
+    VENDOR("VENDOR", "供应商"),
+    CUSTOMER("CUSTOMER","终端用户");
+
+    private String val;
+    private String desc;
+
+    /** 解析 */
+    public static EDeptType parseByVal(String val) {
+        for(EDeptType type : EDeptType.values()) {
+            if(type.getVal().equalsIgnoreCase(val)) {
+                return type;
+            }
+        }
+        return EDeptType.PLATFORM;
+    }
+}

+ 10 - 3
08.src/Xingxi/xingxi-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -9,6 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="parentId"   column="parent_id"   />
 		<result property="ancestors"  column="ancestors"   />
 		<result property="deptName"   column="dept_name"   />
+		<result property="deptType"   column="deptType"   />
 		<result property="orderNum"   column="order_num"   />
 		<result property="leader"     column="leader"      />
 		<result property="phone"      column="phone"       />
@@ -23,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</resultMap>
 	
 	<sql id="selectDeptVo">
-        select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time 
+        select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.deptType, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
         from sys_dept d
     </sql>
     
@@ -47,6 +48,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<if test="deptName != null and deptName != ''">
 			AND dept_name like concat('%', #{deptName}, '%')
 		</if>
+		<if test="deptType != null and deptType != ''">
+			AND deptType = #{deptType}
+		</if>
 		<if test="status != null and status != ''">
 			AND status = #{status}
 		</if>
@@ -72,7 +76,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
 
 	<select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
-		select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
+		select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.deptType, d.order_num, d.leader, d.phone, d.email, d.status,
 			(select dept_name from sys_dept where dept_id = d.parent_id) parent_name
 		from sys_dept d
 		where d.dept_id = #{deptId}
@@ -86,11 +90,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
 	</select>
 	
-	<insert id="insertDept" parameterType="SysDept">
+	<insert id="insertDept" parameterType="SysDept" useGeneratedKeys="true" keyProperty="deptId">
  		insert into sys_dept(
  			<if test="deptId != null and deptId != 0">dept_id,</if>
  			<if test="parentId != null and parentId != 0">parent_id,</if>
  			<if test="deptName != null and deptName != ''">dept_name,</if>
+			<if test="deptType != null and deptType != ''">deptType,</if>
  			<if test="ancestors != null and ancestors != ''">ancestors,</if>
  			<if test="orderNum != null">order_num,</if>
  			<if test="leader != null and leader != ''">leader,</if>
@@ -103,6 +108,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="deptId != null and deptId != 0">#{deptId},</if>
  			<if test="parentId != null and parentId != 0">#{parentId},</if>
  			<if test="deptName != null and deptName != ''">#{deptName},</if>
+			<if test="deptType != null and deptType != ''">#{deptType},</if>
  			<if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  			<if test="orderNum != null">#{orderNum},</if>
  			<if test="leader != null and leader != ''">#{leader},</if>
@@ -119,6 +125,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  		<set>
  			<if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  			<if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
+			<if test="deptType != null and deptType != ''">deptType = #{deptType},</if>
  			<if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  			<if test="orderNum != null">order_num = #{orderNum},</if>
  			<if test="leader != null">leader = #{leader},</if>