ServerController.java 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985
  1. package com.rf.psychological.rest;
  2. import cn.hutool.core.date.DatePattern;
  3. import cn.hutool.core.date.DateUtil;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.rf.psychological.base.rest.BaseController;
  7. import com.rf.psychological.dao.dto.*;
  8. import com.rf.psychological.dao.model.*;
  9. import com.rf.psychological.enums.UserRole;
  10. import com.rf.psychological.enums.UserStatus;
  11. import com.rf.psychological.group.dao.model.GroupAuthEntity;
  12. import com.rf.psychological.group.dao.model.GroupEntity;
  13. import com.rf.psychological.group.service.GroupAuthService;
  14. import com.rf.psychological.group.service.GroupInfoService;
  15. import com.rf.psychological.institution.model.InstitutionAuthEntity;
  16. import com.rf.psychological.institution.model.InstitutionEntity;
  17. import com.rf.psychological.institution.service.InstitutionAuthService;
  18. import com.rf.psychological.institution.service.InstitutionService;
  19. import com.rf.psychological.plan.service.TestPlanContendService;
  20. import com.rf.psychological.scale.dao.dto.SubjectEntityDto2;
  21. import com.rf.psychological.scale.dao.model.*;
  22. import com.rf.psychological.scale.service.*;
  23. import com.rf.psychological.security.SafetyProcess;
  24. import com.rf.psychological.socket.MyClient;
  25. import com.rf.psychological.user.dao.model.UserEntity;
  26. import com.rf.psychological.user.dao.model.UserFileEntity;
  27. import com.rf.psychological.user.service.UserFileService;
  28. import com.rf.psychological.user.service.UserService;
  29. import com.rf.psychological.utils.*;
  30. import com.rf.psychological.wxpay.model.PromotionInfo;
  31. import com.rf.psychological.wxpay.service.OrderInfoService;
  32. import com.rf.psychological.wxpay.service.PromotionInfoService;
  33. import io.swagger.annotations.Api;
  34. import io.swagger.annotations.ApiOperation;
  35. import lombok.extern.slf4j.Slf4j;
  36. import net.sourceforge.pinyin4j.PinyinHelper;
  37. import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
  38. import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
  39. import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
  40. import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
  41. import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
  42. import org.apache.commons.collections4.CollectionUtils;
  43. import org.apache.commons.io.FileUtils;
  44. import org.apache.commons.lang.StringUtils;
  45. import org.springframework.beans.BeanUtils;
  46. import org.springframework.beans.factory.annotation.Autowired;
  47. import org.springframework.beans.factory.annotation.Value;
  48. import org.springframework.data.domain.Page;
  49. import org.springframework.transaction.annotation.Transactional;
  50. import org.springframework.util.DigestUtils;
  51. import org.springframework.web.bind.annotation.*;
  52. import org.springframework.web.multipart.MultipartFile;
  53. import javax.servlet.http.HttpServletResponse;
  54. import javax.servlet.http.HttpSession;
  55. import java.io.*;
  56. import java.nio.charset.StandardCharsets;
  57. import java.nio.file.Files;
  58. import java.text.DateFormat;
  59. import java.text.SimpleDateFormat;
  60. import java.time.LocalDateTime;
  61. import java.util.*;
  62. /**
  63. * @author zzf
  64. * @description:扫描服务器时进行验证
  65. * @date 2021/5/11 17:24
  66. */
  67. @Slf4j
  68. @Api(tags = "量表操作-detail")
  69. @RestController
  70. public class ServerController extends BaseController {
  71. /**
  72. * 任务执行状态 0-->未开始;1-->进行中;2-->已结束
  73. **/
  74. public static Map<String,String> TASK_STATUS = new HashMap<>();
  75. @Autowired
  76. private ScaleService scaleService;
  77. @Autowired
  78. private UserService userService;
  79. @Autowired
  80. private SubjectService subjectService;
  81. @Autowired
  82. private UserRecordService userRecordService;
  83. @Autowired
  84. private AnswerService answerService;
  85. @Autowired
  86. private ScaleMarksService scaleMarksService;
  87. @Autowired
  88. private CognitiveTaskService cognitiveTaskService;
  89. @Autowired
  90. private InstitutionAuthService institutionAuthService;
  91. @Autowired
  92. private CategorySubjectService categorySubjectService;
  93. @Autowired
  94. private DimensionService dimensionService;
  95. @Autowired
  96. private TestPlanContendService testPlanContendService;
  97. @Autowired
  98. private GroupAuthService groupAuthService;
  99. @Autowired
  100. private GroupInfoService groupInfoService;
  101. @Autowired
  102. private InstitutionService institutionService;
  103. @Autowired(required = false)
  104. private OrderInfoService orderInfoService;
  105. @Autowired
  106. private UserFileService userFileService;
  107. @Autowired
  108. private ScaleDetailsService scaleDetailsService;
  109. @Value("${spring.profiles.active}")
  110. private String profileValue;
  111. @Autowired
  112. private PromotionInfoService promotionInfoService;
  113. @SafetyProcess
  114. @GetMapping("server")
  115. public Result scanServer() {
  116. return success("", "psychological");
  117. }
  118. /**
  119. * 导入量表
  120. * 1、量表名称 2、量表指导语 3、量表录入人
  121. *
  122. * @return
  123. */
  124. //@SafetyProcess
  125. @PostMapping("import")
  126. @ApiOperation(value = "量表导入")
  127. public Result importScale(String scaleName, String scaleDesc, String uploader, String eName, String scoringPrinciple, MultipartFile file) throws Exception {
  128. if (file == null) {
  129. return fail("文件为空");
  130. }
  131. String message = "提交成功";
  132. //保存基本信息
  133. //量表标志自动生成唯一值,yyyyMMddHHmmss
  134. String flag = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
  135. SubjectEntity subjectEntity = new SubjectEntity();
  136. subjectEntity.setName(scaleName);
  137. subjectEntity.setFlag(flag);
  138. //类型默认量表
  139. subjectEntity.setType("0");
  140. // 新增量表默认为热门测试
  141. subjectEntity.setIsHot("1");
  142. // 新增量表默认为最新测试
  143. subjectEntity.setIsNew(1);
  144. subjectEntity.setDescription(scaleDesc);
  145. subjectEntity.setUploader(uploader);
  146. subjectEntity.setEName(eName);
  147. subjectEntity.setScoringPrinciple(scoringPrinciple);
  148. if (subjectEntity.getName() == null || subjectEntity.getName().trim().length() == 0) {
  149. return fail(null, "量表名称为空");
  150. }
  151. if (subjectEntity.getUploader() == null || subjectEntity.getUploader().trim().length() <= 0) {
  152. return fail(null, "请输入上传人信息");
  153. }
  154. List<List<Object>> datas = ExcelUtil.getBankListByExcel(file.getInputStream(), file.getOriginalFilename());
  155. for (int i = 0; i < datas.size(); i++) {
  156. List<Object> scales = datas.get(i);
  157. System.out.println(scales);
  158. ScaleEntity scaleEntity = new ScaleEntity();
  159. scaleEntity.setQuestionNo(scales.get(0).toString());
  160. scaleEntity.setSerialNo(scales.get(1).toString());
  161. scaleEntity.setAnswer(scales.get(2).toString());
  162. scaleEntity.setCheckItems(scales.get(3).toString());
  163. //类型:0-单选 1-多选 2-填空
  164. String questionType = scales.get(4).toString();
  165. if (questionType.equals("多选")) {
  166. scaleEntity.setQuestionType(Constant.MAGIC_NUM_1);
  167. } else if (questionType.equals("填空")) {
  168. scaleEntity.setQuestionType(Constant.MAGIC_NUM_2);
  169. } else {
  170. scaleEntity.setQuestionType(Constant.MAGIC_NUM_0);
  171. }
  172. scaleEntity.setWeight("");
  173. String scoreDirection = scales.get(5).toString();
  174. if (scoreDirection.equals("正向")) {
  175. scoreDirection = Constant.MAGIC_NUM_1;
  176. } else if (scoreDirection.equals("反向")) {
  177. scoreDirection = Constant.MAGIC_NUM_MINUS_1;
  178. }
  179. scaleEntity.setScoreDirection(scoreDirection);
  180. // 量表模板不提供分值
  181. scaleEntity.setScore("");
  182. scaleEntity.setFlag(flag);
  183. this.scaleService.saveScale(scaleEntity);
  184. }
  185. //文件保存
  186. String fileName;
  187. String FILEDIR;
  188. if (OSUtil.getOSname().equalsIgnoreCase("Windows")) {
  189. FILEDIR = "./psychological/scales/";
  190. } else {
  191. FILEDIR = "./scales/";
  192. }
  193. String suffix = file.getOriginalFilename();
  194. if (!file.isEmpty()) {
  195. fileName = suffix;
  196. subjectEntity.setFileName(fileName);
  197. try {
  198. File temp = new File(FILEDIR);
  199. if (!temp.exists()) {
  200. temp.mkdirs();
  201. }
  202. File fileLocal = new File(FILEDIR, fileName);
  203. FileUtils.copyInputStreamToFile(file.getInputStream(), fileLocal);
  204. } catch (Exception e) {
  205. message = message + "文件上传失败";
  206. e.printStackTrace();
  207. return fail(message);
  208. }
  209. }
  210. this.subjectService.save(subjectEntity);
  211. return success();
  212. }
  213. /**
  214. * 查询列表
  215. *
  216. * @return
  217. */
  218. @GetMapping("subjectInfo")
  219. @ApiOperation(value = "量表全量查询,包含认知任务")
  220. public Result getScaleList(int pageNum, int pageSize, String searchName) {
  221. List<SubjectEntity> subjectEntityList = new ArrayList<>();
  222. int num = 0;
  223. if (pageSize == 0) {
  224. pageSize = 20;
  225. }
  226. System.out.println("searchName-----" + searchName);
  227. if (searchName == null || searchName.equals("")) {
  228. subjectEntityList = this.subjectService.findAll(pageNum, pageSize);
  229. num = this.subjectService.allNum();
  230. } else {
  231. try {
  232. subjectEntityList = this.subjectService.findByNameOrUploader(pageNum, pageSize, searchName);
  233. num = this.subjectService.allNumByNameOrUploader(searchName);
  234. } catch (Exception e) {
  235. e.printStackTrace();
  236. }
  237. }
  238. List<SubjectEntityDto> dto = new ArrayList<>();
  239. for (SubjectEntity subjectEntity : subjectEntityList) {
  240. SubjectEntityDto subjectEntityDto = new SubjectEntityDto(subjectEntity);
  241. //--add by zzf 量表查询新增价格字段 key=price---
  242. PromotionInfo infoBySubjectId = promotionInfoService.findInfoBySubjectId(subjectEntity.getId());
  243. subjectEntityDto.setPrice(infoBySubjectId == null ? 0.0 : infoBySubjectId.getPrice());
  244. //-----end-----
  245. List<CategorySubjectEntity> categorySubjectEntityList = this.categorySubjectService.findByFlag(subjectEntity.getFlag());
  246. if (categorySubjectEntityList != null && categorySubjectEntityList.size() > 0) {
  247. subjectEntityDto.setCategory(categorySubjectEntityList);
  248. } else {
  249. subjectEntityDto.setCategory(null);
  250. }
  251. dto.add(subjectEntityDto);
  252. }
  253. JSONObject jsonObject = new JSONObject();
  254. jsonObject.put("data", dto);
  255. jsonObject.put("allNum", num);
  256. return success(jsonObject);
  257. }
  258. /**
  259. * 量表上传多条件查询列表
  260. *
  261. * @return
  262. */
  263. @PostMapping("subjectInfoList")
  264. @ApiOperation(value = "量表多条件全量查询")
  265. public Result getScales(@RequestBody JSONObject jsonObject) {
  266. /*
  267. * 量表名称、量表分类、适用人群、量表权限
  268. * */
  269. String name = null;
  270. if (jsonObject.containsKey("name")) {
  271. name = jsonObject.getString("name");
  272. }
  273. String scaleCate = null;
  274. if (jsonObject.containsKey("scaleCate")) {
  275. scaleCate = jsonObject.getString("scaleCate");
  276. }
  277. String people = null;
  278. if (jsonObject.containsKey("people")) {
  279. people = jsonObject.getString("people");
  280. }
  281. String currentLimit = null;
  282. if (jsonObject.containsKey("currentLimit")) {
  283. currentLimit = jsonObject.getString("currentLimit");
  284. }
  285. int pageNum = jsonObject.getInteger("pageNum");
  286. int pageSize = jsonObject.getInteger("pageSize");
  287. if (pageSize == 0) {
  288. pageSize = 20;
  289. }
  290. List<SubjectEntity> subjectEntityList = new ArrayList<>();
  291. Page<SubjectEntity> subjectEntitys = this.subjectService.getsubjectListMultiCondition(name, scaleCate, people, currentLimit, pageNum, pageSize);
  292. subjectEntityList = subjectEntitys.getContent();
  293. List<SubjectEntityDto> dto = new ArrayList<>();
  294. for (SubjectEntity subjectEntity : subjectEntityList) {
  295. SubjectEntityDto subjectEntityDto = new SubjectEntityDto(subjectEntity);
  296. List<CategorySubjectEntity> categorySubjectEntityList = this.categorySubjectService.findByFlag(subjectEntity.getFlag());
  297. if (categorySubjectEntityList != null && categorySubjectEntityList.size() > 0) {
  298. subjectEntityDto.setCategory(categorySubjectEntityList);
  299. } else {
  300. subjectEntityDto.setCategory(null);
  301. }
  302. dto.add(subjectEntityDto);
  303. }
  304. JSONObject json = new JSONObject();
  305. json.put("data", dto);
  306. json.put("allNum", subjectEntitys.getTotalElements());
  307. return success(json);
  308. }
  309. /**
  310. * 查询机构自定义量表列表
  311. *
  312. * @return
  313. */
  314. @GetMapping("subjectInfo/institutionByTC")
  315. @ApiOperation(value = "查询机构自定义量表列表")
  316. public Result getInstitutionByTC(int pageNum, int pageSize, String institutionNo) {
  317. List<SubjectEntity> subjectEntityList;
  318. int num = 0;
  319. if (pageSize == 0) {
  320. pageSize = 20;
  321. }
  322. subjectEntityList = this.subjectService.institutionByTC(pageNum, pageSize, institutionNo);
  323. num = this.subjectService.institutionByTCNum(institutionNo);
  324. JSONObject jsonObject = new JSONObject();
  325. jsonObject.put("data", subjectEntityList);
  326. jsonObject.put("allNum", num);
  327. System.out.println(subjectEntityList);
  328. return success(jsonObject);
  329. }
  330. /**
  331. * 征冰心理健康测评消息推送
  332. *
  333. * @return
  334. */
  335. @GetMapping("push/message/{phone}")
  336. @ApiOperation(value = "心理健康测评消息推送")
  337. public Result pushMessage(@PathVariable String phone) throws InterruptedException {
  338. String url = "ws://127.0.0.1:54378/ws";
  339. MyClient myClient = new MyClient(url);
  340. myClient.connectBlocking();
  341. JSONObject dataJson = new JSONObject();
  342. dataJson.put("flag","begin");
  343. dataJson.put("date", LocalDateTime.now().toString());
  344. myClient.send(dataJson.toString());
  345. Thread.sleep(500);
  346. myClient.close();
  347. this.TASK_STATUS.put(phone,"1");
  348. return success();
  349. }
  350. /**
  351. * 征冰心理健康测评状态查询
  352. *
  353. * @return
  354. */
  355. @GetMapping("push/status/{phoneNumber}")
  356. @ApiOperation(value = "征冰心理健康测评状态查询")
  357. public Result pushStatus(@PathVariable String phoneNumber) {
  358. return success(this.TASK_STATUS.get(phoneNumber) == null?"0":this.TASK_STATUS.get(phoneNumber));
  359. }
  360. /**
  361. * 用户查询靶向神经振荡评估与训练记录
  362. *
  363. * @return
  364. */
  365. @SafetyProcess
  366. @GetMapping("RHYTHM/{phone}/{institutionNo}/{testPlanId}")
  367. @ApiOperation(value = "用户查询靶向神经振荡评估与训练记录")
  368. public Result RHYTHM(@PathVariable String phone, @PathVariable String institutionNo, @PathVariable String testPlanId) {
  369. UserRecordEntity userRecordEntity = this.userRecordService.getRHYTHM(phone, institutionNo, testPlanId);
  370. if (userRecordEntity != null && userRecordEntity.getImg() != null) {
  371. return success(userRecordEntity.getImg());
  372. }
  373. return success("");
  374. }
  375. /**
  376. * 删除机构自定义量表
  377. *
  378. * @return
  379. */
  380. @GetMapping("subjectInfo/delete")
  381. public Result deleteSubjectInfo(String flag) {
  382. //删除量表分类关联信息
  383. this.categorySubjectService.deleteCategorySubjectByFlag(flag);
  384. //删除量表权限关联信息
  385. this.institutionAuthService.deleteInstitutionByFlag(flag);
  386. //删除量表分组信息
  387. this.groupAuthService.deleteGroupByFlag(flag);
  388. //删除量表测试计划信息
  389. this.testPlanContendService.deleteTestPlanByFlag(flag);
  390. //删除量表计分规则信息
  391. this.answerService.deleteAnswerByFlag(flag);
  392. //删除量表判断标准信息
  393. this.scaleMarksService.deleteScaleMarkByFlag(flag);
  394. //删除量表维度信息
  395. this.dimensionService.deleteDimensionByFlag(flag);
  396. //删除量表题目信息
  397. this.scaleService.deleteScaleByFlag(flag);
  398. //删除量表基本信息
  399. this.subjectService.deleteSubjectByFlag(flag);
  400. return success();
  401. }
  402. @PostMapping("subjectInfo/update")
  403. public Result updateSubjectInfo(@RequestBody JSONObject jsonObject) {
  404. JSONArray categoryList = jsonObject.getJSONArray("type");
  405. String flag = jsonObject.getString("flag");
  406. String scaleLimit = jsonObject.getString("scaleLimit");
  407. /*String men = jsonObject.getString("people");
  408. men = men.replace("[","").replace("]","");
  409. if(men.contains("0")){
  410. men = "0";
  411. }*/
  412. this.categorySubjectService.deleteCategorySubjectByFlag(flag);
  413. for (Object obj : categoryList) {
  414. CategorySubjectEntity categorySubjectEntity = new CategorySubjectEntity();
  415. categorySubjectEntity.setFlag(flag);
  416. categorySubjectEntity.setEname((String) obj);
  417. this.categorySubjectService.save(categorySubjectEntity);
  418. }
  419. SubjectEntity subjectEntity = this.subjectService.getSubjectEntityByFlag(flag);
  420. if (subjectEntity != null) {
  421. subjectEntity.setScaleLimit(scaleLimit);
  422. //subjectEntity.setMen(men.replace(" ",""));
  423. this.subjectService.save(subjectEntity);
  424. }
  425. return success();
  426. }
  427. /**
  428. * 量表上传需要接口
  429. *
  430. * @return
  431. */
  432. @PostMapping("subjectInfoUpload/update")
  433. public Result updateSubjectInfoUpload(@RequestBody JSONObject jsonObject) {
  434. JSONArray categoryList = jsonObject.getJSONArray("type");
  435. String flag = jsonObject.getString("flag");
  436. String scaleLimit = jsonObject.getString("scaleLimit");
  437. String men = jsonObject.getString("people");
  438. men = men.replace("[","").replace("]","");
  439. if(men.contains("0")){
  440. men = "0";
  441. }
  442. this.categorySubjectService.deleteCategorySubjectByFlag(flag);
  443. for (Object obj : categoryList) {
  444. CategorySubjectEntity categorySubjectEntity = new CategorySubjectEntity();
  445. categorySubjectEntity.setFlag(flag);
  446. categorySubjectEntity.setEname((String) obj);
  447. this.categorySubjectService.save(categorySubjectEntity);
  448. }
  449. SubjectEntity subjectEntity = this.subjectService.getSubjectEntityByFlag(flag);
  450. if (subjectEntity != null) {
  451. subjectEntity.setScaleLimit(scaleLimit);
  452. subjectEntity.setMen(men.replace(" ",""));
  453. this.subjectService.save(subjectEntity);
  454. }
  455. return success();
  456. }
  457. /**
  458. * 查询列表
  459. *
  460. * @return
  461. */
  462. @SafetyProcess
  463. @ApiOperation(value = "量表查询,type=0 量表。type=1 认知任务")
  464. @GetMapping("subjectInfo/{type}")
  465. public Result getScaleListByType(@PathVariable String type) {
  466. List<SubjectEntity> subjectEntityList = this.subjectService.findAll(type);
  467. return success(subjectEntityList);
  468. }
  469. /**
  470. * 保存量表
  471. *
  472. * @param subjectEntity
  473. * @return
  474. */
  475. @PostMapping("save/scale")
  476. @ApiOperation("增加量表")
  477. public Result saveScaleInfo(SubjectEntity subjectEntity) {
  478. System.out.println(subjectEntity);
  479. if (subjectEntity.getType() == null || subjectEntity.getType().trim().length() <= 0) {
  480. subjectEntity.setType("0");
  481. }
  482. if (subjectEntity.getIsHot() == null || subjectEntity.getIsHot().trim().length() <= 0) {
  483. subjectEntity.setIsHot("1");
  484. }
  485. if (subjectEntity.getIsNew() != 0) {
  486. subjectEntity.setIsNew(1);
  487. }
  488. if (subjectEntity.getName() == null || subjectEntity.getName().trim().length() == 0) {
  489. return fail(null, "量表名称为空");
  490. }
  491. if (subjectEntity.getUploader() == null || subjectEntity.getUploader().trim().length() <= 0) {
  492. return fail(null, "请输入上传人信息");
  493. }
  494. this.subjectService.save(subjectEntity);
  495. return success();
  496. }
  497. /**
  498. * getSubjectListByAuth
  499. * 根据名称模糊查询量表列表
  500. *
  501. * @return
  502. */
  503. @SafetyProcess
  504. @GetMapping("subjectInfo/getSubjectListByName")
  505. @ApiOperation(value = "根据名称模糊查询量表列表")
  506. public Result getSubjectListByName(int pageNum, int pageSize, String scaleName, String categoryEname) {
  507. if (pageSize == 0) {
  508. pageSize = 20;
  509. }
  510. int num;
  511. List<SubjectEntity> subjectEntityList;
  512. if (categoryEname.equals("ALL")) {
  513. if (StringUtils.isEmpty(scaleName)) {
  514. subjectEntityList = this.subjectService.findAll(pageNum, pageSize);
  515. num = this.subjectService.allNum();
  516. } else {
  517. subjectEntityList = this.subjectService.getSubjectListByName(pageNum, pageSize, scaleName);
  518. num = this.subjectService.allNumByName(scaleName);
  519. }
  520. } else {
  521. if (StringUtils.isEmpty(scaleName)) {
  522. subjectEntityList = this.subjectService.findAllCategory(pageNum, pageSize, categoryEname);
  523. num = this.subjectService.allNumCategory(categoryEname);
  524. } else {
  525. subjectEntityList = this.subjectService.getSubjectListByNameCategory(pageNum, pageSize, scaleName, categoryEname);
  526. num = this.subjectService.allNumByNameCategory(scaleName, categoryEname);
  527. }
  528. }
  529. List<SubjectEntityDto2> dto2List = new ArrayList<>();
  530. if(num>0){
  531. subjectEntityList.forEach(subjectEntity -> {
  532. SubjectEntityDto2 dto = new SubjectEntityDto2(subjectEntity);
  533. PromotionInfo infoBySubjectId = promotionInfoService.findInfoBySubjectId(subjectEntity.getId());
  534. dto.setPrice( infoBySubjectId ==null?0.0:infoBySubjectId.getPrice());
  535. dto2List.add(dto);
  536. });
  537. }
  538. JSONObject jsonObject = new JSONObject();
  539. jsonObject.put("data", dto2List);
  540. jsonObject.put("allNum", num);
  541. return success(jsonObject);
  542. }
  543. /**
  544. * 根据名称模糊查询认知任务列表
  545. *
  546. * @return
  547. */
  548. @SafetyProcess
  549. @GetMapping("subjectInfo/getCognizeListByName")
  550. @ApiOperation(value = "根据名称模糊查询认知任务列表")
  551. public Result getCognizeListByName(int pageNum, int pageSize, String scaleName, String categoryEname) {
  552. if (pageSize == 0) {
  553. pageSize = 20;
  554. }
  555. int num;
  556. List<CognitiveTaskEntity> cognitiveTaskEntityList;
  557. if (categoryEname.equals("CALL")) {
  558. if (StringUtils.isEmpty(scaleName)) {
  559. cognitiveTaskEntityList = this.cognitiveTaskService.findAll(pageNum, pageSize);
  560. num = this.cognitiveTaskService.allNum();
  561. } else {
  562. cognitiveTaskEntityList = this.cognitiveTaskService.getCognizeListByName(pageNum, pageSize, scaleName);
  563. num = this.cognitiveTaskService.allNumByName(scaleName);
  564. }
  565. } else {
  566. if (StringUtils.isEmpty(scaleName)) {
  567. cognitiveTaskEntityList = this.cognitiveTaskService.findAllCategory(pageNum, pageSize, categoryEname);
  568. num = this.cognitiveTaskService.allNumCategory(categoryEname);
  569. } else {
  570. cognitiveTaskEntityList = this.cognitiveTaskService.getCognizeListByNameCategory(pageNum, pageSize, scaleName, categoryEname);
  571. num = this.cognitiveTaskService.allNumByNameCategory(scaleName, categoryEname);
  572. }
  573. }
  574. //------add by zzf begin 认知任务列表查询,新增价格字段 key=price----
  575. List<CognitiveTaskEntityDto> dto2List = new ArrayList<>();
  576. if(num>0){
  577. cognitiveTaskEntityList.forEach(cognitiveTaskEntity -> {
  578. CognitiveTaskEntityDto dto = new CognitiveTaskEntityDto(cognitiveTaskEntity);
  579. PromotionInfo infoBySubjectId = promotionInfoService.findInfoBySubjectId(cognitiveTaskEntity.getId());
  580. dto.setPrice( infoBySubjectId ==null?0.0:infoBySubjectId.getPrice());
  581. dto2List.add(dto);
  582. });
  583. }
  584. //----end----
  585. JSONObject jsonObject = new JSONObject();
  586. jsonObject.put("data", dto2List);
  587. jsonObject.put("allNum", num);
  588. return success(jsonObject);
  589. }
  590. /**
  591. * 根据权限,查看用户的认知任务权限
  592. *
  593. * @return
  594. */
  595. @SafetyProcess
  596. @GetMapping("subjectInfo/getCognizeListByAuth")
  597. @ApiOperation(value = "根据名称模糊查询认知任务列表")
  598. public Result getCognizeListByAuth(int pageNum, int pageSize, String scaleName, String categoryEname, String uId, String institutionNo,
  599. @RequestParam(value = "mobile", defaultValue = "false") Boolean mobile) {
  600. if (pageSize == 0) {
  601. pageSize = 20;
  602. }
  603. //游客用户无id,数据库配置特定用户
  604. if (StringUtils.isEmpty(uId)){
  605. uId = Constant.PUBLIC_VISITOR_ID;
  606. }
  607. int num;
  608. List<CognitiveTaskEntity> cognitiveTaskEntityList = new ArrayList<>();
  609. UserEntity one = userService.getOne(uId);
  610. System.out.println(one);
  611. if (("0").equals(one.getGId())) {
  612. if (categoryEname.equals("CALL")) {
  613. List<InstitutionAuthConTaskDto> allConTask = this.institutionAuthService.getAllConTask(pageNum, pageSize, institutionNo, "1", scaleName, mobile);
  614. for (InstitutionAuthConTaskDto institutionAuthConTaskDto : allConTask) {
  615. CognitiveTaskEntity cognitiveTaskEntity = new CognitiveTaskEntity();
  616. BeanUtils.copyProperties(institutionAuthConTaskDto, cognitiveTaskEntity);
  617. cognitiveTaskEntityList.add(cognitiveTaskEntity);
  618. }
  619. num = this.institutionAuthService.getAllConTaskNum(institutionNo, "1", scaleName, mobile);
  620. } else {
  621. Page<CognitiveTaskEntity> institutionTaskAuthAndCateEName = this.cognitiveTaskService.findInstitutionTaskAuthAndCateEName(institutionNo, scaleName, categoryEname, pageNum, pageSize, mobile);
  622. cognitiveTaskEntityList = institutionTaskAuthAndCateEName.getContent();
  623. num = (int) institutionTaskAuthAndCateEName.getTotalElements();
  624. }
  625. } else {
  626. if (categoryEname.equals("CALL")) {
  627. Page<CognitiveTaskEntity> userTaskAuth = this.cognitiveTaskService.findUserTaskAuth(uId, scaleName, pageNum, pageSize, mobile);
  628. cognitiveTaskEntityList = userTaskAuth.getContent();
  629. num = (int) userTaskAuth.getTotalElements();
  630. } else {
  631. Page<CognitiveTaskEntity> userTaskAuth = this.cognitiveTaskService.findUserTaskAuthAndCateEName(uId, scaleName, categoryEname, pageNum, pageSize, mobile);
  632. cognitiveTaskEntityList = userTaskAuth.getContent();
  633. num = (int) userTaskAuth.getTotalElements();
  634. }
  635. }
  636. //----add by zzf begin 认知任务查询新增price key=price---
  637. List<CognitiveTaskEntityDto> dto2List = new ArrayList<>();
  638. if(num>0){
  639. cognitiveTaskEntityList.forEach(cognitiveTaskEntity -> {
  640. CognitiveTaskEntityDto dto = new CognitiveTaskEntityDto(cognitiveTaskEntity);
  641. PromotionInfo infoBySubjectId = promotionInfoService.findInfoBySubjectId(cognitiveTaskEntity.getId());
  642. dto.setPrice( infoBySubjectId ==null?0.0:infoBySubjectId.getPrice());
  643. dto2List.add(dto);
  644. });
  645. }
  646. //---end ----
  647. JSONObject jsonObject = new JSONObject();
  648. jsonObject.put("data", dto2List);
  649. jsonObject.put("allNum", num);
  650. return success(jsonObject);
  651. }
  652. /**
  653. * 根据用户的分组权限
  654. * 查看用户的量表权限
  655. * 用户分组为0时查询机构权限
  656. * 用户分组不为0时查询自己分组下的权限
  657. *
  658. * @return
  659. */
  660. @SafetyProcess
  661. @GetMapping("subjectInfo/getSubjectListByAuth")
  662. @ApiOperation(value = "根据权限名称模糊查询量表列表")
  663. public Result getSubjectListByAuth(int pageNum, int pageSize, String scaleName, String categoryEname, String institutionNo, String uId, HttpSession session) {
  664. if (pageSize == 0) {
  665. pageSize = 20;
  666. }
  667. //游客用户无id,数据库配置特定用户
  668. if (StringUtils.isEmpty(uId)){
  669. uId = Constant.PUBLIC_VISITOR_ID;
  670. }
  671. long num;
  672. List<SubjectEntity> subjectEntityList = new ArrayList<>();
  673. UserEntity one = userService.getOne(uId);
  674. if (("0").equals(one.getGId())) {
  675. if (categoryEname.equals("ALL")) {
  676. List<InstitutionAuthSubjectNameDto> byInstitutionNoAndName = this.institutionAuthService.getByInstitutionNoAndName(pageNum, pageSize, institutionNo, "0", scaleName,null);
  677. for (InstitutionAuthSubjectNameDto institutionAuthSubject : byInstitutionNoAndName) {
  678. SubjectEntity subjectEntity = new SubjectEntity();
  679. BeanUtils.copyProperties(institutionAuthSubject, subjectEntity);
  680. subjectEntity.setEName(institutionAuthSubject.getEname());
  681. subjectEntityList.add(subjectEntity);
  682. }
  683. num = this.institutionAuthService.getAllByTableInAuthAndSubInfoNum(institutionNo, "0", scaleName,null);
  684. } else {
  685. subjectEntityList = this.subjectService.getSubjectListByAuthAndCategory(pageNum, pageSize, scaleName, categoryEname, institutionNo);
  686. num = this.subjectService.allNumByAuth(scaleName, categoryEname, institutionNo);
  687. }
  688. } else {
  689. if (categoryEname.equals("ALL")) {
  690. Page<SubjectEntity> userAuth = userService.findUserAuth(uId, pageNum, pageSize, scaleName);
  691. // subjectEntityList = this.subjectService.getSubjectListByAuth(pageNum, pageSize, scaleName, institutionNo);
  692. // System.out.println(subjectEntityList.size());
  693. // num = this.subjectService.allNumByAuth(scaleName, "", institutionNo);
  694. subjectEntityList = userAuth.getContent();
  695. num = userAuth.getTotalElements();
  696. } else {
  697. // subjectEntityList = this.subjectService.getSubjectListByAuthAndCategory(pageNum, pageSize, scaleName, categoryEname, institutionNo);
  698. // num = (long) this.subjectService.allNumByAuth(scaleName, categoryEname, institutionNo);
  699. Page<SubjectEntity> userAuthAndCateEName = this.subjectService.findUserAuthAndCateEName(uId, scaleName, categoryEname, pageNum, pageSize);
  700. subjectEntityList = userAuthAndCateEName.getContent();
  701. num = userAuthAndCateEName.getTotalElements();
  702. }
  703. }
  704. //----add by zzf begin 量表查询新增价格 key=price----
  705. List<SubjectEntityDto2> dto2List = new ArrayList<>();
  706. if(num>0){
  707. subjectEntityList.forEach(subjectEntity -> {
  708. SubjectEntityDto2 dto = new SubjectEntityDto2(subjectEntity);
  709. PromotionInfo infoBySubjectId = promotionInfoService.findInfoBySubjectId(subjectEntity.getId());
  710. dto.setPrice( infoBySubjectId ==null?0.0:infoBySubjectId.getPrice());
  711. List<ScaleEntity> scaleEntityList = this.scaleService.getScaleByFlag(subjectEntity.getFlag());
  712. dto.setTitleNum(scaleEntityList.size());
  713. dto2List.add(dto);
  714. });
  715. }
  716. //-----end------
  717. JSONObject jsonObject = new JSONObject();
  718. jsonObject.put("data", dto2List);
  719. jsonObject.put("allNum", num);
  720. return success(jsonObject);
  721. }
  722. /**
  723. * 量表和认知任务热搜榜
  724. *
  725. * @return
  726. */
  727. @SafetyProcess
  728. @GetMapping("subjectInfo/getTrendingSearches")
  729. @ApiOperation(value = "量表和认知任务热搜榜",notes = " type:类型0量表1认知任务")
  730. public Result getTrendingSearches(String type) {
  731. Set<Integer> set = new HashSet<>(); // 创建Set集合保存随机数
  732. Random random = new Random(); // 创建Random对象生成随机数
  733. while (set.size() < 6) { // 生成6个不重复随机数
  734. int num = random.nextInt(10) + 1; // 生成1到32之间的随机数
  735. set.add(num); // 将随机数添加到Set集合中
  736. }
  737. if (type.equals(Constant.DEFAULT_VALUE_ZERO)) {
  738. List<SubjectEntity> subjectEntities = this.subjectService.getTrendingSearches(Constant.NUMBER_FIFTEEN);
  739. int y = 0;
  740. for (int i = 0; i < subjectEntities.size(); i++){
  741. subjectEntities.get(i).setIsNew(Integer.valueOf(Constant.DEFAULT_VALUE_ZERO));
  742. subjectEntities.get(i).setIsHot(Constant.DEFAULT_VALUE_ZERO);
  743. for (int x : set){
  744. if (i == x){
  745. if (y < 3){
  746. subjectEntities.get(i).setIsHot(Constant.DEFAULT_VALUE_ONE);
  747. set.remove(x);
  748. y ++;
  749. break;
  750. }else if (y >= 3 && y < 6){
  751. subjectEntities.get(i).setIsNew(Integer.valueOf(Constant.DEFAULT_VALUE_ONE));
  752. set.remove(x);
  753. y ++;
  754. break;
  755. }
  756. }
  757. }
  758. }
  759. return success(subjectEntities);
  760. }else if (type.equals(Constant.DEFAULT_VALUE_ONE)){
  761. List<CognitiveTaskEntity> cognitiveTaskEntities = this.cognitiveTaskService.getTrendingSearches(Constant.NUMBER_FIVE);
  762. List<CognitiveTaskEntityDto> dto2List = new ArrayList<>();
  763. int y = 0;
  764. for (int i = 0; i < cognitiveTaskEntities.size(); i++){
  765. CognitiveTaskEntityDto dto = new CognitiveTaskEntityDto(cognitiveTaskEntities.get(i));
  766. for (int x : set){
  767. if (i == x){
  768. if (y < 3){
  769. dto.setIsNew(Constant.DEFAULT_VALUE_ZERO);
  770. dto.setIsHot(Constant.DEFAULT_VALUE_ONE);
  771. set.remove(x);
  772. y ++;
  773. dto2List.add(dto);
  774. break;
  775. }else if (y >= 3 && y < 6){
  776. dto.setIsNew(Constant.DEFAULT_VALUE_ONE);
  777. dto.setIsHot(Constant.DEFAULT_VALUE_ZERO);
  778. set.remove(x);
  779. y ++;
  780. dto2List.add(dto);
  781. break;
  782. }
  783. }else {
  784. dto.setIsNew(Constant.DEFAULT_VALUE_ZERO);
  785. dto.setIsHot(Constant.DEFAULT_VALUE_ZERO);
  786. dto2List.add(dto);
  787. break;
  788. }
  789. }
  790. }
  791. return success(dto2List);
  792. }else {
  793. return fail(null,"参数错误");
  794. }
  795. }
  796. /**
  797. * 根据flag查询检测列表
  798. *
  799. * @param flag
  800. * @return
  801. */
  802. @SafetyProcess
  803. @GetMapping("scaleInfo/{flag}")
  804. @ApiOperation("根据flag查询题目检测列表")
  805. public Result getScaleListByFlag(@PathVariable String flag) {
  806. ScaleDetailsEntity scaleDetailsEntity = scaleDetailsService.getSubjectDetailsByFlag(flag);
  807. if (scaleDetailsEntity == null){
  808. return fail("量表不存在,请联系管理员");
  809. }
  810. if (Constant.DEFAULT_VALUE_ONE.equals(scaleDetailsEntity.getIsValid())){
  811. return fail("无效量表,请联系管理员");
  812. }
  813. log.info("题目查询开始===================="+DateUtil.current());
  814. List<ScaleEntity> scaleEntityList = this.scaleService.getScaleByFlag(flag);
  815. log.info("题目查询结束===================="+DateUtil.current());
  816. return success(scaleEntityList);
  817. }
  818. /**
  819. * 根据flag查询
  820. *
  821. * @return
  822. */
  823. @SafetyProcess
  824. @ApiOperation(value = "根据flag查询")
  825. @GetMapping("subjectInfo/getSubjectByFlag/{flag}")
  826. public Result getSubjectByFlag(@PathVariable String flag) {
  827. List<SubjectEntity> subjectEntityList = this.subjectService.getSubjectByFlag(flag);
  828. List<SubjectEntityDto2> subjectEntityDto2List = new ArrayList<>();
  829. if(subjectEntityList != null && subjectEntityList.size()>0){
  830. subjectEntityList.forEach(subjectEntity -> {
  831. SubjectEntityDto2 subjectEntityDto2 = new SubjectEntityDto2(subjectEntity);
  832. PromotionInfo infoBySubjectId = this.promotionInfoService.findInfoBySubjectId(subjectEntity.getId());
  833. subjectEntityDto2.setPrice(infoBySubjectId == null ? 0.0:infoBySubjectId.getPrice());
  834. List<ScaleEntity> scaleEntityList = this.scaleService.getScaleByFlag(subjectEntity.getFlag());
  835. subjectEntityDto2.setTitleNum(scaleEntityList.size());
  836. int estimatedTime = scaleEntityList.size() / Constant.TEST_PLAN_STATUS_RUNNING + (scaleEntityList.size() % Constant.TEST_PLAN_STATUS_RUNNING != 0 ? 1 : 0);
  837. subjectEntityDto2.setEstimatedTime(estimatedTime);
  838. subjectEntityDto2List.add(subjectEntityDto2);
  839. });
  840. }
  841. return success(subjectEntityDto2List);
  842. }
  843. /**
  844. * 根据flag查询量表新版本详情
  845. *
  846. * @return
  847. */
  848. @SafetyProcess
  849. @ApiOperation(value = "根据flag查询量表新版本详情")
  850. @GetMapping("subjectInfo/getSubjectByFlagV2/{flag}")
  851. public Result getSubjectByFlagV2(@PathVariable String flag) {
  852. try {
  853. List<SubjectEntity> subjectEntityList = this.subjectService.getSubjectByFlag(flag);
  854. List<SubjectEntityDto2> subjectEntityDto2List = new ArrayList<>();
  855. if(subjectEntityList != null && subjectEntityList.size()>0){
  856. subjectEntityList.forEach(subjectEntity -> {
  857. SubjectEntityDto2 subjectEntityDto2 = new SubjectEntityDto2(subjectEntity);
  858. PromotionInfo infoBySubjectId = this.promotionInfoService.findInfoBySubjectId(subjectEntity.getId());
  859. subjectEntityDto2.setPrice(infoBySubjectId == null ? 0.0:infoBySubjectId.getPrice());
  860. List<ScaleEntity> scaleEntityList = this.scaleService.getScaleByFlag(subjectEntity.getFlag());
  861. subjectEntityDto2.setTitleNum(scaleEntityList.size());
  862. int estimatedTime = scaleEntityList.size() / Constant.TEST_PLAN_STATUS_RUNNING + (scaleEntityList.size() % Constant.TEST_PLAN_STATUS_RUNNING != 0 ? 1 : 0);
  863. subjectEntityDto2.setEstimatedTime(estimatedTime);
  864. subjectEntityDto2List.add(subjectEntityDto2);
  865. });
  866. }
  867. ScaleDetailsEntity scaleDetailsEntity = this.scaleDetailsService.getSubjectDetailsByFlag(flag);
  868. if (CollectionUtils.isEmpty(subjectEntityList)){
  869. return fail("量表信息不存在,请联系管理员!");
  870. }
  871. if (Constant.DEFAULT_VALUE_ONE.equals(scaleDetailsEntity.getIsValid())){
  872. return fail("无效量表,请联系管理员!");
  873. }
  874. scaleDetailsEntity.setTestNum(subjectEntityList.get(0).getTestNum());
  875. //获取到题目
  876. List<ScaleEntity> scaleEntityList = scaleService.getScaleByFlag(flag);
  877. JSONObject jsonObject = new JSONObject();
  878. jsonObject.put("subjectEntityDto2List", subjectEntityDto2List);
  879. jsonObject.put("ScaleDetailsEntity", scaleDetailsEntity);
  880. jsonObject.put("questionNum",scaleEntityList== null?0:scaleEntityList.size());
  881. return success(jsonObject);
  882. }catch (Exception e){
  883. e.printStackTrace();
  884. log.error(e.getMessage());
  885. return fail("操作失败");
  886. }
  887. }
  888. /**
  889. * 根据taskCode查询认知任务
  890. *
  891. * @return
  892. */
  893. @SafetyProcess
  894. @ApiOperation(value = "根据taskCode查询认知任务")
  895. @GetMapping("subjectInfo/CognitiveByTaskCode/{taskCode}")
  896. public Result CognitiveByTaskCode(@PathVariable String taskCode) {
  897. CognitiveTaskEntity cognitiveTaskEntity = this.cognitiveTaskService.getCognizeListByTaskCode(taskCode);
  898. CognitiveTaskEntityDto dto = new CognitiveTaskEntityDto(cognitiveTaskEntity);
  899. PromotionInfo infoBySubjectId = promotionInfoService.findInfoBySubjectId(cognitiveTaskEntity.getId());
  900. dto.setPrice( infoBySubjectId ==null?0.0:infoBySubjectId.getPrice());
  901. return success(dto);
  902. }
  903. /**
  904. * 获取到记忆量表字符出厂顺序
  905. *
  906. * @return
  907. */
  908. @SafetyProcess
  909. @ApiOperation(value = "获取到记忆量表字符出厂顺序")
  910. @GetMapping("subjectInfo/getRecallChar")
  911. public Result getRecallChar() {
  912. Map map = RandomUtil.recallChar();
  913. return success(map);
  914. }
  915. /**
  916. * 获取到记忆量表字符出厂顺序2
  917. *
  918. * @return
  919. */
  920. @SafetyProcess
  921. @ApiOperation(value = "获取到记忆量表字符出厂顺序2")
  922. @GetMapping("subjectInfo/getRecallCharTwo")
  923. public Result getRecallCharTwo() {
  924. Map map = RandomUtil.recallCharTwo();
  925. return success(map);
  926. }
  927. /**
  928. * 用户测试记录(我的测试)
  929. *
  930. * @return
  931. */
  932. @SafetyProcess
  933. @GetMapping("mineTest/{phone}/{institutionNo}")
  934. @ApiOperation(value = "用户测试记录(我的测试)")
  935. public Result mineTest(int pageNum, int pageSize, @PathVariable String phone, @PathVariable String institutionNo, String searchKey) {
  936. if (pageSize == 0) {
  937. pageSize = 20;
  938. }
  939. if(pageNum == 0){
  940. pageNum = 1;
  941. }
  942. Page<UserRecordsDto> userRecording = userRecordService.getUserRecording(pageNum, pageSize, phone, institutionNo, searchKey);
  943. //获取到列表
  944. List<UserRecordsDto> list = userRecording.getContent();
  945. //公网版先检验是否为支付订单
  946. if (profileValue != null ){
  947. if (Constant.PROFILE_PUBLIC.equals(profileValue) ){
  948. for (UserRecordsDto userRecord : list){
  949. PromotionInfo infoBySubjectId = promotionInfoService.findInfoBySubjectId(userRecord.getSubjectOrCognitiveId());
  950. if (infoBySubjectId != null && infoBySubjectId.getPrice() != 0){
  951. if (orderInfoService.checkPayOrder(userRecord.getId())){
  952. userRecord.setPay("2");
  953. }else {
  954. userRecord.setPay("1");
  955. }
  956. }else {
  957. userRecord.setPay("0");
  958. }
  959. }
  960. }
  961. }
  962. JSONObject jsonObject = new JSONObject();
  963. jsonObject.put("userRecordEntityList",list);
  964. jsonObject.put("allNum", userRecording.getTotalElements());
  965. return success(jsonObject);
  966. }
  967. /**
  968. *当前量表或者认知任务历史记录
  969. *
  970. * @return
  971. */
  972. @SafetyProcess
  973. @GetMapping("history/{pageNum}/{pageSize}/{phone}/{institutionNo}/{flag}")
  974. @ApiOperation(value = "当前量表或者认知任务历史记录")
  975. public Result history(@PathVariable int pageNum,@PathVariable int pageSize, @PathVariable String phone, @PathVariable String institutionNo, @PathVariable String flag) {
  976. try {
  977. Page<UserRecordEntity> userRecordEntities = userRecordService.getHistoryRecord(pageNum,pageSize,phone,institutionNo,flag);
  978. //公网版先检验是否为支付订单
  979. if (profileValue != null ){
  980. if (Constant.PROFILE_PUBLIC.equals(profileValue) ){
  981. if (CollectionUtils.isNotEmpty(userRecordEntities.getContent())){
  982. userRecordEntities.getContent().forEach(userRecord->{
  983. PromotionInfo infoBySubjectId = promotionInfoService.findInfoByFlag(userRecord.getFlag());
  984. if (infoBySubjectId != null && infoBySubjectId.getPrice() != 0){
  985. if (orderInfoService.checkPayOrder(userRecord.getId())){
  986. userRecord.setPay("2");
  987. }else {
  988. userRecord.setPay("1");
  989. }
  990. }else {
  991. userRecord.setPay("0");
  992. }
  993. });
  994. }
  995. }
  996. }
  997. return success(userRecordEntities);
  998. }catch (Exception e){
  999. e.printStackTrace();
  1000. return fail("操作异常");
  1001. }
  1002. }
  1003. /**
  1004. *当前量表或者认知任务历史记录
  1005. *
  1006. * @return
  1007. */
  1008. @SafetyProcess
  1009. @GetMapping("countHistory/{phone}/{institutionNo}/{flag}")
  1010. @ApiOperation(value = "历史测评统计")
  1011. public Result countHistory(@PathVariable String phone, @PathVariable String institutionNo, @PathVariable String flag) {
  1012. try {
  1013. int count = userRecordService.countHistoryRecord(phone,institutionNo,flag);
  1014. return success(count);
  1015. }catch (Exception e){
  1016. e.printStackTrace();
  1017. return fail("操作异常");
  1018. }
  1019. }
  1020. /**
  1021. * 用户测试记录(我的测试)
  1022. *
  1023. * @return
  1024. */
  1025. @SafetyProcess
  1026. @GetMapping("mineTest2/{phone}/{institutionNo}")
  1027. @ApiOperation(value = "用户测试记录(我的测试)")
  1028. public Result mineTest2(int pageNum, int pageSize, @PathVariable String phone, @PathVariable String institutionNo, String searchKey) {
  1029. Page<UserRecordEntity> userRecording = userRecordService.getUserRecording2(pageNum, pageSize, phone, institutionNo, searchKey);
  1030. //获取到列表
  1031. List<UserRecordEntity> list = userRecording.getContent();
  1032. //获取到所有收费信息
  1033. List<PromotionInfo> infos = promotionInfoService.findAll();
  1034. //公网版先检验是否为支付订单
  1035. if (profileValue != null ){
  1036. if (Constant.PROFILE_PUBLIC.equals(profileValue) ){
  1037. for (UserRecordEntity userRecord : list){
  1038. for (PromotionInfo info:infos){
  1039. if (!userRecord.getFlag().equals(info.getFlag())){
  1040. continue;
  1041. }
  1042. if ( info.getPrice() != 0){
  1043. if (orderInfoService.checkPayOrder(userRecord.getId())){
  1044. userRecord.setPay("2");
  1045. }else {
  1046. userRecord.setPay("1");
  1047. }
  1048. }else {
  1049. userRecord.setPay("0");
  1050. }
  1051. break;
  1052. }
  1053. // PromotionInfo infoBySubjectId = promotionInfoService.findInfoByFlag(userRecord.getFlag());
  1054. // if (infoBySubjectId != null && infoBySubjectId.getPrice() != 0){
  1055. // if (orderInfoService.checkPayOrder(userRecord.getId())){
  1056. // userRecord.setPay("2");
  1057. // }else {
  1058. // userRecord.setPay("1");
  1059. // }
  1060. // }else {
  1061. // userRecord.setPay("0");
  1062. // }
  1063. }
  1064. }
  1065. }
  1066. JSONObject jsonObject = new JSONObject();
  1067. jsonObject.put("userRecordEntityList",list);
  1068. jsonObject.put("allNum", userRecording.getTotalElements());
  1069. return success(jsonObject);
  1070. }
  1071. /**
  1072. * 用户查询枪林弹雨
  1073. *
  1074. * @return
  1075. */
  1076. @SafetyProcess
  1077. @GetMapping("GUNSBULLETS/{userId}")
  1078. @ApiOperation(value = "用户查询枪林弹雨记录")
  1079. public Result GUNSBULLETS(@PathVariable String userId) {
  1080. UserEntity one = this.userService.getOne(userId);
  1081. List<UserRecordEntity> gunsbullets = this.userRecordService.getGUNSBULLETS(one.getPhone(), one.getInstitutionNo());
  1082. return success(gunsbullets);
  1083. }
  1084. /**
  1085. * 根据id查询测试详细信息
  1086. *
  1087. * @return
  1088. */
  1089. @SafetyProcess
  1090. @GetMapping("/getRecordById")
  1091. @ApiOperation(value = "根据id查询测试详细信息")
  1092. public Result getRecordById(String id) {
  1093. //公网版先检验是否为支付订单
  1094. if (profileValue != null ){
  1095. if (Constant.PROFILE_PUBLIC.equals(profileValue) ){
  1096. //认知任务暂时不做支付处理
  1097. UserRecordEntity userRecordEntity = userRecordService.getUserRecordById(id);
  1098. if (userRecordEntity.getType().equals("0")){
  1099. SubjectEntity subjectEntity = this.subjectService.getSubjectEntityByFlag(userRecordEntity.getFlag());
  1100. PromotionInfo infoBySubjectId = promotionInfoService.findInfoBySubjectId(subjectEntity.getId());
  1101. if (infoBySubjectId != null && infoBySubjectId.getPrice() != 0){
  1102. if (userRecordEntity != null && Constant.DEFAULT_VALUE_ZERO.equals(userRecordEntity.getType())){
  1103. if (!orderInfoService.checkPayOrder(id)){
  1104. return fail("未支付");
  1105. }
  1106. }
  1107. }
  1108. }
  1109. }
  1110. }
  1111. //获取测试记录信息
  1112. UserRecordEntity userRecordEntity = this.userRecordService.getUserRecordById(id);
  1113. if (userRecordEntity == null){
  1114. return fail("参数错误");
  1115. }
  1116. //判断是否达到最大测试次数
  1117. InstitutionEntity entity = institutionService.findByInstitutionNo(userRecordEntity.getInstitutionNo());
  1118. if (Constant.DEFAULT_VALUE_ONE.equals(entity.getIsTestNum().toString())){
  1119. //获取该机构下测试数据
  1120. int count = userRecordService.finAllByInstitutionNo(userRecordEntity.getInstitutionNo());
  1121. if (count> entity.getTestNum()){
  1122. if (entity.getTestNum()==0){
  1123. return fail("测试次数已达上限,请联系机构管理员");
  1124. }
  1125. //获取到最后一条测试记录
  1126. String last = userRecordService.findByTestNum(entity.getInstitutionNo(),entity.getTestNum()-1);
  1127. if (last != null){
  1128. int result = DateUtil.compare(DateUtil.parse(userRecordEntity.getTestDate(), DatePattern.CHINESE_DATE_TIME_PATTERN),DateUtil.parse(last,DatePattern.CHINESE_DATE_TIME_PATTERN));
  1129. if (result > 0){
  1130. return fail("测试次数已达上限,请联系机构管理员");
  1131. }
  1132. }
  1133. }
  1134. }
  1135. //获取测试人员信息
  1136. UserEntity userInfo = this.userService.findPhoneAndInstitutionNoAndRoleType(userRecordEntity.getPhone(), userRecordEntity.getInstitutionNo(),UserRole.COMMON.getType());
  1137. UserFileEntity userFileEntity = this.userFileService.findByUserId(userInfo.getId());
  1138. if (userFileEntity != null){
  1139. userInfo.setAvatarUrl(userFileEntity.getPath());
  1140. }
  1141. String flag = userRecordEntity.getFlag();
  1142. String type = userRecordEntity.getType();
  1143. List<SubjectEntity> subjectByFlag;
  1144. JSONObject result = new JSONObject();
  1145. if ("0".equals(type)) {
  1146. subjectByFlag = subjectService.getSubjectByFlag(flag);
  1147. result.put("subject", subjectByFlag.get(0));
  1148. }else if ("1".equals(type)) {
  1149. CognitiveTaskEntity cognitiveTask = this.cognitiveTaskService.getCognizeListByTaskCode(flag);
  1150. result.put("cognitiveTask", cognitiveTask);
  1151. }
  1152. result.put("userRecordEntity", userRecordEntity);
  1153. result.put("userInfo", userInfo);
  1154. return success(result);
  1155. }
  1156. //@SafetyProcess
  1157. @PostMapping("/importSubjectByJson")
  1158. @ApiOperation(value = "第一批导入json格式量表")
  1159. public Result importSubjectByJson(@RequestBody JSONObject jsonObject) {
  1160. System.out.println("jsonobject:" + jsonObject);
  1161. //量表标志自动生成唯一值,yyyyMMddHHmmss
  1162. String flag = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
  1163. JSONObject result = jsonObject.getJSONObject("result");
  1164. //根据量表中文名查询,判断该量表是否存在
  1165. SubjectEntity subject = this.subjectService.getSubjectByname(result.getString("title"));
  1166. if (subject != null) {
  1167. return fail("该量表已存在!");
  1168. }
  1169. //创建量表实体类,并传入数据
  1170. SubjectEntity subjectEntity = new SubjectEntity();
  1171. subjectEntity.setName(result.getString("title"));
  1172. subjectEntity.setFlag(flag);
  1173. //类型默认量表
  1174. subjectEntity.setType("0");
  1175. //新增量表默认为热门测试
  1176. subjectEntity.setIsHot("1");
  1177. //新增量表默认为最新测试
  1178. subjectEntity.setIsNew(1);
  1179. subjectEntity.setDescription(result.getString("desc"));
  1180. subjectEntity.setUploader("雷煜");
  1181. //subjectEntity.setEName(eName);
  1182. subjectEntity.setStatus(0);
  1183. subjectEntity.setFileName("null");
  1184. //计分原则
  1185. String scoringPrinciple = "";
  1186. //获取量表题目信息
  1187. JSONArray items = result.getJSONArray("items");
  1188. for (int i = 0; i < items.size(); i++) {
  1189. JSONObject item = items.getJSONObject(i);
  1190. ScaleEntity scaleEntity = new ScaleEntity();
  1191. scaleEntity.setQuestionNo(item.getString("index"));
  1192. scaleEntity.setSerialNo(item.getString("index"));
  1193. scaleEntity.setAnswer(item.getString("name"));
  1194. //答案选项
  1195. String checkItems = "";
  1196. scaleEntity.setQuestionType(Constant.MAGIC_NUM_0);
  1197. scaleEntity.setWeight("");
  1198. // 量表模板不提供分值
  1199. scaleEntity.setScore("");
  1200. scaleEntity.setFlag(flag);
  1201. scaleEntity.setScoreDirection("1");
  1202. //获取题目选项信息
  1203. JSONArray options = item.getJSONArray("options");
  1204. for (int y = 0; y < options.size(); y++) {
  1205. JSONObject option = options.getJSONObject(y);
  1206. AnswerEntity answerEntity = new AnswerEntity();
  1207. answerEntity.setFlag(flag);
  1208. answerEntity.setQuestionNo(item.getString("index"));
  1209. answerEntity.setName(option.getString("name"));
  1210. answerEntity.setOptions(option.getString("select"));
  1211. answerEntity.setQuestionType("0");
  1212. answerEntity.setScore(option.getString("score"));
  1213. answerEntity.setScoreDirection("1");
  1214. this.answerService.saveAnswer(answerEntity);
  1215. if (y + 1 == options.size()) {
  1216. checkItems = checkItems + option.getString("name");
  1217. } else {
  1218. checkItems = checkItems + option.getString("name") + ";";
  1219. }
  1220. }
  1221. scaleEntity.setCheckItems(checkItems);
  1222. this.scaleService.saveScale(scaleEntity);
  1223. System.out.println(scaleEntity.toString());
  1224. }
  1225. JSONArray scores = result.getJSONArray("scores");
  1226. for (int i = 0; i < scores.size(); i++) {
  1227. JSONObject score = scores.getJSONObject(i);
  1228. int scoreStart = score.getInteger("scoreStart");
  1229. int scoreEnd = score.getInteger("scoreEnd");
  1230. String desc = score.getString("desc");
  1231. String improvementSuggestions = score.getString("improvementSuggestions");
  1232. scoringPrinciple = scoringPrinciple + scoreStart + "-" + scoreEnd + ";" + desc;
  1233. if (improvementSuggestions != null) {
  1234. scoringPrinciple = scoringPrinciple + ";" + improvementSuggestions;
  1235. }
  1236. ScaleMarksEntity scaleMarksEntity = new ScaleMarksEntity();
  1237. scaleMarksEntity.setFlag(flag);
  1238. scaleMarksEntity.setImprovementSuggestions(improvementSuggestions);
  1239. scaleMarksEntity.setSymptom(score.getString("desc"));
  1240. scaleMarksEntity.setScoreEnd(String.valueOf(scoreEnd));
  1241. scaleMarksEntity.setScoreStart(String.valueOf(scoreStart));
  1242. //TODO 设置评分规则表默认值
  1243. scaleMarksEntity.setNameExplain("无");
  1244. scaleMarksEntity.setReference("无");
  1245. scaleMarksEntity.setSuggestion("无");
  1246. scaleMarksEntity.setIsTotalScoreExplain("否");
  1247. this.scaleMarksService.saveScaleMarks(scaleMarksEntity);
  1248. }
  1249. subjectEntity.setScoringPrinciple(scoringPrinciple);
  1250. this.subjectService.save(subjectEntity);
  1251. System.out.println(subjectEntity);
  1252. return success();
  1253. }
  1254. @PostMapping("/importSubjectByJsonb")
  1255. @ApiOperation(value = "第二批导入json格式量表")
  1256. public Result importSubjectByJsonb(@RequestBody JSONObject result) {
  1257. System.out.println("jsonobject:" + result);
  1258. //量表标志自动生成唯一值,yyyyMMddHHmmss
  1259. String flag = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
  1260. //根据量表中文名查询,判断该量表是否存在
  1261. SubjectEntity subject = this.subjectService.getSubjectByname(result.getString("title"));
  1262. if (subject != null) {
  1263. return fail("该量表已存在!");
  1264. }
  1265. //创建量表实体类,并传入数据
  1266. SubjectEntity subjectEntity = new SubjectEntity();
  1267. subjectEntity.setName(result.getString("title"));
  1268. subjectEntity.setFlag(flag);
  1269. //类型默认量表
  1270. subjectEntity.setType("0");
  1271. //新增量表默认为热门测试
  1272. subjectEntity.setIsHot("1");
  1273. //新增量表默认为最新测试
  1274. subjectEntity.setIsNew(1);
  1275. subjectEntity.setDescription(result.getString("instruction"));
  1276. subjectEntity.setUploader("雷煜");
  1277. //subjectEntity.setEName(eName);
  1278. subjectEntity.setStatus(0);
  1279. subjectEntity.setFileName("null");
  1280. subjectEntity.setScaleLimit("public");
  1281. //计分原则
  1282. String scoringPrinciple = "";
  1283. //获取量表题目信息
  1284. JSONArray items = result.getJSONArray("items");
  1285. for (int i = 0; i < items.size(); i++) {
  1286. JSONObject item = items.getJSONObject(i);
  1287. ScaleEntity scaleEntity = new ScaleEntity();
  1288. scaleEntity.setQuestionNo(item.getString("index"));
  1289. scaleEntity.setSerialNo(item.getString("index"));
  1290. scaleEntity.setAnswer(item.getString("name"));
  1291. //答案选项
  1292. String checkItems = "";
  1293. scaleEntity.setQuestionType(Constant.MAGIC_NUM_0);
  1294. scaleEntity.setWeight("");
  1295. // 量表模板不提供分值
  1296. scaleEntity.setScore("");
  1297. scaleEntity.setFlag(flag);
  1298. scaleEntity.setScoreDirection("1");
  1299. //获取题目选项信息
  1300. JSONArray options = item.getJSONArray("options");
  1301. for (int y = 0; y < options.size(); y++) {
  1302. JSONObject option = options.getJSONObject(y);
  1303. AnswerEntity answerEntity = new AnswerEntity();
  1304. answerEntity.setFlag(flag);
  1305. answerEntity.setQuestionNo(item.getString("index"));
  1306. answerEntity.setName(option.getString("select"));
  1307. answerEntity.setOptions("");
  1308. answerEntity.setQuestionType("0");
  1309. answerEntity.setScore(option.getString("score"));
  1310. answerEntity.setScoreDirection("1");
  1311. this.answerService.saveAnswer(answerEntity);
  1312. if (y + 1 == options.size()) {
  1313. checkItems = checkItems + option.getString("select");
  1314. } else {
  1315. checkItems = checkItems + option.getString("select") + ";";
  1316. }
  1317. }
  1318. scaleEntity.setCheckItems(checkItems);
  1319. this.scaleService.saveScale(scaleEntity);
  1320. System.out.println(scaleEntity.toString());
  1321. }
  1322. JSONArray scores = result.getJSONArray("scores");
  1323. for (int i = 0; i < scores.size(); i++) {
  1324. JSONObject score = scores.getJSONObject(i);
  1325. int scoreStart = score.getInteger("scoreStart");
  1326. int scoreEnd = score.getInteger("scoreEnd");
  1327. String desc = score.getString("desc");
  1328. scoringPrinciple = scoringPrinciple + scoreStart + "-" + scoreEnd + ";" + desc;
  1329. ScaleMarksEntity scaleMarksEntity = new ScaleMarksEntity();
  1330. scaleMarksEntity.setFlag(flag);
  1331. scaleMarksEntity.setImprovementSuggestions("");
  1332. scaleMarksEntity.setSymptom(score.getString("desc"));
  1333. scaleMarksEntity.setScoreEnd(String.valueOf(scoreEnd));
  1334. scaleMarksEntity.setScoreStart(String.valueOf(scoreStart));
  1335. //TODO 设置评分规则表默认值
  1336. scaleMarksEntity.setNameExplain("无");
  1337. scaleMarksEntity.setReference("无");
  1338. scaleMarksEntity.setSuggestion("无");
  1339. scaleMarksEntity.setIsTotalScoreExplain("否");
  1340. this.scaleMarksService.saveScaleMarks(scaleMarksEntity);
  1341. }
  1342. subjectEntity.setScoringPrinciple(scoringPrinciple);
  1343. this.subjectService.save(subjectEntity);
  1344. System.out.println(subjectEntity);
  1345. return success();
  1346. }
  1347. /**
  1348. * 删除字段多余字符
  1349. *
  1350. * @return
  1351. */
  1352. //@SafetyProcess
  1353. //@GetMapping("deleteChar")
  1354. //@ApiOperation(value = "删除字段多余字符")
  1355. public Result deleteChar() {
  1356. List<SubjectEntity> subjectEntities = this.subjectService.findAll("0");
  1357. for (SubjectEntity subjectEntity : subjectEntities) {
  1358. if (subjectEntity.getScoringPrinciple() != null) {
  1359. String scoring = subjectEntity.getScoringPrinciple().replaceAll("\\<[^\\<^\\>]*\\>", "");
  1360. scoring = scoring.replace(";null", "");
  1361. this.subjectService.updateById(subjectEntity.getId(), scoring);
  1362. }
  1363. }
  1364. List<ScaleMarksEntity> scaleMarksEntities = this.scaleMarksService.findAll();
  1365. for (ScaleMarksEntity scaleMarksEntity : scaleMarksEntities) {
  1366. String symptom = null;
  1367. String improvement = null;
  1368. if (scaleMarksEntity.getSymptom() != null) {
  1369. symptom = scaleMarksEntity.getSymptom().replaceAll("\\<[^\\<^\\>]*\\>", "");
  1370. }
  1371. if (scaleMarksEntity.getImprovementSuggestions() != null) {
  1372. improvement = scaleMarksEntity.getImprovementSuggestions().replaceAll("\\<[^\\<^\\>]*\\>", "");
  1373. }
  1374. this.scaleMarksService.updateById(scaleMarksEntity.getId(), symptom, improvement);
  1375. }
  1376. return success();
  1377. }
  1378. /**
  1379. * 处理用户测试结果数据格式
  1380. *
  1381. * @return
  1382. */
  1383. //@SafetyProcess
  1384. @GetMapping("userRecord")
  1385. @ApiOperation(value = "处理用户测试结果数据格式")
  1386. public Result userRecord() {
  1387. List<UserRecordEntity> userRecordEntities = this.userRecordService.findAll1();
  1388. for (UserRecordEntity userRecordEntity : userRecordEntities) {
  1389. if (!userRecordEntity.getFlag().contains("YATAI") || !userRecordEntity.getFlag().equals("ANTFISH")) {
  1390. //计算结果
  1391. JSONArray dbJsonList = JSONArray.parseArray(userRecordEntity.getTestResult());
  1392. JSONObject dbJson = dbJsonList.getJSONObject(0);
  1393. JSONArray tableContext = dbJson.getJSONArray("tableContext");
  1394. String testResults = new String();
  1395. for (int i = 0; i < tableContext.size(); i++) {
  1396. JSONObject jsonObject = tableContext.getJSONObject(i);
  1397. if (i == tableContext.size() - 1) {
  1398. testResults += jsonObject.getString("name") + ":" + jsonObject.getJSONArray("value").getString(0);
  1399. } else {
  1400. testResults += jsonObject.getString("name") + ":" + jsonObject.getJSONArray("value").getString(0) + ";";
  1401. }
  1402. }
  1403. }
  1404. }
  1405. return success();
  1406. }
  1407. /* V1版本,暂时保留
  1408. @ApiOperation(value = "用户导入")
  1409. @Transactional(rollbackFor = Exception.class)
  1410. @PostMapping("userImport")
  1411. public Result userImport(String institutionNo, MultipartFile file, HttpServletResponse response) throws Exception {
  1412. if (file == null) {
  1413. return fail("文件为空");
  1414. }
  1415. if (institutionNo == null) {
  1416. return fail("机构编号为空");
  1417. }
  1418. //String message = "提交成功";
  1419. String filePath = "";//用户信息上传之后生成的用户名密码文件保存路径
  1420. String fileName = file.getOriginalFilename();
  1421. List<List<Object>> datas = ExcelUtil.getBankListByExcelForUserImport(file.getInputStream(), fileName);
  1422. if(datas.size() <= 0){
  1423. return fail("内容为空");
  1424. }
  1425. //插入数据库信息
  1426. List<UserEntity> userListDB = new ArrayList<>();
  1427. //生成导入后用户信息
  1428. List<UserEntity> userLists = new ArrayList<>();
  1429. StringBuilder result = new StringBuilder();
  1430. //result.append("账号:");
  1431. //判断是否有已经存在数据库的
  1432. boolean isExist = false;
  1433. //UserEntity tempUserDB;
  1434. String defaultGroupId = null;
  1435. try {
  1436. int y = 0;
  1437. for (int i = 0; i < datas.size(); i++) {
  1438. List<Object> users = datas.get(i);
  1439. if (users.get(0) == null || users.get(0) == "" || users.get(1) == null || users.get(1) == "" || users.get(2) == null || users.get(2) == ""
  1440. || users.get(3) == null || users.get(3) == "" || users.get(4) == null || users.get(4) == "" || users.get(5) == null || users.get(5) == "") {
  1441. y = i + 1;
  1442. result.append("第" + y +"条数据信息不完整").append("\r\n");
  1443. isExist = true;
  1444. continue;
  1445. }
  1446. //北京师范大学亚太实验学校, 陈亚浩2, 男, 2001-10-01, 学生, , 六年级一班, null, null
  1447. //插入数据库的信息
  1448. UserEntity tempUserDB = new UserEntity();
  1449. //导入成功用户信息
  1450. UserEntity userEntity = new UserEntity();
  1451. tempUserDB.setInstitutionName(users.get(0).toString());
  1452. tempUserDB.setPetName(users.get(1).toString());
  1453. userEntity.setInstitutionName(users.get(0).toString());
  1454. userEntity.setPetName(users.get(1).toString());
  1455. userEntity.setGender(users.get(2).toString());
  1456. if ("男".equals(users.get(2).toString())) {
  1457. tempUserDB.setGender("0");
  1458. } else {
  1459. tempUserDB.setGender("1");
  1460. }
  1461. tempUserDB.setBirthday(users.get(3).toString());
  1462. tempUserDB.setProfession(users.get(4).toString());
  1463. tempUserDB.setAdditionInfo(users.get(5).toString());
  1464. userEntity.setBirthday(users.get(3).toString());
  1465. userEntity.setProfession(users.get(4).toString());
  1466. userEntity.setAdditionInfo(users.get(5).toString());
  1467. int repeatNum = userRepeatNameNumService.testOrNotNamePinyin(institutionNo, getPinyin(users.get(1).toString()));
  1468. if (users.size() > 6) {
  1469. if (null == users.get(6) || users.get(6).equals("")) {
  1470. tempUserDB.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
  1471. userEntity.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
  1472. } else {
  1473. tempUserDB.setPhone(users.get(6).toString());
  1474. userEntity.setPhone(users.get(6).toString());
  1475. }
  1476. } else {
  1477. tempUserDB.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
  1478. userEntity.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
  1479. }
  1480. if (users.size() > 7) {
  1481. if (null == users.get(7) || users.get(7).equals("")) {
  1482. tempUserDB.setPassword(DigestUtils.md5DigestAsHex(Constant.DEFAULT_PASSWORD.getBytes(StandardCharsets.UTF_8)));
  1483. userEntity.setPassword(Constant.DEFAULT_PASSWORD);
  1484. } else {
  1485. tempUserDB.setPassword(DigestUtils.md5DigestAsHex(users.get(7).toString().getBytes(StandardCharsets.UTF_8)));
  1486. userEntity.setPassword(users.get(7).toString());
  1487. }
  1488. } else {
  1489. tempUserDB.setPassword(DigestUtils.md5DigestAsHex(Constant.DEFAULT_PASSWORD.getBytes(StandardCharsets.UTF_8)));
  1490. userEntity.setPassword(Constant.DEFAULT_PASSWORD);
  1491. }
  1492. // tempUserDB.setPhone(getPinyin(users.get(1).toString()));
  1493. tempUserDB.setInstitutionNo(institutionNo);
  1494. tempUserDB.setUserStatus("2");
  1495. userEntity.setInstitutionNo(institutionNo);
  1496. userEntity.setUserStatus("2");
  1497. //设置组id,未分组时组id为0
  1498. if (defaultGroupId == null) {
  1499. GroupEntity groupByInstitutionNoAndName = this.groupInfoService.findGroupByInstitutionNoAndName(tempUserDB.getInstitutionNo(), Constant.DEFAULT_GROUP_NAME);
  1500. if (groupByInstitutionNoAndName == null) {
  1501. GroupEntity groupEntity = new GroupEntity();
  1502. groupEntity.setGroupName(Constant.DEFAULT_GROUP_NAME);
  1503. groupEntity.setInstitutionNo(tempUserDB.getInstitutionNo());
  1504. groupEntity = this.groupInfoService.addGroup(groupEntity);
  1505. //创建权限
  1506. List<InstitutionAuthEntity> institutionAuthEntityList = this.institutionAuthService.getByInstitutionNo(tempUserDB.getInstitutionNo());
  1507. for (int mi = 0; mi < institutionAuthEntityList.size(); mi++) {
  1508. InstitutionAuthEntity institutionAuthEntity = new InstitutionAuthEntity();
  1509. GroupAuthEntity groupAuthEntity = new GroupAuthEntity();
  1510. groupAuthEntity.setBId(institutionAuthEntity.getBId());
  1511. groupAuthEntity.setGroupId(groupEntity.getId());
  1512. groupAuthEntity.setType(institutionAuthEntity.getType());
  1513. this.groupAuthService.addGroupAuth(groupAuthEntity);
  1514. }
  1515. defaultGroupId = groupEntity.getId();
  1516. } else {
  1517. defaultGroupId = groupByInstitutionNoAndName.getId();
  1518. }
  1519. }
  1520. tempUserDB.setGId(defaultGroupId);
  1521. tempUserDB.setModelPhone("0");
  1522. tempUserDB.setRoleType(UserRole.COMMON.getType());
  1523. userEntity.setGId(defaultGroupId);
  1524. userEntity.setModelPhone("0");
  1525. userEntity.setRoleType(UserRole.COMMON.getType());
  1526. //查看当前用户是否已经在数据库存在
  1527. UserEntity phoneAndInstitutionNo = userService.findPhoneAndInstitutionNo(tempUserDB.getPhone(), institutionNo);
  1528. if (phoneAndInstitutionNo != null) {
  1529. y = i + 1;
  1530. result.append("第" + y +"条数据账号" + phoneAndInstitutionNo.getPhone() + "已存在").append("\r\n");
  1531. isExist = true;
  1532. continue;
  1533. }
  1534. this.userService.save(tempUserDB);
  1535. userListDB.add(tempUserDB);
  1536. userLists.add(userEntity);
  1537. }
  1538. if (OSUtil.isLinux()) {
  1539. filePath = "./userImport/" + institutionNo + "/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "/";
  1540. } else {
  1541. filePath = "./userImport/" + institutionNo + "/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "/";
  1542. }
  1543. ExcelUtil.createExcelFileForPublic(UserEntity.class, userLists, null, new ExcelClass().userExportExcel(), fileName, filePath);
  1544. if (isExist) {
  1545. result.append(",跳过该信息。(请检查该信息)");
  1546. return success(filePath + fileName, result.toString());
  1547. } else {
  1548. return success(filePath + fileName, "批量导入成功");
  1549. }
  1550. } catch (Exception exception) {
  1551. exception.printStackTrace();
  1552. return fail("导入失败,请联系管理员");
  1553. }
  1554. }*/
  1555. @ApiOperation(value = "用户导入")
  1556. @Transactional(rollbackFor = Exception.class)
  1557. @PostMapping("userImport")
  1558. public Result userImport(String institutionNo, MultipartFile file, HttpServletResponse response) throws Exception {
  1559. if (file == null) {
  1560. return fail("文件为空");
  1561. }
  1562. if (institutionNo == null) {
  1563. return fail("机构编号为空");
  1564. }
  1565. String fileName = file.getOriginalFilename();
  1566. List<List<Object>> datas = ExcelUtil.getBankListByExcelForUserImport(file.getInputStream(), fileName);
  1567. if(datas.size() <= 0){
  1568. return fail("内容为空");
  1569. }
  1570. StringBuilder result = new StringBuilder();
  1571. //判断是否有已经存在数据库的
  1572. boolean isExist = false;
  1573. String defaultGroupId = null;
  1574. try {
  1575. int y = 0;
  1576. for (int i = 0; i < datas.size(); i++) {
  1577. List<Object> users = datas.get(i);
  1578. if (users.get(0) == null || users.get(0) == "" || users.get(1) == null || users.get(1) == "" || users.get(2) == null || users.get(2) == "") {
  1579. y = i + 1;
  1580. result.append("第" + y +"条数据信息不完整").append("\r\n");
  1581. isExist = true;
  1582. continue;
  1583. }
  1584. String petName = users.get(0).toString();
  1585. if (petName.length() > 18 || petName.contains(" ")){
  1586. y = i + 1;
  1587. result.append("第" + y +"条数据姓名长度大于18位或有空格").append("\r\n");
  1588. isExist = true;
  1589. continue;
  1590. }
  1591. String phone = users.get(1).toString();
  1592. if (phone.length() > 18 || phone.length() < 3 || phone.contains(" ")){
  1593. y = i + 1;
  1594. result.append("第" + y +"条数据账号长度未在3~18位之间或有空格").append("\r\n");
  1595. isExist = true;
  1596. continue;
  1597. }
  1598. String password = users.get(2).toString();
  1599. if (password.length() < 6 || password.length() > 18 || password.contains(" ")){
  1600. y = i + 1;
  1601. result.append("第" + y +"条数据密码长度未在6~18位之间或有空格").append("\r\n");
  1602. isExist = true;
  1603. continue;
  1604. }
  1605. //插入数据库的信息
  1606. UserEntity tempUserDB = new UserEntity();
  1607. //设置组id,未分组时组id为0
  1608. if (defaultGroupId == null) {
  1609. GroupEntity groupByInstitutionNoAndName = this.groupInfoService.findGroupByInstitutionNoAndName(institutionNo, Constant.DEFAULT_GROUP_NAME);
  1610. if (groupByInstitutionNoAndName == null) {
  1611. GroupEntity groupEntity = new GroupEntity();
  1612. groupEntity.setGroupName(Constant.DEFAULT_GROUP_NAME);
  1613. groupEntity.setInstitutionNo(institutionNo);
  1614. groupEntity = this.groupInfoService.addGroup(groupEntity);
  1615. //创建权限
  1616. List<InstitutionAuthEntity> institutionAuthEntityList = this.institutionAuthService.getByInstitutionNo(institutionNo);
  1617. for (int mi = 0; mi < institutionAuthEntityList.size(); mi++) {
  1618. InstitutionAuthEntity institutionAuthEntity = new InstitutionAuthEntity();
  1619. GroupAuthEntity groupAuthEntity = new GroupAuthEntity();
  1620. groupAuthEntity.setBId(institutionAuthEntity.getBId());
  1621. groupAuthEntity.setGroupId(groupEntity.getId());
  1622. groupAuthEntity.setType(institutionAuthEntity.getType());
  1623. this.groupAuthService.addGroupAuth(groupAuthEntity);
  1624. }
  1625. defaultGroupId = groupEntity.getId();
  1626. } else {
  1627. defaultGroupId = groupByInstitutionNoAndName.getId();
  1628. }
  1629. }
  1630. InstitutionEntity institutionEntity = this.institutionService.findByInstitutionNo(institutionNo);
  1631. /*
  1632. `gender` varchar(2) NOT NULL COMMENT '性别(0-男;1-女)',
  1633. `birthday` varchar(15) NOT NULL COMMENT '出生日期',
  1634. `profession` varchar(50) DEFAULT NULL COMMENT '职业',
  1635. `addition_info` varchar(500) DEFAULT NULL COMMENT '附加信息',
  1636. `model_phone` varchar(11) DEFAULT '0' COMMENT '用户手机号:0->用户不填手机号', 可为空
  1637. */
  1638. tempUserDB.setInstitutionName(institutionEntity.getInstitutionName());
  1639. //姓名、账号、密码格式未效验
  1640. tempUserDB.setPetName(users.get(0).toString());
  1641. tempUserDB.setPhone(users.get(1).toString());
  1642. tempUserDB.setPassword(DigestUtils.md5DigestAsHex(users.get(2).toString().getBytes(StandardCharsets.UTF_8)));
  1643. tempUserDB.setGender(Constant.DEFAULT_VALUE_ZERO);
  1644. tempUserDB.setBirthday("2001-01-01");
  1645. tempUserDB.setInstitutionNo(institutionNo);
  1646. tempUserDB.setUserStatus(UserStatus.PERFECT.getType());
  1647. tempUserDB.setGId(defaultGroupId);
  1648. tempUserDB.setModelPhone(Constant.DEFAULT_VALUE_ZERO);
  1649. tempUserDB.setRoleType(UserRole.COMMON.getType());
  1650. //查看当前用户是否已经在数据库存在
  1651. UserEntity phoneAndInstitutionNo = userService.findPhoneAndInstitutionNoAndRoleType(tempUserDB.getPhone(), institutionNo,Constant.DEFAULT_VALUE_ONE);
  1652. if (phoneAndInstitutionNo != null) {
  1653. y = i + 1;
  1654. result.append("第" + y +"条数据账号" + phoneAndInstitutionNo.getPhone() + "已存在").append("\r\n");
  1655. isExist = true;
  1656. continue;
  1657. }
  1658. this.userService.save(tempUserDB);
  1659. }
  1660. if (isExist) {
  1661. result.append(",跳过该信息。(请检查该信息)");
  1662. return success("", result.toString());
  1663. } else {
  1664. return success("", "批量导入成功");
  1665. }
  1666. } catch (Exception exception) {
  1667. exception.printStackTrace();
  1668. return fail("导入失败,请联系管理员");
  1669. }
  1670. }
  1671. @PostMapping("/saveCognitiveTask")
  1672. @ApiOperation(value = "添加认知任务信息")
  1673. public Result completeTest(@RequestBody JSONArray jsonArray) throws Exception {
  1674. List<CognitiveTaskEntity> cognitiveTaskEntityList = jsonArray.toJavaList(CognitiveTaskEntity.class);
  1675. for (CognitiveTaskEntity cognitiveTaskEntity : cognitiveTaskEntityList) {
  1676. this.cognitiveTaskService.save(cognitiveTaskEntity);
  1677. }
  1678. return null;
  1679. }
  1680. @ApiOperation(value = "用户模板下载")
  1681. @GetMapping("/download/userTemplateDownload")
  1682. public String userTemplateDownload(HttpServletResponse response) {
  1683. String filePath = "";
  1684. if (OSUtil.isLinux()) {
  1685. filePath = "./userTemplate/importTemplate.xlsx";
  1686. } else {
  1687. filePath = "./userTemplate/importTemplate.xlsx";
  1688. }
  1689. File fileReturn = new File(filePath);
  1690. response.reset();
  1691. response.setContentType("application/octet-stream");
  1692. response.setCharacterEncoding("utf-8");
  1693. response.setContentLength((int) fileReturn.length());
  1694. response.setHeader("Content-Disposition", "attachment;filename=template.xlsx");
  1695. byte[] buffer = new byte[1024];
  1696. BufferedInputStream bis = null;
  1697. try {
  1698. bis = new BufferedInputStream(Files.newInputStream(fileReturn.toPath()));
  1699. OutputStream os = response.getOutputStream();
  1700. int i = bis.read(buffer);
  1701. while (i != -1) {
  1702. os.write(buffer, 0, i);
  1703. i = bis.read(buffer);
  1704. }
  1705. return "下载成功";
  1706. } catch (Exception e) {
  1707. e.printStackTrace();
  1708. return "下载失败";
  1709. } finally {
  1710. if (bis != null) {
  1711. try {
  1712. bis.close();
  1713. } catch (IOException e) {
  1714. e.printStackTrace();
  1715. }
  1716. }
  1717. }
  1718. }
  1719. @ApiOperation(value = "用户导入结果下载")
  1720. @GetMapping("/download/userImportResult")
  1721. public String userImportResult(HttpServletResponse response, String filePath) {
  1722. File fileReturn = new File(filePath);
  1723. response.reset();
  1724. response.setContentType("application/octet-stream");
  1725. response.setCharacterEncoding("utf-8");
  1726. response.setContentLength((int) fileReturn.length());
  1727. response.setHeader("Content-Disposition", "attachment;filename=userImportResult.xlsx");
  1728. byte[] buffer = new byte[1024];
  1729. FileInputStream fis = null;
  1730. BufferedInputStream bis = null;
  1731. try {
  1732. fis = new FileInputStream(fileReturn);
  1733. bis = new BufferedInputStream(fis);
  1734. OutputStream os = response.getOutputStream();
  1735. int i = bis.read(buffer);
  1736. while (i != -1) {
  1737. os.write(buffer, 0, i);
  1738. i = bis.read(buffer);
  1739. }
  1740. return "下载成功";
  1741. } catch (Exception e) {
  1742. e.printStackTrace();
  1743. return "下载失败";
  1744. } finally {
  1745. if (bis != null) {
  1746. try {
  1747. bis.close();
  1748. } catch (IOException e) {
  1749. e.printStackTrace();
  1750. }
  1751. }
  1752. if (fis != null) {
  1753. try {
  1754. fis.close();
  1755. } catch (IOException e) {
  1756. e.printStackTrace();
  1757. }
  1758. }
  1759. }
  1760. }
  1761. @ApiOperation(value = "SCL90--各个维度评分规则--excel导入")
  1762. @PostMapping("/import/marks/scl901/{flag}")
  1763. public Result Scl90ExcelImport(@PathVariable String flag, MultipartFile file) throws Exception {
  1764. if (file == null) {
  1765. return fail("文件为空");
  1766. }
  1767. if (flag == null) {
  1768. return fail("所属量表标识为空");
  1769. }
  1770. List<ScaleMarksEntity> scaleMarksByFlag = scaleMarksService.getScaleMarksByFlag(flag);
  1771. if (scaleMarksByFlag.size() != 0) {
  1772. return fail("该量表的维度评分信息已入库,请联系管理员");
  1773. }
  1774. //用户信息上传之后生成的用户名密码文件保存路径
  1775. String fileName = file.getOriginalFilename();
  1776. List<List<Object>> marks = ExcelUtil.getBankListByExcelForUserImport(file.getInputStream(), fileName);
  1777. try {
  1778. for (List<Object> mark : marks) {
  1779. System.out.println(mark);
  1780. //因子(维度名称) 最低分(起始分)最高分(结束分) 常模参考值 标准差 结论(该分段症状)
  1781. //因子解释 等级解释(该分段指导语) 建议 是否为总分结论
  1782. //图表信息iconInfo isIconFlag
  1783. ScaleMarksEntity tempUserDB = new ScaleMarksEntity();
  1784. tempUserDB.setName(String.valueOf(mark.get(0)));
  1785. tempUserDB.setScoreStart(String.valueOf(mark.get(1)));
  1786. tempUserDB.setScoreEnd(String.valueOf(mark.get(2)));
  1787. if (("").equals(String.valueOf(mark.get(3)))) {
  1788. tempUserDB.setReference("无");
  1789. } else {
  1790. tempUserDB.setReference(String.valueOf(mark.get(3)));
  1791. }
  1792. if (("无").equals(tempUserDB.getReference())) {
  1793. tempUserDB.setStandardDeviation("无");
  1794. } else {
  1795. tempUserDB.setStandardDeviation(String.valueOf(mark.get(4)));
  1796. }
  1797. tempUserDB.setSymptom(String.valueOf(mark.get(5)));
  1798. tempUserDB.setNameExplain(String.valueOf(mark.get(6)));
  1799. tempUserDB.setImprovementSuggestions(String.valueOf(mark.get(7)));
  1800. tempUserDB.setSuggestion(String.valueOf(mark.get(8)));
  1801. tempUserDB.setIsTotalScoreExplain(String.valueOf(mark.get(9)));
  1802. tempUserDB.setFlag(flag);
  1803. System.out.println(tempUserDB.toString());
  1804. this.scaleMarksService.saveScaleMarks(tempUserDB);
  1805. }
  1806. } catch (Exception exception) {
  1807. exception.printStackTrace();
  1808. return fail("导入失败,请联系管理员");
  1809. }
  1810. return success("入库成功");
  1811. }
  1812. @ApiOperation(value = "新增/更新 认知任务",notes = "id 主键,新增时为空更新必传, description 任务说明,name 认知任务名称,imageUrl 图片路径,imageName 图片名称," +
  1813. "testDescription 测试任务描述,testNum 测试次数,type 类型:0-量表;1-认知任务,pageUrl 分页路径,testExplain 任务解释,status 状态:0-可用;9-不可用,scaleLimit 认知任务权限:private 私密 public 公开" +
  1814. "no 编号,用于排序,mobileDescription 移动端任务说明,mobilePageUrl 移动端前台页面路径,mobileTestDescription 移动端测试任务描述,mobileStatus 移动端任务状态:0-不可用;1-可用," +
  1815. "reportVersion 报告版本:1-老模板报告;2-新模板报告,practice 类型:1-有练习测试;2-无练习测试")
  1816. @PostMapping("/cognize/save")
  1817. @SafetyProcess
  1818. public Result saveCognize(@RequestBody String json) {
  1819. CognitiveTaskEntity taskEntity = JSONObject.parseObject(JSONObject.parseObject(json).getString("data")).toJavaObject(CognitiveTaskEntity.class);
  1820. if(StringUtils.isBlank(taskEntity.getTaskCode())){
  1821. return fail("标识为空");
  1822. }
  1823. if(StringUtils.isBlank(taskEntity.getMobileStatus())){
  1824. taskEntity.setMobileStatus(Constant.MAGIC_NUM_0);
  1825. }
  1826. if(StringUtils.isBlank(taskEntity.getReportVersion())){
  1827. taskEntity.setReportVersion(Constant.MAGIC_NUM_1);
  1828. }
  1829. if(StringUtils.isBlank(taskEntity.getPractice())){
  1830. taskEntity.setPractice(Constant.MAGIC_NUM_2);
  1831. }
  1832. this.cognitiveTaskService.save(taskEntity);
  1833. return success();
  1834. }
  1835. /**
  1836. * 汉字转拼音
  1837. *
  1838. * @param china
  1839. * @return
  1840. */
  1841. public static String getPinyin(String china) {
  1842. HanyuPinyinOutputFormat formart = new HanyuPinyinOutputFormat();
  1843. formart.setCaseType(HanyuPinyinCaseType.LOWERCASE);
  1844. formart.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
  1845. formart.setVCharType(HanyuPinyinVCharType.WITH_V);
  1846. char[] arrays = china.trim().toCharArray();
  1847. StringBuilder result = new StringBuilder();
  1848. try {
  1849. for (int i = 0; i < arrays.length; i++) {
  1850. char ti = arrays[i];
  1851. if (Character.toString(ti).matches("[\\u4e00-\\u9fa5]")) { //匹配是否是中文
  1852. String[] temp = PinyinHelper.toHanyuPinyinStringArray(ti, formart);
  1853. result.append(temp[0]);
  1854. } else {
  1855. result.append(ti);
  1856. }
  1857. }
  1858. } catch (BadHanyuPinyinOutputFormatCombination e) {
  1859. e.printStackTrace();
  1860. }
  1861. return result.toString();
  1862. }
  1863. }