Browse Source

用户/专家/承办单位删除

licailing 5 năm trước cách đây
mục cha
commit
f5af9ae6f1

+ 14 - 1
src/main/java/com/izouma/wenlvju/domain/MessageRecord.java

@@ -1,19 +1,32 @@
 package com.izouma.wenlvju.domain;
 
+import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import javax.persistence.Entity;
+import java.time.LocalDateTime;
+
 
 @Data
 @Builder
+@Entity
 @AllArgsConstructor
 @NoArgsConstructor
-public class MessageRecord extends BaseEntity{
+public class MessageRecord extends BaseEntity {
     private String phone;
 
+    private String token;
+
+    @ApiModelProperty(value = "过期时间戳")
+    private String expiryDate;
+
     private String requestContent;
 
     private String responseContent;
+
+    @ApiModelProperty(value = "过期时间", name = "expiresAt")
+    private LocalDateTime expiresAt;
 }

+ 19 - 0
src/main/java/com/izouma/wenlvju/repo/MessageRecordRepo.java

@@ -0,0 +1,19 @@
+package com.izouma.wenlvju.repo;
+
+import com.izouma.wenlvju.domain.MessageRecord;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+
+import javax.transaction.Transactional;
+import java.time.LocalDateTime;
+
+public interface MessageRecordRepo extends JpaRepository<MessageRecord, Long>, JpaSpecificationExecutor<MessageRecord> {
+    @Query("update MessageRecord t set t.del = true where t.id = ?1")
+    @Modifying
+    @Transactional
+    void softDelete(Long id);
+
+    MessageRecord findFirstByExpiresAtBefore(LocalDateTime expiresAt);
+}

+ 1 - 0
src/main/java/com/izouma/wenlvju/repo/OrganizationRepo.java

@@ -21,4 +21,5 @@ public interface OrganizationRepo extends JpaRepository<Organization, Long>, Jpa
     int nextSort();
 
     Organization findByUscc(String uscc);
+
 }

+ 5 - 0
src/main/java/com/izouma/wenlvju/repo/RateAuditRepo.java

@@ -13,4 +13,9 @@ public interface RateAuditRepo extends JpaRepository<RateAudit, Long>, JpaSpecif
     @Modifying
     @Transactional
     void softDelete(Long id);
+
+    @Query("update RateAudit t set t.del = true where t.rateId in ?1")
+    @Modifying
+    @Transactional
+    void softDeleteByRateIdIn(Iterable<Long> rateIds);
 }

+ 5 - 0
src/main/java/com/izouma/wenlvju/repo/RateExpertAuditRepo.java

@@ -17,5 +17,10 @@ public interface RateExpertAuditRepo extends JpaRepository<RateExpertAudit, Long
 
     List<RateExpertAudit> findAllByRateId(Long rateId);
 
+    @Query("update RateExpertAudit t set t.del = true where t.rateId in ?1")
+    @Modifying
+    @Transactional
+    void softDeleteByRateIdIn(Iterable<Long> rateId);
+
     RateExpertAudit findByRateIdAndType(Long rateId, String type);
 }

+ 10 - 0
src/main/java/com/izouma/wenlvju/repo/RateRepo.java

@@ -17,7 +17,17 @@ public interface RateRepo extends JpaRepository<Rate, Long>, JpaSpecificationExe
     @Transactional
     void softDelete(Long id);
 
+    @Query("update Rate t set t.del = true where t.organizationId = ?1")
+    @Modifying
+    @Transactional
+    void softDeleteByOrganizationId(Long organizationId);
+
+    List<Rate> findAllByOrganizationId(@NonNull Long organizationId);
+
     Long countAllByOrganizationIdAndYearAndStatusNot(@NonNull Long organizationId, String year, RateStatus status);
 
     Long countAllByOrganizationIdAndYear(@NonNull Long organizationId, String year);
+
+    @Query(nativeQuery = true, value = "select count(1) from rate where expert_user_id = ?1 or find_in_set(?1,expert_member_user_id)")
+    Long countByExpertId(Long userId);
 }

+ 26 - 1
src/main/java/com/izouma/wenlvju/service/OrganizationService.java

@@ -1,21 +1,31 @@
 package com.izouma.wenlvju.service;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import com.izouma.wenlvju.domain.Organization;
 import com.izouma.wenlvju.domain.Rate;
 import com.izouma.wenlvju.dto.PageQuery;
 import com.izouma.wenlvju.exception.BusinessException;
 import com.izouma.wenlvju.repo.OrganizationRepo;
