DataboardController.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. package com.xjrsoft.module.databoard.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.github.yulichang.toolkit.MPJWrappers;
  6. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  7. import com.xjrsoft.common.enums.DeleteMark;
  8. import com.xjrsoft.common.enums.GenderDictionaryEnum;
  9. import com.xjrsoft.common.enums.StudyStatusEnum;
  10. import com.xjrsoft.common.model.result.RT;
  11. import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
  12. import com.xjrsoft.common.utils.VoToColumnUtil;
  13. import com.xjrsoft.module.courseTable.entity.CourseTable;
  14. import com.xjrsoft.module.courseTable.service.ICourseTableService;
  15. import com.xjrsoft.module.databoard.dto.StatisticsDetailDto;
  16. import com.xjrsoft.module.databoard.dto.StatisticsDto;
  17. import com.xjrsoft.module.databoard.vo.AttendanceStatisticsVo;
  18. import com.xjrsoft.module.databoard.vo.CourseStatisticsVo;
  19. import com.xjrsoft.module.databoard.vo.HealthStatisticsVo;
  20. import com.xjrsoft.module.databoard.vo.ItemCountAmountVo;
  21. import com.xjrsoft.module.databoard.vo.MeetingStatisticsVo;
  22. import com.xjrsoft.module.databoard.vo.PersonStatisticsVo;
  23. import com.xjrsoft.module.databoard.vo.ProcessStatisticsVo;
  24. import com.xjrsoft.module.databoard.vo.ReimbursementStatisticsVo;
  25. import com.xjrsoft.module.databoard.vo.RepairStatisticsVo;
  26. import com.xjrsoft.module.databoard.vo.VisitorStatisticsVo;
  27. import com.xjrsoft.module.outint.entity.VisitorOutInRecord;
  28. import com.xjrsoft.module.outint.service.IVisitorOutInRecordService;
  29. import com.xjrsoft.module.student.dto.BaseStudentUserPageDto;
  30. import com.xjrsoft.module.student.service.IBaseStudentService;
  31. import com.xjrsoft.module.student.vo.BaseStudentUserPageVo;
  32. import com.xjrsoft.module.system.entity.DictionaryDetail;
  33. import com.xjrsoft.module.teacher.entity.BaseTeacher;
  34. import com.xjrsoft.module.teacher.entity.XjrUser;
  35. import com.xjrsoft.module.teacher.service.ITeacherbaseManagerService;
  36. import com.xjrsoft.module.teacher.vo.XjrUserPageVo;
  37. import com.xjrsoft.module.workflow.entity.WorkflowFormRelation;
  38. import com.xjrsoft.module.workflow.service.IWorkflowFormRelationService;
  39. import io.swagger.annotations.Api;
  40. import io.swagger.annotations.ApiOperation;
  41. import lombok.AllArgsConstructor;
  42. import org.camunda.bpm.engine.history.HistoricProcessInstance;
  43. import org.springframework.web.bind.annotation.GetMapping;
  44. import org.springframework.web.bind.annotation.RequestMapping;
  45. import org.springframework.web.bind.annotation.RestController;
  46. import javax.validation.Valid;
  47. import java.time.LocalDate;
  48. import java.time.LocalDateTime;
  49. import java.time.format.DateTimeFormatter;
  50. import java.util.ArrayList;
  51. import java.util.Arrays;
  52. import java.util.HashSet;
  53. import java.util.List;
  54. import java.util.Map;
  55. import java.util.Set;
  56. import java.util.stream.Collectors;
  57. /**
  58. * @title: 数据看板代码
  59. * @Date: 2024年8月2日
  60. * @Version 1.0
  61. */
  62. @RestController
  63. @RequestMapping("/databoard" + "/databoard")
  64. @Api(value = "/databoard" + "/databoard",tags = "数据看板代码")
  65. @AllArgsConstructor
  66. public class DataboardController {
  67. private final ICourseTableService courseTableService;
  68. private final IVisitorOutInRecordService visitorService;
  69. private final IBaseStudentService studentService;
  70. private final ITeacherbaseManagerService teacherService;
  71. private final IWorkflowFormRelationService formRelationService;
  72. @GetMapping(value = "/process-statistics")
  73. @ApiOperation(value="流程统计")
  74. @SaCheckPermission("databoard:detail")
  75. public RT<ProcessStatisticsVo> processStatistics(@Valid StatisticsDto dto){
  76. ProcessStatisticsVo result = new ProcessStatisticsVo();
  77. List<WorkflowFormRelation> relations = formRelationService.list();
  78. result.setAllCount(Long.parseLong(relations.size() + ""));
  79. long completeCount = 0L;
  80. long uncompleteCount = 0L;
  81. for (WorkflowFormRelation relation : relations) {
  82. if(HistoricProcessInstance.STATE_COMPLETED.equals(relation.getCurrentState())){
  83. completeCount ++;
  84. }else if(HistoricProcessInstance.STATE_INTERNALLY_TERMINATED.equals(relation.getCurrentState())){
  85. completeCount ++;
  86. }else if(HistoricProcessInstance.STATE_EXTERNALLY_TERMINATED.equals(relation.getCurrentState())){
  87. completeCount ++;
  88. }else{
  89. uncompleteCount ++;
  90. }
  91. }
  92. result.setCompleteCount(completeCount);
  93. result.setUncompleteCount(uncompleteCount);
  94. return RT.ok(result);
  95. }
  96. @GetMapping(value = "/meeting-statistics")
  97. @ApiOperation(value="会议统计")
  98. @SaCheckPermission("databoard:detail")
  99. public RT<MeetingStatisticsVo> meetingStatistics(@Valid StatisticsDetailDto dto){
  100. LocalDateTime startTime = null;
  101. LocalDateTime endTime = null;
  102. if(dto.getStartDate() != null){
  103. startTime = dto.getStartDate().atStartOfDay();
  104. }
  105. if(dto.getEndDate() != null){
  106. endTime = dto.getEndDate().atStartOfDay().plusDays(1).plusNanos(-1);
  107. }
  108. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  109. String sql = "SELECT t1.id, (SELECT COUNT(*) FROM xjr_user WHERE FIND_IN_SET(id, t1.meeting_apply_participants)) AS person_count FROM wf_meeting_apply t1" +
  110. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  111. " WHERE t2.current_state = 'COMPLETED'";
  112. if(startTime != null && endTime != null){
  113. sql += " and t1.meeting_apply_date between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  114. }
  115. if(dto.getUserId() != null){
  116. sql += " and FIND_IN_SET(" + dto.getUserId() +", t1.meeting_apply_participants)";
  117. }
  118. List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
  119. MeetingStatisticsVo result = new MeetingStatisticsVo();
  120. result.setAllCount(list.size());
  121. int personCount = 0;
  122. for (Map<String, Object> objectMap : list) {
  123. personCount += (Long)objectMap.get("person_count");
  124. }
  125. result.setPersonCount(personCount);
  126. return RT.ok(result);
  127. }
  128. @GetMapping(value = "/course-statistics")
  129. @ApiOperation(value="课表统计")
  130. @SaCheckPermission("databoard:detail")
  131. public RT<CourseStatisticsVo> courseStatistics(@Valid StatisticsDetailDto dto){
  132. List<CourseTable> list = courseTableService.list(
  133. new QueryWrapper<CourseTable>().lambda()
  134. .eq((dto.getStartDate() == null && dto.getEndDate() == null), CourseTable::getScheduleDate, LocalDate.now())
  135. .between((dto.getStartDate() != null && dto.getEndDate() != null), CourseTable::getScheduleDate, dto.getStartDate(), dto.getEndDate())
  136. );
  137. CourseStatisticsVo result = new CourseStatisticsVo();
  138. result.setAllCount(list.size());
  139. Set<String> teacherCountSet = new HashSet<>();
  140. int noTeacherCount = 0;
  141. for (CourseTable courseTable : list) {
  142. if(courseTable.getTeacherId() != null && !"0".equals(courseTable.getTeacherId())){
  143. String[] split = courseTable.getTeacherId().split(",");
  144. teacherCountSet.addAll(Arrays.asList(split));
  145. }else{
  146. noTeacherCount ++;
  147. }
  148. }
  149. result.setTeacherCount(teacherCountSet.size());
  150. result.setNoTeacherCount(noTeacherCount);
  151. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  152. String sql = "SELECT t1.* FROM wf_course_adjust t1" +
  153. " INNER JOIN xjr_workflow_form_relation t2 ON t2.form_key_value = t1.id" +
  154. " WHERE t1.adjust_type = 'course_exchange'" +
  155. " AND t2.current_state = 'COMPLETED'";
  156. if(dto.getStartDate() != null && dto.getEndDate() != null){
  157. sql += " AND t1.adjust_date between '" + dto.getStartDate().format(formatter) + "' and '" + dto.getEndDate().format(formatter) + "'";
  158. }else{
  159. sql += " AND t1.adjust_date = DATE_FORMAT(NOW(),'%Y-%m-%d')";
  160. }
  161. result.setAdjustCount(SqlRunnerAdapter.db().selectList(sql).size());
  162. sql = "SELECT t1.* FROM wf_course_adjust t1" +
  163. " INNER JOIN xjr_workflow_form_relation t2 ON t2.form_key_value = t1.id" +
  164. " WHERE t1.adjust_type = 'course_substitute'" +
  165. " AND t2.current_state = 'COMPLETED'";
  166. if(dto.getStartDate() != null && dto.getEndDate() != null){
  167. sql += " AND t1.adjust_date between '" + dto.getStartDate().format(formatter) + "' and '" + dto.getEndDate().format(formatter) + "'";
  168. }else{
  169. sql += " AND t1.adjust_date = DATE_FORMAT(NOW(),'%Y-%m-%d')";
  170. }
  171. result.setReplaceCount(SqlRunnerAdapter.db().selectList(sql).size());
  172. return RT.ok(result);
  173. }
  174. @GetMapping(value = "/visitor-statistics")
  175. @ApiOperation(value="访客统计")
  176. @SaCheckPermission("databoard:detail")
  177. public RT<VisitorStatisticsVo> visitorStatistics(@Valid StatisticsDto dto){
  178. List<VisitorOutInRecord> list = visitorService.list(
  179. new QueryWrapper<VisitorOutInRecord>().lambda()
  180. .eq(VisitorOutInRecord::getDeleteMark, DeleteMark.NODELETE.getCode())
  181. );
  182. VisitorStatisticsVo result = new VisitorStatisticsVo();
  183. result.setAllCount(list.size());
  184. LocalDate today = LocalDate.now();
  185. int todayCount = 0;
  186. for (VisitorOutInRecord record : list) {
  187. if(today.equals(record.getRecordTime().toLocalDate())){
  188. todayCount ++;
  189. }
  190. }
  191. result.setTodayCount(todayCount);
  192. return RT.ok(result);
  193. }
  194. @GetMapping(value = "/person-statistics")
  195. @ApiOperation(value="全校师生数据概览")
  196. @SaCheckPermission("databoard:detail")
  197. public RT<PersonStatisticsVo> personStatistics(@Valid StatisticsDto dto){
  198. List<BaseStudentUserPageVo> studentList = studentService.getStudentList(new BaseStudentUserPageDto());
  199. PersonStatisticsVo result = new PersonStatisticsVo();
  200. result.setStudentCount(studentList.size());
  201. Set<String> studentMaleSet = studentList.stream()
  202. .filter(x -> (x.getGenderCn() != null && x.getGenderCn().equals(GenderDictionaryEnum.MALE.getCode())))
  203. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  204. result.setStudentMaleCount(studentMaleSet.size());
  205. Set<String> studentFemaleSet = studentList.stream()
  206. .filter(x -> (x.getGenderCn() != null && x.getGenderCn().equals(GenderDictionaryEnum.FEMALE.getCode())))
  207. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  208. result.setStudentFemaleCount(studentFemaleSet.size());
  209. Set<String> studentStayMaleSet = studentList.stream()
  210. .filter(x -> (
  211. x.getGenderCn() != null
  212. && x.getGenderCn().equals(GenderDictionaryEnum.MALE.getCode())
  213. && x.getStduyStatusCn() != null
  214. && x.getStduyStatusCn().equals(StudyStatusEnum.InResidence.getCode())
  215. ))
  216. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  217. result.setStudentStayMaleCount(studentStayMaleSet.size());
  218. Set<String> studentNotStayMaleSet = studentList.stream()
  219. .filter(x -> (
  220. x.getGenderCn() != null
  221. && x.getGenderCn().equals(GenderDictionaryEnum.MALE.getCode())
  222. && x.getStduyStatusCn() != null
  223. && x.getStduyStatusCn().equals(StudyStatusEnum.AttendDaySchool.getCode())
  224. ))
  225. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  226. result.setStudentNotStayMaleCount(studentNotStayMaleSet.size());
  227. Set<String> studentStayFemaleSet = studentList.stream()
  228. .filter(x -> (
  229. x.getGenderCn() != null
  230. && x.getGenderCn().equals(GenderDictionaryEnum.FEMALE.getCode())
  231. && x.getStduyStatusCn() != null
  232. && x.getStduyStatusCn().equals(StudyStatusEnum.InResidence.getCode())
  233. ))
  234. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  235. result.setStudentStayFemaleCount(studentStayFemaleSet.size());
  236. Set<String> studentNotStayFemaleSet = studentList.stream()
  237. .filter(x -> (
  238. x.getGenderCn() != null
  239. && x.getGenderCn().equals(GenderDictionaryEnum.FEMALE.getCode())
  240. && x.getStduyStatusCn() != null
  241. && x.getStduyStatusCn().equals(StudyStatusEnum.AttendDaySchool.getCode())
  242. ))
  243. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  244. result.setStudentNotStayFemaleCount(studentNotStayFemaleSet.size());
  245. MPJLambdaWrapper<XjrUser> queryWrapper = MPJWrappers.<XjrUser>lambdaJoin()
  246. .disableSubLogicDel()
  247. .orderByDesc(XjrUser::getId)
  248. .select(XjrUser::getId)
  249. .select(XjrUser.class,x -> VoToColumnUtil.fieldsToColumns(XjrUserPageVo.class).contains(x.getProperty()))
  250. .innerJoin(BaseTeacher.class,BaseTeacher::getUserId,XjrUser::getId)
  251. .leftJoin(DictionaryDetail.class,DictionaryDetail::getCode,BaseTeacher::getJobState, ext->ext.selectAs(DictionaryDetail::getName, XjrUserPageVo::getJobState))
  252. .leftJoin(DictionaryDetail.class,DictionaryDetail::getCode,XjrUser::getCredentialType,ext->ext.selectAs(DictionaryDetail::getName, XjrUserPageVo::getCredentialType))
  253. .leftJoin(DictionaryDetail.class,DictionaryDetail::getCode,BaseTeacher::getEmployWay,ext->ext.selectAs(DictionaryDetail::getName, XjrUserPageVo::getEmployWay))
  254. .selectAsClass(BaseTeacher.class, XjrUserPageVo.class);
  255. List<XjrUserPageVo> teacherList = teacherService.selectJoinList(XjrUserPageVo.class, queryWrapper);
  256. result.setTeacherCount(teacherList.size());
  257. Set<String> teacherMaleSet = teacherList.stream()
  258. .filter(x -> (x.getGender() != null && x.getGender().equals(GenderDictionaryEnum.MALE.getCode())))
  259. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  260. result.setTeacherMaleCount(teacherMaleSet.size());
  261. Set<String> teacherFemaleSet = teacherList.stream()
  262. .filter(x -> (x.getGender() != null && x.getGender().equals(GenderDictionaryEnum.FEMALE.getCode())))
  263. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  264. result.setTeacherFemaleCount(teacherFemaleSet.size());
  265. Set<String> teacherSet1 = teacherList.stream()
  266. .filter(x -> (x.getEmployWay() != null && x.getEmployWay().equals("FB1601")))
  267. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  268. result.setTeacherCount1(teacherSet1.size());
  269. Set<String> teacherSet2 = teacherList.stream()
  270. .filter(x -> (x.getEmployWay() != null && x.getEmployWay().equals("FB1602")))
  271. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  272. result.setTeacherCount2(teacherSet2.size());
  273. Set<String> teacherSet3 = teacherList.stream()
  274. .filter(x -> (x.getEmployWay() != null && x.getEmployWay().equals("FB1606")))
  275. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  276. result.setTeacherCount3(teacherSet3.size());
  277. Set<String> teacherSet4 = teacherList.stream()
  278. .filter(x -> (x.getEmployWay() != null && x.getEmployWay().equals("FB1609")))
  279. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  280. result.setTeacherCount4(teacherSet4.size());
  281. Set<String> teacherSet5 = teacherList.stream()
  282. .filter(x -> (x.getEmployWay() != null && x.getEmployWay().equals("FB1608")))
  283. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  284. result.setTeacherCount5(teacherSet5.size());
  285. return RT.ok(result);
  286. }
  287. @GetMapping(value = "/health-statistics")
  288. @ApiOperation(value="学生健康统计")
  289. @SaCheckPermission("databoard:detail")
  290. public RT<HealthStatisticsVo> healthStatistics(@Valid StatisticsDto dto){
  291. String sql = "SELECT t1.gender,COUNT(t1.id) AS a_count FROM student_infection t1" +
  292. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  293. " WHERE t2.current_state = 'COMPLETED' GROUP BY t1.gender";
  294. List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
  295. HealthStatisticsVo result = new HealthStatisticsVo();
  296. for (Map<String, Object> objectMap : list) {
  297. if(objectMap.get("gender") != null && GenderDictionaryEnum.FEMALE.getCode().equals(objectMap.get("gender").toString())){
  298. result.setInfectionFemaleCount(Integer.parseInt(objectMap.get("a_count").toString()));
  299. }if(objectMap.get("gender") != null && GenderDictionaryEnum.MALE.getCode().equals(objectMap.get("gender").toString())){
  300. result.setInfectionMaleCount(Integer.parseInt(objectMap.get("a_count").toString()));
  301. }
  302. }
  303. sql = "SELECT t1.gender,COUNT(t1.id) AS a_count FROM student_psychological t1" +
  304. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  305. " WHERE t2.current_state = 'COMPLETED' GROUP BY t1.gender";
  306. list = SqlRunnerAdapter.db().selectList(sql);
  307. for (Map<String, Object> objectMap : list) {
  308. if(objectMap.get("gender") != null && GenderDictionaryEnum.FEMALE.getCode().equals(objectMap.get("gender").toString())){
  309. result.setInfectionFemaleCount(Integer.parseInt(objectMap.get("a_count").toString()));
  310. }if(objectMap.get("gender") != null && GenderDictionaryEnum.MALE.getCode().equals(objectMap.get("gender").toString())){
  311. result.setPsychologicalMaleCount(Integer.parseInt(objectMap.get("a_count").toString()));
  312. }
  313. }
  314. return RT.ok(result);
  315. }
  316. @GetMapping(value = "/reimbursement-statistics")
  317. @ApiOperation(value="差旅费报销申请")
  318. @SaCheckPermission("databoard:detail")
  319. public RT<ReimbursementStatisticsVo> reimbursementStatistics(@Valid StatisticsDetailDto dto){
  320. LocalDateTime startTime = null;
  321. LocalDateTime endTime = null;
  322. if(dto.getStartDate() != null){
  323. startTime = dto.getStartDate().atStartOfDay();
  324. }
  325. if(dto.getEndDate() != null){
  326. endTime = dto.getEndDate().atStartOfDay().plusDays(1).plusNanos(-1);
  327. }
  328. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  329. String sql = "SELECT t2.* FROM billing_reimbursement t1" +
  330. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  331. " where 1 = 1";
  332. if(startTime != null && endTime != null){
  333. sql += " and t1.aply_time between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  334. }
  335. if(dto.getUserId() != null){
  336. sql += " and t1.applicant_id = " + dto.getUserId();
  337. }
  338. List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
  339. ReimbursementStatisticsVo result = new ReimbursementStatisticsVo();
  340. result.setAllCount(list.size());
  341. int completeCount = 0;
  342. int uncompleteCount = 0;
  343. for (Map<String, Object> objectMap : list) {
  344. String statusObj = objectMap.get("current_state").toString();
  345. if(HistoricProcessInstance.STATE_COMPLETED.equals(statusObj)){
  346. completeCount ++;
  347. }else if(HistoricProcessInstance.STATE_INTERNALLY_TERMINATED.equals(statusObj)){
  348. completeCount ++;
  349. }else if(HistoricProcessInstance.STATE_EXTERNALLY_TERMINATED.equals(statusObj)){
  350. completeCount ++;
  351. }else if(HistoricProcessInstance.STATE_ACTIVE.equals(statusObj)){
  352. uncompleteCount ++;
  353. }
  354. }
  355. result.setCompleteCount(completeCount);
  356. result.setUncompleteCount(uncompleteCount);
  357. sql = "SELECT t1.city_in,SUM(t1.total_amount) AS total_amount FROM billing_reimbursement t1" +
  358. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  359. " WHERE t2.current_state = 'COMPLETED'";
  360. if(startTime != null && endTime != null){
  361. sql += " and t1.aply_time between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  362. }
  363. sql += " group by t1.city_in ";
  364. list = SqlRunnerAdapter.db().selectList(sql);
  365. List<ItemCountAmountVo> amountList = new ArrayList<>();
  366. for (Map<String, Object> objectMap : list) {
  367. Object cityInObj = objectMap.get("city_in");
  368. String item = "";
  369. if(cityInObj != null && Integer.parseInt(cityInObj.toString()) == 1){
  370. item = "市外";
  371. }else if(cityInObj != null && Integer.parseInt(cityInObj.toString()) == 0){
  372. item = "室内";
  373. }
  374. ItemCountAmountVo amountVo = new ItemCountAmountVo();
  375. amountVo.setItem(item);
  376. amountVo.setAmount(Double.parseDouble(objectMap.get("total_amount").toString()));
  377. amountList.add(amountVo);
  378. }
  379. result.setAmountList(amountList);
  380. return RT.ok(result);
  381. }
  382. @GetMapping(value = "/repair-statistics")
  383. @ApiOperation(value="维修申报")
  384. @SaCheckPermission("databoard:detail")
  385. public RT<RepairStatisticsVo> repairStatistics(@Valid StatisticsDetailDto dto){
  386. LocalDateTime startTime = null;
  387. LocalDateTime endTime = null;
  388. if(dto.getStartDate() != null){
  389. startTime = dto.getStartDate().atStartOfDay();
  390. }
  391. if(dto.getEndDate() != null){
  392. endTime = dto.getEndDate().atStartOfDay().plusDays(1).plusNanos(-1);
  393. }
  394. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  395. RepairStatisticsVo result = new RepairStatisticsVo();
  396. String sql = "SELECT t1.* FROM wf_repair_declaration t1" +
  397. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  398. " WHERE t2.current_state = 'COMPLETED'";
  399. if(startTime != null && endTime != null){
  400. sql += " and t1.application_time between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  401. }
  402. List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
  403. result.setAllCount(list.size());
  404. int completeCount = 0;
  405. int uncompleteCount = 0;
  406. int personCount = 0;
  407. for (Map<String, Object> objectMap : list) {
  408. Object statusObj = objectMap.get("maintenance_feedback");
  409. if(statusObj != null && !statusObj.toString().isEmpty()){
  410. completeCount ++;
  411. }else{
  412. uncompleteCount ++;
  413. }
  414. if(objectMap.get("is_artificial") != null && "是".equals(objectMap.get("is_artificial").toString())){
  415. personCount ++;
  416. }
  417. }
  418. result.setCompleteCount(completeCount);
  419. result.setUncompleteCount(uncompleteCount);
  420. result.setPersonCount(personCount);
  421. sql = "SELECT ifnull(SUM(t1.indemnity), 0) as indemnity FROM wf_repair_declaration t1" +
  422. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  423. " WHERE t2.current_state = 'COMPLETED'";
  424. list = SqlRunnerAdapter.db().selectList(sql);
  425. result.setTotalAmount(Double.parseDouble(list.get(0).get("indemnity").toString()));
  426. return RT.ok(result);
  427. }
  428. @GetMapping(value = "/attendance-statistics")
  429. @ApiOperation(value="个人考勤")
  430. @SaCheckPermission("databoard:detail")
  431. public RT<AttendanceStatisticsVo> attendanceStatistics(@Valid StatisticsDetailDto dto){
  432. if(dto.getUserId() == null){
  433. dto.setUserId(StpUtil.getLoginIdAsLong());
  434. }
  435. LocalDateTime startTime = null;
  436. LocalDateTime endTime = null;
  437. if(dto.getStartDate() != null){
  438. startTime = dto.getStartDate().atStartOfDay();
  439. }
  440. if(dto.getEndDate() != null){
  441. endTime = dto.getEndDate().atStartOfDay().plusDays(1).plusNanos(-1);
  442. }
  443. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  444. AttendanceStatisticsVo result = new AttendanceStatisticsVo();
  445. String sql = " SELECT ifnull(sum(t1.leave_days), 0) as leave_days FROM wf_teacherleave t1" +
  446. " INNER JOIN xjr_workflow_form_relation t2 ON t2.form_key_value = t1.id" +
  447. " WHERE t2.current_state = 'COMPLETED'";
  448. if(startTime != null && endTime != null){
  449. String startTimeStr = startTime.format(formatter);
  450. String endTimeStr = endTime.format(formatter);
  451. sql +=" AND (" +
  452. " (t1.leave_start_time BETWEEN '" + startTimeStr + "' and '" + endTimeStr + "')" +
  453. " OR (t1.leave_end_time BETWEEN '" + startTimeStr + "' and '" + endTimeStr + "')" +
  454. " OR (t1.leave_start_time > '" + startTimeStr + "' and '" + endTimeStr + "' > t1.leave_end_time)" +
  455. " OR ('" + startTimeStr + "' > t1.leave_start_time and t1.leave_end_time > '" + endTimeStr + "')" +
  456. " )";
  457. }
  458. if(dto.getUserId() != null){
  459. sql += " and user_id = " + dto.getUserId();
  460. }
  461. List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
  462. result.setLeaveDays(Double.parseDouble(list.get(0).get("leave_days").toString()));
  463. sql = "SELECT * FROM teacher_attendance_record WHERE delete_mark = 0 and attendance_status = '迟到'";
  464. formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  465. if(startTime != null && endTime != null){
  466. sql +=" AND attendance_date between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  467. }
  468. if(dto.getUserId() != null){
  469. sql += " and user_id = " + dto.getUserId();
  470. }
  471. list = SqlRunnerAdapter.db().selectList(sql);
  472. result.setLateCount(list.size());
  473. sql = "SELECT COUNT(t1.id) AS a_count FROM wf_course_adjust t1" +
  474. " INNER JOIN xjr_workflow_form_relation t2 ON t2.form_key_value = t1.id" +
  475. " WHERE t1.adjust_type = 'course_exchange'" +
  476. " AND t2.current_state = 'COMPLETED'" +
  477. " and t1.delete_mark = 0 and t1.enabled_mark = 1";
  478. if(startTime != null && endTime != null){
  479. sql +=" AND t1.adjust_date between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  480. }
  481. if(dto.getUserId() != null){
  482. sql += " and (t1.user_id = " + dto.getUserId() + " or t1.exchange_teacher_id = '" + dto.getUserId() + "')";
  483. }
  484. list = SqlRunnerAdapter.db().selectList(sql);
  485. result.setAdjustCount(Integer.parseInt(list.get(0).get("a_count").toString()));
  486. sql = "SELECT t1.* FROM wf_course_adjust t1" +
  487. " INNER JOIN xjr_workflow_form_relation t2 ON t2.form_key_value = t1.id" +
  488. " WHERE t1.adjust_type = 'course_substitute'" +
  489. " AND t2.current_state = 'COMPLETED'" +
  490. " and t1.delete_mark = 0 and t1.enabled_mark = 1";
  491. if(startTime != null && endTime != null){
  492. sql +=" AND t1.adjust_date between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  493. }
  494. if(dto.getUserId() != null){
  495. sql += " and t1.user_id = " + dto.getUserId();
  496. }
  497. list = SqlRunnerAdapter.db().selectList(sql);
  498. int subCount = list.size();
  499. sql = "SELECT t1.* FROM wf_course_adjust t1" +
  500. " INNER JOIN xjr_workflow_form_relation t2 ON t2.form_key_value = t1.id" +
  501. " WHERE t1.adjust_type = 'course_substitute'" +
  502. " AND t2.current_state = 'COMPLETED'" +
  503. " and t1.delete_mark = 0 and t1.enabled_mark = 1";
  504. if(startTime != null && endTime != null){
  505. sql +=" AND t1.adjust_date between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  506. }
  507. if(dto.getUserId() != null){
  508. sql += " and t1.exchange_teacher_id = " + dto.getUserId();
  509. }
  510. list = SqlRunnerAdapter.db().selectList(sql);
  511. int addCount = list.size();
  512. result.setExchangeCount(addCount - subCount);
  513. List<CourseTable> courseList = courseTableService.list(
  514. new QueryWrapper<CourseTable>().lambda()
  515. .like(CourseTable::getTeacherId, dto.getUserId())
  516. .between(dto.getStartDate() != null && dto.getEndDate() != null, CourseTable::getScheduleDate, dto.getStartDate(), dto.getEndDate())
  517. );
  518. result.setCourseCount(courseList.size());
  519. return RT.ok(result);
  520. }
  521. }