|
@@ -0,0 +1,162 @@
|
|
|
|
+package com.sd.business.service.department.impl;
|
|
|
|
+
|
|
|
|
+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.annotation.TenantIgnore;
|
|
|
|
+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.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 com.sd.framework.util.Assert;
|
|
|
|
+import com.sd.framework.util.sql.Sql;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 事业部 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author
|
|
|
|
+ * @since 2023-11-09
|
|
|
|
+ */
|
|
|
|
+@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) {
|
|
|
|
+
|
|
|
|
+ List<Long> detpIdList = sysUserService.getDetpIdListByUserId(SecurityUtils.getUserId());
|
|
|
|
+
|
|
|
|
+ Page<DepartmentVo> page = Sql.create(DepartmentVo.class)
|
|
|
|
+ .selectAll(Department.class)
|
|
|
|
+ .from(Department.class)
|
|
|
|
+ .in(Department::getId, detpIdList)
|
|
|
|
+ .like(Department::getName, dto.getName())
|
|
|
|
+ .eq(Department::getPriceSystemId, dto.getPriceSystemId())
|
|
|
|
+ .like(Department::getContactPerson, dto.getContactPerson())
|
|
|
|
+ .findInSet(Department::getPriceBillingStandardId, dto.getPriceBillingStandardId())
|
|
|
|
+ .orderByDesc(Department::getId)
|
|
|
|
+ .page(dto.getPage());
|
|
|
|
+
|
|
|
|
+ return page;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public DepartmentVo detail(Long id) {
|
|
|
|
+
|
|
|
|
+ DepartmentVo vo = Sql.create(DepartmentVo.class)
|
|
|
|
+ .selectAll(Department.class)
|
|
|
|
+ .from(Department.class)
|
|
|
|
+ .eq(Department::getId, id)
|
|
|
|
+ .one();
|
|
|
|
+
|
|
|
|
+ Assert.notNull(vo, "未知数据");
|
|
|
|
+
|
|
|
|
+ return vo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @TenantIgnore
|
|
|
|
+ @DSTransactional
|
|
|
|
+ @Override
|
|
|
|
+ public void add(DepartmentDto dto) {
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ String tenantId = "000000";
|
|
|
|
+ String name = dto.getName();
|
|
|
|
+ String adminUsername = dto.getAdminUsername();
|
|
|
|
+ String adminPassword = dto.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("admin");
|
|
|
|
+ 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("admin");
|
|
|
|
+ sysUser.setCreateTime(date);
|
|
|
|
+ sysUserService.save(sysUser);
|
|
|
|
+
|
|
|
|
+ sysRoleService.insertAuthUsers(10L, new Long[]{sysUser.getUserId()});
|
|
|
|
+
|
|
|
|
+ dto.setId(sysDept.getDeptId());
|
|
|
|
+ save(dto);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @TenantIgnore
|
|
|
|
+ @DSTransactional
|
|
|
|
+ @Override
|
|
|
|
+ public void edit(DepartmentDto dto) {
|
|
|
|
+
|
|
|
|
+ Department department = getById(dto.getId());
|
|
|
|
+
|
|
|
|
+ if (ObjectUtil.notEqual(department.getAdminUsername(), dto.getAdminUsername())) {
|
|
|
|
+ long count = sysUserService.count(Wrappers.<SysUser>lambdaQuery()
|
|
|
|
+ .eq(SysUser::getUserName, dto.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(dto.getAdminUsername());
|
|
|
|
+ oldUser.setPassword(SecurityUtils.encryptPassword(dto.getAdminPassword()));
|
|
|
|
+ sysUserService.updateById(oldUser);
|
|
|
|
+ } else if (ObjectUtil.notEqual(department.getAdminPassword(), dto.getAdminPassword())) {
|
|
|
|
+ sysUserService.update(Wrappers.lambdaUpdate(SysUser.class)
|
|
|
|
+ .eq(SysUser::getUserName, dto.getAdminUsername())
|
|
|
|
+ .set(SysUser::getPassword, SecurityUtils.encryptPassword(dto.getAdminPassword()))
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ updateById(dto);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void delete(Long id) {
|
|
|
|
+ removeById(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|