| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- package cn.com.goldenwater.dcproj.controller.ducha;
- import cn.com.goldenwater.core.web.BaseController;
- import cn.com.goldenwater.core.web.BaseResponse;
- import cn.com.goldenwater.dcproj.model.BisInspPlanChk;
- import cn.com.goldenwater.dcproj.param.BisInspPlanChkParam;
- import cn.com.goldenwater.dcproj.service.BisInspPlanChkService;
- import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
- import cn.com.goldenwater.dcproj.util.ReadExcelUtil;
- import cn.com.goldenwater.dcproj.utils.AdLevelUtil;
- import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
- 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.apache.poi.openxml4j.exceptions.InvalidFormatException;
- 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.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletResponse;
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.Paths;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * @author lhc
- * @date 2021-4-1
- */
- @Api(value = "年度计划方案-年度督查检查计划管理", tags = "年度计划方案-年度督查检查计划管理")
- @RestController
- @RequestMapping("/bis/insp/plan/chk")
- public class BisInspPlanChkController extends BaseController {
- private Logger logger = LoggerFactory.getLogger(getClass());
- @Value("${export.templatePath}")
- private String templatePath;
- @Autowired
- private BisInspPlanChkService bisInspPlanChkService;
- @Autowired
- private OlBisInspOrgService olBisInspOrgService;
- @ApiOperation(value = "修改年度计划方案-年度督查检查计划")
- @RequestMapping(value = "", method = RequestMethod.POST)
- public BaseResponse<BisInspPlanChk> insert(@ApiParam(name = "bisInspPlanChk", value = "BisInspPlanChk", required = true)
- @RequestBody BisInspPlanChk bisInspPlanChk) {
- int ret = 0;
- if (StringUtils.isBlank(bisInspPlanChk.getId())) {
- bisInspPlanChk.setAdCode(olBisInspOrgService.getProvince(getCurrentOrgId()));
- bisInspPlanChk.setPersId(getCurrentPersId());
- ret = bisInspPlanChkService.insert(bisInspPlanChk);
- } else {
- ret = bisInspPlanChkService.update(bisInspPlanChk);
- }
- return buildSuccessResponse(bisInspPlanChk);
- }
- @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 = bisInspPlanChkService.delete(id);
- return buildSuccessResponse();
- }
- @ApiOperation(value = "根据ID获取年度计划方案-年度督查检查计划(单表)")
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- public BaseResponse<BisInspPlanChk> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
- BisInspPlanChk bisInspPlanChk = bisInspPlanChkService.get(id);
- return buildSuccessResponse(bisInspPlanChk);
- }
- @ApiOperation(value = "根据ID获取年度计划方案-年度督查检查计划(单表)")
- @RequestMapping(value = "/listOfPage", method = RequestMethod.POST)
- public BaseResponse<PageInfo<BisInspPlanChk>> listOfPage(@ApiParam(name = "bisInspPlanChkcc", value = "bisInspPlanChkcc", required = true)
- @RequestBody BisInspPlanChkParam bisInspPlanChk) {
- bisInspPlanChk.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())));
- return buildSuccessResponse(bisInspPlanChkService.findPageInfo(bisInspPlanChk));
- }
- @ApiOperation(value = "导出检查表")
- @RequestMapping(value = "/export/checkList", method = RequestMethod.POST)
- public void exportCheckList(HttpServletResponse response, @RequestBody BisInspPlanChkParam bisInspPlanChkParam) {
- bisInspPlanChkService.exportCheckList(response, bisInspPlanChkParam);
- }
- @ApiOperation("获取导入模板")
- @GetMapping(value = "/getExl")
- public BaseResponse getExl(HttpServletResponse response) {
- String path = templatePath + File.separator + "chk_plan.xls";
- try {
- ExpAndImpUtil.downloadFile(response, path, "年度检查表");
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
- return buildSuccessResponse();
- }
- @ApiOperation("上传 xls 导入数据")
- @RequestMapping(value = "/impExl", method = RequestMethod.POST)
- public BaseResponse<Map<String, Object>> impExl(@RequestParam("file") MultipartFile multfile) throws IOException, InvalidFormatException {
- // 获取文件名
- String fileName = multfile.getOriginalFilename();
- // 获取文件后缀
- String prefix = fileName.substring(fileName.lastIndexOf("."));
- // 用uuid作为文件名,防止生成的临时文件重复
- String uuid = UuidUtil.uuid();
- File file = File.createTempFile(uuid, prefix);
- // MultipartFile to File
- multfile.transferTo(Paths.get(file.getPath()));
- Map<String, Object> map = new HashMap<>(2);
- int shu = 0;
- int success = 0;
- String[][] data = ReadExcelUtil.getData(file, 3);
- if (data.length > 0) {
- for (String[] datum : data) {
- if (StringUtils.isBlank(datum[1])) {
- continue;
- }
- try {
- BisInspPlanChk planChk = new BisInspPlanChk();
- planChk.setChkYear(Long.parseLong(datum[1]));
- planChk.setChkItem(datum[2]);
- planChk.setChkMatter(datum[3]);
- planChk.setChkBatch(datum[4]);
- planChk.setChkTm(datum[5]);
- planChk.setChkCity(datum[6]);
- planChk.setChkCounty(datum[7]);
- planChk.setChkContent(datum[8]);
- planChk.setChkDep(datum[9]);
- planChk.setChkType(datum[10]);
- insert(planChk);
- success++;
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- shu++;
- }
- }
- }
- map.put("false", shu);
- map.put("success", success);
- return buildSuccessResponse(map);
- }
- }
|