2cf40096fb501f50aab962ca55db5c76e5ed731d.svn-base 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package cn.com.goldenwater.dcproj.controller.gdyjhtc;
  2. import cn.com.goldenwater.dcproj.model.BisInspPlanMonth;
  3. import cn.com.goldenwater.dcproj.param.BisInspPlanMonthParam;
  4. import cn.com.goldenwater.dcproj.service.BisInspPlanMonthService;
  5. import cn.com.goldenwater.core.web.BaseController;
  6. import cn.com.goldenwater.core.web.BaseResponse;
  7. import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
  8. import cn.com.goldenwater.dcproj.utils.AdLevelUtil;
  9. import cn.com.goldenwater.dcproj.utils.StringUtils;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import io.swagger.annotations.ApiParam;
  13. import org.slf4j.Logger;
  14. import org.slf4j.LoggerFactory;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.beans.factory.annotation.Value;
  17. import org.springframework.util.Assert;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import javax.servlet.http.HttpServletResponse;
  21. import java.io.FileInputStream;
  22. import java.io.IOException;
  23. import java.io.InputStream;
  24. import java.net.URLEncoder;
  25. import java.util.List;
  26. @Api(value = "广东月计划统筹",tags="广东月计划统筹")
  27. @RestController
  28. @RequestMapping("/bis/insp/planMonth")
  29. public class BisInspPlanMonthController extends BaseController {
  30. private Logger logger = LoggerFactory.getLogger(getClass());
  31. @Autowired
  32. private BisInspPlanMonthService bisInspPlanMonthService;
  33. @Autowired
  34. private OlBisInspOrgService olBisInspOrgService;
  35. @ApiOperation(value = "添加广东月计划统筹表")
  36. @RequestMapping(value = "/", method = RequestMethod.POST)
  37. public BaseResponse<BisInspPlanMonth> insert(@ApiParam(name = "bisInspPlanMonth", value = "BisInspPlanMonth", required = true) @RequestBody BisInspPlanMonth bisInspPlanMonth) {
  38. bisInspPlanMonth.setPersId(getCurrentPersId());
  39. bisInspPlanMonth.setAdCode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  40. if(StringUtils.isBlank(bisInspPlanMonth.getId())) {
  41. bisInspPlanMonthService.insert(bisInspPlanMonth);
  42. }
  43. else{
  44. bisInspPlanMonthService.update(bisInspPlanMonth);
  45. }
  46. return buildSuccessResponse(bisInspPlanMonth);
  47. }
  48. @ApiOperation(value = "根据ID删除广东月计划统筹表")
  49. @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
  50. public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  51. int ret = bisInspPlanMonthService.delete(id);
  52. return buildSuccessResponse();
  53. }
  54. @ApiOperation(value = "更新广东月计划统筹表")
  55. @RequestMapping(value = "/update", method = RequestMethod.POST)
  56. public BaseResponse<BisInspPlanMonth> update(@ApiParam(name = "bisInspPlanMonth", value = "BisInspPlanMonth", required = true) @RequestBody BisInspPlanMonth bisInspPlanMonth) {
  57. Assert.notNull(bisInspPlanMonth.getId(), "主键id为必填参数");
  58. int ret = bisInspPlanMonthService.update(bisInspPlanMonth);
  59. return buildSuccessResponse(bisInspPlanMonth);
  60. }
  61. @ApiOperation(value = "根据ID获取广东月计划统筹表(单表)")
  62. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  63. public BaseResponse<BisInspPlanMonth> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  64. BisInspPlanMonth bisInspPlanMonth = bisInspPlanMonthService.getOne(id);
  65. return buildSuccessResponse(bisInspPlanMonth);
  66. }
  67. @ApiOperation(value = "不分页查询")
  68. @PostMapping("/getPageInfo")
  69. public BaseResponse<List<BisInspPlanMonth>> getPageInfo(@RequestBody BisInspPlanMonthParam param) {
  70. param.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())));
  71. List<BisInspPlanMonth> select = bisInspPlanMonthService.getPageInfo(param);
  72. return buildSuccessResponse(select);
  73. }
  74. @ApiOperation(value = "导出excel")
  75. @PostMapping("/export")
  76. public void export(@RequestBody BisInspPlanMonthParam param, HttpServletResponse response) throws Exception {
  77. param.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())));
  78. bisInspPlanMonthService.export(param, response);
  79. }
  80. @Value("${export.templatePath}")
  81. String excelFilePath;
  82. @ApiOperation(value = "导入excel")
  83. @PostMapping("/import")
  84. public BaseResponse<List<String>> importExcel(MultipartFile file) throws Exception {
  85. String addvcd = AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  86. List<String> strings = bisInspPlanMonthService.importExcel(file, getCurrentOrgId(), addvcd);
  87. return buildSuccessResponse(strings);
  88. }
  89. @ApiOperation(value = "下载Excel导入模板")
  90. @GetMapping("/downloadExcel")
  91. public void downExcelModel(HttpServletResponse response) throws Exception {
  92. String addvcd = AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  93. String filePath;
  94. if ("37".equals(addvcd)) {
  95. filePath = excelFilePath + "/importPlanMonthSD.xls";
  96. } else {
  97. filePath = excelFilePath + "/importPlanMonth.xls";
  98. }
  99. InputStream inStream = new FileInputStream(filePath);
  100. response.reset();
  101. response.setContentType("application/octet-stream; charset=UTF-8");
  102. response.setCharacterEncoding("utf-8");
  103. response.addHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("月计划统筹导入模板.xlsx", "UTF-8"));
  104. byte[] b = new byte[4096];
  105. int len;
  106. try {
  107. while ((len = inStream.read(b)) > 0)
  108. response.getOutputStream().write(b, 0, len);
  109. inStream.close();
  110. } catch (IOException e) {
  111. e.printStackTrace();
  112. }
  113. }
  114. }