Browse Source

add合作单位导入

周箭河 5 years ago
parent
commit
4017b3e84c

+ 10 - 0
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/ExamSongService.java

@@ -5,6 +5,7 @@ import com.keao.edu.common.service.BaseService;
 import com.keao.edu.user.entity.ExamSong;
 import com.keao.edu.user.entity.ExamSong;
 import com.keao.edu.user.page.ExamSongQueryInfo;
 import com.keao.edu.user.page.ExamSongQueryInfo;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
+import org.springframework.web.multipart.MultipartFile;
 
 
 import java.util.List;
 import java.util.List;
 
 
@@ -28,4 +29,13 @@ public interface ExamSongService extends BaseService<Integer, ExamSong> {
     PageInfo<ExamSong> querySongPage(ExamSongQueryInfo queryInfo);
     PageInfo<ExamSong> querySongPage(ExamSongQueryInfo queryInfo);
 
 
 
 
+    /**
+     * 导入考级曲库
+     * @param file
+     * @param tenantId
+     * @return
+     */
+   List<ExamSong> importExamSong(MultipartFile file,String tenantId) throws Exception;
+
+
 }
 }

+ 103 - 18
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/ExamSongServiceImpl.java

@@ -10,38 +10,53 @@ import com.keao.edu.common.service.impl.BaseServiceImpl;
 import com.keao.edu.common.tenant.TenantContextHolder;
 import com.keao.edu.common.tenant.TenantContextHolder;
 import com.keao.edu.user.dao.ExamRegistrationDao;
 import com.keao.edu.user.dao.ExamRegistrationDao;
 import com.keao.edu.user.dao.ExamSongDao;
 import com.keao.edu.user.dao.ExamSongDao;
+import com.keao.edu.user.dao.SubjectDao;
 import com.keao.edu.user.entity.ExamSong;
 import com.keao.edu.user.entity.ExamSong;
+import com.keao.edu.user.entity.Subject;
+import com.keao.edu.user.entity.Teacher;
+import com.keao.edu.user.enums.SongTypeEnum;
+import com.keao.edu.user.enums.TeacherSettlementTypeEnum;
 import com.keao.edu.user.page.ExamSongQueryInfo;
 import com.keao.edu.user.page.ExamSongQueryInfo;
 import com.keao.edu.user.service.ExamSongService;
 import com.keao.edu.user.service.ExamSongService;
 import com.keao.edu.util.collection.MapUtil;
 import com.keao.edu.util.collection.MapUtil;
+import com.keao.edu.util.excel.POIUtil;
+import com.keao.edu.util.iniFile.IniFileEntity;
+import com.keao.edu.util.iniFile.IniFileUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
 
