单位bugfix

main
杜函宇 2 months ago
parent 13a7763cf3
commit f28e09acc1

@ -0,0 +1,136 @@
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.Unit;
import com.ruoyi.common.core.domain.request.UnitRequest;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.UnitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
/**
* (unit)
* @author du
* @since 2024/11/18 17:11
*/
@Api(tags = "单位表控制层")
@RestController
//@PreAuthorize("@ss.hasAnyRoles('admin,common')")
@RequestMapping("/tc/unit")
public class UnitController {
@Resource
private UnitService unitService;
/**
*
*/
@ApiOperation(value = "获取单位列表",response = Unit.class)
@GetMapping("/list")
public AjaxResult list(Page<Unit> page, UnitRequest unit) {
return AjaxResult.success(unitService.page(page,unit));
}
/**
*
*/
@ApiOperation(value = "单位导出")
@Log(title = "单位导出", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, UnitRequest unit) {
List<Unit> list = unitService.selectUnitList(unit);
ExcelUtil<Unit> util = new ExcelUtil<>(Unit.class);
util.exportExcel(response, list, "单位数据");
}
/**
*
*/
@ApiOperation(value = "单位导入")
@Log(title = "单位导入", businessType = BusinessType.IMPORT)
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file) throws Exception {
ExcelUtil<Unit> util = new ExcelUtil<>(Unit.class);
List<Unit> list = util.importExcel(file.getInputStream());
unitService.saveBatch(list);
for (Unit x : list) {
//查询用户表是否存在该用户
unitService.validUser(x);
}
return AjaxResult.success();
}
@PostMapping("/importTemplate")
public void importTemplate(HttpServletResponse response) {
ExcelUtil<Unit> util = new ExcelUtil<>(Unit.class);
util.importTemplateExcel(response, "单位模板");
}
/**
* id
*/
@ApiOperation(value = "根据用户编号获取详细信息")
@GetMapping("/{id}")
public AjaxResult getInfo(@PathVariable(value = "id") Long id) {
return AjaxResult.success(unitService.getById(id));
}
/**
*
*/
@ApiOperation(value = "新增单位")
@Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping
@Transactional(rollbackFor = Exception.class)
public AjaxResult add(@Valid @RequestBody Unit unit) {
if (!unitService.lambdaQuery().eq(Unit::getUserName, unit.getUserName()).eq(Unit::getDelFlag,"0").list().isEmpty()) {
throw new ServiceException(unit.getUserName() + "'已存在单位!");
}
//新增单位到单位信息表
unitService.save(unit);
//查询用户表是否存在该用户
unitService.validUser(unit);
return AjaxResult.success();
}
/**
*
*/
@ApiOperation(value = "修改用户")
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping
@Transactional(rollbackFor = Exception.class)
public AjaxResult edit(@Valid @RequestBody Unit x) {
Unit byId = unitService.getById(x.getId());
if (!byId.getUserName().equals(x.getUserName())||!byId.getNickName().equals(x.getNickName())) {
throw new ServiceException("不允许修改单位名称和统一信用代码!");
}
unitService.updateById(x);
return AjaxResult.success();
}
/**
*
*/
@ApiOperation(value = "删除单位")
@Log(title = "删除单位", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
List<String> userNames = unitService.selectByIds(ids);
//逻辑删除单位和用户
unitService.deleteUsers(userNames);
unitService.deleteUnits(ids);
return AjaxResult.success();
}
}

