feat(warehouse): 仓库管理模块增加负责人选择功能

- 在新增和编辑页面将负责人输入框改为下拉选择,集成Select2组件
- 添加负责人用户ID字段到AmsWarehouse实体类并完善getter/setter方法
- 在数据库映射文件中增加manager_user_id字段的映射和查询条件
- 控制器中注入用户服务并提供正常用户列表供选择
- 服务实现中添加负责人快照行为,确保负责人信息一致性
- 列表页面搜索条件改为负责人下拉选择,提升用户体验
- 联系电话字段设置为只读,通过负责人选择自动填充
- 实现选择负责人时自动填充联系电话的功能逻辑
main
yangk 1 month ago
parent 7de57b4994
commit 69da08a942

@ -18,9 +18,11 @@ import com.ruoyi.asset.service.IAmsWarehouseService;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.ISysDeptService; import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
/** /**
* Controller * Controller
@ -40,11 +42,15 @@ public class AmsWarehouseController extends BaseController
@Autowired @Autowired
private ISysDeptService sysDeptService; private ISysDeptService sysDeptService;
@Autowired
private ISysUserService sysUserService;
@RequiresPermissions("asset:warehouse:view") @RequiresPermissions("asset:warehouse:view")
@GetMapping() @GetMapping()
public String warehouse(ModelMap mmap) public String warehouse(ModelMap mmap)
{ {
mmap.put("deptList", selectNormalDeptList()); mmap.put("deptList", selectNormalDeptList());
mmap.put("userList", selectNormalUserList());
return prefix + "/warehouse"; return prefix + "/warehouse";
} }
@ -95,6 +101,7 @@ public class AmsWarehouseController extends BaseController
public String add(ModelMap mmap) public String add(ModelMap mmap)
{ {
mmap.put("deptList", selectNormalDeptList()); mmap.put("deptList", selectNormalDeptList());
mmap.put("userList", selectNormalUserList());
return prefix + "/add"; return prefix + "/add";
} }
@ -125,6 +132,7 @@ public class AmsWarehouseController extends BaseController
AmsWarehouse amsWarehouse = amsWarehouseService.selectAmsWarehouseByWarehouseId(warehouseId); AmsWarehouse amsWarehouse = amsWarehouseService.selectAmsWarehouseByWarehouseId(warehouseId);
mmap.put("amsWarehouse", amsWarehouse); mmap.put("amsWarehouse", amsWarehouse);
mmap.put("deptList", selectNormalDeptList()); mmap.put("deptList", selectNormalDeptList());
mmap.put("userList", selectNormalUserList());
return prefix + "/edit"; return prefix + "/edit";
} }
@ -166,4 +174,14 @@ public class AmsWarehouseController extends BaseController
dept.setStatus(UserConstants.DEPT_NORMAL); dept.setStatus(UserConstants.DEPT_NORMAL);
return sysDeptService.selectDeptList(dept); return sysDeptService.selectDeptList(dept);
} }
/**
*
*/
private List<SysUser> selectNormalUserList()
{
SysUser user = new SysUser();
user.setStatus(UserConstants.NORMAL);
return sysUserService.selectUserList(user);
}
} }

