Bläddra i källkod

Merge branch 'test' of http://git.izouma.com/licailing/wenlvju into test

panhui 4 år sedan
förälder
incheckning
49db74c135

+ 32 - 1
src/main/java/com/izouma/wenlvju/domain/TrainingInstitution.java

@@ -1,7 +1,9 @@
 package com.izouma.wenlvju.domain;
 
+import com.alibaba.excel.annotation.ExcelIgnore;
 import com.alibaba.excel.annotation.ExcelProperty;
 import com.izouma.wenlvju.annotations.Searchable;
+import com.izouma.wenlvju.utils.excel.BooleanConverter;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
@@ -21,19 +23,24 @@ import java.math.BigDecimal;
 @ApiModel("培训机构")
 public class TrainingInstitution extends BaseEntity {
     @Searchable
+    @ExcelProperty(value = "企业名称")
     @ApiModelProperty("企业名称")
     private String name;
 
+    @ExcelProperty(value = "注册号")
     @ApiModelProperty("注册号")
     private String uscc;
 
+    @ExcelProperty(value = "经营范围")
     @Column(columnDefinition = "TEXT")
     @ApiModelProperty("经营范围")
     private String businessScope;
 
+    @ExcelProperty(value = "企业住所")
     @ApiModelProperty("企业住所")
     private String address;
 
+    @ExcelProperty(value = "生产经营场所")
     @ApiModelProperty("生产经营场所")
     private String businessPremise;
 
@@ -41,74 +48,98 @@ public class TrainingInstitution extends BaseEntity {
     @ApiModelProperty(value = "法人姓名")
     private String privacyPolicy;
 
+    @ExcelIgnore
     @ApiModelProperty(value = "短信号码")
     private String phone;
 
+    @ExcelProperty(value = "企业联系方式")
     @ApiModelProperty(value = "企业联系方式")
     private String contactPhone;
 
+    @ExcelProperty(value = "所属管区")
     @ApiModelProperty(value = "所属管区")
     private String district;
 
+    @ExcelProperty(value = "注册资本(万)")
     @ApiModelProperty(value = "注册资本(万)")
     private BigDecimal registeredCapital;
 
+    @ExcelProperty(value = "单位性质")
     @ApiModelProperty(value = "单位性质")
     private String category;
 
+    @ExcelProperty(value = "专业种类")
     @ApiModelProperty(value = "专业种类")
     private String specialty;
 
+    @ExcelProperty(value = "培训点数量三楼及以下")
     @ApiModelProperty(value = "培训点数量三楼及以下")
     private int trainingSite;
 
+    @ExcelProperty(value = "培训点数量四楼及以上")
     @ApiModelProperty(value = "培训点数量四楼及以上")
     private int trainingSiteFour;
 
+    @ExcelProperty(value = "总面积")
     @ApiModelProperty(value = "总面积")
     private double area;
 
+    @ExcelProperty(value = "教室数量")
     @ApiModelProperty(value = "教室数量")
     private int classroomNum;
 
+    @ExcelProperty(value = "教师总数")
     @ApiModelProperty(value = "教师总数")
     private int teacherNum;
 
+    @ExcelProperty(value = "专职数量")
     @ApiModelProperty(value = "专职数量")
     private int fullTimeNum;
 
+    @ExcelProperty(value = "兼职数量")
     @ApiModelProperty(value = "兼职数量")
     private int partTimeNum;
 
+    @ExcelProperty(value = "音乐类")
     @ApiModelProperty(value = "音乐类")
     private int musicNum;
 
+    @ExcelProperty(value = "舞蹈类")
     @ApiModelProperty(value = "舞蹈类")
     private int danceNum;
 
+    @ExcelProperty(value = "美术类")
     @ApiModelProperty(value = "美术类")
     private int artNum;
 
-    @ApiModelProperty(value = "戏剧戏曲")
+    @ExcelProperty(value = "戏剧戏曲类")
+    @ApiModelProperty(value = "戏剧戏曲类")
     private int theatreOperaNum;
 
+    @ExcelProperty(value = "曲艺类")
     @ApiModelProperty(value = "曲艺类")
     private int folkMusicNum;
 
+    @ExcelProperty(value = "有教师资格证")
     @ApiModelProperty(value = "有教师资格证")
     private int qualificationNum;
 
+    @ExcelProperty(value = "年培训人数")
     @ApiModelProperty(value = "年培训人数")
     private long traineesPerYearNum;
 
+    @ExcelProperty(value = "是否是艺术水平考级考点", converter = BooleanConverter.class)
     @ApiModelProperty(value = "是否是艺术水平考级考点")
     private boolean examPoint;
 
+    @ExcelProperty(value = "艺术水平考级机构名称")
     @ApiModelProperty(value = "艺术水平考级机构名称")
     private String gradingOrganization;
 
+    @ExcelProperty(value = "备注")
     @Column(columnDefinition = "TEXT")
     @ApiModelProperty(value = "备注")
     private String remark;
 
+    private boolean submit;
 }

+ 37 - 0
src/main/java/com/izouma/wenlvju/dto/TrainingInstitutionDTO.java

@@ -0,0 +1,37 @@
+package com.izouma.wenlvju.dto;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.izouma.wenlvju.domain.TrainingInstitution;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@ApiModel("培训机构")
+public class TrainingInstitutionDTO {
+    @ExcelProperty(value = "编号")
+    private Long id;
+
+    @ExcelProperty(value = "企业名称")
+    @ApiModelProperty("企业名称")
+    private String name;
+
+    @ExcelProperty(value = "固定电话")
+    @ApiModelProperty(value = "固定电话")
+    private String contactPhone;
+
+    @ExcelProperty(value = "移动电话")
+    @ApiModelProperty(value = "移动电话")
+    private String phone;
+
+    public TrainingInstitutionDTO(TrainingInstitution trainingInstitution) {
+        BeanUtil.copyProperties(trainingInstitution, this);
+    }
+}

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

@@ -15,5 +15,10 @@ public interface TrainingInstitutionRepo extends JpaRepository<TrainingInstituti
     @Transactional
     void softDelete(Long id);
 
+    @Query("select phone from TrainingInstitution where submit = false and phone is not null")
+    List<String> findAllBySubmitFalseAndPhoneIsNotNull();
+
+    List<TrainingInstitution> findAllByPhoneIsNull();
+
     List<TrainingInstitution> findAllByNameLike(String name);
 }

