package cn.com.goldenwater.dcproj.controller.gdyjhtc; import cn.com.goldenwater.dcproj.model.BisInspPlanMonth; import cn.com.goldenwater.dcproj.param.BisInspPlanMonthParam; import cn.com.goldenwater.dcproj.service.BisInspPlanMonthService; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.service.OlBisInspOrgService; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import cn.com.goldenwater.dcproj.utils.StringUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import java.util.List; @Api(value = "广东月计划统筹",tags="广东月计划统筹") @RestController @RequestMapping("/bis/insp/planMonth") public class BisInspPlanMonthController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private BisInspPlanMonthService bisInspPlanMonthService; @Autowired private OlBisInspOrgService olBisInspOrgService; @ApiOperation(value = "添加广东月计划统筹表") @RequestMapping(value = "/", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "bisInspPlanMonth", value = "BisInspPlanMonth", required = true) @RequestBody BisInspPlanMonth bisInspPlanMonth) { bisInspPlanMonth.setPersId(getCurrentPersId()); bisInspPlanMonth.setAdCode(olBisInspOrgService.getRlProvince(getCurrentOrgId())); if(StringUtils.isBlank(bisInspPlanMonth.getId())) { bisInspPlanMonthService.insert(bisInspPlanMonth); } else{ bisInspPlanMonthService.update(bisInspPlanMonth); } return buildSuccessResponse(bisInspPlanMonth); } @ApiOperation(value = "根据ID删除广东月计划统筹表") @RequestMapping(value = "delete/{id}", method = RequestMethod.POST) public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { int ret = bisInspPlanMonthService.delete(id); return buildSuccessResponse(); } @ApiOperation(value = "更新广东月计划统筹表") @RequestMapping(value = "/update", method = RequestMethod.POST) public BaseResponse update(@ApiParam(name = "bisInspPlanMonth", value = "BisInspPlanMonth", required = true) @RequestBody BisInspPlanMonth bisInspPlanMonth) { Assert.notNull(bisInspPlanMonth.getId(), "主键id为必填参数"); int ret = bisInspPlanMonthService.update(bisInspPlanMonth); return buildSuccessResponse(bisInspPlanMonth); } @ApiOperation(value = "根据ID获取广东月计划统筹表(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { BisInspPlanMonth bisInspPlanMonth = bisInspPlanMonthService.getOne(id); return buildSuccessResponse(bisInspPlanMonth); } @ApiOperation(value = "不分页查询") @PostMapping("/getPageInfo") public BaseResponse> getPageInfo(@RequestBody BisInspPlanMonthParam param) { param.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()))); List select = bisInspPlanMonthService.getPageInfo(param); return buildSuccessResponse(select); } @ApiOperation(value = "导出excel") @PostMapping("/export") public void export(@RequestBody BisInspPlanMonthParam param, HttpServletResponse response) throws Exception { param.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()))); bisInspPlanMonthService.export(param, response); } @Value("${export.templatePath}") String excelFilePath; @ApiOperation(value = "导入excel") @PostMapping("/import") public BaseResponse> importExcel(MultipartFile file) throws Exception { String addvcd = AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())); List strings = bisInspPlanMonthService.importExcel(file, getCurrentOrgId(), addvcd); return buildSuccessResponse(strings); } @ApiOperation(value = "下载Excel导入模板") @GetMapping("/downloadExcel") public void downExcelModel(HttpServletResponse response) throws Exception { String addvcd = AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())); String filePath; if ("37".equals(addvcd)) { filePath = excelFilePath + "/importPlanMonthSD.xls"; } else { filePath = excelFilePath + "/importPlanMonth.xls"; } InputStream inStream = new FileInputStream(filePath); response.reset(); response.setContentType("application/octet-stream; charset=UTF-8"); response.setCharacterEncoding("utf-8"); response.addHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("月计划统筹导入模板.xlsx", "UTF-8")); byte[] b = new byte[4096]; int len; try { while ((len = inStream.read(b)) > 0) response.getOutputStream().write(b, 0, len); inStream.close(); } catch (IOException e) { e.printStackTrace(); } } }