[修改] 修改用户页面的bug

This commit is contained in:
bupengxiang
2023-05-23 16:45:19 +08:00
parent d896e8f426
commit f38f5b76f1
8 changed files with 107 additions and 17 deletions
@@ -35,10 +35,15 @@
#spring.datasource.mysql.password = root #spring.datasource.mysql.password = root
spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://121.36.69.172:3307/report-library?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai #spring.datasource.url = jdbc:mysql://121.36.69.172:3307/report-library?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
#spring.datasource.url = jdbc:mysql://121.36.69\ #spring.datasource.url = jdbc:mysql://121.36.69\
# .172:3307/report-library_test?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false\ # .172:3307/report_library_new?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false\
# &allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai # &allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
#spring.datasource.url = jdbc:mysql://121.36.69\
# .172:3307/report-library-dev?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false\
# &allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
spring.datasource.url = jdbc:mysql://121.36.69.172:3307/report-library_test?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false
&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
spring.datasource.username = root spring.datasource.username = root
spring.datasource.password = hzwlsoft.com spring.datasource.password = hzwlsoft.com
@@ -17,4 +17,6 @@ public interface OrgEODao extends BaseMapper<OrgEO> {
IPage<OrgEO> selectPageByVO(Page<OrgEO> page,@Param("pageVO")OrgEOPage orgEOPage); IPage<OrgEO> selectPageByVO(Page<OrgEO> page,@Param("pageVO")OrgEOPage orgEOPage);
long selectCountByOrgCode(@Param("pageVO")OrgEO orgEO); long selectCountByOrgCode(@Param("pageVO")OrgEO orgEO);
List<OrgEO> selectNameAll(OrgEO orgEO);
} }
@@ -50,4 +50,7 @@ public interface UserEODao extends BaseMapper<UserEO> {
List<UserEO> getOwnLeader(@Param("Vo") List<OrgEO> orgEOList); List<UserEO> getOwnLeader(@Param("Vo") List<OrgEO> orgEOList);
long listCount(@Param("account") String account, @Param("roleName") String roleName); long listCount(@Param("account") String account, @Param("roleName") String roleName);
List<String> selectAccout();
} }
@@ -46,6 +46,12 @@ public class OrgEO extends BaseEntity implements Serializable {
@TableField("PARENT_ID") @TableField("PARENT_ID")
private String ParentID; private String ParentID;
/**
* 父部门 编码
*/
@TableField(exist = false)
private String ParentCode;
/** /**
* 部门路径 * 部门路径
*/ */
@@ -6,6 +6,7 @@ import cn.hutool.json.JSONUtil;
import com.adc.da.sys.constant.SsoConstants; import com.adc.da.sys.constant.SsoConstants;
import com.adc.da.sys.constant.SysConstants; import com.adc.da.sys.constant.SysConstants;
import com.adc.da.sys.constant.UserBelongEnum; import com.adc.da.sys.constant.UserBelongEnum;
import com.adc.da.sys.dao.mysql.OrgEODao;
import com.adc.da.sys.dao.mysql.UserEODao; import com.adc.da.sys.dao.mysql.UserEODao;
import com.adc.da.sys.dao.mysql.UserOrgEODao; import com.adc.da.sys.dao.mysql.UserOrgEODao;
import com.adc.da.sys.dao.mysql.UserRoleEODao; import com.adc.da.sys.dao.mysql.UserRoleEODao;
@@ -29,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.binding.MapperMethod; import org.apache.ibatis.binding.MapperMethod;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -67,6 +69,9 @@ public class UserEOServiceImpl implements IUserEoService {
@Resource @Resource
private UserOrgEODao userOrgEODao; private UserOrgEODao userOrgEODao;
@Autowired
private OrgEODao orgEODao;
@Resource @Resource
private RoleEOService roleEOService; private RoleEOService roleEOService;
@@ -366,9 +371,11 @@ public class UserEOServiceImpl implements IUserEoService {
List<UserImportVO> userEOArrayList = dataMap.get(key); List<UserImportVO> userEOArrayList = dataMap.get(key);
ArrayList<UserEO> addList = new ArrayList<>(); ArrayList<UserEO> addList = new ArrayList<>();
ArrayList<UserRoleEO> addRoleList = new ArrayList<>(); ArrayList<UserRoleEO> addRoleList = new ArrayList<>();
ArrayList<UserOrgEO> addOrgList = new ArrayList<>();
userEOArrayList.forEach(userImportVO -> { userEOArrayList.forEach(userImportVO -> {
UserEO userEO = new UserEO(); UserEO userEO = new UserEO();
BeanUtils.copyProperties(userImportVO, userEO); BeanUtils.copyProperties(userImportVO, userEO);
userEO.setUsid(UUID.randomUUID().toString().replace("-",""));
userEO.setDelFlag(0); userEO.setDelFlag(0);
userEO.setIsSelf(UserBelongEnum.LOCAL.getValue()); userEO.setIsSelf(UserBelongEnum.LOCAL.getValue());
userEO.setUsid(com.adc.da.util.utils.UUID.randomUUID10()); userEO.setUsid(com.adc.da.util.utils.UUID.randomUUID10());
@@ -379,7 +386,16 @@ public class UserEOServiceImpl implements IUserEoService {
userEO.setUpdateTime(simpleDateFormat.format(date)); userEO.setUpdateTime(simpleDateFormat.format(date));
userEO.setRoleId(userImportVO.getRoleId()); userEO.setRoleId(userImportVO.getRoleId());
addList.add(userEO); addList.add(userEO);
//部门
if (StringUtils.isNotEmpty(userImportVO.getOrgId())){
String[] split = userImportVO.getOrgId().split(",");
for (String s : split) {
UserOrgEO userOrgEO = new UserOrgEO();
userOrgEO.setUserId(userEO.getUsid());
userOrgEO.setOrgId(s);
addOrgList.add(userOrgEO);
}
}
}); });
saveBatch(addList); saveBatch(addList);
//添加角色 //添加角色
@@ -391,6 +407,9 @@ public class UserEOServiceImpl implements IUserEoService {
addRoleList.add(userRoleEO); addRoleList.add(userRoleEO);
}); });
userRoleEODao.insertBatch(addRoleList); userRoleEODao.insertBatch(addRoleList);
if (addOrgList.size()>0){
userOrgEODao.insertBatch(addOrgList);
}
} }
//更新 //更新
@@ -398,6 +417,7 @@ public class UserEOServiceImpl implements IUserEoService {
List<UserImportVO> userEOArrayList = dataMap.get(key); List<UserImportVO> userEOArrayList = dataMap.get(key);
ArrayList<String> userIDList = new ArrayList<>(); ArrayList<String> userIDList = new ArrayList<>();
ArrayList<UserRoleEO> userRoleList = new ArrayList<>(); ArrayList<UserRoleEO> userRoleList = new ArrayList<>();
ArrayList<UserOrgEO> addOrgList = new ArrayList<>();
userEOArrayList.forEach(userImportVO -> { userEOArrayList.forEach(userImportVO -> {
QueryWrapper<UserEO> queryWrapper = new QueryWrapper(); QueryWrapper<UserEO> queryWrapper = new QueryWrapper();
queryWrapper.eq("ACCOUNT", userImportVO.getAccount()); queryWrapper.eq("ACCOUNT", userImportVO.getAccount());
@@ -414,12 +434,28 @@ public class UserEOServiceImpl implements IUserEoService {
userRoleEO.setUserId(userEO.getUsid()); userRoleEO.setUserId(userEO.getUsid());
userRoleEO.setRoleId(userImportVO.getRoleId()); userRoleEO.setRoleId(userImportVO.getRoleId());
userRoleList.add(userRoleEO); userRoleList.add(userRoleEO);
if (StringUtils.isNotEmpty(userImportVO.getOrgId())){
String[] split = userImportVO.getOrgId().split(",");
for (String s : split) {
UserOrgEO userOrgEO = new UserOrgEO();
userOrgEO.setUserId(userEO.getUsid());
userOrgEO.setOrgId(s);
addOrgList.add(userOrgEO);
}
}
} }
}); });
QueryWrapper<UserRoleEO> deleteWapper = new QueryWrapper<>(); QueryWrapper<UserRoleEO> deleteWapper = new QueryWrapper<>();
deleteWapper.in("user_id", userIDList); deleteWapper.in("user_id", userIDList);
userRoleEODao.delete(deleteWapper); userRoleEODao.delete(deleteWapper);
userRoleEODao.insertBatch(userRoleList); userRoleEODao.insertBatch(userRoleList);
//保存用户部门关系表
userOrgEODao.deleteBatchByUserIds(userIDList);
if (addOrgList.size()>0){
userOrgEODao.insertBatch(addOrgList);
}
} }
}); });
} }
@@ -503,6 +539,8 @@ public class UserEOServiceImpl implements IUserEoService {
return user.getAccount(); return user.getAccount();
} }
void checkExcel(List<UserImportVO> list) { void checkExcel(List<UserImportVO> list) {
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
throw new AdcDaBaseException("数据不能为空"); throw new AdcDaBaseException("数据不能为空");
@@ -516,25 +554,27 @@ public class UserEOServiceImpl implements IUserEoService {
//所有用户 //所有用户
List<String> existUserAccounts = new ArrayList<>(); List<String> existUserAccounts = new ArrayList<>();
List<String> existUserAccountsUpdate = new ArrayList<>(); List<String> existUserAccountsUpdate = new ArrayList<>();
QueryWrapper<UserEO> queryWrapper = new QueryWrapper<>(); List<String> accoutList = dao.selectAccout();
queryWrapper.eq("del_flag", 0); existUserAccounts = accoutList;
List<UserEO> allUsers = dao.selectList(queryWrapper); existUserAccountsUpdate = accoutList;
for (UserEO userEO : allUsers) { //所有部门
existUserAccounts.add(userEO.getAccount()); List<OrgEO> orgEOList = orgEODao.selectNameAll(new OrgEO());
existUserAccountsUpdate.add(userEO.getAccount()); Map<String, OrgEO> orgEOMap = orgEOList.stream().collect(Collectors.toMap(OrgEO::getLongName, e -> e,
} (k1,k2)->k1));
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
UserImportVO userImportVO = list.get(i); UserImportVO userImportVO = list.get(i);
if (StringUtils.isEmpty(userImportVO.getAccount())) { if (StringUtils.isEmpty(userImportVO.getAccount())) {
throw new AdcDaBaseException(""+(i+1)+""+"用户名不能为空"); throw new AdcDaBaseException(""+(i+1)+""+"用户名不能为空");
} }
if (userImportVO.getAccount().length() > 20) {
throw new AdcDaBaseException(""+(i+1)+""+"用户名不能超过20字符");
}
if (StringUtils.isEmpty(userImportVO.getUsname())) { if (StringUtils.isEmpty(userImportVO.getUsname())) {
throw new AdcDaBaseException(""+(i+1)+""+"姓名不能为空"); throw new AdcDaBaseException(""+(i+1)+""+"姓名不能为空");
} }
if (userImportVO.getUsname().length() > 20) { if (userImportVO.getUsname().length() > 20) {
throw new AdcDaBaseException(""+(i+1)+""+"姓名不超过20字符"); throw new AdcDaBaseException(""+(i+1)+""+"姓名不超过20字符");
} }
if ("admin".equals(userImportVO.getAccount()) || if ("admin".equals(userImportVO.getAccount()) ||
"root".equals(userImportVO.getAccount()) || "root".equals(userImportVO.getAccount()) ||
@@ -544,11 +584,28 @@ public class UserEOServiceImpl implements IUserEoService {
throw new AdcDaBaseException(""+(i+1)+""+"用户名不符合规则"); throw new AdcDaBaseException(""+(i+1)+""+"用户名不符合规则");
} }
if (StringUtils.isNotBlank(userImportVO.getEmail())) { if (StringUtils.isNotBlank(userImportVO.getEmail())) {
// if (!(userImportVO.getEmail().matches("^[\\w-.]+@[a-z\\d-]+(\\.[a-z\\d-]+)*\\.[a-z\\d]{2,6}$/i"))) {
if (!(userImportVO.getEmail().matches("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$"))) {
throw new AdcDaBaseException(""+(i+1)+""+"邮箱不符合规则!");
}
userImportVO.setEmail(userImportVO.getEmail().replace("amp;", "")); userImportVO.setEmail(userImportVO.getEmail().replace("amp;", ""));
} }
if (StringUtils.isNotBlank(userImportVO.getCellPhoneNumber())) { if (StringUtils.isNotBlank(userImportVO.getCellPhoneNumber())) {
if (!userImportVO.getCellPhoneNumber().matches("^[1][3,4,5,7,8,9][0-9]{9}$")) { if (!(userImportVO.getCellPhoneNumber().matches("^(?:\\+86)?-(1[3456789]\\d)\\d{8}$") ||
throw new AdcDaBaseException(""+(i+1)+""+"手机号不符合规则"); userImportVO.getCellPhoneNumber().matches("^1(3\\d|4[5-9]|5[0-35-9]|6[56]|7[0135678]|8\\d|9[89])\\d{8}$"))) {
throw new AdcDaBaseException(""+(i+1)+""+"手机号不符合规则!");
}
}
if (StringUtils.isNotEmpty(userImportVO.getOrgName())) {
String[] split = userImportVO.getOrgName().split(",");
for (String s : split) {
OrgEO orgEO = orgEOMap.get(s);
if (orgEO == null){
throw new AdcDaBaseException(""+(i+1)+""+s+"部门不存在");
}else {
userImportVO.setOrgId(StringUtils.isEmpty(userImportVO.getOrgId()) ? orgEO.getId()
: "," + orgEO.getId());
}
} }
} }
if (StringUtils.isEmpty(userImportVO.getOperation())) { if (StringUtils.isEmpty(userImportVO.getOperation())) {
@@ -560,6 +617,9 @@ public class UserEOServiceImpl implements IUserEoService {
if (!roleEOMap.keySet().contains(userImportVO.getRoleName())) { if (!roleEOMap.keySet().contains(userImportVO.getRoleName())) {
throw new AdcDaBaseException(""+(i+1)+""+"角色:" + userImportVO.getRoleName() + "不存在,请检查"); throw new AdcDaBaseException(""+(i+1)+""+"角色:" + userImportVO.getRoleName() + "不存在,请检查");
} }
if(StringUtils.isNotEmpty(userImportVO.getOperation()) && !"add".equals(userImportVO.getOperation()) && !"full".equals(userImportVO.getOperation())){
throw new AdcDaBaseException(""+(i+1)+""+"操作(add添加、full覆盖角色)只能填写add和full");
}
if ("add".equals(userImportVO.getOperation())) { if ("add".equals(userImportVO.getOperation())) {
if (existUserAccounts.contains(userImportVO.getAccount())) { if (existUserAccounts.contains(userImportVO.getAccount())) {
throw new AdcDaBaseException(""+(i+1)+""+"用户名:" + userImportVO.getAccount() + "已存在,请检查"); throw new AdcDaBaseException(""+(i+1)+""+"用户名:" + userImportVO.getAccount() + "已存在,请检查");
@@ -573,8 +633,6 @@ public class UserEOServiceImpl implements IUserEoService {
} }
} }
userImportVO.setRoleId(roleEOMap.get(userImportVO.getRoleName()).getId()); userImportVO.setRoleId(roleEOMap.get(userImportVO.getRoleName()).getId());
} }
} }
@@ -37,6 +37,14 @@ public class UserImportVO {
@Excel(name = "邮箱", width = 20) @Excel(name = "邮箱", width = 20)
private String email; private String email;
private String orgId;
/**
* 部门
*/
@Excel(name = "部门", width = 20)
private String orgName;
/** /**
* 创建时间 * 创建时间
*/ */
@@ -32,7 +32,8 @@
</where> </where>
</select> </select>
<select id="selectPageByVO" resultType="com.adc.da.sys.entity.OrgEO"> <select id="selectPageByVO" resultType="com.adc.da.sys.entity.OrgEO">
select * from TS_ORG select org.* , forg.DEPARTMENT_CODE as ParentCode from TS_ORG org
LEFT JOIN TS_ORG forg on org.PARENT_ID = forg.id
<where> <where>
<include refid="Base_Where_Clause"/> <include refid="Base_Where_Clause"/>
</where> </where>
@@ -48,4 +49,7 @@
</if> </if>
</where> </where>
</select> </select>
<select id="selectNameAll" resultType="com.adc.da.sys.entity.OrgEO">
select ID as id,LONG_NAME as LongName from TS_ORG
</select>
</mapper> </mapper>
@@ -290,6 +290,10 @@
and u.del_flag = 0 and u.del_flag = 0
</where> </where>
</select> </select>
<select id="selectAccout" resultType="java.lang.String">
select ACCOUNT as account from ts_user
where del_flag = 0
</select>
</mapper> </mapper>