licailing 4 лет назад
Родитель
Сommit
4473ddd172

+ 17 - 0
src/main/java/com/izouma/wenlvju/service/performance/ParticipantService.java

@@ -2,12 +2,16 @@ package com.izouma.wenlvju.service.performance;
 
 import com.izouma.wenlvju.domain.performance.Participant;
 import com.izouma.wenlvju.dto.PageQuery;
+import com.izouma.wenlvju.exception.BusinessException;
 import com.izouma.wenlvju.repo.performance.ParticipantRepo;
 import com.izouma.wenlvju.utils.JpaUtils;
+import com.izouma.wenlvju.utils.ObjUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
 @AllArgsConstructor
 public class ParticipantService {
@@ -17,4 +21,17 @@ public class ParticipantService {
     public Page<Participant> all(PageQuery pageQuery) {
         return participantRepo.findAll(JpaUtils.toSpecification(pageQuery, Participant.class), JpaUtils.toPageRequest(pageQuery));
     }
+
+    public void batchSave(List<Participant> participants) {
+        participants.forEach(participant -> {
+            if (participant.getId() != null) {
+                Participant orig = participantRepo.findById(participant.getId())
+                        .orElseThrow(new BusinessException("无记录"));
+                ObjUtils.merge(orig, participant);
+                participantRepo.save(orig);
+            } else {
+                participantRepo.save(participant);
+            }
+        });
+    }
 }

+ 6 - 1
src/main/java/com/izouma/wenlvju/web/performance/ParticipantController.java

@@ -23,7 +23,7 @@ import java.util.List;
 @AllArgsConstructor
 public class ParticipantController extends BaseController {
     private ParticipantService participantService;
-    private ParticipantRepo participantRepo;
+    private ParticipantRepo    participantRepo;
 
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
@@ -59,5 +59,10 @@ public class ParticipantController extends BaseController {
         List<Participant> data = all(pageQuery).getContent();
         ExcelUtils.export(response, data);
     }
+
+    @PostMapping("/batchSave")
+    public void batchSave(@RequestBody List<Participant> participants) {
+        participantService.batchSave(participants);
+    }
 }
 

+ 2 - 1
src/main/vue/src/views/performance/PerformanceEdit.vue

@@ -133,7 +133,6 @@ export default {
     name: 'PerformanceEdit',
     created() {
         if (this.$route.query.id) {
-            this.performanceId = Number(this.$route.query.id);
             this.$http
                 .get('performance/get/' + this.$route.query.id)
                 .then(res => {
@@ -214,6 +213,8 @@ export default {
                 .post('/performance/save', data, { body: 'json' })
                 .then(res => {
                     this.saving = false;
+
+                    this.performanceId = res.id;
                     this.$nextTick(() => {
                         this.$http.post('/performanceSchedule/batchSave', {
                             schedules: this.saveOtherJson

+ 37 - 4
src/main/vue/src/views/performance/ProgrammeEdit.vue

@@ -16,7 +16,7 @@
                 <el-cascader
                     ref="artCascader"
                     style="width: 100%"
-                    v-model="formData.artTypeId"
+                    v-model="formData.specialtyId"
                     :props="optionProps"
                     :options="artTypes"
                     :show-all-levels="false"
@@ -154,7 +154,10 @@
                     <el-row>
                         <el-col :span="11">
                             <el-form-item prop="sex" label="性别">
-                                <el-select v-model="item.sex"></el-select>
+                                <el-select v-model="item.sex">
+                                    <el-option label="男" value="男"></el-option>
+                                    <el-option label="女" value="女"></el-option>
+                                </el-select>
                             </el-form-item>
                         </el-col>
                         <el-col :span="11">
@@ -202,6 +205,16 @@ export default {
                 .get('programme/get/' + this.$route.query.id)
                 .then(res => {
                     this.formData = res;
+
+                    this.$http
+                        .post(
+                            '/participant/all',
+                            { size: 100, query: { programmeId: this.$route.query.id } },
+                            { body: 'json' }
+                        )
+                        .then(res => {
+                            this.participants = res.content;
+                        });
                 })
                 .catch(e => {
                     console.log(e);
@@ -321,11 +334,26 @@ export default {
                 checkStrictly: true,
                 expandTrigger: 'hover'
             },
-            participants: []
+            participants: [],
+            programmeId: ''
         };
     },
     computed: {
-        ...mapState(['organization'])
+        ...mapState(['organization']),
+        saveOtherJson() {
+            return [...this.participants]
+                .filter(item => {
+                    return !!item.name || !!item.sex || !!item.phone;
+                })
+                .map(item => {
+                    return {
+                        ...item,
+                        programmeId: this.programmeId
+                    };
+                });
+
+            // return JSON.stringify(participants);
+        }
     },
     methods: {
         onSave() {
@@ -345,6 +373,11 @@ export default {
                 .post('/programme/save', data, { body: 'json' })
                 .then(res => {
                     this.saving = false;
+
+                    this.programmeId = res.id;
+                    this.$nextTick(() => {
+                        this.$http.post('/participant/batchSave', this.saveOtherJson, { body: 'json' });
+                    });
                     this.$message.success('成功');
                     this.$router.go(-1);
                 })