ServerController.java 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982
  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. List<ScaleEntity> scaleEntityList = this.scaleService.getScaleByFlag(flag);
  807. return success(scaleEntityList);
  808. }
  809. /**
  810. * 根据flag查询
  811. *
  812. * @return
  813. */
  814. @SafetyProcess
  815. @ApiOperation(value = "根据flag查询")
  816. @GetMapping("subjectInfo/getSubjectByFlag/{flag}")
  817. public Result getSubjectByFlag(@PathVariable String flag) {
  818. List<SubjectEntity> subjectEntityList = this.subjectService.getSubjectByFlag(flag);
  819. List<SubjectEntityDto2> subjectEntityDto2List = new ArrayList<>();
  820. if(subjectEntityList != null && subjectEntityList.size()>0){
  821. subjectEntityList.forEach(subjectEntity -> {
  822. SubjectEntityDto2 subjectEntityDto2 = new SubjectEntityDto2(subjectEntity);
  823. PromotionInfo infoBySubjectId = this.promotionInfoService.findInfoBySubjectId(subjectEntity.getId());
  824. subjectEntityDto2.setPrice(infoBySubjectId == null ? 0.0:infoBySubjectId.getPrice());
  825. List<ScaleEntity> scaleEntityList = this.scaleService.getScaleByFlag(subjectEntity.getFlag());
  826. subjectEntityDto2.setTitleNum(scaleEntityList.size());
  827. int estimatedTime = scaleEntityList.size() / Constant.TEST_PLAN_STATUS_RUNNING + (scaleEntityList.size() % Constant.TEST_PLAN_STATUS_RUNNING != 0 ? 1 : 0);
  828. subjectEntityDto2.setEstimatedTime(estimatedTime);
  829. subjectEntityDto2List.add(subjectEntityDto2);
  830. });
  831. }
  832. return success(subjectEntityDto2List);
  833. }
  834. /**
  835. * 根据flag查询量表新版本详情
  836. *
  837. * @return
  838. */
  839. @SafetyProcess
  840. @ApiOperation(value = "根据flag查询量表新版本详情")
  841. @GetMapping("subjectInfo/getSubjectByFlagV2/{flag}")
  842. public Result getSubjectByFlagV2(@PathVariable String flag) {
  843. List<SubjectEntity> subjectEntityList = this.subjectService.getSubjectByFlag(flag);
  844. List<SubjectEntityDto2> subjectEntityDto2List = new ArrayList<>();
  845. if(subjectEntityList != null && subjectEntityList.size()>0){
  846. subjectEntityList.forEach(subjectEntity -> {
  847. SubjectEntityDto2 subjectEntityDto2 = new SubjectEntityDto2(subjectEntity);
  848. PromotionInfo infoBySubjectId = this.promotionInfoService.findInfoBySubjectId(subjectEntity.getId());
  849. subjectEntityDto2.setPrice(infoBySubjectId == null ? 0.0:infoBySubjectId.getPrice());
  850. List<ScaleEntity> scaleEntityList = this.scaleService.getScaleByFlag(subjectEntity.getFlag());
  851. subjectEntityDto2.setTitleNum(scaleEntityList.size());
  852. int estimatedTime = scaleEntityList.size() / Constant.TEST_PLAN_STATUS_RUNNING + (scaleEntityList.size() % Constant.TEST_PLAN_STATUS_RUNNING != 0 ? 1 : 0);
  853. subjectEntityDto2.setEstimatedTime(estimatedTime);
  854. subjectEntityDto2List.add(subjectEntityDto2);
  855. });
  856. }
  857. ScaleDetailsEntity scaleDetailsEntity = this.scaleDetailsService.getSubjectDetailsByFlag(flag);
  858. scaleDetailsEntity.setTestNum(subjectEntityList.get(0).getTestNum());
  859. JSONObject jsonObject = new JSONObject();
  860. jsonObject.put("subjectEntityDto2List", subjectEntityDto2List);
  861. jsonObject.put("ScaleDetailsEntity", scaleDetailsEntity);
  862. return success(jsonObject);
  863. }
  864. /**
  865. * 根据taskCode查询认知任务
  866. *
  867. * @return
  868. */
  869. @SafetyProcess
  870. @ApiOperation(value = "根据taskCode查询认知任务")
  871. @GetMapping("subjectInfo/CognitiveByTaskCode/{taskCode}")
  872. public Result CognitiveByTaskCode(@PathVariable String taskCode) {
  873. CognitiveTaskEntity cognitiveTaskEntity = this.cognitiveTaskService.getCognizeListByTaskCode(taskCode);
  874. CognitiveTaskEntityDto dto = new CognitiveTaskEntityDto(cognitiveTaskEntity);
  875. PromotionInfo infoBySubjectId = promotionInfoService.findInfoBySubjectId(cognitiveTaskEntity.getId());
  876. dto.setPrice( infoBySubjectId ==null?0.0:infoBySubjectId.getPrice());
  877. return success(dto);
  878. }
  879. /**
  880. * 获取到记忆量表字符出厂顺序
  881. *
  882. * @return
  883. */
  884. @SafetyProcess
  885. @ApiOperation(value = "获取到记忆量表字符出厂顺序")
  886. @GetMapping("subjectInfo/getRecallChar")
  887. public Result getRecallChar() {
  888. Map map = RandomUtil.recallChar();
  889. return success(map);
  890. }
  891. /**
  892. * 获取到记忆量表字符出厂顺序2
  893. *
  894. * @return
  895. */
  896. @SafetyProcess
  897. @ApiOperation(value = "获取到记忆量表字符出厂顺序2")
  898. @GetMapping("subjectInfo/getRecallCharTwo")
  899. public Result getRecallCharTwo() {
  900. Map map = RandomUtil.recallCharTwo();
  901. return success(map);
  902. }
  903. /**
  904. * 用户测试记录(我的测试)
  905. *
  906. * @return
  907. */
  908. @SafetyProcess
  909. @GetMapping("mineTest/{phone}/{institutionNo}")
  910. @ApiOperation(value = "用户测试记录(我的测试)")
  911. public Result mineTest(int pageNum, int pageSize, @PathVariable String phone, @PathVariable String institutionNo, String searchKey) {
  912. if (pageSize == 0) {
  913. pageSize = 20;
  914. }
  915. if(pageNum == 0){
  916. pageNum = 1;
  917. }
  918. Page<UserRecordsDto> userRecording = userRecordService.getUserRecording(pageNum, pageSize, phone, institutionNo, searchKey);
  919. //获取到列表
  920. List<UserRecordsDto> list = userRecording.getContent();
  921. //公网版先检验是否为支付订单
  922. if (profileValue != null ){
  923. if (Constant.PROFILE_PUBLIC.equals(profileValue) ){
  924. for (UserRecordsDto userRecord : list){
  925. PromotionInfo infoBySubjectId = promotionInfoService.findInfoBySubjectId(userRecord.getSubjectOrCognitiveId());
  926. if (infoBySubjectId != null && infoBySubjectId.getPrice() != 0){
  927. if (orderInfoService.checkPayOrder(userRecord.getId())){
  928. userRecord.setPay("2");
  929. }else {
  930. userRecord.setPay("1");
  931. }
  932. }else {
  933. userRecord.setPay("0");
  934. }
  935. }
  936. }
  937. }
  938. JSONObject jsonObject = new JSONObject();
  939. jsonObject.put("userRecordEntityList",list);
  940. jsonObject.put("allNum", userRecording.getTotalElements());
  941. return success(jsonObject);
  942. }
  943. /**
  944. *当前量表或者认知任务历史记录
  945. *
  946. * @return
  947. */
  948. @SafetyProcess
  949. @GetMapping("history/{pageNum}/{pageSize}/{phone}/{institutionNo}/{flag}")
  950. @ApiOperation(value = "当前量表或者认知任务历史记录")
  951. public Result history(@PathVariable int pageNum,@PathVariable int pageSize, @PathVariable String phone, @PathVariable String institutionNo, @PathVariable String flag) {
  952. try {
  953. Page<UserRecordEntity> userRecordEntities = userRecordService.getHistoryRecord(pageNum,pageSize,phone,institutionNo,flag);
  954. //公网版先检验是否为支付订单
  955. if (profileValue != null ){
  956. if (Constant.PROFILE_PUBLIC.equals(profileValue) ){
  957. if (CollectionUtils.isNotEmpty(userRecordEntities.getContent())){
  958. userRecordEntities.getContent().forEach(userRecord->{
  959. PromotionInfo infoBySubjectId = promotionInfoService.findInfoByFlag(userRecord.getFlag());
  960. if (infoBySubjectId != null && infoBySubjectId.getPrice() != 0){
  961. if (orderInfoService.checkPayOrder(userRecord.getId())){
  962. userRecord.setPay("2");
  963. }else {
  964. userRecord.setPay("1");
  965. }
  966. }else {
  967. userRecord.setPay("0");
  968. }
  969. });
  970. }
  971. }
  972. }
  973. return success(userRecordEntities);
  974. }catch (Exception e){
  975. e.printStackTrace();
  976. return fail("操作异常");
  977. }
  978. }
  979. /**
  980. *当前量表或者认知任务历史记录
  981. *
  982. * @return
  983. */
  984. @SafetyProcess
  985. @GetMapping("countHistory/{phone}/{institutionNo}/{flag}")
  986. @ApiOperation(value = "历史测评统计")
  987. public Result countHistory(@PathVariable String phone, @PathVariable String institutionNo, @PathVariable String flag) {
  988. try {
  989. int count = userRecordService.countHistoryRecord(phone,institutionNo,flag);
  990. return success(count);
  991. }catch (Exception e){
  992. e.printStackTrace();
  993. return fail("操作异常");
  994. }
  995. }
  996. /**
  997. * 用户测试记录(我的测试)
  998. *
  999. * @return
  1000. */
  1001. @SafetyProcess
  1002. @GetMapping("mineTest2/{phone}/{institutionNo}")
  1003. @ApiOperation(value = "用户测试记录(我的测试)")
  1004. public Result mineTest2(int pageNum, int pageSize, @PathVariable String phone, @PathVariable String institutionNo, String searchKey) {
  1005. Page<UserRecordEntity> userRecording = userRecordService.getUserRecording2(pageNum, pageSize, phone, institutionNo, searchKey);
  1006. //获取到列表
  1007. List<UserRecordEntity> list = userRecording.getContent();
  1008. //获取到所有收费信息
  1009. List<PromotionInfo> infos = promotionInfoService.findAll();
  1010. //公网版先检验是否为支付订单
  1011. if (profileValue != null ){
  1012. if (Constant.PROFILE_PUBLIC.equals(profileValue) ){
  1013. for (UserRecordEntity userRecord : list){
  1014. for (PromotionInfo info:infos){
  1015. if (!userRecord.getFlag().equals(info.getFlag())){
  1016. continue;
  1017. }
  1018. if ( info.getPrice() != 0){
  1019. if (orderInfoService.checkPayOrder(userRecord.getId())){
  1020. userRecord.setPay("2");
  1021. }else {
  1022. userRecord.setPay("1");
  1023. }
  1024. }else {
  1025. userRecord.setPay("0");
  1026. }
  1027. break;
  1028. }
  1029. // PromotionInfo infoBySubjectId = promotionInfoService.findInfoByFlag(userRecord.getFlag());
  1030. // if (infoBySubjectId != null && infoBySubjectId.getPrice() != 0){
  1031. // if (orderInfoService.checkPayOrder(userRecord.getId())){
  1032. // userRecord.setPay("2");
  1033. // }else {
  1034. // userRecord.setPay("1");
  1035. // }
  1036. // }else {
  1037. // userRecord.setPay("0");
  1038. // }
  1039. }
  1040. }
  1041. }
  1042. JSONObject jsonObject = new JSONObject();
  1043. jsonObject.put("userRecordEntityList",list);
  1044. jsonObject.put("allNum", userRecording.getTotalElements());
  1045. return success(jsonObject);
  1046. }
  1047. /**
  1048. * 用户查询枪林弹雨
  1049. *
  1050. * @return
  1051. */
  1052. @SafetyProcess
  1053. @GetMapping("GUNSBULLETS/{userId}")
  1054. @ApiOperation(value = "用户查询枪林弹雨记录")
  1055. public Result GUNSBULLETS(@PathVariable String userId) {
  1056. UserEntity one = this.userService.getOne(userId);
  1057. List<UserRecordEntity> gunsbullets = this.userRecordService.getGUNSBULLETS(one.getPhone(), one.getInstitutionNo());
  1058. return success(gunsbullets);
  1059. }
  1060. /**
  1061. * 根据id查询测试详细信息
  1062. *
  1063. * @return
  1064. */
  1065. @SafetyProcess
  1066. @GetMapping("/getRecordById")
  1067. @ApiOperation(value = "根据id查询测试详细信息")
  1068. public Result getRecordById(String id) {
  1069. //公网版先检验是否为支付订单
  1070. if (profileValue != null ){
  1071. if (Constant.PROFILE_PUBLIC.equals(profileValue) ){
  1072. //认知任务暂时不做支付处理
  1073. UserRecordEntity userRecordEntity = userRecordService.getUserRecordById(id);
  1074. if (userRecordEntity.getType().equals("0")){
  1075. SubjectEntity subjectEntity = this.subjectService.getSubjectEntityByFlag(userRecordEntity.getFlag());
  1076. PromotionInfo infoBySubjectId = promotionInfoService.findInfoBySubjectId(subjectEntity.getId());
  1077. if (infoBySubjectId != null && infoBySubjectId.getPrice() != 0){
  1078. if (userRecordEntity != null && Constant.DEFAULT_VALUE_ZERO.equals(userRecordEntity.getType())){
  1079. if (!orderInfoService.checkPayOrder(id)){
  1080. return fail("未支付");
  1081. }
  1082. }
  1083. }
  1084. }
  1085. }
  1086. }
  1087. //获取测试记录信息
  1088. UserRecordEntity userRecordEntity = this.userRecordService.getUserRecordById(id);
  1089. if (userRecordEntity == null){
  1090. return fail("参数错误");
  1091. }
  1092. //判断是否达到最大测试次数
  1093. InstitutionEntity entity = institutionService.findByInstitutionNo(userRecordEntity.getInstitutionNo());
  1094. if (Constant.DEFAULT_VALUE_ONE.equals(entity.getIsTestNum().toString())){
  1095. //获取该机构下测试数据
  1096. int count = userRecordService.finAllByInstitutionNo(userRecordEntity.getInstitutionNo());
  1097. if (count> entity.getTestNum()){
  1098. if (entity.getTestNum()==0){
  1099. return fail("测试次数已达上限,请联系机构管理员");
  1100. }
  1101. //获取到最后一条测试记录
  1102. String last = userRecordService.findByTestNum(entity.getInstitutionNo(),entity.getTestNum()-1);
  1103. if (last != null){
  1104. int result = DateUtil.compare(DateUtil.parse(userRecordEntity.getTestDate(), DatePattern.CHINESE_DATE_TIME_PATTERN),DateUtil.parse(last,DatePattern.CHINESE_DATE_TIME_PATTERN));
  1105. if (result > 0){
  1106. return fail("测试次数已达上限,请联系机构管理员");
  1107. }
  1108. }
  1109. }
  1110. }
  1111. //获取测试人员信息
  1112. UserEntity userInfo = this.userService.findPhoneAndInstitutionNoAndRoleType(userRecordEntity.getPhone(), userRecordEntity.getInstitutionNo(),UserRole.COMMON.getType());
  1113. UserFileEntity userFileEntity = this.userFileService.findByUserId(userInfo.getId());
  1114. if (userFileEntity != null){
  1115. userInfo.setAvatarUrl(userFileEntity.getPath());
  1116. }
  1117. String flag = userRecordEntity.getFlag();
  1118. String type = userRecordEntity.getType();
  1119. List<SubjectEntity> subjectByFlag;
  1120. JSONObject result = new JSONObject();
  1121. if ("0".equals(type)) {
  1122. subjectByFlag = subjectService.getSubjectByFlag(flag);
  1123. result.put("subject", subjectByFlag.get(0));
  1124. }else if ("1".equals(type)) {
  1125. CognitiveTaskEntity cognitiveTask = this.cognitiveTaskService.getCognizeListByTaskCode(flag);
  1126. result.put("cognitiveTask", cognitiveTask);
  1127. }
  1128. result.put("userRecordEntity", userRecordEntity);
  1129. result.put("userInfo", userInfo);
  1130. return success(result);
  1131. }
  1132. /**
  1133. * 根据id查询测试详细信息
  1134. *
  1135. * @return
  1136. */
  1137. @SafetyProcess
  1138. @GetMapping("/getWeiboRecordById")
  1139. @ApiOperation(value = "根据id查询测试详细信息")
  1140. public Result getWeiboRecordById(String id) {
  1141. try {
  1142. //获取测试记录信息
  1143. UserRecordEntity userRecordEntity = this.userRecordService.getUserRecordById(id);
  1144. if (userRecordEntity == null){
  1145. return fail("参数错误");
  1146. }
  1147. JSONObject result = new JSONObject();
  1148. result.put("userRecordEntity", userRecordEntity);
  1149. return success(result);
  1150. }catch (Exception e){
  1151. log.error(e.getMessage());
  1152. return fail("操作失败");
  1153. }
  1154. }
  1155. //@SafetyProcess
  1156. @PostMapping("/importSubjectByJson")
  1157. @ApiOperation(value = "第一批导入json格式量表")
  1158. public Result importSubjectByJson(@RequestBody JSONObject jsonObject) {
  1159. System.out.println("jsonobject:" + jsonObject);
  1160. //量表标志自动生成唯一值,yyyyMMddHHmmss
  1161. String flag = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
  1162. JSONObject result = jsonObject.getJSONObject("result");
  1163. //根据量表中文名查询,判断该量表是否存在
  1164. SubjectEntity subject = this.subjectService.getSubjectByname(result.getString("title"));
  1165. if (subject != null) {
  1166. return fail("该量表已存在!");
  1167. }
  1168. //创建量表实体类,并传入数据
  1169. SubjectEntity subjectEntity = new SubjectEntity();
  1170. subjectEntity.setName(result.getString("title"));
  1171. subjectEntity.setFlag(flag);
  1172. //类型默认量表
  1173. subjectEntity.setType("0");
  1174. //新增量表默认为热门测试
  1175. subjectEntity.setIsHot("1");
  1176. //新增量表默认为最新测试
  1177. subjectEntity.setIsNew(1);
  1178. subjectEntity.setDescription(result.getString("desc"));
  1179. subjectEntity.setUploader("雷煜");
  1180. //subjectEntity.setEName(eName);
  1181. subjectEntity.setStatus(0);
  1182. subjectEntity.setFileName("null");
  1183. //计分原则
  1184. String scoringPrinciple = "";
  1185. //获取量表题目信息
  1186. JSONArray items = result.getJSONArray("items");
  1187. for (int i = 0; i < items.size(); i++) {
  1188. JSONObject item = items.getJSONObject(i);
  1189. ScaleEntity scaleEntity = new ScaleEntity();
  1190. scaleEntity.setQuestionNo(item.getString("index"));
  1191. scaleEntity.setSerialNo(item.getString("index"));
  1192. scaleEntity.setAnswer(item.getString("name"));
  1193. //答案选项
  1194. String checkItems = "";
  1195. scaleEntity.setQuestionType(Constant.MAGIC_NUM_0);
  1196. scaleEntity.setWeight("");
  1197. // 量表模板不提供分值
  1198. scaleEntity.setScore("");
  1199. scaleEntity.setFlag(flag);
  1200. scaleEntity.setScoreDirection("1");
  1201. //获取题目选项信息
  1202. JSONArray options = item.getJSONArray("options");
  1203. for (int y = 0; y < options.size(); y++) {
  1204. JSONObject option = options.getJSONObject(y);
  1205. AnswerEntity answerEntity = new AnswerEntity();
  1206. answerEntity.setFlag(flag);
  1207. answerEntity.setQuestionNo(item.getString("index"));
  1208. answerEntity.setName(option.getString("name"));
  1209. answerEntity.setOptions(option.getString("select"));
  1210. answerEntity.setQuestionType("0");
  1211. answerEntity.setScore(option.getString("score"));
  1212. answerEntity.setScoreDirection("1");
  1213. this.answerService.saveAnswer(answerEntity);
  1214. if (y + 1 == options.size()) {
  1215. checkItems = checkItems + option.getString("name");
  1216. } else {
  1217. checkItems = checkItems + option.getString("name") + ";";
  1218. }
  1219. }
  1220. scaleEntity.setCheckItems(checkItems);
  1221. this.scaleService.saveScale(scaleEntity);
  1222. System.out.println(scaleEntity.toString());
  1223. }
  1224. JSONArray scores = result.getJSONArray("scores");
  1225. for (int i = 0; i < scores.size(); i++) {
  1226. JSONObject score = scores.getJSONObject(i);
  1227. int scoreStart = score.getInteger("scoreStart");
  1228. int scoreEnd = score.getInteger("scoreEnd");
  1229. String desc = score.getString("desc");
  1230. String improvementSuggestions = score.getString("improvementSuggestions");
  1231. scoringPrinciple = scoringPrinciple + scoreStart + "-" + scoreEnd + ";" + desc;
  1232. if (improvementSuggestions != null) {
  1233. scoringPrinciple = scoringPrinciple + ";" + improvementSuggestions;
  1234. }
  1235. ScaleMarksEntity scaleMarksEntity = new ScaleMarksEntity();
  1236. scaleMarksEntity.setFlag(flag);
  1237. scaleMarksEntity.setImprovementSuggestions(improvementSuggestions);
  1238. scaleMarksEntity.setSymptom(score.getString("desc"));
  1239. scaleMarksEntity.setScoreEnd(String.valueOf(scoreEnd));
  1240. scaleMarksEntity.setScoreStart(String.valueOf(scoreStart));
  1241. //TODO 设置评分规则表默认值
  1242. scaleMarksEntity.setNameExplain("无");
  1243. scaleMarksEntity.setReference("无");
  1244. scaleMarksEntity.setSuggestion("无");
  1245. scaleMarksEntity.setIsTotalScoreExplain("否");
  1246. this.scaleMarksService.saveScaleMarks(scaleMarksEntity);
  1247. }
  1248. subjectEntity.setScoringPrinciple(scoringPrinciple);
  1249. this.subjectService.save(subjectEntity);
  1250. System.out.println(subjectEntity);
  1251. return success();
  1252. }
  1253. @PostMapping("/importSubjectByJsonb")
  1254. @ApiOperation(value = "第二批导入json格式量表")
  1255. public Result importSubjectByJsonb(@RequestBody JSONObject result) {
  1256. System.out.println("jsonobject:" + result);
  1257. //量表标志自动生成唯一值,yyyyMMddHHmmss
  1258. String flag = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
  1259. //根据量表中文名查询,判断该量表是否存在
  1260. SubjectEntity subject = this.subjectService.getSubjectByname(result.getString("title"));
  1261. if (subject != null) {
  1262. return fail("该量表已存在!");
  1263. }
  1264. //创建量表实体类,并传入数据
  1265. SubjectEntity subjectEntity = new SubjectEntity();
  1266. subjectEntity.setName(result.getString("title"));
  1267. subjectEntity.setFlag(flag);
  1268. //类型默认量表
  1269. subjectEntity.setType("0");
  1270. //新增量表默认为热门测试
  1271. subjectEntity.setIsHot("1");
  1272. //新增量表默认为最新测试
  1273. subjectEntity.setIsNew(1);
  1274. subjectEntity.setDescription(result.getString("instruction"));
  1275. subjectEntity.setUploader("雷煜");
  1276. //subjectEntity.setEName(eName);
  1277. subjectEntity.setStatus(0);
  1278. subjectEntity.setFileName("null");
  1279. subjectEntity.setScaleLimit("public");
  1280. //计分原则
  1281. String scoringPrinciple = "";
  1282. //获取量表题目信息
  1283. JSONArray items = result.getJSONArray("items");
  1284. for (int i = 0; i < items.size(); i++) {
  1285. JSONObject item = items.getJSONObject(i);
  1286. ScaleEntity scaleEntity = new ScaleEntity();
  1287. scaleEntity.setQuestionNo(item.getString("index"));
  1288. scaleEntity.setSerialNo(item.getString("index"));
  1289. scaleEntity.setAnswer(item.getString("name"));
  1290. //答案选项
  1291. String checkItems = "";
  1292. scaleEntity.setQuestionType(Constant.MAGIC_NUM_0);
  1293. scaleEntity.setWeight("");
  1294. // 量表模板不提供分值
  1295. scaleEntity.setScore("");
  1296. scaleEntity.setFlag(flag);
  1297. scaleEntity.setScoreDirection("1");
  1298. //获取题目选项信息
  1299. JSONArray options = item.getJSONArray("options");
  1300. for (int y = 0; y < options.size(); y++) {
  1301. JSONObject option = options.getJSONObject(y);
  1302. AnswerEntity answerEntity = new AnswerEntity();
  1303. answerEntity.setFlag(flag);
  1304. answerEntity.setQuestionNo(item.getString("index"));
  1305. answerEntity.setName(option.getString("select"));
  1306. answerEntity.setOptions("");
  1307. answerEntity.setQuestionType("0");
  1308. answerEntity.setScore(option.getString("score"));
  1309. answerEntity.setScoreDirection("1");
  1310. this.answerService.saveAnswer(answerEntity);
  1311. if (y + 1 == options.size()) {
  1312. checkItems = checkItems + option.getString("select");
  1313. } else {
  1314. checkItems = checkItems + option.getString("select") + ";";
  1315. }
  1316. }
  1317. scaleEntity.setCheckItems(checkItems);
  1318. this.scaleService.saveScale(scaleEntity);
  1319. System.out.println(scaleEntity.toString());
  1320. }
  1321. JSONArray scores = result.getJSONArray("scores");
  1322. for (int i = 0; i < scores.size(); i++) {
  1323. JSONObject score = scores.getJSONObject(i);
  1324. int scoreStart = score.getInteger("scoreStart");
  1325. int scoreEnd = score.getInteger("scoreEnd");
  1326. String desc = score.getString("desc");
  1327. scoringPrinciple = scoringPrinciple + scoreStart + "-" + scoreEnd + ";" + desc;
  1328. ScaleMarksEntity scaleMarksEntity = new ScaleMarksEntity();
  1329. scaleMarksEntity.setFlag(flag);
  1330. scaleMarksEntity.setImprovementSuggestions("");
  1331. scaleMarksEntity.setSymptom(score.getString("desc"));
  1332. scaleMarksEntity.setScoreEnd(String.valueOf(scoreEnd));
  1333. scaleMarksEntity.setScoreStart(String.valueOf(scoreStart));
  1334. //TODO 设置评分规则表默认值
  1335. scaleMarksEntity.setNameExplain("无");
  1336. scaleMarksEntity.setReference("无");
  1337. scaleMarksEntity.setSuggestion("无");
  1338. scaleMarksEntity.setIsTotalScoreExplain("否");
  1339. this.scaleMarksService.saveScaleMarks(scaleMarksEntity);
  1340. }
  1341. subjectEntity.setScoringPrinciple(scoringPrinciple);
  1342. this.subjectService.save(subjectEntity);
  1343. System.out.println(subjectEntity);
  1344. return success();
  1345. }
  1346. /**
  1347. * 删除字段多余字符
  1348. *
  1349. * @return
  1350. */
  1351. //@SafetyProcess
  1352. //@GetMapping("deleteChar")
  1353. //@ApiOperation(value = "删除字段多余字符")
  1354. public Result deleteChar() {
  1355. List<SubjectEntity> subjectEntities = this.subjectService.findAll("0");
  1356. for (SubjectEntity subjectEntity : subjectEntities) {
  1357. if (subjectEntity.getScoringPrinciple() != null) {
  1358. String scoring = subjectEntity.getScoringPrinciple().replaceAll("\\<[^\\<^\\>]*\\>", "");
  1359. scoring = scoring.replace(";null", "");
  1360. this.subjectService.updateById(subjectEntity.getId(), scoring);
  1361. }
  1362. }
  1363. List<ScaleMarksEntity> scaleMarksEntities = this.scaleMarksService.findAll();
  1364. for (ScaleMarksEntity scaleMarksEntity : scaleMarksEntities) {
  1365. String symptom = null;
  1366. String improvement = null;
  1367. if (scaleMarksEntity.getSymptom() != null) {
  1368. symptom = scaleMarksEntity.getSymptom().replaceAll("\\<[^\\<^\\>]*\\>", "");
  1369. }
  1370. if (scaleMarksEntity.getImprovementSuggestions() != null) {
  1371. improvement = scaleMarksEntity.getImprovementSuggestions().replaceAll("\\<[^\\<^\\>]*\\>", "");
  1372. }
  1373. this.scaleMarksService.updateById(scaleMarksEntity.getId(), symptom, improvement);
  1374. }
  1375. return success();
  1376. }
  1377. /**
  1378. * 处理用户测试结果数据格式
  1379. *
  1380. * @return
  1381. */
  1382. //@SafetyProcess
  1383. @GetMapping("userRecord")
  1384. @ApiOperation(value = "处理用户测试结果数据格式")
  1385. public Result userRecord() {
  1386. List<UserRecordEntity> userRecordEntities = this.userRecordService.findAll1();
  1387. for (UserRecordEntity userRecordEntity : userRecordEntities) {
  1388. if (!userRecordEntity.getFlag().contains("YATAI") || !userRecordEntity.getFlag().equals("ANTFISH")) {
  1389. //计算结果
  1390. JSONArray dbJsonList = JSONArray.parseArray(userRecordEntity.getTestResult());
  1391. JSONObject dbJson = dbJsonList.getJSONObject(0);
  1392. JSONArray tableContext = dbJson.getJSONArray("tableContext");
  1393. String testResults = new String();
  1394. for (int i = 0; i < tableContext.size(); i++) {
  1395. JSONObject jsonObject = tableContext.getJSONObject(i);
  1396. if (i == tableContext.size() - 1) {
  1397. testResults += jsonObject.getString("name") + ":" + jsonObject.getJSONArray("value").getString(0);
  1398. } else {
  1399. testResults += jsonObject.getString("name") + ":" + jsonObject.getJSONArray("value").getString(0) + ";";
  1400. }
  1401. }
  1402. }
  1403. }
  1404. return success();
  1405. }
  1406. /* V1版本,暂时保留
  1407. @ApiOperation(value = "用户导入")
  1408. @Transactional(rollbackFor = Exception.class)
  1409. @PostMapping("userImport")
  1410. public Result userImport(String institutionNo, MultipartFile file, HttpServletResponse response) throws Exception {
  1411. if (file == null) {
  1412. return fail("文件为空");
  1413. }
  1414. if (institutionNo == null) {
  1415. return fail("机构编号为空");
  1416. }
  1417. //String message = "提交成功";
  1418. String filePath = "";//用户信息上传之后生成的用户名密码文件保存路径
  1419. String fileName = file.getOriginalFilename();
  1420. List<List<Object>> datas = ExcelUtil.getBankListByExcelForUserImport(file.getInputStream(), fileName);
  1421. if(datas.size() <= 0){
  1422. return fail("内容为空");
  1423. }
  1424. //插入数据库信息
  1425. List<UserEntity> userListDB = new ArrayList<>();
  1426. //生成导入后用户信息
  1427. List<UserEntity> userLists = new ArrayList<>();
  1428. StringBuilder result = new StringBuilder();
  1429. //result.append("账号:");
  1430. //判断是否有已经存在数据库的
  1431. boolean isExist = false;
  1432. //UserEntity tempUserDB;
  1433. String defaultGroupId = null;
  1434. try {
  1435. int y = 0;
  1436. for (int i = 0; i < datas.size(); i++) {
  1437. List<Object> users = datas.get(i);
  1438. if (users.get(0) == null || users.get(0) == "" || users.get(1) == null || users.get(1) == "" || users.get(2) == null || users.get(2) == ""
  1439. || users.get(3) == null || users.get(3) == "" || users.get(4) == null || users.get(4) == "" || users.get(5) == null || users.get(5) == "") {
  1440. y = i + 1;
  1441. result.append("第" + y +"条数据信息不完整").append("\r\n");
  1442. isExist = true;
  1443. continue;
  1444. }
  1445. //北京师范大学亚太实验学校, 陈亚浩2, 男, 2001-10-01, 学生, , 六年级一班, null, null
  1446. //插入数据库的信息
  1447. UserEntity tempUserDB = new UserEntity();
  1448. //导入成功用户信息
  1449. UserEntity userEntity = new UserEntity();
  1450. tempUserDB.setInstitutionName(users.get(0).toString());
  1451. tempUserDB.setPetName(users.get(1).toString());
  1452. userEntity.setInstitutionName(users.get(0).toString());
  1453. userEntity.setPetName(users.get(1).toString());
  1454. userEntity.setGender(users.get(2).toString());
  1455. if ("男".equals(users.get(2).toString())) {
  1456. tempUserDB.setGender("0");
  1457. } else {
  1458. tempUserDB.setGender("1");
  1459. }
  1460. tempUserDB.setBirthday(users.get(3).toString());
  1461. tempUserDB.setProfession(users.get(4).toString());
  1462. tempUserDB.setAdditionInfo(users.get(5).toString());
  1463. userEntity.setBirthday(users.get(3).toString());
  1464. userEntity.setProfession(users.get(4).toString());
  1465. userEntity.setAdditionInfo(users.get(5).toString());
  1466. int repeatNum = userRepeatNameNumService.testOrNotNamePinyin(institutionNo, getPinyin(users.get(1).toString()));
  1467. if (users.size() > 6) {
  1468. if (null == users.get(6) || users.get(6).equals("")) {
  1469. tempUserDB.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
  1470. userEntity.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
  1471. } else {
  1472. tempUserDB.setPhone(users.get(6).toString());
  1473. userEntity.setPhone(users.get(6).toString());
  1474. }
  1475. } else {
  1476. tempUserDB.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
  1477. userEntity.setPhone(repeatNum == 0 ? getPinyin(users.get(1).toString()) : getPinyin(users.get(1).toString()) + repeatNum);
  1478. }
  1479. if (users.size() > 7) {
  1480. if (null == users.get(7) || users.get(7).equals("")) {
  1481. tempUserDB.setPassword(DigestUtils.md5DigestAsHex(Constant.DEFAULT_PASSWORD.getBytes(StandardCharsets.UTF_8)));
  1482. userEntity.setPassword(Constant.DEFAULT_PASSWORD);
  1483. } else {
  1484. tempUserDB.setPassword(DigestUtils.md5DigestAsHex(users.get(7).toString().getBytes(StandardCharsets.UTF_8)));
  1485. userEntity.setPassword(users.get(7).toString());
  1486. }
  1487. } else {
  1488. tempUserDB.setPassword(DigestUtils.md5DigestAsHex(Constant.DEFAULT_PASSWORD.getBytes(StandardCharsets.UTF_8)));
  1489. userEntity.setPassword(Constant.DEFAULT_PASSWORD);
  1490. }
  1491. // tempUserDB.setPhone(getPinyin(users.get(1).toString()));
  1492. tempUserDB.setInstitutionNo(institutionNo);
  1493. tempUserDB.setUserStatus("2");
  1494. userEntity.setInstitutionNo(institutionNo);
  1495. userEntity.setUserStatus("2");
  1496. //设置组id,未分组时组id为0
  1497. if (defaultGroupId == null) {
  1498. GroupEntity groupByInstitutionNoAndName = this.groupInfoService.findGroupByInstitutionNoAndName(tempUserDB.getInstitutionNo(), Constant.DEFAULT_GROUP_NAME);
  1499. if (groupByInstitutionNoAndName == null) {
  1500. GroupEntity groupEntity = new GroupEntity();
  1501. groupEntity.setGroupName(Constant.DEFAULT_GROUP_NAME);
  1502. groupEntity.setInstitutionNo(tempUserDB.getInstitutionNo());
  1503. groupEntity = this.groupInfoService.addGroup(groupEntity);
  1504. //创建权限
  1505. List<InstitutionAuthEntity> institutionAuthEntityList = this.institutionAuthService.getByInstitutionNo(tempUserDB.getInstitutionNo());
  1506. for (int mi = 0; mi < institutionAuthEntityList.size(); mi++) {
  1507. InstitutionAuthEntity institutionAuthEntity = new InstitutionAuthEntity();
  1508. GroupAuthEntity groupAuthEntity = new GroupAuthEntity();
  1509. groupAuthEntity.setBId(institutionAuthEntity.getBId());
  1510. groupAuthEntity.setGroupId(groupEntity.getId());
  1511. groupAuthEntity.setType(institutionAuthEntity.getType());
  1512. this.groupAuthService.addGroupAuth(groupAuthEntity);
  1513. }
  1514. defaultGroupId = groupEntity.getId();
  1515. } else {
  1516. defaultGroupId = groupByInstitutionNoAndName.getId();
  1517. }
  1518. }
  1519. tempUserDB.setGId(defaultGroupId);
  1520. tempUserDB.setModelPhone("0");
  1521. tempUserDB.setRoleType(UserRole.COMMON.getType());
  1522. userEntity.setGId(defaultGroupId);
  1523. userEntity.setModelPhone("0");
  1524. userEntity.setRoleType(UserRole.COMMON.getType());
  1525. //查看当前用户是否已经在数据库存在
  1526. UserEntity phoneAndInstitutionNo = userService.findPhoneAndInstitutionNo(tempUserDB.getPhone(), institutionNo);
  1527. if (phoneAndInstitutionNo != null) {
  1528. y = i + 1;
  1529. result.append("第" + y +"条数据账号" + phoneAndInstitutionNo.getPhone() + "已存在").append("\r\n");
  1530. isExist = true;
  1531. continue;
  1532. }
  1533. this.userService.save(tempUserDB);
  1534. userListDB.add(tempUserDB);
  1535. userLists.add(userEntity);
  1536. }
  1537. if (OSUtil.isLinux()) {
  1538. filePath = "./userImport/" + institutionNo + "/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "/";
  1539. } else {
  1540. filePath = "./userImport/" + institutionNo + "/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "/";
  1541. }
  1542. ExcelUtil.createExcelFileForPublic(UserEntity.class, userLists, null, new ExcelClass().userExportExcel(), fileName, filePath);
  1543. if (isExist) {
  1544. result.append(",跳过该信息。(请检查该信息)");
  1545. return success(filePath + fileName, result.toString());
  1546. } else {
  1547. return success(filePath + fileName, "批量导入成功");
  1548. }
  1549. } catch (Exception exception) {
  1550. exception.printStackTrace();
  1551. return fail("导入失败,请联系管理员");
  1552. }
  1553. }*/
  1554. @ApiOperation(value = "用户导入")
  1555. @Transactional(rollbackFor = Exception.class)
  1556. @PostMapping("userImport")
  1557. public Result userImport(String institutionNo, MultipartFile file, HttpServletResponse response) throws Exception {
  1558. if (file == null) {
  1559. return fail("文件为空");
  1560. }
  1561. if (institutionNo == null) {
  1562. return fail("机构编号为空");
  1563. }
  1564. String fileName = file.getOriginalFilename();
  1565. List<List<Object>> datas = ExcelUtil.getBankListByExcelForUserImport(file.getInputStream(), fileName);
  1566. if(datas.size() <= 0){
  1567. return fail("内容为空");
  1568. }
  1569. StringBuilder result = new StringBuilder();
  1570. //判断是否有已经存在数据库的
  1571. boolean isExist = false;
  1572. String defaultGroupId = null;
  1573. try {
  1574. int y = 0;
  1575. for (int i = 0; i < datas.size(); i++) {
  1576. List<Object> users = datas.get(i);
  1577. if (users.get(0) == null || users.get(0) == "" || users.get(1) == null || users.get(1) == "" || users.get(2) == null || users.get(2) == "") {
  1578. y = i + 1;
  1579. result.append("第" + y +"条数据信息不完整").append("\r\n");
  1580. isExist = true;
  1581. continue;
  1582. }
  1583. String petName = users.get(0).toString();
  1584. if (petName.length() > 18 || petName.contains(" ")){
  1585. y = i + 1;
  1586. result.append("第" + y +"条数据姓名长度大于18位或有空格").append("\r\n");
  1587. isExist = true;
  1588. continue;
  1589. }
  1590. String phone = users.get(1).toString();
  1591. if (phone.length() > 18 || phone.length() < 3 || phone.contains(" ")){
  1592. y = i + 1;
  1593. result.append("第" + y +"条数据账号长度未在3~18位之间或有空格").append("\r\n");
  1594. isExist = true;
  1595. continue;
  1596. }
  1597. String password = users.get(2).toString();
  1598. if (password.length() < 6 || password.length() > 18 || password.contains(" ")){
  1599. y = i + 1;
  1600. result.append("第" + y +"条数据密码长度未在6~18位之间或有空格").append("\r\n");
  1601. isExist = true;
  1602. continue;
  1603. }
  1604. //插入数据库的信息
  1605. UserEntity tempUserDB = new UserEntity();
  1606. //设置组id,未分组时组id为0
  1607. if (defaultGroupId == null) {
  1608. GroupEntity groupByInstitutionNoAndName = this.groupInfoService.findGroupByInstitutionNoAndName(institutionNo, Constant.DEFAULT_GROUP_NAME);
  1609. if (groupByInstitutionNoAndName == null) {
  1610. GroupEntity groupEntity = new GroupEntity();
  1611. groupEntity.setGroupName(Constant.DEFAULT_GROUP_NAME);
  1612. groupEntity.setInstitutionNo(institutionNo);
  1613. groupEntity = this.groupInfoService.addGroup(groupEntity);
  1614. //创建权限
  1615. List<InstitutionAuthEntity> institutionAuthEntityList = this.institutionAuthService.getByInstitutionNo(institutionNo);
  1616. for (int mi = 0; mi < institutionAuthEntityList.size(); mi++) {
  1617. InstitutionAuthEntity institutionAuthEntity = new InstitutionAuthEntity();
  1618. GroupAuthEntity groupAuthEntity = new GroupAuthEntity();
  1619. groupAuthEntity.setBId(institutionAuthEntity.getBId());
  1620. groupAuthEntity.setGroupId(groupEntity.getId());
  1621. groupAuthEntity.setType(institutionAuthEntity.getType());
  1622. this.groupAuthService.addGroupAuth(groupAuthEntity);
  1623. }
  1624. defaultGroupId = groupEntity.getId();
  1625. } else {
  1626. defaultGroupId = groupByInstitutionNoAndName.getId();
  1627. }
  1628. }
  1629. InstitutionEntity institutionEntity = this.institutionService.findByInstitutionNo(institutionNo);
  1630. /*
  1631. `gender` varchar(2) NOT NULL COMMENT '性别(0-男;1-女)',
  1632. `birthday` varchar(15) NOT NULL COMMENT '出生日期',
  1633. `profession` varchar(50) DEFAULT NULL COMMENT '职业',
  1634. `addition_info` varchar(500) DEFAULT NULL COMMENT '附加信息',
  1635. `model_phone` varchar(11) DEFAULT '0' COMMENT '用户手机号:0->用户不填手机号', 可为空
  1636. */
  1637. tempUserDB.setInstitutionName(institutionEntity.getInstitutionName());
  1638. //姓名、账号、密码格式未效验
  1639. tempUserDB.setPetName(users.get(0).toString());
  1640. tempUserDB.setPhone(users.get(1).toString());
  1641. tempUserDB.setPassword(DigestUtils.md5DigestAsHex(users.get(2).toString().getBytes(StandardCharsets.UTF_8)));
  1642. tempUserDB.setGender(Constant.DEFAULT_VALUE_ZERO);
  1643. tempUserDB.setBirthday("2001-01-01");
  1644. tempUserDB.setInstitutionNo(institutionNo);
  1645. tempUserDB.setUserStatus(UserStatus.PERFECT.getType());
  1646. tempUserDB.setGId(defaultGroupId);
  1647. tempUserDB.setModelPhone(Constant.DEFAULT_VALUE_ZERO);
  1648. tempUserDB.setRoleType(UserRole.COMMON.getType());
  1649. //查看当前用户是否已经在数据库存在
  1650. UserEntity phoneAndInstitutionNo = userService.findPhoneAndInstitutionNoAndRoleType(tempUserDB.getPhone(), institutionNo,Constant.DEFAULT_VALUE_ONE);
  1651. if (phoneAndInstitutionNo != null) {
  1652. y = i + 1;
  1653. result.append("第" + y +"条数据账号" + phoneAndInstitutionNo.getPhone() + "已存在").append("\r\n");
  1654. isExist = true;
  1655. continue;
  1656. }
  1657. this.userService.save(tempUserDB);
  1658. }
  1659. if (isExist) {
  1660. result.append(",跳过该信息。(请检查该信息)");
  1661. return success("", result.toString());
  1662. } else {
  1663. return success("", "批量导入成功");
  1664. }
  1665. } catch (Exception exception) {
  1666. exception.printStackTrace();
  1667. return fail("导入失败,请联系管理员");
  1668. }
  1669. }
  1670. @PostMapping("/saveCognitiveTask")
  1671. @ApiOperation(value = "添加认知任务信息")
  1672. public Result completeTest(@RequestBody JSONArray jsonArray) throws Exception {
  1673. List<CognitiveTaskEntity> cognitiveTaskEntityList = jsonArray.toJavaList(CognitiveTaskEntity.class);
  1674. for (CognitiveTaskEntity cognitiveTaskEntity : cognitiveTaskEntityList) {
  1675. this.cognitiveTaskService.save(cognitiveTaskEntity);
  1676. }
  1677. return null;
  1678. }
  1679. @ApiOperation(value = "用户模板下载")
  1680. @GetMapping("/download/userTemplateDownload")
  1681. public String userTemplateDownload(HttpServletResponse response) {
  1682. String filePath = "";
  1683. if (OSUtil.isLinux()) {
  1684. filePath = "./userTemplate/importTemplate.xlsx";
  1685. } else {
  1686. filePath = "./userTemplate/importTemplate.xlsx";
  1687. }
  1688. File fileReturn = new File(filePath);
  1689. response.reset();
  1690. response.setContentType("application/octet-stream");
  1691. response.setCharacterEncoding("utf-8");
  1692. response.setContentLength((int) fileReturn.length());
  1693. response.setHeader("Content-Disposition", "attachment;filename=template.xlsx");
  1694. byte[] buffer = new byte[1024];
  1695. BufferedInputStream bis = null;
  1696. try {
  1697. bis = new BufferedInputStream(Files.newInputStream(fileReturn.toPath()));
  1698. OutputStream os = response.getOutputStream();
  1699. int i = bis.read(buffer);
  1700. while (i != -1) {
  1701. os.write(buffer, 0, i);
  1702. i = bis.read(buffer);
  1703. }
  1704. return "下载成功";
  1705. } catch (Exception e) {
  1706. e.printStackTrace();
  1707. return "下载失败";
  1708. } finally {
  1709. if (bis != null) {
  1710. try {
  1711. bis.close();
  1712. } catch (IOException e) {
  1713. e.printStackTrace();
  1714. }
  1715. }
  1716. }
  1717. }
  1718. @ApiOperation(value = "用户导入结果下载")
  1719. @GetMapping("/download/userImportResult")
  1720. public String userImportResult(HttpServletResponse response, String filePath) {
  1721. File fileReturn = new File(filePath);
  1722. response.reset();
  1723. response.setContentType("application/octet-stream");
  1724. response.setCharacterEncoding("utf-8");
  1725. response.setContentLength((int) fileReturn.length());
  1726. response.setHeader("Content-Disposition", "attachment;filename=userImportResult.xlsx");
  1727. byte[] buffer = new byte[1024];
  1728. FileInputStream fis = null;
  1729. BufferedInputStream bis = null;
  1730. try {
  1731. fis = new FileInputStream(fileReturn);
  1732. bis = new BufferedInputStream(fis);
  1733. OutputStream os = response.getOutputStream();
  1734. int i = bis.read(buffer);
  1735. while (i != -1) {
  1736. os.write(buffer, 0, i);
  1737. i = bis.read(buffer);
  1738. }
  1739. return "下载成功";
  1740. } catch (Exception e) {
  1741. e.printStackTrace();
  1742. return "下载失败";
  1743. } finally {
  1744. if (bis != null) {
  1745. try {
  1746. bis.close();
  1747. } catch (IOException e) {
  1748. e.printStackTrace();
  1749. }
  1750. }
  1751. if (fis != null) {
  1752. try {
  1753. fis.close();
  1754. } catch (IOException e) {
  1755. e.printStackTrace();
  1756. }
  1757. }
  1758. }
  1759. }
  1760. @ApiOperation(value = "SCL90--各个维度评分规则--excel导入")
  1761. @PostMapping("/import/marks/scl901/{flag}")
  1762. public Result Scl90ExcelImport(@PathVariable String flag, MultipartFile file) throws Exception {
  1763. if (file == null) {
  1764. return fail("文件为空");
  1765. }
  1766. if (flag == null) {
  1767. return fail("所属量表标识为空");
  1768. }
  1769. List<ScaleMarksEntity> scaleMarksByFlag = scaleMarksService.getScaleMarksByFlag(flag);
  1770. if (scaleMarksByFlag.size() != 0) {
  1771. return fail("该量表的维度评分信息已入库,请联系管理员");
  1772. }
  1773. //用户信息上传之后生成的用户名密码文件保存路径
  1774. String fileName = file.getOriginalFilename();
  1775. List<List<Object>> marks = ExcelUtil.getBankListByExcelForUserImport(file.getInputStream(), fileName);
  1776. try {
  1777. for (List<Object> mark : marks) {
  1778. System.out.println(mark);
  1779. //因子(维度名称) 最低分(起始分)最高分(结束分) 常模参考值 标准差 结论(该分段症状)
  1780. //因子解释 等级解释(该分段指导语) 建议 是否为总分结论
  1781. //图表信息iconInfo isIconFlag
  1782. ScaleMarksEntity tempUserDB = new ScaleMarksEntity();
  1783. tempUserDB.setName(String.valueOf(mark.get(0)));
  1784. tempUserDB.setScoreStart(String.valueOf(mark.get(1)));
  1785. tempUserDB.setScoreEnd(String.valueOf(mark.get(2)));
  1786. if (("").equals(String.valueOf(mark.get(3)))) {
  1787. tempUserDB.setReference("无");
  1788. } else {
  1789. tempUserDB.setReference(String.valueOf(mark.get(3)));
  1790. }
  1791. if (("无").equals(tempUserDB.getReference())) {
  1792. tempUserDB.setStandardDeviation("无");
  1793. } else {
  1794. tempUserDB.setStandardDeviation(String.valueOf(mark.get(4)));
  1795. }
  1796. tempUserDB.setSymptom(String.valueOf(mark.get(5)));
  1797. tempUserDB.setNameExplain(String.valueOf(mark.get(6)));
  1798. tempUserDB.setImprovementSuggestions(String.valueOf(mark.get(7)));
  1799. tempUserDB.setSuggestion(String.valueOf(mark.get(8)));
  1800. tempUserDB.setIsTotalScoreExplain(String.valueOf(mark.get(9)));
  1801. tempUserDB.setFlag(flag);
  1802. System.out.println(tempUserDB.toString());
  1803. this.scaleMarksService.saveScaleMarks(tempUserDB);
  1804. }
  1805. } catch (Exception exception) {
  1806. exception.printStackTrace();
  1807. return fail("导入失败,请联系管理员");
  1808. }
  1809. return success("入库成功");
  1810. }
  1811. @ApiOperation(value = "新增/更新 认知任务",notes = "id 主键,新增时为空更新必传, description 任务说明,name 认知任务名称,imageUrl 图片路径,imageName 图片名称," +
  1812. "testDescription 测试任务描述,testNum 测试次数,type 类型:0-量表;1-认知任务,pageUrl 分页路径,testExplain 任务解释,status 状态:0-可用;9-不可用,scaleLimit 认知任务权限:private 私密 public 公开" +
  1813. "no 编号,用于排序,mobileDescription 移动端任务说明,mobilePageUrl 移动端前台页面路径,mobileTestDescription 移动端测试任务描述,mobileStatus 移动端任务状态:0-不可用;1-可用," +
  1814. "reportVersion 报告版本:1-老模板报告;2-新模板报告,practice 类型:1-有练习测试;2-无练习测试")
  1815. @PostMapping("/cognize/save")
  1816. @SafetyProcess
  1817. public Result saveCognize(@RequestBody String json) {
  1818. CognitiveTaskEntity taskEntity = JSONObject.parseObject(JSONObject.parseObject(json).getString("data")).toJavaObject(CognitiveTaskEntity.class);
  1819. if(StringUtils.isBlank(taskEntity.getTaskCode())){
  1820. return fail("标识为空");
  1821. }
  1822. if(StringUtils.isBlank(taskEntity.getMobileStatus())){
  1823. taskEntity.setMobileStatus(Constant.MAGIC_NUM_0);
  1824. }
  1825. if(StringUtils.isBlank(taskEntity.getReportVersion())){
  1826. taskEntity.setReportVersion(Constant.MAGIC_NUM_1);
  1827. }
  1828. if(StringUtils.isBlank(taskEntity.getPractice())){
  1829. taskEntity.setPractice(Constant.MAGIC_NUM_2);
  1830. }
  1831. this.cognitiveTaskService.save(taskEntity);
  1832. return success();
  1833. }
  1834. /**
  1835. * 汉字转拼音
  1836. *
  1837. * @param china
  1838. * @return
  1839. */
  1840. public static String getPinyin(String china) {
  1841. HanyuPinyinOutputFormat formart = new HanyuPinyinOutputFormat();
  1842. formart.setCaseType(HanyuPinyinCaseType.LOWERCASE);
  1843. formart.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
  1844. formart.setVCharType(HanyuPinyinVCharType.WITH_V);
  1845. char[] arrays = china.trim().toCharArray();
  1846. StringBuilder result = new StringBuilder();
  1847. try {
  1848. for (int i = 0; i < arrays.length; i++) {
  1849. char ti = arrays[i];
  1850. if (Character.toString(ti).matches("[\\u4e00-\\u9fa5]")) { //匹配是否是中文
  1851. String[] temp = PinyinHelper.toHanyuPinyinStringArray(ti, formart);
  1852. result.append(temp[0]);
  1853. } else {
  1854. result.append(ti);
  1855. }
  1856. }
  1857. } catch (BadHanyuPinyinOutputFormatCombination e) {
  1858. e.printStackTrace();
  1859. }
  1860. return result.toString();
  1861. }
  1862. }