DataboardController.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. VisitorStatisticsVo result = new VisitorStatisticsVo();
  179. String sql = "SELECT * FROM reservation_school_people t1" +
  180. " INNER JOIN reservation_school t2 ON t1.reservation_schoo_id = t2.id" +
  181. " INNER JOIN xjr_workflow_form_relation t3 ON CAST(t2.id AS CHAR) = t3.form_key_value" +
  182. " WHERE t3.current_state = 'COMPLETED' AND t1.delete_mark = 0 AND t1.enabled_mark = 1" +
  183. " AND t2.delete_mark = 0 AND t2.enabled_mark = 1";
  184. int size = SqlRunnerAdapter.db().selectList(sql).size();
  185. result.setAllCount(size);
  186. sql += " AND DATE_FORMAT(NOW(),'%Y-%m-%d') BETWEEN DATE_FORMAT(t2.start_time,'%Y-%m-%d') AND DATE_FORMAT(t2.end_time,'%Y-%m-%d')";
  187. int todayCount = SqlRunnerAdapter.db().selectList(sql).size();
  188. result.setTodayCount(todayCount);
  189. return RT.ok(result);
  190. }
  191. @GetMapping(value = "/person-statistics")
  192. @ApiOperation(value="全校师生数据概览")
  193. @SaCheckPermission("databoard:detail")
  194. public RT<PersonStatisticsVo> personStatistics(@Valid StatisticsDto dto){
  195. List<BaseStudentUserPageVo> studentList = studentService.getStudentList(new BaseStudentUserPageDto());
  196. PersonStatisticsVo result = new PersonStatisticsVo();
  197. result.setStudentCount(studentList.size());
  198. Set<String> studentMaleSet = studentList.stream()
  199. .filter(x -> (x.getGenderCn() != null && x.getGenderCn().equals(GenderDictionaryEnum.MALE.getCode())))
  200. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  201. result.setStudentMaleCount(studentMaleSet.size());
  202. Set<String> studentFemaleSet = studentList.stream()
  203. .filter(x -> (x.getGenderCn() != null && x.getGenderCn().equals(GenderDictionaryEnum.FEMALE.getCode())))
  204. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  205. result.setStudentFemaleCount(studentFemaleSet.size());
  206. Set<String> studentStayMaleSet = studentList.stream()
  207. .filter(x -> (
  208. x.getGenderCn() != null
  209. && x.getGenderCn().equals(GenderDictionaryEnum.MALE.getCode())
  210. && x.getStduyStatusCn() != null
  211. && x.getStduyStatusCn().equals(StudyStatusEnum.InResidence.getCode())
  212. ))
  213. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  214. result.setStudentStayMaleCount(studentStayMaleSet.size());
  215. Set<String> studentNotStayMaleSet = studentList.stream()
  216. .filter(x -> (
  217. x.getGenderCn() != null
  218. && x.getGenderCn().equals(GenderDictionaryEnum.MALE.getCode())
  219. && x.getStduyStatusCn() != null
  220. && x.getStduyStatusCn().equals(StudyStatusEnum.AttendDaySchool.getCode())
  221. ))
  222. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  223. result.setStudentNotStayMaleCount(studentNotStayMaleSet.size());
  224. Set<String> studentStayFemaleSet = studentList.stream()
  225. .filter(x -> (
  226. x.getGenderCn() != null
  227. && x.getGenderCn().equals(GenderDictionaryEnum.FEMALE.getCode())
  228. && x.getStduyStatusCn() != null
  229. && x.getStduyStatusCn().equals(StudyStatusEnum.InResidence.getCode())
  230. ))
  231. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  232. result.setStudentStayFemaleCount(studentStayFemaleSet.size());
  233. Set<String> studentNotStayFemaleSet = studentList.stream()
  234. .filter(x -> (
  235. x.getGenderCn() != null
  236. && x.getGenderCn().equals(GenderDictionaryEnum.FEMALE.getCode())
  237. && x.getStduyStatusCn() != null
  238. && x.getStduyStatusCn().equals(StudyStatusEnum.AttendDaySchool.getCode())
  239. ))
  240. .map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
  241. result.setStudentNotStayFemaleCount(studentNotStayFemaleSet.size());
  242. MPJLambdaWrapper<XjrUser> queryWrapper = MPJWrappers.<XjrUser>lambdaJoin()
  243. .disableSubLogicDel()
  244. .orderByDesc(XjrUser::getId)
  245. .select(XjrUser::getId)
  246. .select(XjrUser.class,x -> VoToColumnUtil.fieldsToColumns(XjrUserPageVo.class).contains(x.getProperty()))
  247. .innerJoin(BaseTeacher.class,BaseTeacher::getUserId,XjrUser::getId)
  248. .leftJoin(DictionaryDetail.class,DictionaryDetail::getCode,BaseTeacher::getJobState, ext->ext.selectAs(DictionaryDetail::getName, XjrUserPageVo::getJobState))
  249. .leftJoin(DictionaryDetail.class,DictionaryDetail::getCode,XjrUser::getCredentialType,ext->ext.selectAs(DictionaryDetail::getName, XjrUserPageVo::getCredentialType))
  250. .leftJoin(DictionaryDetail.class,DictionaryDetail::getCode,BaseTeacher::getEmployType,ext->ext.selectAs(DictionaryDetail::getName, XjrUserPageVo::getEmployWay))
  251. .selectAsClass(BaseTeacher.class, XjrUserPageVo.class);
  252. List<XjrUserPageVo> teacherList = teacherService.selectJoinList(XjrUserPageVo.class, queryWrapper);
  253. result.setTeacherCount(teacherList.size());
  254. Set<String> teacherMaleSet = teacherList.stream()
  255. .filter(x -> (x.getGender() != null && x.getGender().equals(GenderDictionaryEnum.MALE.getCode())))
  256. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  257. result.setTeacherMaleCount(teacherMaleSet.size());
  258. Set<String> teacherFemaleSet = teacherList.stream()
  259. .filter(x -> (x.getGender() != null && x.getGender().equals(GenderDictionaryEnum.FEMALE.getCode())))
  260. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  261. result.setTeacherFemaleCount(teacherFemaleSet.size());
  262. Set<String> teacherSet1 = teacherList.stream()
  263. .filter(x -> (x.getEmployWay() != null && x.getEmployWay().equals("FB1601")))
  264. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  265. result.setTeacherCount1(teacherSet1.size());
  266. Set<String> teacherSet2 = teacherList.stream()
  267. .filter(x -> (x.getEmployWay() != null && x.getEmployWay().equals("FB1605")))
  268. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  269. result.setTeacherCount2(teacherSet2.size());
  270. Set<String> teacherSet4 = teacherList.stream()
  271. .filter(x -> (x.getEmployWay() != null && x.getEmployWay().equals("FB1609")))
  272. .map(XjrUserPageVo::getId).collect(Collectors.toSet());
  273. result.setTeacherCount4(teacherSet4.size());
  274. return RT.ok(result);
  275. }
  276. @GetMapping(value = "/health-statistics")
  277. @ApiOperation(value="学生健康统计")
  278. @SaCheckPermission("databoard:detail")
  279. public RT<HealthStatisticsVo> healthStatistics(@Valid StatisticsDto dto){
  280. String sql = "SELECT t1.gender,COUNT(t1.id) AS a_count FROM student_infection t1" +
  281. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  282. " WHERE t2.current_state = 'COMPLETED' GROUP BY t1.gender";
  283. List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
  284. HealthStatisticsVo result = new HealthStatisticsVo();
  285. for (Map<String, Object> objectMap : list) {
  286. if(objectMap.get("gender") != null && GenderDictionaryEnum.FEMALE.getCode().equals(objectMap.get("gender").toString())){
  287. result.setInfectionFemaleCount(Integer.parseInt(objectMap.get("a_count").toString()));
  288. }if(objectMap.get("gender") != null && GenderDictionaryEnum.MALE.getCode().equals(objectMap.get("gender").toString())){
  289. result.setInfectionMaleCount(Integer.parseInt(objectMap.get("a_count").toString()));
  290. }
  291. }
  292. sql = "SELECT t1.gender,COUNT(t1.id) AS a_count FROM student_psychological t1" +
  293. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  294. " WHERE t2.current_state = 'COMPLETED' GROUP BY t1.gender";
  295. list = SqlRunnerAdapter.db().selectList(sql);
  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.setPsychologicalMaleCount(Integer.parseInt(objectMap.get("a_count").toString()));
  301. }
  302. }
  303. return RT.ok(result);
  304. }
  305. @GetMapping(value = "/reimbursement-statistics")
  306. @ApiOperation(value="差旅费报销申请")
  307. @SaCheckPermission("databoard:detail")
  308. public RT<ReimbursementStatisticsVo> reimbursementStatistics(@Valid StatisticsDetailDto dto){
  309. LocalDateTime startTime = null;
  310. LocalDateTime endTime = null;
  311. if(dto.getStartDate() != null){
  312. startTime = dto.getStartDate().atStartOfDay();
  313. }
  314. if(dto.getEndDate() != null){
  315. endTime = dto.getEndDate().atStartOfDay().plusDays(1).plusNanos(-1);
  316. }
  317. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  318. String sql = "SELECT t2.* FROM billing_reimbursement t1" +
  319. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  320. " where 1 = 1";
  321. if(startTime != null && endTime != null){
  322. sql += " and t1.aply_time between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  323. }
  324. if(dto.getUserId() != null){
  325. sql += " and t1.applicant_id = " + dto.getUserId();
  326. }
  327. List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
  328. ReimbursementStatisticsVo result = new ReimbursementStatisticsVo();
  329. result.setAllCount(list.size());
  330. int completeCount = 0;
  331. int uncompleteCount = 0;
  332. for (Map<String, Object> objectMap : list) {
  333. String statusObj = objectMap.get("current_state").toString();
  334. if(HistoricProcessInstance.STATE_COMPLETED.equals(statusObj)){
  335. completeCount ++;
  336. }else if(HistoricProcessInstance.STATE_INTERNALLY_TERMINATED.equals(statusObj)){
  337. completeCount ++;
  338. }else if(HistoricProcessInstance.STATE_EXTERNALLY_TERMINATED.equals(statusObj)){
  339. completeCount ++;
  340. }else if(HistoricProcessInstance.STATE_ACTIVE.equals(statusObj)){
  341. uncompleteCount ++;
  342. }
  343. }
  344. result.setCompleteCount(completeCount);
  345. result.setUncompleteCount(uncompleteCount);
  346. sql = "SELECT t1.city_in,SUM(t1.total_amount) AS total_amount FROM billing_reimbursement t1" +
  347. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  348. " WHERE t2.current_state = 'COMPLETED'";
  349. if(startTime != null && endTime != null){
  350. sql += " and t1.aply_time between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  351. }
  352. sql += " group by t1.city_in ";
  353. list = SqlRunnerAdapter.db().selectList(sql);
  354. List<ItemCountAmountVo> amountList = new ArrayList<>();
  355. for (Map<String, Object> objectMap : list) {
  356. Object cityInObj = objectMap.get("city_in");
  357. String item = "";
  358. if(cityInObj != null && Integer.parseInt(cityInObj.toString()) == 1){
  359. item = "市外";
  360. }else if(cityInObj != null && Integer.parseInt(cityInObj.toString()) == 0){
  361. item = "室内";
  362. }
  363. ItemCountAmountVo amountVo = new ItemCountAmountVo();
  364. amountVo.setItem(item);
  365. amountVo.setAmount(Double.parseDouble(objectMap.get("total_amount").toString()));
  366. amountList.add(amountVo);
  367. }
  368. result.setAmountList(amountList);
  369. return RT.ok(result);
  370. }
  371. @GetMapping(value = "/repair-statistics")
  372. @ApiOperation(value="维修申报")
  373. @SaCheckPermission("databoard:detail")
  374. public RT<RepairStatisticsVo> repairStatistics(@Valid StatisticsDetailDto dto){
  375. LocalDateTime startTime = null;
  376. LocalDateTime endTime = null;
  377. if(dto.getStartDate() != null){
  378. startTime = dto.getStartDate().atStartOfDay();
  379. }
  380. if(dto.getEndDate() != null){
  381. endTime = dto.getEndDate().atStartOfDay().plusDays(1).plusNanos(-1);
  382. }
  383. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  384. RepairStatisticsVo result = new RepairStatisticsVo();
  385. String sql = "SELECT t1.is_artificial,t2.current_state FROM wf_repair_declaration t1" +
  386. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  387. " WHERE 1 = 1 ";
  388. if(startTime != null && endTime != null){
  389. sql += " and t1.application_time between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  390. }
  391. List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
  392. result.setAllCount(list.size());
  393. int completeCount = 0;
  394. int uncompleteCount = 0;
  395. int personCount = 0;
  396. for (Map<String, Object> objectMap : list) {
  397. Object statusObj = objectMap.get("current_state");
  398. if(HistoricProcessInstance.STATE_COMPLETED.equals(statusObj.toString())){
  399. completeCount ++;
  400. }else{
  401. uncompleteCount ++;
  402. }
  403. if(objectMap.get("is_artificial") != null && "是".equals(objectMap.get("is_artificial").toString())){
  404. personCount ++;
  405. }
  406. }
  407. result.setCompleteCount(completeCount);
  408. result.setUncompleteCount(uncompleteCount);
  409. result.setPersonCount(personCount);
  410. sql = "SELECT ifnull(SUM(t1.indemnity), 0) as indemnity FROM wf_repair_declaration t1" +
  411. " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
  412. " WHERE t2.current_state = 'COMPLETED'";
  413. list = SqlRunnerAdapter.db().selectList(sql);
  414. result.setTotalAmount(Double.parseDouble(list.get(0).get("indemnity").toString()));
  415. return RT.ok(result);
  416. }
  417. @GetMapping(value = "/attendance-statistics")
  418. @ApiOperation(value="个人考勤")
  419. @SaCheckPermission("databoard:detail")
  420. public RT<AttendanceStatisticsVo> attendanceStatistics(@Valid StatisticsDetailDto dto){
  421. if(dto.getUserId() == null){
  422. dto.setUserId(StpUtil.getLoginIdAsLong());
  423. }
  424. LocalDateTime startTime = null;
  425. LocalDateTime endTime = null;
  426. if(dto.getStartDate() != null){
  427. startTime = dto.getStartDate().atStartOfDay();
  428. }
  429. if(dto.getEndDate() != null){
  430. endTime = dto.getEndDate().atStartOfDay().plusDays(1).plusNanos(-1);
  431. }
  432. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  433. AttendanceStatisticsVo result = new AttendanceStatisticsVo();
  434. String sql = " SELECT ifnull(sum(t1.leave_days), 0) as leave_days FROM wf_teacherleave t1" +
  435. " INNER JOIN xjr_workflow_form_relation t2 ON t2.form_key_value = t1.id" +
  436. " WHERE t2.current_state = 'COMPLETED'";
  437. if(startTime != null && endTime != null){
  438. String startTimeStr = startTime.format(formatter);
  439. String endTimeStr = endTime.format(formatter);
  440. sql +=" AND (" +
  441. " (t1.leave_start_time BETWEEN '" + startTimeStr + "' and '" + endTimeStr + "')" +
  442. " OR (t1.leave_end_time BETWEEN '" + startTimeStr + "' and '" + endTimeStr + "')" +
  443. " OR (t1.leave_start_time > '" + startTimeStr + "' and '" + endTimeStr + "' > t1.leave_end_time)" +
  444. " OR ('" + startTimeStr + "' > t1.leave_start_time and t1.leave_end_time > '" + endTimeStr + "')" +
  445. " )";
  446. }
  447. if(dto.getUserId() != null){
  448. sql += " and user_id = " + dto.getUserId();
  449. }
  450. List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
  451. result.setLeaveDays(Double.parseDouble(list.get(0).get("leave_days").toString()));
  452. sql = "SELECT * FROM teacher_attendance_record WHERE delete_mark = 0 and attendance_status = '迟到'";
  453. formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  454. if(startTime != null && endTime != null){
  455. sql +=" AND attendance_date between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  456. }
  457. if(dto.getUserId() != null){
  458. sql += " and user_id = " + dto.getUserId();
  459. }
  460. list = SqlRunnerAdapter.db().selectList(sql);
  461. result.setLateCount(list.size());
  462. sql = "SELECT COUNT(t1.id) AS a_count FROM wf_course_adjust t1" +
  463. " INNER JOIN xjr_workflow_form_relation t2 ON t2.form_key_value = t1.id" +
  464. " WHERE t1.adjust_type = 'course_exchange'" +
  465. " AND t2.current_state = 'COMPLETED'" +
  466. " and t1.delete_mark = 0 and t1.enabled_mark = 1";
  467. if(startTime != null && endTime != null){
  468. sql +=" AND t1.adjust_date between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  469. }
  470. if(dto.getUserId() != null){
  471. sql += " and (t1.user_id = " + dto.getUserId() + " or t1.exchange_teacher_id = '" + dto.getUserId() + "')";
  472. }
  473. list = SqlRunnerAdapter.db().selectList(sql);
  474. result.setAdjustCount(Integer.parseInt(list.get(0).get("a_count").toString()));
  475. sql = "SELECT t1.* FROM wf_course_adjust t1" +
  476. " INNER JOIN xjr_workflow_form_relation t2 ON t2.form_key_value = t1.id" +
  477. " WHERE t1.adjust_type = 'course_substitute'" +
  478. " AND t2.current_state = 'COMPLETED'" +
  479. " and t1.delete_mark = 0 and t1.enabled_mark = 1";
  480. if(startTime != null && endTime != null){
  481. sql +=" AND t1.adjust_date between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  482. }
  483. if(dto.getUserId() != null){
  484. sql += " and t1.user_id = " + dto.getUserId();
  485. }
  486. list = SqlRunnerAdapter.db().selectList(sql);
  487. int subCount = list.size();
  488. sql = "SELECT t1.* FROM wf_course_adjust t1" +
  489. " INNER JOIN xjr_workflow_form_relation t2 ON t2.form_key_value = t1.id" +
  490. " WHERE t1.adjust_type = 'course_substitute'" +
  491. " AND t2.current_state = 'COMPLETED'" +
  492. " and t1.delete_mark = 0 and t1.enabled_mark = 1";
  493. if(startTime != null && endTime != null){
  494. sql +=" AND t1.adjust_date between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
  495. }
  496. if(dto.getUserId() != null){
  497. sql += " and t1.exchange_teacher_id = " + dto.getUserId();
  498. }
  499. list = SqlRunnerAdapter.db().selectList(sql);
  500. int addCount = list.size();
  501. result.setExchangeCount(addCount - subCount);
  502. List<CourseTable> courseList = courseTableService.list(
  503. new QueryWrapper<CourseTable>().lambda()
  504. .like(CourseTable::getTeacherId, dto.getUserId())
  505. .between(dto.getStartDate() != null && dto.getEndDate() != null, CourseTable::getScheduleDate, dto.getStartDate(), dto.getEndDate())
  506. );
  507. result.setCourseCount(courseList.size());
  508. return RT.ok(result);
  509. }
  510. }