+import java.io.InputStream;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.*;
 
 
 @Service
 @Service
 public class ExamSongServiceImpl extends BaseServiceImpl<Integer, ExamSong> implements ExamSongService {
 public class ExamSongServiceImpl extends BaseServiceImpl<Integer, ExamSong> implements ExamSongService {
-	
-	@Autowired
-	private ExamSongDao examSongDao;
-	@Autowired
-	private ExamRegistrationDao examRegistrationDao;
-	@Autowired
-	private SysUserFeignService sysUserFeignService;
 
 
-	@Override
-	public BaseDAO<Integer, ExamSong> getDAO() {
-		return examSongDao;
-	}
+    @Autowired
+    private ExamSongDao examSongDao;
+    @Autowired
+    private ExamRegistrationDao examRegistrationDao;
+    @Autowired
+    private SysUserFeignService sysUserFeignService;
+    @Autowired
+    private SubjectDao subjectDao;
+
+    @Override
+    public BaseDAO<Integer, ExamSong> getDAO() {
+        return examSongDao;
+    }
 
 
     @Override
     @Override
     public long insert(ExamSong examSong) {
     public long insert(ExamSong examSong) {
-        if(StringUtils.isBlank(examSong.getSubjectList())){
+        if (StringUtils.isBlank(examSong.getSubjectList())) {
             throw new BizException("请选择专业");
             throw new BizException("请选择专业");
         }
         }
-	    if(Objects.isNull(examSong.getType())){
-	        throw new BizException("请选择曲库类别");
+        if (Objects.isNull(examSong.getType())) {
+            throw new BizException("请选择曲库类别");
         }
         }
 //      List<ExamSong> existsExamSongs = examSongDao.getWithLevelAndType(examSong.getTenantId(), examSong.getLevelList(), examSong.getType());
 //      List<ExamSong> existsExamSongs = examSongDao.getWithLevelAndType(examSong.getTenantId(), examSong.getLevelList(), examSong.getType());
 //	    if(!CollectionUtils.isEmpty(existsExamSongs)){
 //	    if(!CollectionUtils.isEmpty(existsExamSongs)){
@@ -69,8 +84,8 @@ public class ExamSongServiceImpl extends BaseServiceImpl<Integer, ExamSong> impl
 
 
     @Override
     @Override
     public List<ExamSong> getWithSubject(Integer subjectId) {
     public List<ExamSong> getWithSubject(Integer subjectId) {
-	    if(Objects.isNull(subjectId)){
-	        throw new BizException("请选择专业");
+        if (Objects.isNull(subjectId)) {
+            throw new BizException("请选择专业");
         }
         }
         return examSongDao.getWithSubject(subjectId, TenantContextHolder.getTenantId());
         return examSongDao.getWithSubject(subjectId, TenantContextHolder.getTenantId());
     }
     }
@@ -78,10 +93,10 @@ public class ExamSongServiceImpl extends BaseServiceImpl<Integer, ExamSong> impl
     @Override
     @Override
     public PageInfo<ExamSong> querySongPage(ExamSongQueryInfo queryInfo) {
     public PageInfo<ExamSong> querySongPage(ExamSongQueryInfo queryInfo) {
         PageInfo<ExamSong> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
         PageInfo<ExamSong> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
-	    //获取学员所在机构
+        //获取学员所在机构
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         List<Integer> tenantIds = examRegistrationDao.queryStudentTenantId(sysUser.getId());
         List<Integer> tenantIds = examRegistrationDao.queryStudentTenantId(sysUser.getId());
-        if(tenantIds == null || tenantIds.size() == 0){
+        if (tenantIds == null || tenantIds.size() == 0) {
             return pageInfo;
             return pageInfo;
         }
         }
         Map<String, Object> params = new HashMap<String, Object>();
         Map<String, Object> params = new HashMap<String, Object>();
@@ -98,4 +113,74 @@ public class ExamSongServiceImpl extends BaseServiceImpl<Integer, ExamSong> impl
         pageInfo.setRows(dataList);
         pageInfo.setRows(dataList);
         return pageInfo;
         return pageInfo;
     }
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public List<ExamSong> importExamSong(MultipartFile file, String tenantId) throws Exception {
+        Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(file.getInputStream(), 2, file.getOriginalFilename());
+        InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
+        List<IniFileEntity> columns = IniFileUtil.readIniFile(inputStream).get("examSong");
+        List<Subject> subSubjects = subjectDao.findSubSubjects();
+        List<ExamSong> examSongs = new ArrayList<>();
+        sheetsListMap.keySet().forEach(e -> {
+            List<Map<String, Object>> sheet = sheetsListMap.get(e);
+            for (Map<String, Object> row : sheet) {
+                Map<String, Object> objectMap = new HashMap<>();
+
+                for (String s : row.keySet()) {
+                    for (IniFileEntity column : columns) {
+                        if (!s.equals(column.getKey())) continue;
+                        objectMap.put(column.getValue(), row.get(s));
+                        if (column.getValue().equals("levelList")) {
+                            int i = Integer.parseInt(row.get(s).toString());
+                            if (i <= 0 || i > 10) {
+                                throw new BizException("曲目级别只能填1-10的数字");
+                            }
+                        }
+                        if (column.getValue().equals("subjectList")) {
+                            if (row.get(s) == null) {
+                                throw new BizException("专业不能为空");
+                            }
+                            String[] subjects = row.get(s).toString().split(",");
+                            String subjectIds = "";
+                            for (String subject : subjects) {
+                                boolean has = false;
+                                for (Subject subSubject : subSubjects) {
+                                    if (subject.equals(subSubject.getName())) {
+                                        has = true;
+                                        subjectIds = subjectIds + "," + subSubject.getId();
+                                        break;
+                                    }
+                                }
+                                if (!has) {
+                                    throw new BizException(subject + "专业不存在,请核查");
+                                }
+                            }
+                            objectMap.put("subjectList", subjectIds.substring(1));
+                        }
+
+                        if (column.getValue().equals("type")) {
+                            for (SongTypeEnum songType : SongTypeEnum.values()) {
+                                if (songType.getMsg().equals(row.get(s).toString())) {
+                                    objectMap.put("type", songType);
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
+
+                ExamSong examSong = null;
+                try {
+                    examSong = MapUtil.mapToJavaBean(ExamSong.class, objectMap);
+                    examSong.setTenantId(tenantId);
+                    examSongs.add(examSong);
+                } catch (Exception ex) {
+                    throw new BizException("导入数据出错");
+                }
+                this.insert(examSong);
+            }
+        });
+        return examSongs;
+    }
 }
 }

+ 61 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/ExamSongController.java

@@ -5,17 +5,33 @@ import com.keao.edu.common.entity.HttpResponseResult;
 import com.keao.edu.common.page.PageInfo;
 import com.keao.edu.common.page.PageInfo;
 import com.keao.edu.common.tenant.TenantContextHolder;
 import com.keao.edu.common.tenant.TenantContextHolder;
 import com.keao.edu.user.entity.ExamSong;
 import com.keao.edu.user.entity.ExamSong;
+import com.keao.edu.user.entity.Teacher;
 import com.keao.edu.user.page.ExamSongQueryInfo;
 import com.keao.edu.user.page.ExamSongQueryInfo;
 import com.keao.edu.user.service.ExamSongService;
 import com.keao.edu.user.service.ExamSongService;
+import com.keao.edu.util.date.DateUtil;
+import com.keao.edu.util.excel.POIUtil;
+import com.keao.edu.util.iniFile.IniFileEntity;
+import com.keao.edu.util.iniFile.IniFileUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.util.ResourceUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 /**
 /**
  * @Author Joburgess
  * @Author Joburgess
@@ -82,4 +98,49 @@ public class ExamSongController extends BaseController {
     public HttpResponseResult<List<ExamSong>> getWithSubject(Integer subjectId){
     public HttpResponseResult<List<ExamSong>> getWithSubject(Integer subjectId){
         return succeed(examSongService.getWithSubject(subjectId));
         return succeed(examSongService.getWithSubject(subjectId));
     }
     }
+
+    @ApiOperation(value = "导入曲目")
+    @PostMapping(value = "importExamSong")
+    @PreAuthorize("@pcs.hasPermissions('examSong/importExamSong')")
+    public HttpResponseResult<List<ExamSong>> importExamSong(@RequestParam("file") MultipartFile file) throws Exception {
+        String tenantId = TenantContextHolder.getTenantId();
+        List<ExamSong> examSongs = examSongService.importExamSong(file, tenantId);
+        return succeed(examSongs);
+    }
+
+    @ApiOperation(value = "获取导入模板")
+    @GetMapping(value = "getImportTemplate")
+    @PreAuthorize("@pcs.hasPermissions('examSong/getImportTemplate')")
+    public void getImportTemplate(HttpServletResponse response) throws IOException {
+        InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
+        List<IniFileEntity> columns = IniFileUtil.readIniFile(inputStream).get("examSong");
+
+        OutputStream outputStream = response.getOutputStream();
+        try {
+            String[] header = columns.stream().map(IniFileEntity::getKey).toArray(String[]::new);
+
+            List<Teacher> teachers = new ArrayList<>();
+
+            HSSFWorkbook workbook = POIUtil.exportExcel(header, null, teachers);
+            response.setContentType("application/octet-stream");
+            response.setHeader("Content-Disposition", "attachment;filename=examSong-" + DateUtil.getDate(new Date()) + ".xls");
+            response.flushBuffer();
+            outputStream = response.getOutputStream();
+            workbook.write(outputStream);
+            outputStream.flush();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (outputStream != null) {
+                try {
+                    outputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+
+
 }
 }

+ 4 - 3
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/OrganizationController.java

@@ -19,6 +19,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.util.ResourceUtils;
 import org.springframework.util.ResourceUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
@@ -27,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStream;
 import java.util.*;
 import java.util.*;
 
 
@@ -119,9 +121,8 @@ public class OrganizationController extends BaseController {
     @GetMapping(value = "getImportTemplate")
     @GetMapping(value = "getImportTemplate")
     @PreAuthorize("@pcs.hasPermissions('organization/getImportTemplate')")
     @PreAuthorize("@pcs.hasPermissions('organization/getImportTemplate')")
     public void getImportTemplate(HttpServletResponse response) throws IOException {
     public void getImportTemplate(HttpServletResponse response) throws IOException {
-        File file = ResourceUtils.getFile("classpath:" + "columnMapper.ini");
-        Map<String, List<IniFileEntity>> stringListMap = IniFileUtil.readIniFile(file);
-        List<IniFileEntity> organizationColumns = stringListMap.get("organization");
+        InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
+        List<IniFileEntity> organizationColumns = IniFileUtil.readIniFile(inputStream).get("organization");
 
 
         OutputStream outputStream = response.getOutputStream();
         OutputStream outputStream = response.getOutputStream();
         try {
         try {

+ 4 - 3
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/TeacherController.java

@@ -18,6 +18,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.util.ResourceUtils;
 import org.springframework.util.ResourceUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
@@ -26,6 +27,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStream;
 import java.util.*;
 import java.util.*;
 
 
@@ -98,9 +100,8 @@ public class TeacherController extends BaseController {
     @GetMapping(value = "getImportTemplate")
     @GetMapping(value = "getImportTemplate")
     @PreAuthorize("@pcs.hasPermissions('teacher/getImportTemplate')")
     @PreAuthorize("@pcs.hasPermissions('teacher/getImportTemplate')")
     public void getImportTemplate(HttpServletResponse response) throws IOException {
     public void getImportTemplate(HttpServletResponse response) throws IOException {
-        File file = ResourceUtils.getFile("classpath:" + "columnMapper.ini");
-        Map<String, List<IniFileEntity>> stringListMap = IniFileUtil.readIniFile(file);
-        List<IniFileEntity> columns = stringListMap.get("teacher");
+        InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
+        List<IniFileEntity> columns = IniFileUtil.readIniFile(inputStream).get("teacher");
 
 
         OutputStream outputStream = response.getOutputStream();
         OutputStream outputStream = response.getOutputStream();
         try {
         try {

+ 6 - 7
edu-user/edu-user-server/src/main/resources/columnMapper.ini

@@ -1,16 +1,15 @@
 [examSong]
 [examSong]
-曲目名称=songName
-曲目作者=songAuthor
-曲目专业=subjectList
-曲目级别=levelList
-曲目类别(练习曲or演奏曲)=type
-曲谱=fileUrlList
+曲目名称 = songName
+曲目作者 = songAuthor
+曲目专业(英文逗号分隔) = subjectList
+曲目级别(填1-10的数字) = levelList
+曲目类别(练习曲or演奏曲) = type
 
 
 [organization]
 [organization]
 合作单位名字 = name
 合作单位名字 = name
 联系人名字 = contactName
 联系人名字 = contactName
 联系人电话 = contactPhone
 联系人电话 = contactPhone
-角色= roleName
+角色 = roleName
 分润方式 = settlementType
 分润方式 = settlementType
 分润比 = shareProfitAmount
 分润比 = shareProfitAmount