Pārlūkot izejas kodu

删除判断+user邮箱

he.dujuan 3 gadi atpakaļ
vecāks
revīzija
3a85a0f4ac

+ 2 - 1
eladmin-common/src/main/java/me/zhengjie/exception/EntityExistException.java

@@ -29,6 +29,7 @@ public class EntityExistException extends RuntimeException {
 
     private static String generateMessage(String entity, String field, String val) {
         return StringUtils.capitalize(entity)
-                + " with " + field + " "+ val + " existed";
+                + " 已存在 " + field + " "+ val + " 的用户";
+//                + " with " + field + " "+ val + " existed";
     }
 }

+ 6 - 5
eladmin-system/src/main/java/me/zhengjie/modules/dm/company/rest/DmCompanyController.java

@@ -30,6 +30,7 @@ import io.swagger.annotations.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
+import java.util.Map;
 import javax.servlet.http.HttpServletResponse;
 
 /**
@@ -64,8 +65,8 @@ public class DmCompanyController {
     @PostMapping
     @Log("新增单位")
     @ApiOperation("新增单位")
-    @PreAuthorize("@el.check('dmCompany:add')")
-    public ResponseEntity<Object> create(@Validated @RequestBody DmCompany resources, @RequestParam("file") MultipartFile file){
+    @PreAuthorize("@el.check('dmCompany:add')")                                     //, @RequestParam("file") MultipartFile file
+    public ResponseEntity<Object> create(@Validated @RequestBody DmCompany resources){
         return new ResponseEntity<>(dmCompanyService.create(resources),HttpStatus.CREATED);
     }
 
@@ -83,7 +84,7 @@ public class DmCompanyController {
     @PreAuthorize("@el.check('dmCompany:del')")
     @DeleteMapping
     public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
-        dmCompanyService.deleteAll(ids);
-        return new ResponseEntity<>(HttpStatus.OK);
+        Map<String,Object> map = dmCompanyService.deleteAll(ids);
+        return new ResponseEntity<>(map ,HttpStatus.OK);
     }
-}
+}

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/dm/company/service/DmCompanyService.java

@@ -71,7 +71,7 @@ public interface DmCompanyService {
     * 多选删除
     * @param ids /
     */
-    void deleteAll(Long[] ids);
+    Map<String,Object> deleteAll(Long[] ids);
 
     /**
     * 导出数据

+ 17 - 6
eladmin-system/src/main/java/me/zhengjie/modules/dm/company/service/impl/DmCompanyServiceImpl.java

@@ -16,6 +16,7 @@
 package me.zhengjie.modules.dm.company.service.impl;
 
 import me.zhengjie.modules.dm.company.domain.DmCompany;
+import me.zhengjie.modules.system.repository.UserRepository;
 import me.zhengjie.utils.ValidationUtil;
 import me.zhengjie.utils.FileUtil;
 import lombok.RequiredArgsConstructor;
@@ -24,6 +25,7 @@ import me.zhengjie.modules.dm.company.service.DmCompanyService;
 import me.zhengjie.modules.dm.company.service.dto.DmCompanyDto;
 import me.zhengjie.modules.dm.company.service.dto.DmCompanyQueryCriteria;
 import me.zhengjie.modules.dm.company.service.mapstruct.DmCompanyMapper;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import cn.hutool.core.lang.Snowflake;
@@ -32,12 +34,10 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import me.zhengjie.utils.PageUtil;
 import me.zhengjie.utils.QueryHelp;
-import java.util.List;
-import java.util.Map;
+
+import java.util.*;
 import java.io.IOException;
 import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
 
 /**
 * @website https://el-admin.vip
@@ -51,6 +51,8 @@ public class DmCompanyServiceImpl implements DmCompanyService {
 
     private final DmCompanyRepository dmCompanyRepository;
     private final DmCompanyMapper dmCompanyMapper;
+    @Autowired
+    private final UserRepository userRepository;
 
     @Override
     public Map<String,Object> queryAll(DmCompanyQueryCriteria criteria, Pageable pageable){
@@ -89,10 +91,19 @@ public class DmCompanyServiceImpl implements DmCompanyService {
     }
 
     @Override
-    public void deleteAll(Long[] ids) {
+    public Map<String,Object> deleteAll(Long[] ids) {
+        Map<String,Object> map= new HashMap<>();
+        List name=userRepository.selectCompanyName(ids);
         for (Long companyId : ids) {
-            dmCompanyRepository.deleteById(companyId);
+            Integer count = userRepository.selecIsNotCompany(companyId);
+            if(count<=0){
+                dmCompanyRepository.deleteById(companyId);
+            }else {
+                map.put("lose",name+"已绑定用户,不能删除");
+                map.put("type", "company");
+            }
         }
+        return map;
     }
 
     @Override

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/dm/order/repository/DmOrderRecordRepository.java

@@ -41,7 +41,7 @@ public interface DmOrderRecordRepository extends JpaRepository<DmOrderRecord, Lo
      * 昨日收入
      * @return
      */
