LocationEndPoint.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.yihu.ehr.basic.emergency.controller;
  2. import com.yihu.ehr.basic.emergency.service.AmbulanceService;
  3. import com.yihu.ehr.basic.emergency.service.LocationService;
  4. import com.yihu.ehr.constants.ApiVersion;
  5. import com.yihu.ehr.constants.ServiceApi;
  6. import com.yihu.ehr.controller.EnvelopRestEndPoint;
  7. import com.yihu.ehr.entity.emergency.Ambulance;
  8. import com.yihu.ehr.entity.emergency.Location;
  9. import com.yihu.ehr.util.rest.Envelop;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import io.swagger.annotations.ApiParam;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.http.MediaType;
  15. import org.springframework.web.bind.annotation.*;
  16. import java.util.List;
  17. /**
  18. * EndPoint - 待命地点
  19. * Created by progr1mmer on 2017/11/22.
  20. */
  21. @RestController
  22. @RequestMapping(ApiVersion.Version1_0)
  23. @Api(value = "LocationEndPoint", description = "待命地点", tags = {"应急指挥-待命地点"})
  24. public class LocationEndPoint extends EnvelopRestEndPoint {
  25. @Autowired
  26. private LocationService locationService;
  27. @Autowired
  28. private AmbulanceService ambulanceService;
  29. @RequestMapping(value = ServiceApi.Emergency.LocationList, method = RequestMethod.GET)
  30. @ApiOperation("获取待命地点列表")
  31. public Envelop list(
  32. @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
  33. @RequestParam(value = "fields", required = false) String fields,
  34. @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
  35. @RequestParam(value = "filters", required = false) String filters,
  36. @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
  37. @RequestParam(value = "sorts", required = false) String sorts,
  38. @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
  39. @RequestParam(value = "page") int page,
  40. @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
  41. @RequestParam(value = "size") int size) throws Exception {
  42. List<Location> locations = locationService.search(fields, filters, sorts, page, size);
  43. int count = (int)locationService.getCount(filters);
  44. Envelop envelop = getPageResult(locations, count, page, size);
  45. return envelop;
  46. }
  47. @RequestMapping(value = ServiceApi.Emergency.LocationSave, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  48. @ApiOperation("保存单条记录")
  49. public Envelop save(
  50. @ApiParam(name = "location", value = "待命地点")
  51. @RequestBody String location) throws Exception {
  52. Location newLocation = objectMapper.readValue(location, Location.class);
  53. Location location1 = locationService.save(newLocation);
  54. return success(location1);
  55. }
  56. @RequestMapping(value = ServiceApi.Emergency.LocationUpdate, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  57. @ApiOperation("更新单条记录")
  58. public Envelop update(
  59. @ApiParam(name = "location", value = "排班")
  60. @RequestBody String location) throws Exception {
  61. Location newLocation = objectMapper.readValue(location, Location.class);
  62. Location oldLocation = locationService.findById(newLocation.getId());
  63. if (oldLocation == null) {
  64. return failed("无相关待命地点记录");
  65. }
  66. Location location1 = locationService.save(newLocation);
  67. return success(location1);
  68. }
  69. @RequestMapping(value = ServiceApi.Emergency.LocationDelete, method = RequestMethod.DELETE)
  70. @ApiOperation("删除待命地点")
  71. public Envelop delete(
  72. @ApiParam(name = "ids", value = "id列表(int)1,2,3,...")
  73. @RequestParam(value = "ids") String ids) throws Exception {
  74. //List<Integer> idList = toEntity(ids, List.class);
  75. List<Ambulance> ambulanceList = ambulanceService.search("location=" + ids);
  76. if (ambulanceList == null || ambulanceList.size() > 0) {
  77. return failed("不能删除已有关联车辆的待命地点");
  78. }
  79. String [] idArrStr = ids.split(",");
  80. Integer [] idArrInt = new Integer[idArrStr.length];
  81. for (int i = 0; i < idArrStr.length; i++) {
  82. idArrInt[i] = new Integer(idArrStr[i]);
  83. }
  84. locationService.delete(idArrInt);
  85. return success(true);
  86. }
  87. }