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.BisInspAllRlationPers; import cn.com.goldenwater.dcproj.model.BisInspMtprggd; import cn.com.goldenwater.dcproj.model.BisInspPlanDp; import cn.com.goldenwater.dcproj.model.BisInspPlanYear; import cn.com.goldenwater.dcproj.model.BisInspPlanYearPrg; import cn.com.goldenwater.dcproj.param.BisInspPlanDpParam; import cn.com.goldenwater.dcproj.param.BisInspPlanYearParam; import cn.com.goldenwater.dcproj.param.BisInspPlanYearPrgParam; import cn.com.goldenwater.dcproj.param.BisInspPlandpRlParam; import cn.com.goldenwater.dcproj.service.*; import cn.com.goldenwater.dcproj.util.ReadExcelUtil; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import cn.com.goldenwater.dcproj.utils.Constant; 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.util.Assert; 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.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; /** * @author lhc * @date 2022-3-3 */ @Api(value = "山东年度计划管理", tags = "山东年度计划管理") @RestController @RequestMapping("/bis/insp/plan/year") public class BisInspPlanYearController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private BisInspPlanYearService bisInspPlanYearService; @Autowired private BisInspPlanYearPrgService bisInspPlanYearPrgService; @Autowired private BisInspMtprggdService mtprggdService; @Autowired private BisInspMtprggdService bisInspMtprggdService; @Autowired private OlBisInspOrgService olBisInspOrgService; @Autowired private BisInspPlandpRlService bisInspPlandpRlService; @Autowired private BisInspAllRlationPersService bisInspAllRlationPersService; @Autowired private BisInspPlanDpService bisInspPlanDpService; private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); @Value("${export.templatePath}") private String templatePath; @ApiOperation(value = "添加山东年度计划") @RequestMapping(value = "/", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "bisInspPlanYear", value = "BisInspPlanYear", required = true) @RequestBody BisInspPlanYear bisInspPlanYear) { bisInspPlanYear.setOrgId(getCurrentOrgId()); String addvcd = AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())); if (StringUtils.isBlank(bisInspPlanYear.getId())) { bisInspPlanYear.setAdCode(olBisInspOrgService.getRlProvince(getCurrentOrgId())); bisInspPlanYear.setPersId(getCurrentPersId()); bisInspPlanYearService.insert(bisInspPlanYear); } else { bisInspPlanYearService.update(bisInspPlanYear); } //山东 if (StringUtils.equalsAny(addvcd, "37")) { bisInspPlanYearService.updatePostProcessing(bisInspPlanYear); } return buildSuccessResponse(bisInspPlanYear); } @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 = bisInspPlanYearService.delete(id); return buildSuccessResponse(); } @ApiOperation(value = "更新山东年度计划信息") @RequestMapping(value = "/update", method = RequestMethod.POST) public BaseResponse update(@ApiParam(name = "bisInspPlanYear", value = "BisInspPlanYear", required = true) @RequestBody BisInspPlanYear bisInspPlanYear) { Assert.notNull(bisInspPlanYear.getId(), "主键id为必填参数"); int ret = bisInspPlanYearService.update(bisInspPlanYear); return buildSuccessResponse(bisInspPlanYear); } @ApiOperation(value = "更新山东年度计划信息") @RequestMapping(value = "/bingObjType", method = RequestMethod.POST) public BaseResponse bingObjType(@ApiParam(name = "bisInspPlanYear", value = "BisInspPlanYear", required = true) @RequestBody BisInspPlanYear bisInspPlanYear) { Assert.notNull(bisInspPlanYear.getId(), "主键id为必填参数"); String curentOrgId = getCurrentOrgId(); bisInspPlanYear.setOrgId(curentOrgId); int ret = bisInspPlanYearService.bingObjType(bisInspPlanYear); return buildSuccessResponse(bisInspPlanYear); } @ApiOperation(value = "根据ID获取山东年度计划(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { BisInspPlanYear bisInspPlanYear = bisInspPlanYearService.get(id); if (Objects.nonNull(bisInspPlanYear)) { String addvcd = AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())); //山东 if (StringUtils.equalsAny(addvcd,"37")){ //参加处室单位 ids List planDpIdList = bisInspPlandpRlService.findByPlanDpIdList(new BisInspPlandpRlParam(id, Constant.STRING_ZERO)); bisInspPlanYear.setPlanDpRlIds(planDpIdList); //参加处室单位 names List dpList = bisInspPlanDpService.findList(new BisInspPlanDpParam(addvcd)); bisInspPlanYear.setJoinDep(dpList.stream().filter(dp -> planDpIdList.contains(dp.getId())).map(BisInspPlanDp::getDpName).collect(Collectors.joining(","))); } } return buildSuccessResponse(bisInspPlanYear); } @ApiOperation(value = "获取列 表(分页)") @RequestMapping(value = "findPageList", method = RequestMethod.POST) public BaseResponse> findPageList(@ApiParam(name = "BisInspPlanYearPrgParam", value = "BisInspPlanYearPrgParam", required = true) @RequestBody BisInspPlanYearParam bisInspPlanYearParam, HttpServletResponse response) { bisInspPlanYearParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()))); BisInspAllRlationPers byId = bisInspAllRlationPersService.getById(getCurrentPersId()); //山东 if (StringUtils.equalsAny(bisInspPlanYearParam.getAdCode(),"37")){ bisInspPlanYearParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId()))); String planDpId = byId.getPlanDpId(); if (StringUtils.isBlank(planDpId)){ return buildSuccessResponse(new PageInfo<>()); } Optional.ofNullable(bisInspPlanDpService.get(planDpId)).ifPresent(dp ->{ if (!StringUtils.equals(Constant.STRING_TWO,dp.getDpType())){ bisInspPlanYearParam.setPlanDpId(dp.getId()); } }); } PageInfo bisInspPlanYearPageInfo = bisInspPlanYearService.findPageList(bisInspPlanYearParam); return buildSuccessResponse(bisInspPlanYearPageInfo); } @ApiOperation(value = "获取列表") @RequestMapping(value = "findList", method = RequestMethod.POST) public BaseResponse> findList(@ApiParam(name = "BisInspPlanYearPrgParam", value = "BisInspPlanYearPrgParam", required = true) @RequestBody BisInspPlanYearParam bisInspPlanYearParam, HttpServletResponse response) { bisInspPlanYearParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()))); BisInspAllRlationPers byId = bisInspAllRlationPersService.getById(getCurrentPersId()); //山东 if (StringUtils.equalsAny(bisInspPlanYearParam.getAdCode(),"37")){ String planDpId = byId.getPlanDpId(); if (StringUtils.isBlank(planDpId)){ return buildSuccessResponse(new ArrayList<>()); } Optional.ofNullable(bisInspPlanDpService.get(planDpId)).ifPresent(dp ->{ if (!StringUtils.equals(Constant.STRING_TWO,dp.getDpType())){ bisInspPlanYearParam.setPlanDpId(dp.getId()); } }); } List bisInspPlanYearPageInfo = bisInspPlanYearService.findList(bisInspPlanYearParam); return buildSuccessResponse(bisInspPlanYearPageInfo); } @ApiOperation(value = "获取列表") @RequestMapping(value = "findListByMonth", method = RequestMethod.POST) public BaseResponse findListByMonth(@ApiParam(name = "BisInspPlanYearPrgParam", value = "BisInspPlanYearPrgParam", required = true) @RequestBody BisInspPlanYearPrgParam bisInspPlanYearPrgParam, HttpServletResponse response) { bisInspPlanYearPrgParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()))); if ("37".equals(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())))) { List list = bisInspPlanYearPrgService.findListByMonth(bisInspPlanYearPrgParam); return buildSuccessResponse(list); } else { List list = bisInspMtprggdService.findListByMonth(bisInspPlanYearPrgParam); return buildSuccessResponse(list); } } @ApiOperation(value = "导出检查表") @RequestMapping(value = "/exportMonth", method = RequestMethod.POST) public void export(HttpServletResponse response, @RequestBody BisInspPlanYearPrgParam bisInspPlanYearPrgParam) { bisInspPlanYearPrgParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()))); if ("37".equals(bisInspPlanYearPrgParam.getAdCode())) { bisInspPlanYearPrgParam.setOrgId(getCurrentOrgId()); bisInspPlanYearPrgService.export(response, bisInspPlanYearPrgParam, "1"); } else { mtprggdService.exportMonth(response, null, bisInspPlanYearPrgParam, "1"); } } @ApiOperation("获取导入模板") @GetMapping(value = "/getExl") public BaseResponse getExl(HttpServletResponse response) { String path = templatePath + File.separator + "planCheckSd.xls"; try { ExpAndImpUtil.downloadFile(response, path, "年度检查表"); } catch (Exception e) { logger.error(e.getMessage(), e); } return buildSuccessResponse(); } @ApiOperation(value = "导出检查表") @RequestMapping(value = "/export", method = RequestMethod.POST) public void export(HttpServletResponse response, @RequestBody BisInspPlanYearParam bisInspPlanYearParam) { bisInspPlanYearParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()))); bisInspPlanYearService.export(response, bisInspPlanYearParam); } @ApiOperation("上传 xls 导入数据") @RequestMapping(value = "/impExl", method = RequestMethod.POST) public BaseResponse> 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 map = new HashMap<>(2); int shu = 0; int success = 0; String[][] data = ReadExcelUtil.getData(file, 3); try { if (data != null && data.length > 0) { for (int i = 0; i < data.length; i++) { BisInspPlanYear bisInspPlanYear = new BisInspPlanYear(); bisInspPlanYear.setChkName(data[i][1]); bisInspPlanYear.setChkType(data[i][2]); bisInspPlanYear.setPlanSttm(simpleDateFormat.parse(data[i][3])); bisInspPlanYear.setPlanEntm(simpleDateFormat.parse(data[i][4])); bisInspPlanYear.setLeadDep(data[i][5]); bisInspPlanYear.setJoinDep(data[i][6]); bisInspPlanYear.setChkForm(data[i][7]); bisInspPlanYear.setChkScope(data[i][8]); bisInspPlanYear.setChkRly(data[i][9]); bisInspPlanYear.setNote(data[i][10]); insert(bisInspPlanYear); success++; } } } catch (Exception e) { shu++; logger.error(e.getMessage(), e); } map.put("false", shu); map.put("success", success); return buildSuccessResponse(map); } }