|
@@ -1,17 +1,31 @@
|
|
|
package com.sd.business.service.department.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.core.domain.BaseEntity;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.ruoyi.system.service.ISysDeptService;
|
|
|
+import com.ruoyi.system.service.ISysRoleService;
|
|
|
+import com.ruoyi.system.service.ISysUserService;
|
|
|
import com.sd.business.entity.department.dto.DepartmentDto;
|
|
|
import com.sd.business.entity.department.dto.DepartmentSelectDto;
|
|
|
import com.sd.business.entity.department.po.Department;
|
|
|
import com.sd.business.entity.department.vo.DepartmentVo;
|
|
|
import com.sd.business.mapper.department.DepartmentMapper;
|
|
|
import com.sd.business.service.department.DepartmentService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -24,10 +38,22 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysDeptService sysDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysRoleService sysRoleService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<DepartmentVo> getPage(DepartmentSelectDto dto) {
|
|
|
IWrapper<Department> wrapper = getWrapper();
|
|
|
wrapper.orderByDesc("d", Department::getId);
|
|
|
+ wrapper.like("d", Department::getName, dto.getName());
|
|
|
+ wrapper.eq("d", Department::getSellingPriceSystem, dto.getSellingPriceSystem());
|
|
|
+ wrapper.like("d", Department::getContactPerson, dto.getContactPerson());
|
|
|
Page<DepartmentVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
return page;
|
|
|
}
|
|
@@ -39,13 +65,76 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
- public void add(DepartmentDto departmentDto) {
|
|
|
+ public synchronized void add(DepartmentDto departmentDto) {
|
|
|
+ String username = SecurityUtils.getUsername();
|
|
|
+ Date date = new Date();
|
|
|
+ String tenantId = "000000";
|
|
|
+ String name = departmentDto.getName();
|
|
|
+ String adminUsername = departmentDto.getAdminUsername();
|
|
|
+ String adminPassword = departmentDto.getAdminPassword();
|
|
|
+
|
|
|
+ long count = sysUserService.count(Wrappers.<SysUser>lambdaQuery()
|
|
|
+ .eq(SysUser::getUserName, adminUsername).last("limit 1"));
|
|
|
+ if (count != 0) {
|
|
|
+ throw new ServiceException("用户名已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysDept sysDept = new SysDept();
|
|
|
+ sysDept.setDeptName(name);
|
|
|
+ sysDept.setParentId(0L);
|
|
|
+ sysDept.setOrderNum(1);
|
|
|
+ sysDept.setStatus("0");
|
|
|
+ sysDept.setType(0);
|
|
|
+ sysDept.setTenantId(tenantId);
|
|
|
+ sysDept.setCreateBy(username);
|
|
|
+ sysDept.setCreateTime(date);
|
|
|
+ sysDeptService.save(sysDept);
|
|
|
+
|
|
|
+ SysUser sysUser = new SysUser();
|
|
|
+ sysUser.setDeptId(sysDept.getDeptId());
|
|
|
+ sysUser.setUserName(adminUsername);
|
|
|
+ sysUser.setNickName(name + "管理员");
|
|
|
+ sysUser.setPassword(SecurityUtils.encryptPassword(adminPassword));
|
|
|
+ sysUser.setStatus("0");
|
|
|
+ sysUser.setTenantId(tenantId);
|
|
|
+ sysUser.setCreateBy(username);
|
|
|
+ sysUser.setCreateTime(date);
|
|
|
+ sysUserService.save(sysUser);
|
|
|
+
|
|
|
+ sysRoleService.insertAuthUsers(10L, new Long[]{sysUser.getUserId()});
|
|
|
+
|
|
|
+ departmentDto.setId(sysDept.getDeptId());
|
|
|
this.save(departmentDto);
|
|
|
}
|
|
|
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
- public void edit(DepartmentDto departmentDto) {
|
|
|
+ public synchronized void edit(DepartmentDto departmentDto) {
|
|
|
+ Department department = getById(departmentDto.getId());
|
|
|
+
|
|
|
+ if (ObjectUtil.notEqual(department.getAdminUsername(), departmentDto.getAdminUsername())) {
|
|
|
+ long count = sysUserService.count(Wrappers.<SysUser>lambdaQuery()
|
|
|
+ .eq(SysUser::getUserName, departmentDto.getAdminUsername()).last("limit 1"));
|
|
|
+ if (count != 0) {
|
|
|
+ throw new ServiceException("用户名已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUser oldUser = sysUserService.getOne(Wrappers.<SysUser>lambdaQuery()
|
|
|
+ .eq(SysUser::getUserName, department.getAdminUsername()).last("limit 1"));
|
|
|
+ oldUser.setUserName(departmentDto.getAdminUsername());
|
|
|
+ oldUser.setPassword(SecurityUtils.encryptPassword(departmentDto.getAdminPassword()));
|
|
|
+ sysUserService.updateById(oldUser);
|
|
|
+ } else if (ObjectUtil.notEqual(department.getAdminPassword(), departmentDto.getAdminPassword())) {
|
|
|
+ sysUserService.update(Wrappers.<SysUser>lambdaUpdate()
|
|
|
+ .eq(SysUser::getUserName, departmentDto.getAdminUsername())
|
|
|
+ .set(SysUser::getPassword, SecurityUtils.encryptPassword(departmentDto.getAdminPassword()))
|
|
|
+ .set(BaseEntity::getCreateBy, SecurityUtils.getUsername())
|
|
|
+ .set(BaseEntity::getCreateTime, new Date())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
this.updateById(departmentDto);
|
|
|
}
|
|
|
|