diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index 723b761..9cd0285 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -36,6 +36,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers("/global/configuration/**").permitAll() .antMatchers("/push/**").permitAll() .antMatchers("/queryFirePoint").permitAll() + .antMatchers(HttpMethod.POST, "/api/user/updateSysUser").permitAll() .antMatchers(HttpMethod.GET, "/selectGlobalConfigDict").permitAll() .antMatchers(HttpMethod.GET, "/selectGlobalConfigValue").permitAll() .antMatchers(HttpMethod.GET, "/selectGlobalConfig").permitAll() diff --git a/src/main/java/com/xkrs/controller/SysUserController.java b/src/main/java/com/xkrs/controller/SysUserController.java index 3a43b33..00eef35 100644 --- a/src/main/java/com/xkrs/controller/SysUserController.java +++ b/src/main/java/com/xkrs/controller/SysUserController.java @@ -17,6 +17,7 @@ import com.xkrs.service.RedisService; import com.xkrs.service.SysUserService; import com.xkrs.sms.SMSHelper; import com.xkrs.utils.FirePointCodeUtils; +import com.xkrs.utils.ListUtils; import com.xkrs.utils.RandomUtil; import org.apache.hc.core5.util.TextUtils; import org.springframework.context.i18n.LocaleContextHolder; @@ -37,14 +38,11 @@ import static com.xkrs.utils.EncryptDecryptUtil.encry256; /** * 系统用户Controller - * - * @author tajocehn */ @RestController @RequestMapping(value = "/api/user") public class SysUserController { - // 获取区域信息 private final Locale locale = LocaleContextHolder.getLocale(); @Resource @@ -62,6 +60,56 @@ public class SysUserController { @Resource private SMSHelper smsHelper; + /** + * 更新(批量)系统用户信息 + * + * @param paramMap + * @return + */ + @Transactional(rollbackFor = Exception.class) + @RequestMapping(value = "/updateSysUser", method = RequestMethod.POST) + public String updateSysUser(@RequestBody Map paramMap) { + String userIdArray = paramMap.get("userIdArray"); + String overTime = paramMap.get("overTime"); + String remark = paramMap.get("remark"); + List userIdList = ListUtils.toStringList(userIdArray, ",");//解析的ID集合 + if (userIdList.isEmpty()) { + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "修改失败,请输入正确的ID", locale); + } + List successIdList = new ArrayList<>();//操作成功的ID集合 + List failureIdList = new ArrayList<>();//操作失败的ID集合 + for (String userId : userIdList) { + try { + Optional targetEntityOptional = sysUserDao.findById(Integer.parseInt(userId)); + if (targetEntityOptional.isPresent()) { + SysUserEntity targetEntity = targetEntityOptional.get(); + if (!TextUtils.isEmpty(overTime)) { + targetEntity.setOverTime(overTime); + } + if (!TextUtils.isEmpty(remark)) { + targetEntity.setRemark(remark); + } + sysUserDao.save(targetEntity); + successIdList.add(userId); + } else { + failureIdList.add(userId); + } + } catch (Exception e) { + e.printStackTrace(); + failureIdList.add(userId); + } + } + if (userIdList.size() == successIdList.size()) { + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale); + } + StringBuilder builder = new StringBuilder(); + if (successIdList.size() > 0) { + builder.append("ID:").append(ListUtils.fromStringList(successIdList, "、")).append("修改成功,"); + } + builder.append("ID:").append(ListUtils.fromStringList(failureIdList, "、")).append("修改失败"); + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "修改失败," + builder, locale); + } + /** * 修改vip等级 */ @@ -142,7 +190,7 @@ public class SysUserController { @GetMapping("/selectAgentOrgList") public String selectAgentOrgList() { - List agentOrgList= agentOrgDao.findAll(Sort.by(Sort.Direction.ASC, "id")); + List agentOrgList = agentOrgDao.findAll(Sort.by(Sort.Direction.ASC, "id")); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, agentOrgList, locale); } diff --git a/src/main/java/com/xkrs/utils/ListUtils.java b/src/main/java/com/xkrs/utils/ListUtils.java index 54e5dd4..e6875d0 100644 --- a/src/main/java/com/xkrs/utils/ListUtils.java +++ b/src/main/java/com/xkrs/utils/ListUtils.java @@ -16,10 +16,13 @@ public class ListUtils { * @return */ public static List toStringList(String content, String splitRegex) { + List list = new ArrayList<>(); + if (TextUtils.isEmpty(content)) { + return list; + } if (TextUtils.isEmpty(splitRegex)) { throw new RuntimeException("splitRegex == null"); } - List list = new ArrayList<>(); if (content.contains(splitRegex)) { String[] splitArray = content.split(splitRegex); if (splitArray.length > 0) {