+import com.izouma.wenlvju.repo.RateAuditRepo;
+import com.izouma.wenlvju.repo.RateExpertAuditRepo;
+import com.izouma.wenlvju.repo.RateRepo;
 import com.izouma.wenlvju.utils.JpaUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 @Service
 @AllArgsConstructor
 public class OrganizationService {
 
-    private OrganizationRepo organizationRepo;
+    private final OrganizationRepo    organizationRepo;
+    private final RateRepo            rateRepo;
+    private final RateAuditRepo       rateAuditRepo;
+    private final RateExpertAuditRepo rateExpertAuditRepo;
 
     public Page<Organization> all(PageQuery pageQuery) {
         return organizationRepo.findAll(JpaUtils.toSpecification(pageQuery, Organization.class), JpaUtils.toPageRequest(pageQuery));
@@ -41,4 +51,19 @@ public class OrganizationService {
             organizationRepo.save(organization);
         }
     }
+
+    public void del(Long id) {
+        List<Rate> rates = rateRepo.findAllByOrganizationId(id);
+        List<Long> rateIds = rates.stream().map(Rate::getId).collect(Collectors.toList());
+        if (CollUtil.isNotEmpty(rateIds)) {
+            // 评分审核记录
+            rateAuditRepo.softDeleteByRateIdIn(rateIds);
+            // 评分细则
+            rateExpertAuditRepo.softDeleteByRateIdIn(rateIds);
+        }
+
+        // 评定申请
+        rateRepo.softDeleteByOrganizationId(id);
+        organizationRepo.softDelete(id);
+    }
 }

+ 16 - 0
src/main/java/com/izouma/wenlvju/service/UserService.java

