AomengAppointmentController.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /**
  2. *
  3. */
  4. package com.alldream.manage.controller;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import javax.servlet.http.HttpServletRequest;
  10. import com.alldream.manage.annotation.AomengHandleLogAnnotation;
  11. import org.apache.commons.lang.StringUtils;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.http.HttpStatus;
  16. import org.springframework.http.ResponseEntity;
  17. import org.springframework.stereotype.Controller;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RequestMethod;
  20. import org.springframework.web.bind.annotation.RequestParam;
  21. import org.springframework.web.bind.annotation.ResponseBody;
  22. import org.springframework.web.multipart.commons.CommonsMultipartFile;
  23. import com.alldream.manage.bean.AomengAdmin;
  24. import com.alldream.manage.bean.AomengAppointment;
  25. import com.alldream.manage.bean.AomengStudent;
  26. import com.alldream.manage.bean.vo.AomengAppointmentVo;
  27. import com.alldream.manage.common.utils.Constant;
  28. import com.alldream.manage.common.utils.OSSUtil;
  29. import com.alldream.manage.exception.BusinessException;
  30. import com.alldream.manage.service.AomengAppointmentService;
  31. import com.alldream.manage.service.AomengStudentService;
  32. import com.github.pagehelper.PageInfo;
  33. /**
  34. * @author Administrator
  35. *
  36. */
  37. @Controller
  38. @RequestMapping("appointment")
  39. public class AomengAppointmentController extends BaseController {
  40. private static final Logger LOGGER = LoggerFactory
  41. .getLogger(AomengAppointmentController.class);
  42. @Autowired
  43. private AomengAppointmentService aomengAppointmentService;
  44. @Autowired
  45. private AomengStudentService aomengStudentService;
  46. private String validate(AomengAppointment appointment,
  47. CommonsMultipartFile picture, String oper) throws BusinessException {
  48. if (null == appointment) {
  49. return "获取预约信息失败";
  50. }
  51. if (StringUtils.isBlank(appointment.getAppointmentName())) {
  52. return "预约名称不能为空";
  53. }
  54. if ("add".equals(oper)) {
  55. appointment.setId(createUUID());
  56. }
  57. if (picture != null && !picture.isEmpty()) {
  58. // 保存
  59. try {
  60. String fileName = Constant.OSS_PICTURE
  61. + "/"
  62. + appointment.getId()
  63. + picture.getOriginalFilename().substring(
  64. picture.getOriginalFilename().lastIndexOf("."));
  65. appointment.setPictureUrl(fileName);
  66. // 上传到oss
  67. OSSUtil.uploadFile(fileName, picture.getInputStream(),
  68. picture.getSize());
  69. } catch (Exception e) {
  70. e.printStackTrace();
  71. }
  72. }
  73. return null;
  74. }
  75. @RequestMapping(value = "edit", produces = "application/json; charset=utf-8")
  76. @ResponseBody
  77. @AomengHandleLogAnnotation(description = "编辑预约信息")
  78. public Object editCourseCatagory(
  79. @RequestParam(value = "oper", required = true) String oper,
  80. @RequestParam(required = false) CommonsMultipartFile picture,
  81. AomengAppointment appointment, HttpServletRequest request) {
  82. if (StringUtils.isNotBlank(oper)) {
  83. try {
  84. if ("del".equals(oper)) {
  85. // 删除操作
  86. List<Object> idlist = getDeleteIds(appointment.getId());
  87. for (Object id : idlist) {
  88. Map<String, Object> param = new HashMap<String, Object>();
  89. param.put("appointmentId", id);
  90. PageInfo<AomengStudent> pageInfo = aomengStudentService
  91. .queryStudentAppointmentByPage(1, 1, param);
  92. if (pageInfo != null && pageInfo.getTotal() > 0) {
  93. return error("已有学生预约,无法删除");
  94. } else {
  95. aomengAppointmentService.deleteById(id);
  96. }
  97. }
  98. return success("删除成功");
  99. } else {
  100. String msg = validate(appointment, picture, oper);
  101. if (StringUtils.isNotBlank(msg)) {
  102. return error(msg);
  103. }
  104. AomengAdmin user = (AomengAdmin) request.getSession()
  105. .getAttribute("user");
  106. if ("add".equals(oper)) {
  107. // 添加操作
  108. appointment.setCreateTime(new Date());
  109. appointment.setCreateName(user.getName());
  110. appointment.setUpdateTime(new Date());
  111. appointment.setUpdateName(user.getName());
  112. aomengAppointmentService.insert(appointment);
  113. return success(msg);
  114. } else if ("edit".equals(oper)) {
  115. // 编辑操作
  116. appointment.setUpdateTime(new Date());
  117. appointment.setUpdateName(user.getName());
  118. aomengAppointmentService.updateSelective(appointment);
  119. return success(msg);
  120. }
  121. }
  122. } catch (Exception e) {
  123. e.printStackTrace();
  124. LOGGER.error(oper + "[预约]" + e.getMessage());
  125. return error(e.getMessage());
  126. }
  127. }
  128. return error("系统内部错误");
  129. }
  130. @RequestMapping(value = "list", method = RequestMethod.GET)
  131. public ResponseEntity<PageInfo<AomengAppointmentVo>> listCourseCatagory(
  132. String name, String student, String teacher, String studentId,
  133. @RequestParam(value = "page", defaultValue = "1") Integer page,
  134. @RequestParam(value = "rows", defaultValue = "10") int rows) {
  135. try {
  136. Map<String, Object> param = new HashMap<String, Object>();
  137. if (StringUtils.isNotBlank(name)) {
  138. param.put("name", "%" + name + "%");
  139. }
  140. if (StringUtils.isNotBlank(student)) {
  141. param.put("student", "%" + student + "%");
  142. }
  143. if (StringUtils.isNotBlank(studentId)) {
  144. param.put("studentId", studentId);
  145. }
  146. if (StringUtils.isNotBlank(teacher)) {
  147. param.put("teacher", teacher);
  148. }
  149. PageInfo<AomengAppointmentVo> pageInfo = aomengAppointmentService
  150. .queryByPage(page, rows, param);
  151. return ResponseEntity.ok(pageInfo);
  152. } catch (Exception e) {
  153. e.printStackTrace();
  154. LOGGER.error("查询预约列表失败!");
  155. }
  156. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(
  157. null);
  158. }
  159. @RequestMapping(value = "get", method = RequestMethod.GET)
  160. @ResponseBody
  161. public Object getById(@RequestParam(value = "id", required = true) String id) {
  162. AomengAppointmentVo app = null;
  163. try {
  164. app = aomengAppointmentService.queryVoById(id);
  165. } catch (Exception e) {
  166. e.printStackTrace();
  167. LOGGER.error("查询预约列表失败!");
  168. return error(e.getMessage());
  169. }
  170. return success(app);
  171. }
  172. @RequestMapping(value = "studentapp", method = RequestMethod.GET)
  173. @ResponseBody
  174. public Object getStudentAppointment(HttpServletRequest request,
  175. String appName, String teacheName, String teacherId,
  176. String courseType, String studentName, String studentId,
  177. @RequestParam(value = "page", defaultValue = "1") Integer page,
  178. @RequestParam(value = "rows", defaultValue = "10") int rows) {
  179. PageInfo<AomengAppointmentVo> pageInfo = null;
  180. try {
  181. Map<String, Object> param = new HashMap<String, Object>();
  182. if (StringUtils.isNotBlank(courseType)) {
  183. param.put("courseType", courseType);
  184. }
  185. if (StringUtils.isNotBlank(studentId)) {
  186. param.put("studentId", studentId);
  187. }
  188. if (StringUtils.isNotBlank(teacherId)) {
  189. param.put("teacher", teacherId);
  190. }
  191. if (StringUtils.isNotBlank(appName)) {
  192. param.put("name", "%" + appName + "%");
  193. }
  194. if (StringUtils.isNotBlank(studentName)) {
  195. param.put("student", "%" + studentName + "%");
  196. }
  197. if (StringUtils.isNotBlank(teacheName)) {
  198. param.put("teacheName", "%" + teacheName + "%");
  199. }
  200. pageInfo = aomengAppointmentService.queryByPage(page, rows, param);
  201. } catch (Exception e) {
  202. e.printStackTrace();
  203. LOGGER.error("查询预约列表失败!");
  204. return error(e.getMessage());
  205. }
  206. return success(pageInfo);
  207. }
  208. }