31bb8e25506a1a951468ace9452d72558097d7c4.svn-base 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package cn.com.goldenwater.dcproj.controller.rsfco;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.constValue.CommonLabel;
  5. import cn.com.goldenwater.dcproj.dto.BisInspRgstrDto;
  6. import cn.com.goldenwater.dcproj.model.BisInspRsfcoRgstr;
  7. import cn.com.goldenwater.dcproj.param.BisInspRsfcoRgstrParam;
  8. import cn.com.goldenwater.dcproj.param.FileParam;
  9. import cn.com.goldenwater.dcproj.param.TypeParam;
  10. import cn.com.goldenwater.dcproj.service.BisInspRsfcoRgstrService;
  11. import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
  12. import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
  13. import cn.com.goldenwater.dcproj.utils.impexcel.ImportExcel;
  14. import cn.com.goldenwater.dcproj.utils.impexcel.format.RsfcoFieldFromatImp;
  15. import cn.com.goldenwater.id.util.UuidUtil;
  16. import com.github.pagehelper.PageInfo;
  17. import io.swagger.annotations.Api;
  18. import io.swagger.annotations.ApiOperation;
  19. import io.swagger.annotations.ApiParam;
  20. import org.apache.commons.lang3.StringUtils;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.beans.factory.annotation.Value;
  25. import org.springframework.data.redis.core.RedisTemplate;
  26. import org.springframework.web.bind.annotation.*;
  27. import org.springframework.web.multipart.MultipartFile;
  28. import javax.servlet.http.HttpServletResponse;
  29. import java.io.IOException;
  30. import java.text.SimpleDateFormat;
  31. import java.util.Date;
  32. import java.util.LinkedHashMap;
  33. import java.util.List;
  34. import java.util.Map;
  35. import static cn.com.goldenwater.dcproj.utils.impexcel.ImpUtil.getDateFormatPath;
  36. /**
  37. * @author lune
  38. * @date 2020-4-21
  39. */
  40. @Api(value = "BIS 水库防洪调度督查登记表管理", tags = "BIS 水库防洪调度督查登记表管理")
  41. @RestController
  42. @RequestMapping("/bis/insp/rsfco/rgstr")
  43. public class BisInspRsfcoRgstrController extends BaseController {
  44. private Logger logger = LoggerFactory.getLogger(getClass());
  45. @Autowired
  46. private BisInspRsfcoRgstrService bisInspRsfcoRgstrService;
  47. @Autowired
  48. private OlBisInspOrgService olBisInspOrgService;
  49. @Autowired
  50. private RedisTemplate redisTemplate;
  51. @Value("${export.templatePath}")
  52. private String templatePath;
  53. @Value("${impExcel.basePath}")
  54. private String impExcelPath;
  55. @ApiOperation(value = "添加/修改水库防洪调度督查登记表")
  56. @RequestMapping(value = "", method = RequestMethod.POST)
  57. public BaseResponse<BisInspRsfcoRgstr> insert(@ApiParam(name = "bisInspRsfcoRgstr", value = "BisInspRsfcoRgstr", required = true) @RequestBody BisInspRsfcoRgstr bisInspRsfcoRgstr) {
  58. if (StringUtils.isNotBlank(bisInspRsfcoRgstr.getRgstrId()) && StringUtils.isBlank(bisInspRsfcoRgstr.getId())) {
  59. bisInspRsfcoRgstr.setId(bisInspRsfcoRgstr.getRgstrId());
  60. }
  61. if (StringUtils.isBlank(bisInspRsfcoRgstr.getId())) {
  62. bisInspRsfcoRgstr.setId(UuidUtil.uuid());
  63. bisInspRsfcoRgstrService.insert(bisInspRsfcoRgstr);
  64. } else {
  65. bisInspRsfcoRgstr.setUptm(new Date());
  66. bisInspRsfcoRgstrService.update(bisInspRsfcoRgstr);
  67. }
  68. return buildSuccessResponse(bisInspRsfcoRgstr);
  69. }
  70. @ApiOperation(value = "根据ID删除水库防洪调度督查登记表")
  71. @RequestMapping(value = "/del/{id}", method = RequestMethod.GET)
  72. public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  73. int ret = bisInspRsfcoRgstrService.delete(id);
  74. return buildSuccessResponse();
  75. }
  76. @ApiOperation(value = "根据ID获取水库防洪调度督查登记表(单表)")
  77. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  78. public BaseResponse<BisInspRsfcoRgstr> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  79. BisInspRsfcoRgstr bisInspRsfcoRgstr = bisInspRsfcoRgstrService.get(id);
  80. return buildSuccessResponse(bisInspRsfcoRgstr);
  81. }
  82. @ApiOperation(value = "获取水库防洪调度督查登记表(列表所有)")
  83. @RequestMapping(value = "/list", method = RequestMethod.POST)
  84. public BaseResponse<List<BisInspRsfcoRgstr>> list(@ApiParam(name = "bisInspRsfcoRgstrParam", value = "bisInspRsfcoRgstrParam", required = true) @RequestBody BisInspRsfcoRgstrParam bisInspRsfcoRgstrParam) {
  85. List<BisInspRsfcoRgstr> bisInspRsfcoRgstrList = bisInspRsfcoRgstrService.findList(bisInspRsfcoRgstrParam);
  86. return buildSuccessResponse(bisInspRsfcoRgstrList);
  87. }
  88. @ApiOperation(value = "获取水库防洪调度督查登记表(列表--分页)")
  89. @RequestMapping(value = "/page", method = RequestMethod.POST)
  90. public BaseResponse<PageInfo<BisInspRsfcoRgstr>> page(@ApiParam(name = "bisInspRsfcoRgstrParam", value = "bisInspRsfcoRgstrParam", required = true) @RequestBody BisInspRsfcoRgstrParam bisInspRsfcoRgstrParam) {
  91. PageInfo<BisInspRsfcoRgstr> bisInspRsfcoRgstrList = bisInspRsfcoRgstrService.findPageInfo(bisInspRsfcoRgstrParam);
  92. return buildSuccessResponse(bisInspRsfcoRgstrList);
  93. }
  94. @ApiOperation(value = "获取督查对象")
  95. @RequestMapping(value = "/findRsfcoPage", method = RequestMethod.POST)
  96. public BaseResponse<PageInfo<BisInspRgstrDto>> findSvwtWuntPage(@RequestBody TypeParam param, HttpServletResponse response) {
  97. param.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId()));
  98. if (StringUtils.isBlank(param.getTabType())) {
  99. param.setTabType(CommonLabel.TAB_TYPE);
  100. }
  101. String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
  102. param.setNowTime(nowTime);
  103. PageInfo<BisInspRgstrDto> pageInfo = bisInspRsfcoRgstrService.findRsfcoPage(param, response);
  104. return buildSuccessResponse(pageInfo);
  105. }
  106. @ApiOperation(value = "下载模板")
  107. @RequestMapping(value = "/downTemplate", method = {RequestMethod.GET, RequestMethod.POST})
  108. public BaseResponse downTemplate(HttpServletResponse response, TypeParam param) {
  109. try {
  110. bisInspRsfcoRgstrService.downloadTemplate(response, param);
  111. } catch (Exception e) {
  112. return buildFailResponse(e);
  113. }
  114. return buildSuccessResponse();
  115. }
  116. @ApiOperation(value = "上传模板")
  117. @RequestMapping(value = "/uploadTemplate", method = RequestMethod.POST)
  118. public BaseResponse uploadTemplate(MultipartFile file) {
  119. String filaPath = "";
  120. try {
  121. filaPath = ExpAndImpUtil.upload(file, getDateFormatPath(impExcelPath));
  122. } catch (Exception e) {
  123. return buildFailResponse(e);
  124. }
  125. return buildSuccessResponse(filaPath);
  126. }
  127. @ApiOperation(value = "解析文件上传数据")
  128. @RequestMapping(value = "/parseUpload", method = RequestMethod.POST)
  129. public BaseResponse<Map<String, Object>> parseUpload(FileParam param) {
  130. Map<String, Object> map = new LinkedHashMap<>();
  131. try {
  132. List<LinkedHashMap<String, Object>> list = ExpAndImpUtil.parseData(param.getPath(), param.getStartRow(), BisInspRgstrDto.class);
  133. if (list.size() > 0) {
  134. String uuid = UuidUtil.uuid();
  135. redisTemplate.opsForList().rightPushAll(uuid, list);
  136. map.put("dataId", uuid);
  137. }
  138. map.put("list", list);
  139. } catch (IOException e) {
  140. buildFailResponse(e.getMessage());
  141. }
  142. return buildSuccessResponse(map);
  143. }
  144. @ApiOperation(value = "文件数据入库")
  145. @RequestMapping(value = "/insertIntoData", method = RequestMethod.POST)
  146. public BaseResponse insertIntoData(FileParam param) {
  147. if (StringUtils.isBlank(param.getDataId())) {
  148. return buildFailResponse();
  149. }
  150. List<LinkedHashMap<String, Object>> list = redisTemplate.opsForList().range(param.getDataId(), 0, -1);
  151. redisTemplate.delete(param.getDataId());
  152. try {
  153. List<LinkedHashMap<String, Object>> showDataList = ImportExcel.getShowData(list, RsfcoFieldFromatImp.class);
  154. bisInspRsfcoRgstrService.insertIntoData(showDataList, param);
  155. } catch (Exception e) {
  156. return buildFailResponse();
  157. }
  158. return buildSuccessResponse();
  159. }
  160. }