| | |
| | | package com.yuanchu.limslaboratory.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.limslaboratory.mapper.CnasSatisfactionSurveyMapper; |
| | | import com.yuanchu.limslaboratory.pojo.CnasSatisfactionSurvey; |
| | | import com.yuanchu.limslaboratory.pojo.Dto.CnasSatisfactionSurveyDto; |
| | | import com.yuanchu.limslaboratory.pojo.Dto.CnasSatisfactionSurveyPageDto; |
| | | import com.yuanchu.limslaboratory.pojo.vo.CnasSatisfactionSurveyVo; |
| | | import com.yuanchu.limslaboratory.service.CnasSatisfactionSurveyService; |
| | | import com.yuanchu.limslaboratory.service.UserService; |
| | | import com.yuanchu.limslaboratory.utils.MultipartFileToFileUtil; |
| | | import org.apache.poi.hwpf.HWPFDocument; |
| | | import org.apache.poi.hwpf.extractor.WordExtractor; |
| | | import org.apache.poi.xwpf.extractor.XWPFWordExtractor; |
| | | import org.apache.poi.xwpf.usermodel.XWPFDocument; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Author 张宾 |
| | |
| | | @Service |
| | | public class CnasSatisfactionSurveyServiceImpl implements CnasSatisfactionSurveyService { |
| | | |
| | | private static final List<String> SELECT_LIST = Arrays.asList( "☑满意=0", "☑一般=1", "☑不满意=2"); |
| | | |
| | | |
| | | @Resource |
| | | private CnasSatisfactionSurveyMapper mapper; |
| | | |
| | | @Resource |
| | | private UserService userService; |
| | | |
| | | @Override |
| | | public CnasSatisfactionSurveyVo getCnasSatisfactionSurvey(CnasSatisfactionSurveyDto cnasSatisfactionSurveyDto) { |
| | | Page<CnasSatisfactionSurvey>page=new Page<>(cnasSatisfactionSurveyDto.getCurrentPage(), cnasSatisfactionSurveyDto.getPageNum(),true); |
| | | IPage<CnasSatisfactionSurvey> cnasSatisfactionSurveyIPage = mapper.selectCnasSatisfactionSurvey(page, cnasSatisfactionSurveyDto); |
| | | public CnasSatisfactionSurveyVo getCnasSatisfactionSurvey(CnasSatisfactionSurveyPageDto cnasSatisfactionSurveyPageDto) { |
| | | Page<CnasSatisfactionSurvey>page=new Page<>(cnasSatisfactionSurveyPageDto.getCurrentPage(), cnasSatisfactionSurveyPageDto.getPageNum(),true); |
| | | String surveyDate=DateUtil.format(cnasSatisfactionSurveyPageDto.getSurveyDate(), "yyyyMMdd"); |
| | | String entryDate=DateUtil.format(cnasSatisfactionSurveyPageDto.getEntryDate(), "yyyyMMdd");; |
| | | IPage<CnasSatisfactionSurvey> cnasSatisfactionSurveyIPage = mapper.selectCnasSatisfactionSurvey(page,surveyDate,entryDate); |
| | | return new CnasSatisfactionSurveyVo(cnasSatisfactionSurveyIPage.getRecords(),cnasSatisfactionSurveyIPage.getTotal()); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param token |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Map<String, Object> getFillNameAndTd(String token) { |
| | | Map<String, Object> userInfo = userService.getUserInfo(token); |
| | | return userInfo; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, String> wordParse(MultipartFile file) { |
| | | Map<String, String>result=null; |
| | | File multipartFileToFile = null; |
| | | try { |
| | | multipartFileToFile=MultipartFileToFileUtil.multipartFileToFile(file); |
| | | result=parseWord(multipartFileToFile); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | MultipartFileToFileUtil.delteTempFile(multipartFileToFile); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean addSurvey(CnasSatisfactionSurvey cnasSatisfactionSurvey) { |
| | | cnasSatisfactionSurvey.setCreatedTime(DateUtil.toLocalDateTime(DateUtil.date())); |
| | | return mapper.insert(cnasSatisfactionSurvey)>1; |
| | | } |
| | | |
| | | /** |
| | | * 解析word |
| | | * @param file |
| | | * @return |
| | | */ |
| | | public static Map<String,String> parseWord(File file){ |
| | | String info = ""; |
| | | try { |
| | | FileInputStream fis = new FileInputStream(file); |
| | | String[] split = file.getName().split("\\."); |
| | | if ("doc".equals(split[split.length-1])) { |
| | | // 读取doc文件 |
| | | HWPFDocument doc = new HWPFDocument(fis); |
| | | WordExtractor docExtractor = new WordExtractor(doc); |
| | | String text = docExtractor.getText(); |
| | | info = text.trim(); |
| | | docExtractor.close(); |
| | | } else if ("docx".equals(split[split.length-1])) { |
| | | // 读取docx文件 |
| | | XWPFDocument docx = new XWPFDocument(fis); |
| | | XWPFWordExtractor docxExtractor = new XWPFWordExtractor(docx); |
| | | String text = docxExtractor.getText(); |
| | | System.out.println("docx:"); |
| | | info = text.trim(); |
| | | docxExtractor.close(); |
| | | } else { |
| | | System.out.println("不是word文件"); |
| | | } |
| | | fis.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | List<String> infoList = new ArrayList<String>(); |
| | | String[] split = info.split("\n"); |
| | | for (int i = 0; i < split.length; i++) { |
| | | if (i > 2) { |
| | | infoList.add(split[i] |
| | | .replaceAll("\r","") |
| | | .replaceAll(" ","") |
| | | .replaceAll("\t","") |
| | | .replaceAll("\\s","").replaceAll(" +","")); |
| | | } |
| | | } |
| | | Map<String, String> result = new HashMap<>(); |
| | | //第一行 |
| | | String unitName="单位名称Unitname"; |
| | | String projectName="项目名称Projectname"; |
| | | String[] one = infoList.get(0).replace(unitName, "").split(projectName); |
| | | result.put("unitName",one[0]); |
| | | result.put("projectName",one[1]); |
| | | String fillName="填表人姓名/日期Name/dateofthepersonfillingintheform"; |
| | | String post="职位Posts"; |
| | | String telephone="联系电话Contactnumber"; |
| | | String email="邮编Zip"; |
| | | String[] split1 = infoList.get(1).replace(fillName, "").split(post); |
| | | result.put("fillName",split1[0]); |
| | | String[] split2 = split1[1].split(telephone); |
| | | result.put("post",split2[0]); |
| | | String[] split3 = split2[1].split(email); |
| | | result.put("telephone",split3[0]); |
| | | result.put("email",split3[1]); |
| | | //第二行 |
| | | String serviceAttitude="服务态度Serviceattitude"; |
| | | //服务态度和建议 |
| | | String two = getSelectAndAdvise(infoList.get(2), serviceAttitude); |
| | | result.put("serviceAttitude",two); |
| | | //第三行 |
| | | String technicalPower="技术能力Technicalcompetence"; |
| | | String three = getSelectAndAdvise(infoList.get(3), technicalPower); |
| | | result.put("technicalPower",three); |
| | | //第四行 |
| | | String testJob="检测工作Inspectionwork"; |
| | | String four = getSelectAndAdvise(infoList.get(4), testJob); |
| | | result.put("testJob",four); |
| | | //第五行 |
| | | String reasonableCharge="收费合理性Reasonablefees"; |
| | | String five = getSelectAndAdvise(infoList.get(5), reasonableCharge); |
| | | result.put("reasonableCharge",five); |
| | | //第六行 |
| | | String improvementRequirements="改进的要求:"; |
| | | String requirementsForImprovement="Requirementsforimprovement:"; |
| | | String six = infoList.get(6).replace(improvementRequirements, "").replace(requirementsForImprovement, ""); |
| | | result.put("improvementRequirements",six); |
| | | //第七行 |
| | | String otherSupplements="您对我们的希望:"; |
| | | String otherEnglish="Whatyouwantfromus:"; |
| | | String seven = infoList.get(7).replace(otherSupplements, "").replace(otherEnglish, ""); |
| | | result.put("otherSupplements",seven); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取选择以及建议 |
| | | * @param str |
| | | * @param type |
| | | * @return |
| | | */ |
| | | public static String getSelectAndAdvise(String str,String type){ |
| | | String adviseInfo="建议:"; |
| | | String suggestion="Suggestion:"; |
| | | String satisfied="Satisfied"; |
| | | String general="General"; |
| | | String dissatisfied="Dissatisfied"; |
| | | String[] split4 = str.replace(type, "").replace(suggestion, "").split(adviseInfo); |
| | | List<String>select=new ArrayList<>(); |
| | | String advise=split4[1]; |
| | | String[] split5 = split4[0].split(satisfied); |
| | | select.add(split5[0]); |
| | | String[] split6 = split5[1].split(general); |
| | | select.add(split6[0]); |
| | | select.add(split6[1].replace(dissatisfied,"")); |
| | | String selected = getSelected(select); |
| | | return selected+"/$"+advise; |
| | | } |
| | | |
| | | public static String getSelected(List<String> select){ |
| | | String collect = SELECT_LIST.stream().filter(item -> select.stream() |
| | | .map(e -> e).collect(Collectors.toList()) |
| | | .contains(item.split("=")[0])).collect(Collectors.joining()); |
| | | return collect.split("=")[1]; |
| | | } |
| | | } |