-    @Query(value = "SELECT SUM(amt) FROM dm_order_record WHERE create_date BETWEEN DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 DAY),'%Y-%m-%d 00:00:00') AND DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 DAY),'%Y-%m-%d 23:59:59') ",nativeQuery = true)
+    @Query(value = "SELECT IF(SUM(amt) is null,0,SUM(amt)) FROM dm_order_record WHERE create_date BETWEEN DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 DAY),'%Y-%m-%d 00:00:00') AND DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 DAY),'%Y-%m-%d 23:59:59') ",nativeQuery = true)
     Integer countIncome();
 
     /**

+ 10 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/user/repository/DmUserRepository.java

@@ -45,4 +45,14 @@ public interface DmUserRepository extends JpaRepository<DmUser, Long>, JpaSpecif
      * @return /
      */
     DmUser findByEmail(String email);
+
+    /**
+     * 查询
+     * @return
+     */
+    @Query(value = "SELECT COUNT(1) FROM dm_user WHERE dept_id = ?1",nativeQuery = true)
+    Integer selecIsNotDept(Long floorId);
+
+    @Query(value = "SELECT DISTINCT name FROM sys_dept WHERE dept_id in (?1)",nativeQuery = true)
+    List selectDeptName(Long floorId);
 }

+ 3 - 3
eladmin-system/src/main/java/me/zhengjie/modules/system/domain/User.java

@@ -82,7 +82,7 @@ public class User extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "用户名称")
     private String username;
 
-//    @NotBlank
+    //    @NotBlank
     @ApiModelProperty(value = "用户昵称")
     private String nickName;
 
@@ -118,7 +118,7 @@ public class User extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "最后修改密码的时间", hidden = true)
     private Date pwdResetTime;
 
-    @NotNull
+    //    @NotNull
     @ApiModelProperty(value = "初始密码", hidden = true)
     private String orgPassword;
 
@@ -150,4 +150,4 @@ public class User extends BaseEntity implements Serializable {
     public int hashCode() {
         return Objects.hash(id, username);
     }
-}
+}

+ 6 - 0
eladmin-system/src/main/java/me/zhengjie/modules/system/repository/UserRepository.java

@@ -133,4 +133,10 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
     @Query(value = "SELECT u.* FROM sys_user u WHERE " +
             "u.dm_user_id = :dmUserId AND if(:userId != '',u.user_id != :userId,1=1)",nativeQuery = true)
     List<User> findByDmUserId(@Param("dmUserId")Long dmUserId, @Param("userId") Long userId);
+
+    @Query(value = "SELECT COUNT(1) FROM sys_user WHERE company_id = ?1",nativeQuery = true)
+    Integer selecIsNotCompany(Long companyId);
+
+    @Query(value = "SELECT DISTINCT full_name FROM dm_company WHERE company_id in (?1)",nativeQuery = true)
+    List selectCompanyName(Long[] companyId);
 }