@ -37,6 +37,9 @@ public class AmsWarehouse extends BaseEntity
@Excel(name = "仓库地址") @Excel(name = "仓库地址")
private String warehouseAddress; private String warehouseAddress;
/** 负责人用户ID */
private Long managerUserId;
/** 负责人 */ /** 负责人 */
@Excel(name = "负责人") @Excel(name = "负责人")
private String managerName; private String managerName;
@ -112,6 +115,16 @@ public class AmsWarehouse extends BaseEntity
return warehouseAddress; return warehouseAddress;
} }
public void setManagerUserId(Long managerUserId)
{
this.managerUserId = managerUserId;
}
public Long getManagerUserId()
{
return managerUserId;
}
public void setManagerName(String managerName) public void setManagerName(String managerName)
{ {
this.managerName = managerName; this.managerName = managerName;
@ -161,6 +174,7 @@ public class AmsWarehouse extends BaseEntity
.append("manageDeptId", getManageDeptId()) .append("manageDeptId", getManageDeptId())
.append("manageDeptName", getManageDeptName()) .append("manageDeptName", getManageDeptName())
.append("warehouseAddress", getWarehouseAddress()) .append("warehouseAddress", getWarehouseAddress())
.append("managerUserId", getManagerUserId())
.append("managerName", getManagerName()) .append("managerName", getManagerName())
.append("contactPhone", getContactPhone()) .append("contactPhone", getContactPhone())
.append("enabled", getEnabled()) .append("enabled", getEnabled())

@ -3,6 +3,7 @@ package com.ruoyi.asset.service.impl;
import java.util.List; import java.util.List;
import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
@ -13,6 +14,7 @@ import com.ruoyi.asset.domain.AmsWarehouse;
import com.ruoyi.asset.service.IAmsWarehouseService; import com.ruoyi.asset.service.IAmsWarehouseService;
import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.text.Convert;
import com.ruoyi.system.service.ISysDeptService; import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
/** /**
* Service * Service
@ -33,6 +35,9 @@ public class AmsWarehouseServiceImpl implements IAmsWarehouseService
@Autowired @Autowired
private ISysDeptService sysDeptService; private ISysDeptService sysDeptService;
@Autowired
private ISysUserService sysUserService;
/** /**
* *
* *
@ -93,6 +98,7 @@ public class AmsWarehouseServiceImpl implements IAmsWarehouseService
amsWarehouse.setEnabled(ENABLED_YES); amsWarehouse.setEnabled(ENABLED_YES);
} }
fillManageDeptName(amsWarehouse); fillManageDeptName(amsWarehouse);
fillManagerUserSnapshot(amsWarehouse);
amsWarehouse.setDelFlag(DEL_FLAG_NORMAL); amsWarehouse.setDelFlag(DEL_FLAG_NORMAL);
amsWarehouse.setCreateTime(DateUtils.getNowDate()); amsWarehouse.setCreateTime(DateUtils.getNowDate());
return amsWarehouseMapper.insertAmsWarehouse(amsWarehouse); return amsWarehouseMapper.insertAmsWarehouse(amsWarehouse);
@ -108,6 +114,7 @@ public class AmsWarehouseServiceImpl implements IAmsWarehouseService
public int updateAmsWarehouse(AmsWarehouse amsWarehouse) public int updateAmsWarehouse(AmsWarehouse amsWarehouse)
{ {
fillManageDeptName(amsWarehouse); fillManageDeptName(amsWarehouse);
fillManagerUserSnapshot(amsWarehouse);
amsWarehouse.setUpdateTime(DateUtils.getNowDate()); amsWarehouse.setUpdateTime(DateUtils.getNowDate());
return amsWarehouseMapper.updateAmsWarehouse(amsWarehouse); return amsWarehouseMapper.updateAmsWarehouse(amsWarehouse);
} }
@ -175,4 +182,28 @@ public class AmsWarehouseServiceImpl implements IAmsWarehouseService
} }
amsWarehouse.setManageDeptName(deptList.get(0).getDeptName()); amsWarehouse.setManageDeptName(deptList.get(0).getDeptName());
} }
/**
* ID
*/
private void fillManagerUserSnapshot(AmsWarehouse amsWarehouse)
{
if (StringUtils.isNull(amsWarehouse.getManagerUserId()))
{
amsWarehouse.setManagerName(null);
amsWarehouse.setContactPhone(null);
return;
}
SysUser user = sysUserService.selectUserById(amsWarehouse.getManagerUserId());
if (StringUtils.isNull(user)
|| !StringUtils.equals(UserConstants.NORMAL, user.getStatus())
|| !StringUtils.equals(DEL_FLAG_NORMAL, user.getDelFlag()))
{
throw new ServiceException("负责人不存在或已停用");
}
amsWarehouse.setManagerName(user.getUserName());
// 联系电话跟随负责人手机号,避免前端手工填写导致负责人和电话不一致。
amsWarehouse.setContactPhone(StringUtils.isEmpty(user.getPhonenumber()) ? null : user.getPhonenumber());
}
} }

