From 368c71aaa842e1b6a2d40494a3ed0a559dfa7643 Mon Sep 17 00:00:00 2001 From: du <1725534722@qq.com> Date: Fri, 22 Nov 2024 14:40:19 +0800 Subject: [PATCH] bugfix --- .../ruoyi/tc/controller/UnitController.java | 20 +++++++++--- .../java/com/ruoyi/tc/mapper/UnitMapper.java | 2 +- .../com/ruoyi/tc/service/UnitService.java | 2 +- .../tc/service/impl/UnitServiceImpl.java | 31 ++++++++++--------- .../resources/mapper/ExamineInfoMapper.xml | 2 +- .../src/main/resources/mapper/UnitMapper.xml | 5 +-- .../main/resources/mapper/UnitOtherConcat.xml | 4 +-- 7 files changed, 37 insertions(+), 29 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java b/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java index 65781f9..b5fa17b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/tc/controller/UnitController.java @@ -3,6 +3,9 @@ package com.ruoyi.tc.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.system.service.ISysUserService; import com.ruoyi.tc.entity.Unit; import com.ruoyi.tc.entity.request.UnitRequest; import com.ruoyi.common.enums.BusinessType; @@ -44,6 +47,9 @@ public class UnitController { @Resource private ExamineInfoService examineInfoService; + @Resource + private ISysUserService iSysUserService; + /** * 获取单位列表 */ @@ -130,10 +136,8 @@ public class UnitController { @PutMapping @Transactional(rollbackFor = Exception.class) public AjaxResult edit(@RequestBody Unit x) { - Unit byId = unitService.getById(x.getId()); - if (!byId.getUserName().equals(x.getUserName()) || !byId.getNickName().equals(x.getNickName())) { - throw new ServiceException("不允许修改单位名称和统一信用代码!"); - } + //查询用户表是否存在该用户 + unitService.validUser(x); unitService.updateById(x); if(!x.getOtherConcat().isEmpty()){ x.getOtherConcat().forEach(y->{ @@ -159,7 +163,13 @@ public class UnitController { public AjaxResult remove(@PathVariable Long id) { List userNames = unitService.selectByIds(id); //逻辑删除单位和用户 - unitService.deleteUsers(userNames); + if(!userNames.isEmpty()){ + for (String it : userNames) { + if(it!=null){ + unitService.deleteUsers(it); + } + } + } unitService.deleteUnits(id); unitOtherConcatService.deleteByUnitIds(id); examineInfoService.deleteByUnitIds(id); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/tc/mapper/UnitMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/tc/mapper/UnitMapper.java index ce451bb..be381e3 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/tc/mapper/UnitMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/tc/mapper/UnitMapper.java @@ -44,7 +44,7 @@ public interface UnitMapper extends BaseMapper { /** * 逻辑删除用户 */ - void deleteUsers(List userNames); + void deleteUsers(@Param("userNames") String userNames); /** * 根据id获取详细信息 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/tc/service/UnitService.java b/ruoyi-admin/src/main/java/com/ruoyi/tc/service/UnitService.java index 20c89e9..ea95e15 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/tc/service/UnitService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/tc/service/UnitService.java @@ -50,7 +50,7 @@ public interface UnitService extends IService { /** * 逻辑删除用户 */ - void deleteUsers(List userNames); + void deleteUsers(String userNames); /** * 逻辑删除单位 */ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/tc/service/impl/UnitServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/tc/service/impl/UnitServiceImpl.java index 714897b..8309910 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/tc/service/impl/UnitServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/tc/service/impl/UnitServiceImpl.java @@ -35,8 +35,6 @@ public class UnitServiceImpl extends ServiceImpl implements Un */ @Override public Page page(Page page, UnitRequest unit) { - - return baseMapper.selectUnitList(page,unit); } @@ -61,21 +59,24 @@ public class UnitServiceImpl extends ServiceImpl implements Un /** - * 检查用户表是否存在该用户 + * 检查用户表是否存在该用户,并做新增和修改 */ @Override public void validUser(Unit x) { - SysUser user = new SysUser(); - user.setUserName(x.getUserName()); - user.setPassword(SecurityUtils.encryptPassword(x.getUserName().substring(x.getUserName().length() - 6))); - user.setNickName(x.getNickName()); - SysUser u = userService.selectUserByUserName(x.getUserName()); - if (StringUtils.isNull(u)) { - userService.insertUser(user); - Long[] roles = new Long[]{100L}; - userService.insertUserAuth(user.getUserId(), roles); - }else { - throw new ServiceException(x.getUserName() + "'已存在单位!"); + if(x.getUserName()!=null && x.getUserName().length()>6){ + SysUser user = new SysUser(); + user.setUserName(x.getUserName()); + user.setPassword(SecurityUtils.encryptPassword(x.getUserName().substring(x.getUserName().length() - 6))); + user.setNickName(x.getNickName()); + SysUser u = userService.selectUserByUserName(x.getUserName()); + if (StringUtils.isNull(u)) { + userService.insertUser(user); + Long[] roles = new Long[]{100L}; + userService.insertUserAuth(user.getUserId(), roles); + }else { + //只修改用户账号,密码,单位名称 + userService.updateUserProfile(user); + } } } @@ -90,7 +91,7 @@ public class UnitServiceImpl extends ServiceImpl implements Un * 逻辑删除用户 */ @Override - public void deleteUsers(List userNames) { + public void deleteUsers(String userNames) { baseMapper.deleteUsers(userNames); } diff --git a/ruoyi-admin/src/main/resources/mapper/ExamineInfoMapper.xml b/ruoyi-admin/src/main/resources/mapper/ExamineInfoMapper.xml index 1eaf8ff..2085cfb 100644 --- a/ruoyi-admin/src/main/resources/mapper/ExamineInfoMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/ExamineInfoMapper.xml @@ -2,7 +2,7 @@ - update asset_examine_info set del_flag = '2' where unit_id = #{id} + update unit_examine_info set del_flag = '2' where unit_id = #{id} diff --git a/ruoyi-admin/src/main/resources/mapper/UnitMapper.xml b/ruoyi-admin/src/main/resources/mapper/UnitMapper.xml index f3c666d..2fd51bf 100644 --- a/ruoyi-admin/src/main/resources/mapper/UnitMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/UnitMapper.xml @@ -133,9 +133,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update unit_info set del_flag = '2' where id = #{id} - update sys_user set del_flag = '2' where user_name in - - #{userNames} - + update sys_user set del_flag = '2' where user_name = #{userNames} \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/mapper/UnitOtherConcat.xml b/ruoyi-admin/src/main/resources/mapper/UnitOtherConcat.xml index 1433925..d6de253 100644 --- a/ruoyi-admin/src/main/resources/mapper/UnitOtherConcat.xml +++ b/ruoyi-admin/src/main/resources/mapper/UnitOtherConcat.xml @@ -5,9 +5,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - update asset_supply_chain set del_flag = '2' where unit_id = #{id} + update unit_other_contact set del_flag = '2' where unit_id = #{id} - update asset_supply_chain set del_flag = '2' where asset_id = #{id} + update unit_other_contact set del_flag = '2' where asset_id = #{id} \ No newline at end of file