+ 60 - 0
src/main/java/com/izouma/wenlvju/service/TrainingInstitutionService.java

@@ -1,20 +1,80 @@
 package com.izouma.wenlvju.service;
 
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.excel.EasyExcel;
 import com.izouma.wenlvju.domain.TrainingInstitution;
 import com.izouma.wenlvju.dto.PageQuery;
+import com.izouma.wenlvju.dto.ProgUploadDTO;
+import com.izouma.wenlvju.dto.TrainingInstitutionDTO;
 import com.izouma.wenlvju.repo.TrainingInstitutionRepo;
+import com.izouma.wenlvju.service.sms.NjwlSmsService;
 import com.izouma.wenlvju.utils.JpaUtils;
+import com.izouma.wenlvju.utils.excel.UploadDataListener;
 import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.transaction.Transactional;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 @AllArgsConstructor
 public class TrainingInstitutionService {
 
     private TrainingInstitutionRepo trainingInstitutionRepo;
+    private NjwlSmsService          njwlSmsService;
 
     public Page<TrainingInstitution> all(PageQuery pageQuery) {
         return trainingInstitutionRepo.findAll(JpaUtils.toSpecification(pageQuery, TrainingInstitution.class), JpaUtils.toPageRequest(pageQuery));
     }
+
+    public void batchSend(List<String> phones) throws InterruptedException {
+
+        int count = phones.size() / 950;
+        String body = "";
+        for (int i = 0; i < count; i++) {
+            int start = i * 950;
+            int end = start + 950;
+            if (end > count) {
+                end = count;
+            }
+            List<String> result = phones.subList(start, end);
+            String sendPhone = String.join(",", result);
+            System.out.println(sendPhone);
+//            njwlSmsService.sendSms(sendPhone, body);
+
+            // 睡眠5分钟
+            Thread.sleep(5 * 60 * 1000);
+        }
+
+    }
+
+    @Transactional(rollbackOn = Exception.class)
+    public void upload(MultipartFile file) throws IOException, InterruptedException {
+        UploadDataListener<TrainingInstitutionDTO> listener = new UploadDataListener<>();
+        List<TrainingInstitutionDTO> dtos = EasyExcel.read(file.getInputStream(), TrainingInstitutionDTO.class, listener)
+                .sheet()
+                .doReadSync();
+        List<Long> ids = dtos.stream().map(TrainingInstitutionDTO::getId).collect(Collectors.toList());
+        List<TrainingInstitution> all = trainingInstitutionRepo.findAllById(ids);
+        Map<Long, TrainingInstitution> tiMap = all
+                .stream()
+                .collect(Collectors.toMap(TrainingInstitution::getId, trainingInstitution -> trainingInstitution));
+
+        dtos.forEach(dto -> {
+            TrainingInstitution trainingInstitution = tiMap.get(dto.getId());
+            if (ObjectUtil.isNotNull(trainingInstitution)) {
+                trainingInstitution.setPhone(dto.getPhone());
+                trainingInstitutionRepo.save(trainingInstitution);
+            }
+        });
+
+        // 发送短信
+        this.batchSend(dtos.stream().map(TrainingInstitutionDTO::getPhone).collect(Collectors.toList()));
+
+    }
 }

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