@ -11,6 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="manageDeptId" column="manage_dept_id" /> <result property="manageDeptId" column="manage_dept_id" />
<result property="manageDeptName" column="manage_dept_name" /> <result property="manageDeptName" column="manage_dept_name" />
<result property="warehouseAddress" column="warehouse_address" /> <result property="warehouseAddress" column="warehouse_address" />
<result property="managerUserId" column="manager_user_id" />
<result property="managerName" column="manager_name" /> <result property="managerName" column="manager_name" />
<result property="contactPhone" column="contact_phone" /> <result property="contactPhone" column="contact_phone" />
<result property="enabled" column="enabled" /> <result property="enabled" column="enabled" />
@ -23,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectAmsWarehouseVo"> <sql id="selectAmsWarehouseVo">
select warehouse_id, warehouse_code, warehouse_name, manage_dept_id, manage_dept_name, warehouse_address, manager_name, contact_phone, enabled, create_by, create_time, update_by, update_time, remark, del_flag from ams_warehouse select warehouse_id, warehouse_code, warehouse_name, manage_dept_id, manage_dept_name, warehouse_address, manager_user_id, manager_name, contact_phone, enabled, create_by, create_time, update_by, update_time, remark, del_flag from ams_warehouse
</sql> </sql>
<select id="selectAmsWarehouseList" parameterType="AmsWarehouse" resultMap="AmsWarehouseResult"> <select id="selectAmsWarehouseList" parameterType="AmsWarehouse" resultMap="AmsWarehouseResult">
@ -34,6 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="warehouseName != null and warehouseName != ''"> and warehouse_name like concat('%', #{warehouseName}, '%')</if> <if test="warehouseName != null and warehouseName != ''"> and warehouse_name like concat('%', #{warehouseName}, '%')</if>
<if test="manageDeptId != null"> and manage_dept_id = #{manageDeptId}</if> <if test="manageDeptId != null"> and manage_dept_id = #{manageDeptId}</if>
<if test="warehouseAddress != null and warehouseAddress != ''"> and warehouse_address = #{warehouseAddress}</if> <if test="warehouseAddress != null and warehouseAddress != ''"> and warehouse_address = #{warehouseAddress}</if>
<if test="managerUserId != null"> and manager_user_id = #{managerUserId}</if>
<if test="managerName != null and managerName != ''"> and manager_name like concat('%', #{managerName}, '%')</if> <if test="managerName != null and managerName != ''"> and manager_name like concat('%', #{managerName}, '%')</if>
<if test="contactPhone != null and contactPhone != ''"> and contact_phone = #{contactPhone}</if> <if test="contactPhone != null and contactPhone != ''"> and contact_phone = #{contactPhone}</if>
<if test="enabled != null and enabled != ''"> and enabled = #{enabled}</if> <if test="enabled != null and enabled != ''"> and enabled = #{enabled}</if>
@ -73,6 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="manageDeptId != null">manage_dept_id,</if> <if test="manageDeptId != null">manage_dept_id,</if>
<if test="manageDeptName != null">manage_dept_name,</if> <if test="manageDeptName != null">manage_dept_name,</if>
<if test="warehouseAddress != null">warehouse_address,</if> <if test="warehouseAddress != null">warehouse_address,</if>
<if test="managerUserId != null">manager_user_id,</if>
<if test="managerName != null">manager_name,</if> <if test="managerName != null">manager_name,</if>
<if test="contactPhone != null">contact_phone,</if> <if test="contactPhone != null">contact_phone,</if>
<if test="enabled != null and enabled != ''">enabled,</if> <if test="enabled != null and enabled != ''">enabled,</if>
@ -89,6 +92,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="manageDeptId != null">#{manageDeptId},</if> <if test="manageDeptId != null">#{manageDeptId},</if>
<if test="manageDeptName != null">#{manageDeptName},</if> <if test="manageDeptName != null">#{manageDeptName},</if>
<if test="warehouseAddress != null">#{warehouseAddress},</if> <if test="warehouseAddress != null">#{warehouseAddress},</if>
<if test="managerUserId != null">#{managerUserId},</if>
<if test="managerName != null">#{managerName},</if> <if test="managerName != null">#{managerName},</if>
<if test="contactPhone != null">#{contactPhone},</if> <if test="contactPhone != null">#{contactPhone},</if>
<if test="enabled != null and enabled != ''">#{enabled},</if> <if test="enabled != null and enabled != ''">#{enabled},</if>
@ -109,7 +113,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
manage_dept_id = #{manageDeptId}, manage_dept_id = #{manageDeptId},
manage_dept_name = #{manageDeptName}, manage_dept_name = #{manageDeptName},
<if test="warehouseAddress != null">warehouse_address = #{warehouseAddress},</if> <if test="warehouseAddress != null">warehouse_address = #{warehouseAddress},</if>
<if test="managerName != null">manager_name = #{managerName},</if> manager_user_id = #{managerUserId},
manager_name = #{managerName},
<if test="contactPhone != null">contact_phone = #{contactPhone},</if> <if test="contactPhone != null">contact_phone = #{contactPhone},</if>
<if test="enabled != null and enabled != ''">enabled = #{enabled},</if> <if test="enabled != null and enabled != ''">enabled = #{enabled},</if>
<if test="createBy != null">create_by = #{createBy},</if> <if test="createBy != null">create_by = #{createBy},</if>

@ -2,6 +2,7 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" > <html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head> <head>
<th:block th:include="include :: header('新增仓库管理')" /> <th:block th:include="include :: header('新增仓库管理')" />
<th:block th:include="include :: select2-css" />
</head> </head>
<body class="white-bg"> <body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content"> <div class="wrapper wrapper-content animated fadeInRight ibox-content">
@ -45,7 +46,10 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-4 control-label">负责人:</label> <label class="col-sm-4 control-label">负责人:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input name="managerName" class="form-control" type="text"> <select id="managerUserId" name="managerUserId" class="form-control">
<option value="">请选择</option>
<option th:each="user : ${userList}" th:text="${user.userName + '' + user.loginName + ''}" th:value="${user.userId}" th:data-phone="${user.phonenumber}"></option>
</select>
</div> </div>
</div> </div>
</div> </div>
@ -53,7 +57,7 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-4 control-label">联系电话:</label> <label class="col-sm-4 control-label">联系电话:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input name="contactPhone" class="form-control" type="text"> <input name="contactPhone" class="form-control" type="text" readonly>
</div> </div>
</div> </div>
</div> </div>
@ -79,8 +83,19 @@
</form> </form>
</div> </div>
<th:block th:include="include :: footer" /> <th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript"> <script th:inline="javascript">
var prefix = ctx + "asset/warehouse" var prefix = ctx + "asset/warehouse"
$("#managerUserId").select2({
placeholder: "请选择负责人",
allowClear: true
}).on("change", fillContactPhone);
function fillContactPhone() {
var phone = $("#managerUserId").find("option:selected").data("phone") || "";
$("input[name='contactPhone']").val(phone);
}
$("#form-warehouse-add").validate({ $("#form-warehouse-add").validate({
focusCleanup: true focusCleanup: true
}); });

@ -2,6 +2,7 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" > <html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head> <head>
<th:block th:include="include :: header('修改仓库管理')" /> <th:block th:include="include :: header('修改仓库管理')" />
<th:block th:include="include :: select2-css" />
</head> </head>
<body class="white-bg"> <body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content"> <div class="wrapper wrapper-content animated fadeInRight ibox-content">
@ -46,7 +47,10 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-4 control-label">负责人:</label> <label class="col-sm-4 control-label">负责人:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input name="managerName" th:field="*{managerName}" class="form-control" type="text"> <select id="managerUserId" name="managerUserId" th:field="*{managerUserId}" class="form-control">
<option value="">请选择</option>
<option th:each="user : ${userList}" th:text="${user.userName + '' + user.loginName + ''}" th:value="${user.userId}" th:data-phone="${user.phonenumber}"></option>
</select>
</div> </div>
</div> </div>
</div> </div>
@ -54,7 +58,7 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-4 control-label">联系电话:</label> <label class="col-sm-4 control-label">联系电话:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input name="contactPhone" th:field="*{contactPhone}" class="form-control" type="text"> <input name="contactPhone" th:field="*{contactPhone}" class="form-control" type="text" readonly>
</div> </div>
</div> </div>
</div> </div>
@ -80,8 +84,19 @@
</form> </form>
</div> </div>
<th:block th:include="include :: footer" /> <th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript"> <script th:inline="javascript">
var prefix = ctx + "asset/warehouse"; var prefix = ctx + "asset/warehouse";
$("#managerUserId").select2({
placeholder: "请选择负责人",
allowClear: true
}).on("change", fillContactPhone);
function fillContactPhone() {
var phone = $("#managerUserId").find("option:selected").data("phone") || "";
$("input[name='contactPhone']").val(phone);
}
$("#form-warehouse-edit").validate({ $("#form-warehouse-edit").validate({
focusCleanup: true focusCleanup: true
}); });

@ -2,6 +2,7 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head> <head>
<th:block th:include="include :: header('仓库管理列表')" /> <th:block th:include="include :: header('仓库管理列表')" />
<th:block th:include="include :: select2-css" />
</head> </head>
<body class="gray-bg"> <body class="gray-bg">
<div class="container-div"> <div class="container-div">
@ -25,17 +26,12 @@
<option th:each="dept : ${deptList}" th:text="${dept.deptName}" th:value="${dept.deptId}"></option> <option th:each="dept : ${deptList}" th:text="${dept.deptName}" th:value="${dept.deptId}"></option>
</select> </select>
</li> </li>
<li>
<label>仓库地址:</label>
<input type="text" name="warehouseAddress"/>
</li>
<li> <li>
<label>负责人:</label> <label>负责人:</label>
<input type="text" name="managerName"/> <select name="managerUserId" class="select2-manager" style="width: 170px">
</li> <option value="">所有</option>
<li> <option th:each="user : ${userList}" th:text="${user.userName + '' + user.loginName + ''}" th:value="${user.userId}"></option>
<label>联系电话:</label> </select>
<input type="text" name="contactPhone"/>
</li> </li>
<li> <li>
<label>启用状态:</label> <label>启用状态:</label>
@ -73,6 +69,7 @@
</div> </div>
</div> </div>
<th:block th:include="include :: footer" /> <th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript"> <script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('asset:warehouse:edit')}]]; var editFlag = [[${@permission.hasPermi('asset:warehouse:edit')}]];
var removeFlag = [[${@permission.hasPermi('asset:warehouse:remove')}]]; var removeFlag = [[${@permission.hasPermi('asset:warehouse:remove')}]];
@ -80,6 +77,11 @@
var prefix = ctx + "asset/warehouse"; var prefix = ctx + "asset/warehouse";
$(function() { $(function() {
$(".select2-manager").select2({
placeholder: "请选择负责人",
allowClear: true
});
var options = { var options = {
url: prefix + "/list", url: prefix + "/list",
viewUrl: prefix + "/view/{id}", viewUrl: prefix + "/view/{id}",

Loading…
Cancel
Save