@ -6,16 +6,15 @@ 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.SysRole; import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.Unit;
import com.ruoyi.common.core.domain.request.UnitRequest;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.*; import com.ruoyi.system.service.ISysDeptService;
import io.swagger.annotations.Api; import com.ruoyi.system.service.ISysPostService;
import io.swagger.annotations.ApiOperation; import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
@ -23,7 +22,6 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -34,7 +32,6 @@ import java.util.stream.Collectors;
* @author ruoyi * @author ruoyi
*/ */
@RestController @RestController
@Api(tags = "用户信息")
@RequestMapping("/system/user") @RequestMapping("/system/user")
public class SysUserController extends BaseController { public class SysUserController extends BaseController {
@Autowired @Autowired
@ -49,13 +46,9 @@ public class SysUserController extends BaseController {
@Autowired @Autowired
private ISysPostService postService; private ISysPostService postService;
@Resource
private UnitService unitService;
/** /**
* *
*/ */
@ApiOperation(value = "获取用户列表")
@PreAuthorize("@ss.hasPermi('system:user:list')") @PreAuthorize("@ss.hasPermi('system:user:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(SysUser user) { public TableDataInfo list(SysUser user) {
@ -63,56 +56,36 @@ public class SysUserController extends BaseController {
List<SysUser> list = userService.selectUserList(user); List<SysUser> list = userService.selectUserList(user);
return getDataTable(list); return getDataTable(list);
} }
@ApiOperation(value = "用户单位导出")
@Log(title = "用户单位管理", businessType = BusinessType.EXPORT) @Log(title = "用户管理", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('system:user:export')") @PreAuthorize("@ss.hasPermi('system:user:export')")
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, UnitRequest unit) { public void export(HttpServletResponse response, SysUser user) {
// List<SysUser> list = userService.selectUserList(user); List<SysUser> list = userService.selectUserList(user);
// ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
// util.exportExcel(response, list, "用户数据"); util.exportExcel(response, list, "用户数据");
List<Unit> list = unitService.selectUnitList(unit);
ExcelUtil<Unit> util = new ExcelUtil<>(Unit.class);
util.exportExcel(response, list, "单位数据");
} }
@ApiOperation(value = "用户单位导入")
@Log(title = "用户单位管理", businessType = BusinessType.IMPORT) @Log(title = "用户管理", businessType = BusinessType.IMPORT)
@PreAuthorize("@ss.hasPermi('system:user:import')") @PreAuthorize("@ss.hasPermi('system:user:import')")
@PostMapping("/importData") @PostMapping("/importData")
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
// ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
// List<SysUser> userList = util.importExcel(file.getInputStream()); List<SysUser> userList = util.importExcel(file.getInputStream());
// String operName = getUsername(); String operName = getUsername();
// String message = userService.importUser(userList, updateSupport, operName); String message = userService.importUser(userList, updateSupport, operName);
ExcelUtil<Unit> util = new ExcelUtil<>(Unit.class); return success(message);
List<Unit> list = util.importExcel(file.getInputStream());
unitService.saveBatch(list);
for (Unit x : list) {
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);
}
//未做修改
}
return success();
} }
@PostMapping("/importTemplate") @PostMapping("/importTemplate")
public void importTemplate(HttpServletResponse response) { public void importTemplate(HttpServletResponse response) {
ExcelUtil<Unit> util = new ExcelUtil<>(Unit.class); ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
util.importTemplateExcel(response, "用户数据"); util.importTemplateExcel(response, "用户数据");
} }
/** /**
* *
*/ */
@ApiOperation(value = "根据用户编号获取详细信息")
@PreAuthorize("@ss.hasPermi('system:user:query')") @PreAuthorize("@ss.hasPermi('system:user:query')")
@GetMapping(value = {"/", "/{userId}"}) @GetMapping(value = {"/", "/{userId}"})
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) { public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {
@ -123,19 +96,16 @@ public class SysUserController extends BaseController {
ajax.put(AjaxResult.DATA_TAG, sysUser); ajax.put(AjaxResult.DATA_TAG, sysUser);
ajax.put("postIds", postService.selectPostListByUserId(userId)); ajax.put("postIds", postService.selectPostListByUserId(userId));
ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList())); ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
ajax.put("unit", unitService.lambdaQuery().eq(Unit::getUserName,sysUser.getUserName()).one());
} }
List<SysRole> roles = roleService.selectRoleAll(); List<SysRole> roles = roleService.selectRoleAll();
ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
ajax.put("posts", postService.selectPostAll()); ajax.put("posts", postService.selectPostAll());
ajax.put("posts", postService.selectPostAll());
return ajax; return ajax;
} }
/** /**
* *
*/ */
@ApiOperation(value = "新增用户")
@PreAuthorize("@ss.hasPermi('system:user:add')") @PreAuthorize("@ss.hasPermi('system:user:add')")
@Log(title = "用户管理", businessType = BusinessType.INSERT) @Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
@ -145,20 +115,12 @@ public class SysUserController extends BaseController {
if (!userService.checkUserNameUnique(user)) { if (!userService.checkUserNameUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
} }
if (!unitService.lambdaQuery().eq(Unit::getUserName, user.getUserName()).list().isEmpty()) { // else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
return error("新增用户'" + user.getUserName() + "'已存在单位!");
}
//新增单位到单位信息表
unitService.save(user.getUnitInfo());
// else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
// {
// return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); // return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
// } // } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
// else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
// {
// return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); // return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
// } // }
// user.setCreateBy(getUsername()); user.setCreateBy(getUsername());
user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
return toAjax(userService.insertUser(user)); return toAjax(userService.insertUser(user));
} }
@ -166,7 +128,6 @@ public class SysUserController extends BaseController {
/** /**
* *
*/ */
@ApiOperation(value = "修改用户")
@PreAuthorize("@ss.hasPermi('system:user:edit')") @PreAuthorize("@ss.hasPermi('system:user:edit')")
@Log(title = "用户管理", businessType = BusinessType.UPDATE) @Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
@ -178,26 +139,18 @@ public class SysUserController extends BaseController {
if (!userService.checkUserNameUnique(user)) { if (!userService.checkUserNameUnique(user)) {
return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
} }
if (!unitService.lambdaQuery().eq(Unit::getUserName, user.getUserName()).list().isEmpty()) { // else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
return error("修改用户'" + user.getUserName() + "'已存在单位!");
}
unitService.updateById(user.getUnitInfo());
// else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
// {
// return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); // return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
// } // } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
// else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
// {
// return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); // return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
// } // }
// user.setUpdateBy(getUsername()); user.setUpdateBy(getUsername());
return toAjax(userService.updateUser(user)); return toAjax(userService.updateUser(user));
} }
/** /**
* *
*/ */
@ApiOperation(value = "删除用户")
@PreAuthorize("@ss.hasPermi('system:user:remove')") @PreAuthorize("@ss.hasPermi('system:user:remove')")
@Log(title = "用户管理", businessType = BusinessType.DELETE) @Log(title = "用户管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{userIds}") @DeleteMapping("/{userIds}")
@ -211,7 +164,6 @@ public class SysUserController extends BaseController {
/** /**
* *
*/ */
@ApiOperation(value = "重置密码")
@PreAuthorize("@ss.hasPermi('system:user:resetPwd')") @PreAuthorize("@ss.hasPermi('system:user:resetPwd')")
@Log(title = "用户管理", businessType = BusinessType.UPDATE) @Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping("/resetPwd") @PutMapping("/resetPwd")
@ -219,28 +171,26 @@ public class SysUserController extends BaseController {
userService.checkUserAllowed(user); userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId()); userService.checkUserDataScope(user.getUserId());
user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
// user.setUpdateBy(getUsername()); user.setUpdateBy(getUsername());
return toAjax(userService.resetPwd(user)); return toAjax(userService.resetPwd(user));
} }
/** /**
* *
*/ */
@ApiOperation(value = "状态修改")
@PreAuthorize("@ss.hasPermi('system:user:edit')") @PreAuthorize("@ss.hasPermi('system:user:edit')")
@Log(title = "用户管理", businessType = BusinessType.UPDATE) @Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping("/changeStatus") @PutMapping("/changeStatus")
public AjaxResult changeStatus(@RequestBody SysUser user) { public AjaxResult changeStatus(@RequestBody SysUser user) {
userService.checkUserAllowed(user); userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId()); userService.checkUserDataScope(user.getUserId());
// user.setUpdateBy(getUsername()); user.setUpdateBy(getUsername());
return toAjax(userService.updateUserStatus(user)); return toAjax(userService.updateUserStatus(user));
} }
/** /**
* *
*/ */
@ApiOperation(value = "根据用户编号获取授权角色")
@PreAuthorize("@ss.hasPermi('system:user:query')") @PreAuthorize("@ss.hasPermi('system:user:query')")
@GetMapping("/authRole/{userId}") @GetMapping("/authRole/{userId}")
public AjaxResult authRole(@PathVariable("userId") Long userId) { public AjaxResult authRole(@PathVariable("userId") Long userId) {
@ -255,7 +205,6 @@ public class SysUserController extends BaseController {
/** /**
* *
*/ */
@ApiOperation(value = "用户授权角色")
@PreAuthorize("@ss.hasPermi('system:user:edit')") @PreAuthorize("@ss.hasPermi('system:user:edit')")
@Log(title = "用户管理", businessType = BusinessType.GRANT) @Log(title = "用户管理", businessType = BusinessType.GRANT)
@PutMapping("/authRole") @PutMapping("/authRole")
@ -269,7 +218,6 @@ public class SysUserController extends BaseController {
/** /**
* *
*/ */
@ApiOperation(value = "获取部门树列表")
@PreAuthorize("@ss.hasPermi('system:user:list')") @PreAuthorize("@ss.hasPermi('system:user:list')")
@GetMapping("/deptTree") @GetMapping("/deptTree")
public AjaxResult deptTree(SysDept dept) { public AjaxResult deptTree(SysDept dept) {

@ -1,6 +1,7 @@
package com.ruoyi.system.mapper; package com.ruoyi.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.entity.Unit; import com.ruoyi.common.core.domain.entity.Unit;
import com.ruoyi.common.core.domain.request.UnitRequest; import com.ruoyi.common.core.domain.request.UnitRequest;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -21,9 +22,26 @@ public interface UnitMapper extends BaseMapper<Unit> {
* @return * @return
*/ */
List<Unit> selectUnitList(@Param("req") UnitRequest a); List<Unit> selectUnitList(@Param("req") UnitRequest a);
/**
*
*
* @param unit
* @return
*/
Page<Unit> selectUnitList(Page<Unit> page, @Param("req") UnitRequest unit);
/**
* id
*/
List<String> selectByIds(Long[] ids);
/**
*
*/
void deleteUnits(Long[] ids);
/** /**
* *
*/ */
void deleteInCode(List<String> code); void deleteUsers(List<String> userNames);
} }

@ -1,5 +1,6 @@
package com.ruoyi.system.service; package com.ruoyi.system.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.domain.entity.Unit; import com.ruoyi.common.core.domain.entity.Unit;
import com.ruoyi.common.core.domain.request.UnitRequest; import com.ruoyi.common.core.domain.request.UnitRequest;
@ -13,6 +14,14 @@ import java.util.List;
*/ */
public interface UnitService extends IService<Unit> { public interface UnitService extends IService<Unit> {
/**
*
*
* @param unit
* @return
*/
Page<Unit> page(Page<Unit> page,UnitRequest unit);
/** /**
* *
* *
@ -21,8 +30,24 @@ public interface UnitService extends IService<Unit> {
*/ */
List<Unit> selectUnitList(UnitRequest unit); List<Unit> selectUnitList(UnitRequest unit);
/**
*
*/
void validUser(Unit unit);
/**
* id
*/
List<String> selectByIds(Long[] ids);
/**
*
*/
void deleteUsers(List<String> userNames);
/** /**
* *
*/ */
void deleteInCode(List<String> code); void deleteUnits(Long[] ids);
} }

@ -3,10 +3,7 @@ package com.ruoyi.system.service.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.validation.Validator; import javax.validation.Validator;
import com.ruoyi.system.service.UnitService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -68,8 +65,6 @@ public class SysUserServiceImpl implements ISysUserService
@Autowired @Autowired
protected Validator validator; protected Validator validator;
@Resource
private UnitService unitService;
/** /**
* *
* *
@ -476,12 +471,6 @@ public class SysUserServiceImpl implements ISysUserService
userRoleMapper.deleteUserRole(userIds); userRoleMapper.deleteUserRole(userIds);
// 删除用户与岗位关联 // 删除用户与岗位关联
userPostMapper.deleteUserPost(userIds); userPostMapper.deleteUserPost(userIds);
List<SysUser> sysUsers = userMapper.selectUserByIds(userIds);
List<String> nl = new ArrayList<>();
sysUsers.forEach(x->{
nl.add(x.getUserName());
});
unitService.deleteInCode(nl);
return userMapper.deleteUserByIds(userIds); return userMapper.deleteUserByIds(userIds);
} }

@ -1,12 +1,19 @@
package com.ruoyi.system.service.impl; package com.ruoyi.system.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.Unit; import com.ruoyi.common.core.domain.entity.Unit;
import com.ruoyi.common.core.domain.request.UnitRequest; import com.ruoyi.common.core.domain.request.UnitRequest;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.UnitMapper; import com.ruoyi.system.mapper.UnitMapper;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.UnitService; import com.ruoyi.system.service.UnitService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List; import java.util.List;
/** /**
@ -17,6 +24,18 @@ import java.util.List;
@Service @Service
public class UnitServiceImpl extends ServiceImpl<UnitMapper, Unit> implements UnitService { public class UnitServiceImpl extends ServiceImpl<UnitMapper, Unit> implements UnitService {
@Resource
private ISysUserService userService;
/**
*
*
* @param unit
* @return
*/
@Override
public Page<Unit> page(Page<Unit> page, UnitRequest unit) {
return baseMapper.selectUnitList(page,unit);
}
/** /**
* *
@ -29,11 +48,47 @@ public class UnitServiceImpl extends ServiceImpl<UnitMapper, Unit> implements Un
return baseMapper.selectUnitList(unit); return baseMapper.selectUnitList(unit);
} }
/** /**
* *
*/ */
@Override @Override
public void deleteInCode(List<String> code) { public void validUser(Unit x) {
baseMapper.deleteInCode(code); 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() + "'已存在单位!");
}
} }
/**
* id
*/
@Override
public List<String> selectByIds(Long[] ids) {
return baseMapper.selectByIds(ids);
}
/**
*
*/
@Override
public void deleteUsers(List<String> userNames) {
baseMapper.deleteUsers(userNames);
}
/**
*
*/
@Override
public void deleteUnits(Long[] ids) {
baseMapper.deleteUnits(ids);
}
} }

@ -47,17 +47,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by"/> <result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/> <result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/> <result property="remark" column="remark"/>
<result property="delFlag" column="del_flag"/>
</resultMap> </resultMap>
<delete id="deleteInCode"> <update id="deleteUnits">
update unit_info set del_flag = '2' where user_name in update unit_info set del_flag = '2' where id in
<foreach collection="array" item="userId" open="(" separator="," close=")"> <foreach collection="array" item="ids" open="(" separator="," close=")">
#{code} #{ids}
</foreach> </foreach>
</delete> </update>
<update id="deleteUsers">
update sys_user set del_flag = '2' where user_name in
<foreach collection="array" item="userNames" open="(" separator="," close=")">
#{userNames}
</foreach>
</update>
<select id="selectUnitList" parameterType="unit" resultMap="unitResult"> <select id="selectUnitList" parameterType="unit" resultMap="unitResult">
select * from unit_info select * from unit_info
<where> <where>
del_flag = '0'
<if test="req.nickName != null and req.nickName != '' "> <if test="req.nickName != null and req.nickName != '' ">
and nick_name like concat('%',#{req.nickName},'%') and nick_name like concat('%',#{req.nickName},'%')
</if> </if>
@ -69,4 +77,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
</where> </where>
</select> </select>
<select id="selectByIds" resultType="java.lang.String">
select user_name from unit_info where id in
<foreach collection="array" item="ids" open="(" separator="," close=")">
#{ids}
</foreach>
</select>
</mapper> </mapper>
Loading…
Cancel
Save