@@ -30,7 +30,7 @@ public class ParticipantService {
                 Participant orig = participantRepo.findById(participant.getId())
                         .orElseThrow(new BusinessException("无记录"));
 
-                if (StrUtil.isNotEmpty(participant.getIdNo())) {
+                if (!participant.isDel() && StrUtil.isNotEmpty(participant.getIdNo())) {
                     List<Participant> byIdNo = participantRepo.findByIdNoAndPerformanceId(participant.getIdNo(), participant.getPerformanceId());
                     if (CollUtil.isNotEmpty(byIdNo)) {
                         if (byIdNo.size() > 1) {

+ 7 - 1
src/main/java/com/izouma/wenlvju/service/performance/ProgrammeService.java

@@ -299,11 +299,17 @@ public class ProgrammeService {
         for (ProgUploadDTO dto : dtos) {
             if (dto.getName() != null && dto.getSpecialty() != null) {
                 Programme programme = new Programme(dto);
+                System.out.println(dto.getSpecialty());
                 ArtType specialty = artTypeMap.get(dto.getSpecialty());
                 programme.setOrganizationId(organization.getId());
                 programme.setGradingOrganizationId(gradeMap.get(dto.getGradingOrganization()));
                 programme.setPerformanceId(performance);
-                programme.setSpecialtyId(specialty.getId());
+
+                // 专业
+                if (ObjectUtil.isNotNull(specialty)){
+                    programme.setSpecialtyId(specialty.getId());
+                }
+
                 // 节目状态
                 programme.setProgrammeStatus(ProgrammeStatus.INITIAL);
                 String level = dto.getLevel();

+ 23 - 3
src/main/java/com/izouma/wenlvju/web/TrainingInstitutionController.java

@@ -1,5 +1,7 @@
 package com.izouma.wenlvju.web;
+
 import com.izouma.wenlvju.domain.TrainingInstitution;
+import com.izouma.wenlvju.dto.TrainingInstitutionDTO;
 import com.izouma.wenlvju.service.TrainingInstitutionService;
 import com.izouma.wenlvju.dto.PageQuery;
 import com.izouma.wenlvju.exception.BusinessException;
@@ -8,26 +10,28 @@ import com.izouma.wenlvju.utils.ObjUtils;
 import com.izouma.wenlvju.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Page;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping("/trainingInstitution")
 @AllArgsConstructor
 public class TrainingInstitutionController extends BaseController {
     private TrainingInstitutionService trainingInstitutionService;
-    private TrainingInstitutionRepo trainingInstitutionRepo;
+    private TrainingInstitutionRepo    trainingInstitutionRepo;
 
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
     public TrainingInstitution save(@RequestBody TrainingInstitution record) {
         if (record.getId() != null) {
-            TrainingInstitution orig = trainingInstitutionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
+            TrainingInstitution orig = trainingInstitutionRepo.findById(record.getId())
+                    .orElseThrow(new BusinessException("无记录"));
             ObjUtils.merge(orig, record);
+            orig.setSubmit(true);
             return trainingInstitutionRepo.save(orig);
         }
         return trainingInstitutionRepo.save(record);
@@ -56,5 +60,21 @@ public class TrainingInstitutionController extends BaseController {
         List<TrainingInstitution> data = all(pageQuery).getContent();
         ExcelUtils.export(response, data);
     }
+
+    @GetMapping("/excel1")
+    @ResponseBody
+    public void excel1(HttpServletResponse response, PageQuery pageQuery) throws IOException {
+        List<TrainingInstitution> data = trainingInstitutionRepo.findAllByPhoneIsNull();
+        List<TrainingInstitutionDTO> dtos = data.stream()
+                .map(TrainingInstitutionDTO::new)
+                .collect(Collectors.toList());
+        ExcelUtils.export(response, dtos);
+    }
+
+    @GetMapping("/batchSend")
+    public void batchSend() throws InterruptedException {
+        List<String> phones = trainingInstitutionRepo.findAllBySubmitFalseAndPhoneIsNotNull();
+        trainingInstitutionService.batchSend(phones);
+    }
 }
 

+ 50 - 2
src/main/vue/src/views/TrainingInstitutionList.vue

@@ -3,7 +3,7 @@
         <div class="filters-container">
             <el-input placeholder="输入关键字" v-model="search" clearable class="filter-item"></el-input>
             <el-button @click="getData" type="primary" icon="el-icon-search" class="filter-item">搜索 </el-button>
-            <el-button @click="addRow" type="primary" icon="el-icon-plus" class="filter-item">添加 </el-button>
+            <!-- <el-button @click="addRow" type="primary" icon="el-icon-plus" class="filter-item">添加 </el-button> -->
             <el-button
                 @click="download"
                 type="primary"
@@ -12,6 +12,15 @@
                 class="filter-item"
                 >导出EXCEL
             </el-button>
+            <el-button
+                @click="downloadTel"
+                type="primary"
+                icon="el-icon-download"
+                :loading="downloading"
+                class="filter-item"
+                >导出固定电话
+            </el-button>
+            <el-button @click="sendSms" type="primary" class="filter-item">短信通知 </el-button>
         </div>
         <el-table
             :data="tableData"
@@ -135,7 +144,31 @@ export default {
             this.$axios
                 .get('/trainingInstitution/excel', {
                     responseType: 'blob',
-                    params: { size: 10000 }
+                    params: { size: 100000 }
+                })
+                .then(res => {
+                    console.log(res);
+                    this.downloading = false;
+                    const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
+                    const link = document.createElement('a');
+                    link.href = downloadUrl;
+                    link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
+                    document.body.appendChild(link);
+                    link.click();
+                    link.remove();
+                })
+                .catch(e => {
+                    console.log(e);
+                    this.downloading = false;
+                    this.$message.error(e.error);
+                });
+        },
+        downloadTel() {
+            this.downloading = true;
+            this.$axios
+                .get('/trainingInstitution/excel1', {
+                    responseType: 'blob',
+                    params: { size: 50000 }
                 })
                 .then(res => {
                     console.log(res);
@@ -177,6 +210,21 @@ export default {
                         this.$message.error(e.error);
                     }
                 });
+        },
+        sendSms() {
+            this.$alert('确认发送短信吗?', '提示')
+                .then(() => {
+                    return this.$http.post(`/trainingInstitution/batchSend`);
+                })
+                .then(() => {
+                    this.$message.success('发送成功');
+                    // this.getData();
+                })
+                .catch(e => {
+                    if (e !== 'cancel') {
+                        this.$message.error(e.error);
+                    }
+                });
         }
     }
 };

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

@@ -74,7 +74,7 @@ public class UserRepoTest {
 
     @Test
     public void test3() {
-        System.out.println(jwtTokenUtil.generateToken(JwtUserFactory.create(userRepo.findById(10130L)
+        System.out.println(jwtTokenUtil.generateToken(JwtUserFactory.create(userRepo.findById(17369L)
                 .orElseThrow(new BusinessException("用户不存在")))));
     }
 

+ 50 - 0
src/test/java/com/izouma/wenlvju/web/TrainingInstitutionControllerTest.java

@@ -0,0 +1,50 @@
+package com.izouma.wenlvju.web;
+
+
+import com.izouma.wenlvju.ApplicationTests;
+import com.izouma.wenlvju.converter.StringArrayConverter;
+import com.izouma.wenlvju.domain.TrainingInstitution;
+import com.izouma.wenlvju.dto.PageQuery;
+import com.izouma.wenlvju.repo.TrainingInstitutionRepo;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TrainingInstitutionControllerTest extends ApplicationTests {
+
+    @Autowired
+    private TrainingInstitutionController trainingInstitutionController;
+
+    @Autowired
+    private TrainingInstitutionRepo trainingInstitutionRepo;
+
+    @Test
+    public void test() throws InterruptedException {
+        long count = trainingInstitutionRepo.count();
+
+        PageQuery pageQuery = new PageQuery();
+        pageQuery.setSize(1000);
+        for (int i = 5; i < count / 1000; i++) {
+            pageQuery.setPage(i);
+            List<TrainingInstitution> content = trainingInstitutionController.all(pageQuery).getContent();
+            List<TrainingInstitution> result = new ArrayList<>();
+            content.forEach(t -> {
+                if (t.getPhone() != null && (t.getPhone().length() < 11 || t.getPhone().contains("-"))) {
+                    t.setPhone(null);
+                    result.add(t);
+                }
+
+            });
+            trainingInstitutionRepo.saveAll(result);
+            System.out.println(i);
+//            Thread.sleep(5 * 60 * 1000);
+//            Thread.sleep(30 * 1000);
+        }
+
+//        System.out.println("12".split(","));
+    }
+
+
+}