package cn.com.goldenwater.dcproj.controller.accunt; import cn.com.goldenwater.dcproj.model.BisInspAccunt; import cn.com.goldenwater.dcproj.model.BisInspMtprggd; import cn.com.goldenwater.dcproj.param.BisInspAccuntParam; import cn.com.goldenwater.dcproj.service.BisInspAccuntService; 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.id.util.UuidUtil; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; 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; /** * @author lhc * @date 2022-3-17 */ @Api(value = "整改追责管理", tags = "整改追责管理") @RestController @RequestMapping("/bis/insp/accunt") public class BisInspAccuntController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private BisInspAccuntService bisInspAccuntService; @Autowired private OlBisInspOrgService olBisInspOrgService; @Value("${export.templatePath}") String excelFilePath; @ApiOperation(value = "添加整改追责") @RequestMapping(value = "/", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "bisInspAccunt", value = "BisInspAccunt", required = true) @RequestBody BisInspAccunt bisInspAccunt) { if (StringUtils.isBlank(bisInspAccunt.getId())) { bisInspAccunt.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId())); bisInspAccunt.setOrgId(getCurrentOrgId()); bisInspAccunt.setPersId(getCurrentPersId()); bisInspAccuntService.insert(bisInspAccunt); } else { bisInspAccuntService.update(bisInspAccunt); } return buildSuccessResponse(bisInspAccunt); } @ApiOperation(value = "批量更新") @RequestMapping(value = "/batch", method = RequestMethod.POST) public BaseResponse batch(@ApiParam(name = "bisInspAccunt", value = "BisInspAccunt", required = true) @RequestBody List bisInspAccunt) { bisInspAccuntService.batch(bisInspAccunt); return buildSuccessResponse(); } @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 = bisInspAccuntService.delete(id); return buildSuccessResponse(); } @ApiOperation(value = "更新整改追责信息") @RequestMapping(value = "/update", method = RequestMethod.POST) public BaseResponse update(@ApiParam(name = "bisInspAccunt", value = "BisInspAccunt", required = true) @RequestBody BisInspAccunt bisInspAccunt) { Assert.notNull(bisInspAccunt.getId(), "主键id为必填参数"); int ret = bisInspAccuntService.update(bisInspAccunt); return buildSuccessResponse(bisInspAccunt); } @ApiOperation(value = "根据ID获取整改追责(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { BisInspAccunt bisInspAccunt = bisInspAccuntService.get(id); return buildSuccessResponse(bisInspAccunt); } @ApiOperation(value = "获取列表数据") @RequestMapping(value = "/page", method = RequestMethod.POST) public BaseResponse findPcPage(@RequestBody BisInspAccuntParam bisInspAccuntParam) { bisInspAccuntParam.setProvince(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()))); bisInspAccuntParam.setOrgId(getCurrentOrgId()); PageInfo pageInfo = bisInspAccuntService.findPageInfo(bisInspAccuntParam); return buildSuccessResponse(pageInfo); } @ApiOperation(value = "导出追责表") @RequestMapping(value = "/export", method = RequestMethod.POST) public void export(HttpServletResponse response, @RequestBody BisInspAccuntParam bisInspAccuntParam) { bisInspAccuntService.export(response, bisInspAccuntParam); } @ApiOperation(value = "导入追责表") @RequestMapping(value = "/import", method = RequestMethod.POST) public BaseResponse> importFile(@RequestParam(value = "file") MultipartFile file) throws Exception { BisInspAccunt accunt = new BisInspAccunt(); accunt.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId())); accunt.setOrgId(getCurrentOrgId()); accunt.setPersId(getCurrentPersId()); List result = bisInspAccuntService.importFile(file, accunt); return buildSuccessResponse(result); } @ApiOperation(value = "下载Excel导入模板") @GetMapping("/downloadExcel") public void downExcelModel(HttpServletResponse response) throws Exception { InputStream inStream = new FileInputStream(excelFilePath + "/importBisInspAccunt.xls"); response.reset(); response.setContentType("application/octet-stream; charset=UTF-8"); response.setCharacterEncoding("utf-8"); response.addHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("追责导入模板.xls", "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(); } } }