@@ -54,6 +54,8 @@ public class UserService {
     private final OrganizationRepo        organizationRepo;
     private final CollaborateRepo         collaborateRepo;
     private final GradingOrganizationRepo gradingOrganizationRepo;
+    private final RateRepo                rateRepo;
+    private final OrganizationService     organizationService;
 
     public Page<User> all(PageQuery pageQuery) {
         return userRepo.findAll(JpaUtils.toSpecification(pageQuery, User.class), JpaUtils.toPageRequest(pageQuery));
@@ -76,6 +78,18 @@ public class UserService {
 
     public void del(Long id) {
         User user = userRepo.findById(id).orElseThrow(new BusinessException("用户不存在"));
+        Set<Authority> authorities = user.getAuthorities();
+        if (authorities.contains(Authority.get(AuthorityName.ROLE_EXPERT)) || authorities
+                .contains(Authority.get(AuthorityName.ROLE_DISTRICT_STAFF))) {
+            // 市政专家
+            if (rateRepo.countByExpertId(id) > 0) {
+                throw new BusinessException("参与的等级评定的专家不能删除!");
+            }
+        } else if (authorities.contains(Authority.get(AuthorityName.ROLE_ORGANIZER))) {
+            // 承办单位
+            organizationRepo.findByUserId(id).ifPresent(organization -> organizationService.del(organization.getId()));
+        }
+
         user.setDel(true);
         if (StringUtils.isNoneEmpty(user.getOpenId())) {
             user.setOpenId(user.getOpenId() + "###" + RandomStringUtils.randomAlphabetic(8));
@@ -84,6 +98,8 @@ public class UserService {
             user.setPhone(user.getPhone() + "###" + RandomStringUtils.randomAlphabetic(8));
         }
         userRepo.save(user);
+
+
     }
 
     public User loginByPhone(String phone) {

+ 0 - 4
src/main/java/com/izouma/wenlvju/service/sms/NjwlSmsService.java

@@ -1,10 +1,7 @@
 package com.izouma.wenlvju.service.sms;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.parser.Feature;
 import com.github.kevinsawicki.http.HttpRequest;
-import com.izouma.wenlvju.domain.MessageRecord;
 import com.izouma.wenlvju.domain.SmsRecord;
 import com.izouma.wenlvju.exception.BusinessException;
 import com.izouma.wenlvju.repo.SmsRecordRepo;
@@ -20,7 +17,6 @@ import java.io.StringWriter;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.util.HashMap;
-import java.util.LinkedHashMap;
 import java.util.Map;
 
 @Service

+ 1 - 1
src/main/java/com/izouma/wenlvju/web/OrganizationController.java

@@ -72,7 +72,7 @@ public class OrganizationController extends BaseController {
 
     @PostMapping("/del/{id}")
     public void del(@PathVariable Long id) {
-        organizationRepo.softDelete(id);
+        organizationService.del(id);
     }
 
     @GetMapping("/excel")

+ 1 - 0
src/main/vue/src/views/organization/OrganizationEdit.vue

@@ -133,6 +133,7 @@
                 <!-- <el-button @click="readonly = false" :loading="saving" type="success">编辑</el-button> -->
                 <div style="margin: 10px">
                     <!-- <el-button @click="onSave" :loading="saving" type="primary">保存</el-button> -->
+                    <el-button @click="onDelete" type="danger" size="mini">删除</el-button>
                     <el-button @click="$router.go(-1)">返回</el-button>
                 </div>
             </el-form-item>

+ 5 - 5
src/main/vue/src/views/organization/OrganizationList.vue

@@ -26,8 +26,8 @@
         >
             <el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
             <el-table-column prop="id" label="ID" width="80"> </el-table-column>
-            <el-table-column prop="name" label="承办单位名称"> </el-table-column>
-            <el-table-column prop="uscc" label="统一社会信用代码"></el-table-column>
+            <el-table-column prop="name" label="承办单位名称" show-overflow-tooltip> </el-table-column>
+            <el-table-column prop="uscc" label="统一社会信用代码" show-overflow-tooltip></el-table-column>
             <el-table-column prop="district" label="所属区县"> </el-table-column>
             <el-table-column prop="businessLicense" label="营业执照">
                 <template slot-scope="{ row }">
@@ -41,12 +41,12 @@
             </el-table-column>
             <el-table-column prop="owner" label="负责人"> </el-table-column>
             <el-table-column prop="privacyPolicy" label="法人姓名"> </el-table-column>
-            <el-table-column prop="idNo" label="证件号码"> </el-table-column>
+            <el-table-column prop="idNo" label="证件号码" show-overflow-tooltip> </el-table-column>
             <el-table-column prop="businessScope" label="经营范围" min-width="150"> </el-table-column>
             <el-table-column label="操作" align="center" fixed="right" min-width="150">
                 <template slot-scope="{ row }">
-                    <el-button @click="editRow(row)" type="primary" size="mini" plain>编辑</el-button>
-                    <!-- <el-button @click="deleteRow(row)" type="danger" size="mini" plain>删除</el-button> -->
+                    <el-button @click="editRow(row)" type="primary" size="mini" plain>查看</el-button>
+                    <el-button @click="deleteRow(row)" type="danger" size="mini" plain>删除</el-button>
                 </template>
             </el-table-column>
         </el-table>

+ 17 - 1
src/main/vue/src/views/user/ExpertList.vue

@@ -41,9 +41,10 @@
                     ></el-image>
                 </template>
             </el-table-column> -->
-            <el-table-column label="操作" align="center" fixed="right">
+            <el-table-column label="操作" align="center" fixed="right" min-width="150">
                 <template slot-scope="{ row }">
                     <el-button @click="editRow(row)" type="primary" size="mini" plain>编辑</el-button>
+                    <el-button @click="deleteRow(row)" type="danger" size="mini" plain>删除</el-button>
                 </template>
             </el-table-column>
         </el-table>
@@ -171,6 +172,21 @@ export default {
                         this.$message.error(e.error);
                     });
             }
+        },
+        deleteRow(row) {
+            this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
+                .then(() => {
+                    return this.$http.post(`/user/del/${row.id}`);
+                })
+                .then(() => {
+                    this.$message.success('删除成功');
+                    this.getData();
+                })
+                .catch(e => {
+                    if (e !== 'cancel') {
+                        this.$message.error(e.error);
+                    }
+                });
         }
     }
 };

+ 17 - 1
src/main/vue/src/views/user/UserList.vue

@@ -48,9 +48,10 @@
             <el-table-column prop="phone" label="手机号" min-width="100"> </el-table-column>
             <el-table-column prop="work" label="工作单位" min-width="100"> </el-table-column>
             <el-table-column prop="position" label="职位" min-width="100"> </el-table-column>
-            <el-table-column label="操作" align="center" fixed="right">
+            <el-table-column label="操作" align="center" fixed="right" min-width="150">
                 <template slot-scope="{ row }">
                     <el-button @click="editRow(row)" type="primary" size="mini" plain>编辑</el-button>
+                    <el-button @click="deleteRow(row)" type="danger" size="mini" plain>删除</el-button>
                 </template>
             </el-table-column>
         </el-table>
@@ -196,6 +197,21 @@ export default {
                 }
             });
             return flag;
+        },
+        deleteRow(row) {
+            this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
+                .then(() => {
+                    return this.$http.post(`/user/del/${row.id}`);
+                })
+                .then(() => {
+                    this.$message.success('删除成功');
+                    this.getData();
+                })
+                .catch(e => {
+                    if (e !== 'cancel') {
+                        this.$message.error(e.error);
+                    }
+                });
         }
     }
 };

+ 0 - 1
src/test/java/com/izouma/wenlvju/repo/RateExpertAuditRepoTest.java

@@ -21,5 +21,4 @@ public class RateExpertAuditRepoTest extends ApplicationTests {
                         "https://ticket-exchange.oss-cn-hangzhou.aliyuncs.com/image/2021-04-08-14-45-42CvVMClla.jpg"))
                 .build());
     }
-
 }

+ 5 - 0
src/test/java/com/izouma/wenlvju/service/RateServiceTest.java

@@ -169,4 +169,9 @@ public class RateServiceTest extends ApplicationTests {
 //        wb.saveToFile("output/ToPDF.pdf", FileFormat.PDF);
     }
 
+
+    @Test
+    public void test10() {
+        System.out.println(rateRepo.countByExpertId(700l));
+    }
 }