diff --git a/src/main/java/com/huaheng/common/utils/StringUtils.java b/src/main/java/com/huaheng/common/utils/StringUtils.java index 268ea90..549ad0f 100644 --- a/src/main/java/com/huaheng/common/utils/StringUtils.java +++ b/src/main/java/com/huaheng/common/utils/StringUtils.java @@ -23,6 +23,12 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { */ private static final char SEPARATOR = '_'; + /**objet NULL判断非empty*/ + public static boolean isNullNew(Object object) + { + return object == null; + } + /** * 获取参数不为空值 * @@ -40,7 +46,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { * @return true:为空 false:非空 */ public static boolean isEmpty(Collection<?> coll) { - return isNull(coll) || coll.isEmpty(); + return isNullNew(coll) || coll.isEmpty(); } /** @@ -60,7 +66,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { * * @return true:为空 false:非空 */ public static boolean isEmpty(Object[] objects) { - return isNull(objects) || (objects.length == 0); + return isNullNew(objects) || (objects.length == 0); } /** @@ -80,7 +86,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { * @return true:为空 false:非空 */ public static boolean isEmpty(Map<?, ?> map) { - return isNull(map) || map.isEmpty(); + return isNullNew(map) || map.isEmpty(); } /** @@ -100,7 +106,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { * @return true:为空 false:非空 */ public static boolean isEmpty(String str) { - return isNull(str) || NULLSTR.equals(str.trim()); + return isNullNew(str) || NULLSTR.equals(str.trim()); } /** @@ -173,7 +179,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { * @return true:是数组 false:不是数组 */ public static boolean isArray(Object object) { - return isNotNull(object) && object.getClass().isArray(); + return !isNullNew(object) && object.getClass().isArray(); } /** diff --git a/src/main/java/com/huaheng/pc/system/user/controller/UserController.java b/src/main/java/com/huaheng/pc/system/user/controller/UserController.java index da474b7..1fee396 100644 --- a/src/main/java/com/huaheng/pc/system/user/controller/UserController.java +++ b/src/main/java/com/huaheng/pc/system/user/controller/UserController.java @@ -138,8 +138,8 @@ public class UserController extends BaseController { mmap.put("user", userService.selectUserById(id)); mmap.put("roles", roleService.selectRolesByUserId(id)); - mmap.put("companys", companyService.selectCompanyByUserId(id)); - mmap.put("warehouses", warehouseService.selectWarehouseByUserId(id)); + mmap.put("companyList", companyService.selectCompanyByUserId(id)); + mmap.put("warehouseList", warehouseService.selectWarehouseByUserId(id)); return prefix + "/edit"; } diff --git a/src/main/java/com/huaheng/pc/system/user/domain/UserCompany.java b/src/main/java/com/huaheng/pc/system/user/domain/UserCompany.java index d23522d..1b08dc5 100644 --- a/src/main/java/com/huaheng/pc/system/user/domain/UserCompany.java +++ b/src/main/java/com/huaheng/pc/system/user/domain/UserCompany.java @@ -39,6 +39,47 @@ public class UserCompany{ @TableField(value = "companyCode") private String companyCode; + private String name; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getUserId() { + return userId; + } + + public void setUserId(Integer userId) { + this.userId = userId; + } + + public Integer getCompanyId() { + return companyId; + } + + public void setCompanyId(Integer companyId) { + this.companyId = companyId; + } + + public String getCompanyCode() { + return companyCode; + } + + public void setCompanyCode(String companyCode) { + this.companyCode = companyCode; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/src/main/java/com/huaheng/pc/system/user/service/UserServiceImpl.java b/src/main/java/com/huaheng/pc/system/user/service/UserServiceImpl.java index a37842d..c2fd42c 100644 --- a/src/main/java/com/huaheng/pc/system/user/service/UserServiceImpl.java +++ b/src/main/java/com/huaheng/pc/system/user/service/UserServiceImpl.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.huaheng.common.exception.service.ServiceException; import com.huaheng.framework.web.domain.AjaxResult; import com.huaheng.pc.config.company.domain.Company; import com.huaheng.pc.config.company.mapper.CompanyMapper; @@ -258,14 +259,29 @@ public class UserServiceImpl implements IUserService user.randomSalt(); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); user.setCreateBy(ShiroUtils.getLoginName()); - // 新增用户信息 - int rows = userMapper.insertUser(user); - // 新增用户货主关联 - insertUserCompany(user); - // 新增用户与角色管理 - insertUserRole(user); - // 新增用户与仓库管理 - insertUserWarehouse(user); + //新建用户名不能重复/ + User u = userMapper.selectUserByLoginName(user.getLoginName()); + int rows = 0; + if(!StringUtils.isNull(u)){ + //新增用户时,如果已经有逻辑删除的则是修改 + if(u.getDeleted()){ + user.setId(u.getId()); + user.setDeleted(false); + //修改用户 + rows = this.updateUser(user); + }else{ + throw new ServiceException("用户名重复!"); + } + }else{ + // 新增用户信息 + rows = userMapper.insertUser(user); + // 新增用户货主关联 + this.insertUserCompany(user); + // 新增用户与角色 + this.insertUserRole(user); + // 新增用户与仓库 + this.insertUserWarehouse(user); + } return rows; } diff --git a/src/main/resources/mybatis/config/CompanyMapper.xml b/src/main/resources/mybatis/config/CompanyMapper.xml index 53ecee2..dbfdfe6 100644 --- a/src/main/resources/mybatis/config/CompanyMapper.xml +++ b/src/main/resources/mybatis/config/CompanyMapper.xml @@ -53,8 +53,11 @@ INNER JOIN company c ON suc.companyId = c.id AND suc.userId = #{userId} INNER JOIN warehouse_company wc ON wc.companyId=c.id AND wc.warehouseCode = #{warehouseCode} </select> - <select id="selectByWarehouseCode" resultType="com.huaheng.pc.config.company.domain.Company"> - select c.id, c.name ,c.code from company c INNER JOIN warehouse_company w ON c.id = w.companyId + + <select id="selectByWarehouseCode" resultType="com.huaheng.pc.config.company.domain.Company"> + select c.id , c.code, c.name, c.warehouseCode, c.deleted + from company c + INNER JOIN warehouse_company wc ON c.id = wc.companyId where c.warehouseCode = #{warehouseCode} </select> diff --git a/src/main/resources/mybatis/config/WarehouseMapper.xml b/src/main/resources/mybatis/config/WarehouseMapper.xml index 4a1437e..9d09118 100644 --- a/src/main/resources/mybatis/config/WarehouseMapper.xml +++ b/src/main/resources/mybatis/config/WarehouseMapper.xml @@ -35,21 +35,25 @@ <result column="deleted" jdbcType="BIT" property="deleted" /> </resultMap> <select id="wareHouseAll" resultType="com.huaheng.pc.system.user.domain.SysUserWarehouse"> - select * from warehouse + select code, address1, address2, city, `state`, district, country, postalCode, attentionTo, + phoneNum, faxNum, email, hostCode, `name`, `enable`, orgCode, created, createdBy, + lastUpdated, lastUpdatedBy, version, userDef1, userDef2, userDef3, userDef4, userDef5, + userDef6, userDef7, userDef8, deleted from warehouse </select> - <select id="selectWarehouseByUserId" - resultType="com.huaheng.pc.config.warehouse.domain.Warehouse"> - SELECT r.`name`, r.code - FROM sys_user u - LEFT JOIN sys_user_warehouse ur ON u.id = ur.userId - LEFT JOIN warehouse r ON ur.warehouseCode = r.code + <select id="selectWarehouseByUserId" resultType="com.huaheng.pc.config.warehouse.domain.Warehouse"> + SELECT r.`name`, r.code ,r.enable + FROM sys_user_warehouse ur + LEFT JOIN warehouse r ON r.code = ur.warehouseCode WHERE ur.userId =#{userId} </select> - <select id="selectWarehouseAll" - resultType="com.huaheng.pc.config.warehouse.domain.Warehouse"> - select * from warehouse where deleted =false + <select id="selectWarehouseAll" resultType="com.huaheng.pc.config.warehouse.domain.Warehouse"> + select code, address1, address2, city, `state`, district, country, postalCode, attentionTo, + phoneNum, faxNum, email, hostCode, `name`, `enable`, orgCode, created, createdBy, + lastUpdated, lastUpdatedBy, version, userDef1, userDef2, userDef3, userDef4, userDef5, + userDef6, userDef7, userDef8, deleted + from warehouse where deleted =false </select> diff --git a/src/main/resources/mybatis/system/UserCompanyMapper.xml b/src/main/resources/mybatis/system/UserCompanyMapper.xml index c0686b4..6207be0 100644 --- a/src/main/resources/mybatis/system/UserCompanyMapper.xml +++ b/src/main/resources/mybatis/system/UserCompanyMapper.xml @@ -3,22 +3,23 @@ <mapper namespace="com.huaheng.pc.system.user.mapper.UserCompanyMapper"> <select id="selectListEntityByEqual" resultType="com.huaheng.pc.system.user.domain.UserCompany"> - SELECT id, userId, companyId, companyCode - FROM sys_user_company - <where> - <if test="id != null"> - AND id = #{id} - </if> - <if test="userId != null"> - AND userId = #{userId} - </if> - <if test="companyId != null"> - AND companyId = #{companyId} - </if> - <if test="companyCode != null"> - AND companyCode = #{companyCode} - </if> - </where> + SELECT sc.id, sc.userId, sc.companyId, sc.companyCode, c.name + FROM sys_user_company sc + inner join company c on c.id = sc.companyId + <where> + <if test="id != null"> + AND sc.id = #{id} + </if> + <if test="userId != null"> + AND sc.userId = #{userId} + </if> + <if test="companyId != null"> + AND sc.companyId = #{companyId} + </if> + <if test="companyCode != null"> + AND sc.companyCode = #{companyCode} + </if> + </where> </select> <select id="countUserCompanyById" resultType="java.lang.Integer"> diff --git a/src/main/resources/mybatis/system/UserMapper.xml b/src/main/resources/mybatis/system/UserMapper.xml index 5646090..12f35b1 100644 --- a/src/main/resources/mybatis/system/UserMapper.xml +++ b/src/main/resources/mybatis/system/UserMapper.xml @@ -42,7 +42,8 @@ </sql> <select id="selectUserList" resultMap="UserResult"> - select u.id, u.deptId, u.loginName, u.userName, u.email, u.phoneNumber, u.password, u.sex, u.avatar, u.salt, u.enable, u.deleted, u.loginIp, u.loginDate, u.createBy, u.createTime, u.remark, d.deptName + select u.id, u.deptId, u.loginName, u.userName, u.email, u.phoneNumber, u.password, u.sex, u.avatar, u.salt, u.enable, u.deleted, + u.loginIp, u.loginDate, u.createBy, u.createTime, u.updateTime, u.updateBy, u.remark, d.deptName from sys_user u left join sys_dept d on u.deptId = d.id WHERE u.deleted = false @@ -103,7 +104,8 @@ </select> <select id="selectmen" resultType="com.huaheng.pc.system.user.domain.User"> - select * from sys_user where loginName = #{loginName} + select id, deptId, loginName, userName, email, phoneNumber, password, sex, avatar, salt, enable, deleted, + loginIp, loginDate, createBy, createTime, updateTime, updateBy, remark from sys_user where loginName = #{loginName} </select> <delete id="deleteUserById"> diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css index d601a69..6069f71 100644 --- a/src/main/resources/static/css/style.css +++ b/src/main/resources/static/css/style.css @@ -3341,9 +3341,10 @@ nav.page-tabs .page-tabs-content { color: #999; display: block; } -.xx_box a:hover{ +.xx_box a.xx:hover{ background: #f2f2f2; } + .xx sup{ /*line-height: 12px; padding: 2px 5px;*/ diff --git a/src/main/resources/templates/system/user/add.html b/src/main/resources/templates/system/user/add.html index af521b6..fe0a8a1 100644 --- a/src/main/resources/templates/system/user/add.html +++ b/src/main/resources/templates/system/user/add.html @@ -85,7 +85,7 @@ <label class="col-sm-3 control-label">角色:</label> <div class="col-sm-8"> <label th:each="role:${roles}" class="checkbox-inline i-checks"> - <input name="role" type="checkbox" th:value="${role.id}" th:text="${role.roleName}" th:disabled="${role.enable == false}"> + <input name="role" type="radio" th:value="${role.id}" th:text="${role.roleName}" th:disabled="${role.enable == false}"> </label> </div> </div> @@ -200,7 +200,7 @@ var phoneNumber = $("input[name='phoneNumber']").val(); var sex = $("#sex option:selected").val(); var enable = $("input[name='enable']").is(':checked') == true ? 1 : 0; - var roleIds = $.form.selectCheckeds("role"); + var roleIds = $("input[name='role']").is(':checked') == true ? 1 : 0; var warehouseCodeList = $.form.selectCheckeds("warehouseCode"); var companyIdList = $.form.selectCheckeds("company"); $.ajax({ diff --git a/src/main/resources/templates/system/user/edit.html b/src/main/resources/templates/system/user/edit.html index 3c52036..30a19f6 100644 --- a/src/main/resources/templates/system/user/edit.html +++ b/src/main/resources/templates/system/user/edit.html @@ -61,18 +61,18 @@ <div class="form-group"> <label class="col-sm-3 control-label">货主:</label> <div class="col-sm-8"> - <label th:each="company:${companys}" class="checkbox-inline i-checks"> - <input name="company" type="checkbox" th:value="${company.id}" th:text=" ${company.name}" th:checked="${company.flag}" > - </label> + <label th:each="company:${companyList}" class="checkbox-inline i-checks"> + <input name="company" id ="company" type="checkbox" th:value="${company.id}" th:text=" ${company.name}" th:checked="${company.flag}" th:disabled="${company.deleted == true}"> + </label> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label">仓库:</label> <div class="col-sm-8"> - <label th:each="warehouse:${warehouses}" class="checkbox-inline i-checks"> - <input name="warehouse" type="checkbox" th:value="${warehouse.code}" th:text="${warehouse.name}" th:checked="${warehouse.flag}" th:disabled="${warehouse.enable == false}"> - </label> + <label th:each="warehouse:${warehouseList}" class="checkbox-inline i-checks"> + <input name="warehouse" id ="warehouse" type="checkbox" th:value="${warehouse.code}" th:text="${warehouse.name}" th:checked="${warehouse.flag}" th:disabled="${warehouse.enable == true}"> + </label> </div> </div> @@ -80,7 +80,7 @@ <label class="col-sm-3 control-label">角色:</label> <div class="col-sm-8"> <label th:each="role:${roles}" class="checkbox-inline i-checks"> - <input name="role" type="checkbox" th:value="${role.id}" th:text="${role.roleName}" th:checked="${role.flag}" th:disabled="${role.enable == false}"> + <input name="role" type="radio" th:value="${role.id}" th:text="${role.roleName}" th:checked="${role.flag}" th:disabled="${role.enable == false}"> </label> </div> </div> @@ -169,7 +169,7 @@ var phoneNumber = $("input[name='phoneNumber']").val(); var sex = $("#sex option:selected").val(); var enable = $("input[name='enable']").is(':checked') == true ? 1 : 0; - var roleIds = $.form.selectCheckeds("role"); + var roleIds = $("input[name='role']").is(':checked') == true ? 1 : 0; var warehouseCodeList = $.form.selectCheckeds("warehouse"); var companyIdList = $.form.selectCheckeds("company"); $.ajax({ diff --git a/src/main/resources/templates/system/user/user.html b/src/main/resources/templates/system/user/user.html index 24511b0..4d6c382 100644 --- a/src/main/resources/templates/system/user/user.html +++ b/src/main/resources/templates/system/user/user.html @@ -150,6 +150,16 @@ title: '创建时间', sortable: true }, + { + field: 'createBy', + title: '创建人', + visible: false, + }, + { + field: 'updateTime', + title: '修改时间', + sortable: true + }, { title: '操作', align: 'center',