+ 2 - 2
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/DeptController.java

@@ -119,7 +119,7 @@ public class DeptController {
         }
         // 验证是否被角色或用户关联
         deptService.verification(deptDtos);
-        deptService.delete(deptDtos);
-        return new ResponseEntity<>(HttpStatus.OK);
+        Map<String,Object> map = deptService.delete(deptDtos);
+        return new ResponseEntity<>(map, HttpStatus.OK);
     }
 }

+ 2 - 1
eladmin-system/src/main/java/me/zhengjie/modules/system/service/DeptService.java

@@ -23,6 +23,7 @@ import org.springframework.data.domain.Pageable;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 /**
@@ -73,7 +74,7 @@ public interface DeptService {
      * @param deptDtos /
      *
      */
-    void delete(Set<DeptDto> deptDtos);
+    Map<String,Object> delete(Set<DeptDto> deptDtos);
 
     /**
      * 根据PID查询

+ 25 - 5
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java

@@ -19,6 +19,7 @@ import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
 import lombok.RequiredArgsConstructor;
 import me.zhengjie.exception.BadRequestException;
+import me.zhengjie.modules.dm.user.repository.DmUserRepository;
 import me.zhengjie.modules.system.domain.Dept;
 import me.zhengjie.modules.system.domain.Dict;
 import me.zhengjie.modules.system.domain.User;
@@ -58,6 +59,7 @@ public class DeptServiceImpl implements DeptService {
     private final UserRepository userRepository;
     private final RedisUtils redisUtils;
     private final RoleRepository roleRepository;
+    private final DmUserRepository dmUserRepository;
 
     @Override
     public List<DeptDto> queryAll2(DeptQueryCriteria criteria,  String[] sortList,Boolean isQuery) throws Exception {
@@ -173,13 +175,31 @@ public class DeptServiceImpl implements DeptService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void delete(Set<DeptDto> deptDtos) {
+    public Map<String,Object> delete(Set<DeptDto> deptDtos) {
+        Map<String,Object> map= new HashMap<>();
+        List list = new ArrayList();
+        for (DeptDto deptDto : deptDtos){
+            list.add(dmUserRepository.selectDeptName(deptDto.getId()));
+        }
         for (DeptDto deptDto : deptDtos) {
-            // 清理缓存
-            delCaches(deptDto.getId());
-            deptRepository.deleteById(deptDto.getId());
-            updateSubCnt(deptDto.getPid());
+            Integer count = dmUserRepository.selecIsNotDept(deptDto.getId());
+            if(count<=0){
+                // 清理缓存
+                delCaches(deptDto.getId());
+                deptRepository.deleteById(deptDto.getId());
+                updateSubCnt(deptDto.getPid());
+            }else {
+                map.put("lose",list+"已绑定人员,不能删除");
+                map.put("type", "dept");
+            }
         }
+        return map;
+//        for (DeptDto deptDto : deptDtos) {
+//            // 清理缓存
+//            delCaches(deptDto.getId());
+//            deptRepository.deleteById(deptDto.getId());
+//            updateSubCnt(deptDto.getPid());
+//        }
     }
 
     @Override

+ 2 - 2
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java

@@ -97,13 +97,13 @@ public class UserServiceImpl implements UserService {
         //设置用户信息
         resources = setDmUserInfoToSysUser(resources);
         if (userRepository.findByUsername(resources.getUsername()) != null) {
-            throw new EntityExistException(User.class, "username", resources.getUsername());
+            throw new EntityExistException(User.class, "用户名称", resources.getUsername());
         }
         /*if (userRepository.findByEmail(resources.getEmail()) != null) {
             throw new EntityExistException(User.class, "email", resources.getEmail());
         }*/
         if (userRepository.findByPhone(resources.getPhone()) != null) {
-            throw new EntityExistException(User.class, "phone", resources.getPhone());
+            throw new EntityExistException(User.class, "手机号", resources.getPhone());
         }
         userRepository.save(resources);
     }