Просмотр исходного кода

Merge branch 'dev-meta' of xiongzhu/raex_back into master

sunkean 3 лет назад
Родитель
Сommit
4b9fec2fb6

+ 6 - 1
src/main/java/com/izouma/nineth/domain/MetaEmail.java

@@ -8,13 +8,14 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import javax.persistence.Entity;
+import javax.persistence.Transient;
 
 @Data
 @AllArgsConstructor
 @NoArgsConstructor
 @Entity
 @ApiModel("元宇宙邮件配置")
-public class MetaEmail extends BaseEntity{
+public class MetaEmail extends BaseEntity {
 
     @ApiModelProperty("邮件标题")
     @ExcelProperty("邮件标题")
@@ -31,5 +32,9 @@ public class MetaEmail extends BaseEntity{
     @ApiModelProperty("是否发布")
     @ExcelProperty("是否发布")
     private boolean publish;
+
+    @ApiModelProperty("是否发布")
+    @Transient
+    private boolean read;
 }
 

+ 35 - 0
src/main/java/com/izouma/nineth/domain/MetaEmailRecord.java

@@ -0,0 +1,35 @@
+package com.izouma.nineth.domain;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Entity;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Entity
+@ApiModel("元宇宙题库记录")
+public class MetaEmailRecord extends BaseEntity {
+
+    @ApiModelProperty("用户ID")
+    @ExcelProperty("用户ID")
+    private Long userId;
+
+    @ApiModelProperty("邮件id")
+    @ExcelProperty("邮件id‘")
+    private Long emailId;
+
+    @ApiModelProperty("是否删除")
+    @ExcelProperty("是否删除")
+    private boolean emailDel;
+
+    @ApiModelProperty("是否已读")
+    @ExcelProperty("是否已读")
+    private boolean emailRead;
+
+}

+ 19 - 0
src/main/java/com/izouma/nineth/repo/MetaEmailRecordRepo.java

@@ -0,0 +1,19 @@
+package com.izouma.nineth.repo;
+
+import com.izouma.nineth.domain.MetaEmailRecord;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.List;
+
+public interface MetaEmailRecordRepo extends JpaRepository<MetaEmailRecord, Long>, JpaSpecificationExecutor<MetaEmailRecord> {
+
+    @Query("SELECT m.emailId FROM MetaEmailRecord m WHERE m.userId = ?1 AND m.emailDel = ?2")
+    List<Long> findEmailIdByDel(Long userId, boolean emailDel);
+
+    @Query("SELECT m.emailId FROM MetaEmailRecord m WHERE m.userId = ?1 AND m.emailRead = ?2")
+    List<Long> findEmailIdRead(Long userId, boolean emailRead);
+
+    MetaEmailRecord findByUserIdAndEmailId(Long userId, Long emailId);
+}

+ 5 - 0
src/main/java/com/izouma/nineth/repo/MetaEmailRepo.java

@@ -7,10 +7,15 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 
 import javax.transaction.Transactional;
+import java.util.List;
 
 public interface MetaEmailRepo extends JpaRepository<MetaEmail, Long>, JpaSpecificationExecutor<MetaEmail> {
     @Query("update MetaEmail t set t.del = true where t.id = ?1")
     @Modifying
     @Transactional
     void softDelete(Long id);
+
+    List<MetaEmail> findAllByDelAndIdNotIn(boolean del, List<Long> id);
+
+    List<MetaEmail> findAllByDel(boolean del);
 }

+ 5 - 2
src/main/java/com/izouma/nineth/repo/MetaZoumaLightRepo.java → src/main/java/com/izouma/nineth/repo/MetaZouMaLightRepo.java

@@ -8,11 +8,14 @@ import org.springframework.data.jpa.repository.Query;
 
 import javax.transaction.Transactional;
 
-public interface MetaZoumaLightRepo extends JpaRepository<MetaZouMaLight, Long>, JpaSpecificationExecutor<MetaZouMaLight> {
+public interface MetaZouMaLightRepo extends JpaRepository<MetaZouMaLight, Long>, JpaSpecificationExecutor<MetaZouMaLight> {
     @Query("update MetaZouMaLight t set t.del = true where t.id = ?1")
     @Modifying
     @Transactional
     void softDelete(Long id);
 
-    MetaZouMaLight findByPublishAndDel (boolean publish, boolean del);
+    MetaZouMaLight findByPublishAndDel(boolean publish, boolean del);
+
+    @Query("SELECT m.description FROM MetaZouMaLight m WHERE m.publish = ?1 AND m.del = ?2")
+    String findDescriptionByPublishAndDel(boolean publish, boolean del);
 }

+ 21 - 0
src/main/java/com/izouma/nineth/service/MetaEmailRecordService.java

@@ -0,0 +1,21 @@
+package com.izouma.nineth.service;
+
+import com.izouma.nineth.domain.MetaEmailRecord;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.repo.MetaEmailRecordRepo;
+import com.izouma.nineth.utils.JpaUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.stereotype.Service;
+
+@Service
+@AllArgsConstructor
+public class MetaEmailRecordService {
+
+    private MetaEmailRecordRepo metaEmailRecordRepo;
+
+    public Page<MetaEmailRecord> all(PageQuery pageQuery) {
+        return metaEmailRecordRepo.findAll(JpaUtils.toSpecification(pageQuery, MetaEmailRecord.class), JpaUtils.toPageRequest(pageQuery));
+    }
+
+}

+ 28 - 0
src/main/java/com/izouma/nineth/service/MetaEmailService.java

@@ -1,20 +1,48 @@
 package com.izouma.nineth.service;
 
 import com.izouma.nineth.domain.MetaEmail;
+import com.izouma.nineth.dto.MetaRestResult;
 import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.repo.MetaEmailRecordRepo;
 import com.izouma.nineth.repo.MetaEmailRepo;
 import com.izouma.nineth.utils.JpaUtils;
+import com.izouma.nineth.utils.SecurityUtils;
 import lombok.AllArgsConstructor;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
 @AllArgsConstructor
 public class MetaEmailService {
 
     private MetaEmailRepo metaEmailRepo;
 
+    private MetaEmailRecordRepo metaEmailRecordRepo;
+
     public Page<MetaEmail> all(PageQuery pageQuery) {
         return metaEmailRepo.findAll(JpaUtils.toSpecification(pageQuery, MetaEmail.class), JpaUtils.toPageRequest(pageQuery));
     }
+
+    public MetaRestResult<List<MetaEmail>> metaQuery() {
+        Long userId = SecurityUtils.getAuthenticatedUser().getId();
+        List<Long> delIds = metaEmailRecordRepo.findEmailIdByDel(userId, true);
+        List<MetaEmail> metaEmails;
+        metaEmails = CollectionUtils.isEmpty(delIds) ? metaEmailRepo.findAllByDel(false) : metaEmailRepo.findAllByDelAndIdNotIn(false, delIds);
+        if (CollectionUtils.isEmpty(metaEmails)) {
+            return MetaRestResult.returnSuccess(metaEmails);
+        }
+        List<Long> readIds = metaEmailRecordRepo.findEmailIdRead(userId, true);
+        if (CollectionUtils.isEmpty(readIds)) {
+            return MetaRestResult.returnSuccess(metaEmails);
+        }
+        metaEmails.forEach(metaEmail -> {
+            if (readIds.contains(metaEmail.getId())) {
+                metaEmail.setRead(true);
+            }
+        });
+        return MetaRestResult.returnSuccess(metaEmails);
+    }
 }

+ 3 - 3
src/main/java/com/izouma/nineth/service/MetaZoumaLightService.java → src/main/java/com/izouma/nineth/service/MetaZouMaLightService.java

@@ -2,7 +2,7 @@ package com.izouma.nineth.service;
 
 import com.izouma.nineth.domain.MetaZouMaLight;
 import com.izouma.nineth.dto.PageQuery;
-import com.izouma.nineth.repo.MetaZoumaLightRepo;
+import com.izouma.nineth.repo.MetaZouMaLightRepo;
 import com.izouma.nineth.utils.JpaUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Page;
@@ -10,9 +10,9 @@ import org.springframework.stereotype.Service;
 
 @Service
 @AllArgsConstructor
-public class MetaZoumaLightService {
+public class MetaZouMaLightService {
 
-    private MetaZoumaLightRepo metaZoumaLightRepo;
+    private MetaZouMaLightRepo metaZoumaLightRepo;
 
     public Page<MetaZouMaLight> all(PageQuery pageQuery) {
         return metaZoumaLightRepo.findAll(JpaUtils.toSpecification(pageQuery, MetaZouMaLight.class), JpaUtils.toPageRequest(pageQuery));

+ 7 - 0
src/main/java/com/izouma/nineth/web/MetaEmailController.java

@@ -1,5 +1,7 @@
 package com.izouma.nineth.web;
+
 import com.izouma.nineth.domain.MetaEmail;
+import com.izouma.nineth.dto.MetaRestResult;
 import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.MetaEmailRepo;
@@ -62,5 +64,10 @@ public class MetaEmailController extends BaseController {
         metaEmail.setPublish(true);
         metaEmailRepo.save(metaEmail);
     }
+
+    @GetMapping("/metaQuery")
+    public MetaRestResult<List<MetaEmail>> metaQuery() {
+        return metaEmailService.metaQuery();
+    }
 }
 

+ 57 - 0
src/main/java/com/izouma/nineth/web/MetaEmailRecordController.java

@@ -0,0 +1,57 @@
+package com.izouma.nineth.web;
+
+import com.izouma.nineth.domain.MetaEmailRecord;
+import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.repo.MetaEmailRecordRepo;
+import com.izouma.nineth.service.MetaEmailRecordService;
+import com.izouma.nineth.utils.SecurityUtils;
+import com.izouma.nineth.utils.excel.ExcelUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.Objects;
+
+@RestController
+@RequestMapping("/metaEmailRecord")
+@AllArgsConstructor
+public class MetaEmailRecordController extends BaseController {
+
+    private MetaEmailRecordService metaEmailRecordService;
+    private MetaEmailRecordRepo metaEmailRecordRepo;
+
+    //@PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/all")
+    public Page<MetaEmailRecord> all(@RequestBody PageQuery pageQuery) {
+        return metaEmailRecordService.all(pageQuery);
+    }
+
+
+    @GetMapping("/excel")
+    @ResponseBody
+    public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
+        List<MetaEmailRecord> data = all(pageQuery).getContent();
+        ExcelUtils.export(response, data);
+    }
+
+    @PostMapping("/{emailId}/readEmail")
+    public void readEmail(@PathVariable Long emailId) {
+        metaEmailRecordRepo.save(new MetaEmailRecord(SecurityUtils.getAuthenticatedUser().getId(), emailId, false, true));
+    }
+
+    @PostMapping("/{emailId}/delEmail")
+    public void delEmail(@PathVariable Long emailId) {
+        Long userId = SecurityUtils.getAuthenticatedUser().getId();
+        MetaEmailRecord metaEmailRecord = metaEmailRecordRepo.findByUserIdAndEmailId(userId, emailId);
+        if (Objects.isNull(metaEmailRecord)) {
+            metaEmailRecordRepo.save(new MetaEmailRecord(userId, emailId, true, true));
+            return;
+        }
+        metaEmailRecord.setEmailDel(true);
+        metaEmailRecordRepo.save(metaEmailRecord);
+    }
+}
+

+ 22 - 15
src/main/java/com/izouma/nineth/web/MetaZoumaLightController.java → src/main/java/com/izouma/nineth/web/MetaZouMaLightController.java

@@ -1,9 +1,11 @@
 package com.izouma.nineth.web;
+
 import com.izouma.nineth.domain.MetaZouMaLight;
+import com.izouma.nineth.dto.MetaRestResult;
 import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.exception.BusinessException;
-import com.izouma.nineth.repo.MetaZoumaLightRepo;
-import com.izouma.nineth.service.MetaZoumaLightService;
+import com.izouma.nineth.repo.MetaZouMaLightRepo;
+import com.izouma.nineth.service.MetaZouMaLightService;
 import com.izouma.nineth.utils.ObjUtils;
 import com.izouma.nineth.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
@@ -16,44 +18,44 @@ import java.util.List;
 import java.util.Objects;
 
 @RestController
-@RequestMapping("/metaZoumaLight")
+@RequestMapping("/metaZouMaLight")
 @AllArgsConstructor
-public class MetaZoumaLightController extends BaseController {
-    private MetaZoumaLightService metaZoumaLightService;
-    private MetaZoumaLightRepo metaZoumaLightRepo;
+public class MetaZouMaLightController extends BaseController {
+
+    private MetaZouMaLightService metaZouMaLightService;
+    private MetaZouMaLightRepo metaZouMaLightRepo;
 
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
     public MetaZouMaLight save(@RequestBody MetaZouMaLight record) {
         if (record.isPublish()) {
-            MetaZouMaLight metaZoumaLight = metaZoumaLightRepo.findByPublishAndDel(true,false);
-            if (Objects.nonNull(metaZoumaLight) && !Objects.equals(metaZoumaLight.getId(), record.getId())){
+            MetaZouMaLight metaZoumaLight = metaZouMaLightRepo.findByPublishAndDel(true, false);
+            if (Objects.nonNull(metaZoumaLight) && !Objects.equals(metaZoumaLight.getId(), record.getId())) {
                 throw new BusinessException("仅允许发布一条!");
             }
         }
         if (record.getId() != null) {
-            MetaZouMaLight orig = metaZoumaLightRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
+            MetaZouMaLight orig = metaZouMaLightRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
             ObjUtils.merge(orig, record);
-            return metaZoumaLightRepo.save(orig);
+            return metaZouMaLightRepo.save(orig);
         }
-        return metaZoumaLightRepo.save(record);
+        return metaZouMaLightRepo.save(record);
     }
 
-
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/all")
     public Page<MetaZouMaLight> all(@RequestBody PageQuery pageQuery) {
-        return metaZoumaLightService.all(pageQuery);
+        return metaZouMaLightService.all(pageQuery);
     }
 
     @GetMapping("/get/{id}")
     public MetaZouMaLight get(@PathVariable Long id) {
-        return metaZoumaLightRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        return metaZouMaLightRepo.findById(id).orElseThrow(new BusinessException("无记录"));
     }
 
     @PostMapping("/del/{id}")
     public void del(@PathVariable Long id) {
-        metaZoumaLightRepo.softDelete(id);
+        metaZouMaLightRepo.softDelete(id);
     }
 
     @GetMapping("/excel")
@@ -62,5 +64,10 @@ public class MetaZoumaLightController extends BaseController {
         List<MetaZouMaLight> data = all(pageQuery).getContent();
         ExcelUtils.export(response, data);
     }
+
+    @PostMapping("/metaQuery")
+    public MetaRestResult<String> metaQuery() {
+        return MetaRestResult.returnSuccess(metaZouMaLightRepo.findDescriptionByPublishAndDel(true, false));
+    }
 }
 

+ 6 - 6
src/main/vue/src/router.js

@@ -1598,17 +1598,17 @@ const router = new Router({
                     },
                 },
                 {
-                    path: '/metaZoumaLightEdit',
-                    name: 'MetaZoumaLightEdit',
-                    component: () => import(/* webpackChunkName: "metaZoumaLightEdit" */ '@/views/MetaZoumaLightEdit.vue'),
+                    path: '/metaZouMaLightEdit',
+                    name: 'MetaZouMaLightEdit',
+                    component: () => import(/* webpackChunkName: "metaZouMaLightEdit" */ '@/views/MetaZouMaLightEdit.vue'),
                     meta: {
                         title: '走马灯编辑',
                     },
                 },
                 {
-                    path: '/metaZoumaLightList',
-                    name: 'MetaZoumaLightList',
-                    component: () => import(/* webpackChunkName: "metaZoumaLightList" */ '@/views/MetaZoumaLightList.vue'),
+                    path: '/metaZouMaLightList',
+                    name: 'MetaZouMaLightList',
+                    component: () => import(/* webpackChunkName: "metaZouMaLightList" */ '@/views/MetaZouMaLightList.vue'),
                     meta: {
                         title: '走马灯',
                     },

+ 4 - 4
src/main/vue/src/views/MetaZoumaLightEdit.vue → src/main/vue/src/views/MetaZouMaLightEdit.vue

@@ -43,11 +43,11 @@
 </template>
 <script>
 export default {
-	name: 'MetaZoumaLightEdit',
+	name: 'MetaZouMaLightEdit',
 	created() {
 		if (this.$route.query.id) {
 			this.$http
-				.get('metaZoumaLight/get/' + this.$route.query.id)
+				.get('metaZouMaLight/get/' + this.$route.query.id)
 				.then(res => {
 					this.formData = res;
 				})
@@ -87,7 +87,7 @@ export default {
 
 			this.saving = true;
 			this.$http
-				.post('/metaZoumaLight/save', data, { body: 'json' })
+				.post('/metaZouMaLight/save', data, { body: 'json' })
 				.then(res => {
 					this.saving = false;
 					this.$message.success('成功');
@@ -102,7 +102,7 @@ export default {
 		onDelete() {
 			this.$confirm('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
 				.then(() => {
-					return this.$http.post(`/metaZoumaLight/del/${this.formData.id}`);
+					return this.$http.post(`/metaZouMaLight/del/${this.formData.id}`);
 				})
 				.then(() => {
 					this.$message.success('删除成功');

+ 8 - 8
src/main/vue/src/views/MetaZoumaLightList.vue → src/main/vue/src/views/MetaZouMaLightList.vue

@@ -58,9 +58,9 @@
 			</el-table-column>
 		</el-table>
 		<div class="pagination-wrapper">
-			<!-- <div class="multiple-mode-wrapper"> 
+			<!-- <div class="multiple-mode-wrapper">
                 <el-button v-if="!multipleMode" @click="toggleMultipleMode(true)"> 批量编辑 </el-button>
-                <el-button-group v-else> 
+                <el-button-group v-else>
                     <el-button @click="operation1"> 批量操作1 </el-button>
                     <el-button @click="operation2"> 批量操作2 </el-button>
                     <el-button @click="toggleMultipleMode(false)"> 取消 </el-button>
@@ -85,13 +85,13 @@ import { mapState } from 'vuex';
 import pageableTable from '@/mixins/pageableTable';
 
 export default {
-	name: 'MetaZoumaLightList',
+	name: 'MetaZouMaLightList',
 	mixins: [pageableTable],
 	data() {
 		return {
 			multipleMode: false,
 			search: '',
-			url: '/metaZoumaLight/all',
+			url: '/metaZouMaLight/all',
 			downloading: false
 		};
 	},
@@ -112,7 +112,7 @@ export default {
 		},
 		addRow() {
 			this.$router.push({
-				path: '/metaZoumaLightEdit',
+				path: '/metaZouMaLightEdit',
 				query: {
 					...this.$route.query
 				}
@@ -120,7 +120,7 @@ export default {
 		},
 		editRow(row) {
 			this.$router.push({
-				path: '/metaZoumaLightEdit',
+				path: '/metaZouMaLightEdit',
 				query: {
 					id: row.id
 				}
@@ -129,7 +129,7 @@ export default {
 		download() {
 			this.downloading = true;
 			this.$axios
-				.get('/metaZoumaLight/excel', {
+				.get('/metaZouMaLight/excel', {
 					responseType: 'blob',
 					params: { size: 10000 }
 				})
@@ -162,7 +162,7 @@ export default {
 		deleteRow(row) {
 			this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
 				.then(() => {
-					return this.$http.post(`/metaZoumaLight/del/${row.id}`);
+					return this.$http.post(`/metaZouMaLight/del/${row.id}`);
 				})
 				.then(() => {
 					this.$message.success('删除成功');