| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- package cn.com.goldenwater.dcproj.controller.plansd;
- import cn.com.goldenwater.core.web.BaseController;
- import cn.com.goldenwater.core.web.BaseResponse;
- import cn.com.goldenwater.dcproj.dto.BisInspPlanDtlDto;
- import cn.com.goldenwater.dcproj.model.BisInspAllRlationPers;
- import cn.com.goldenwater.dcproj.model.BisInspPlanDtl;
- import cn.com.goldenwater.dcproj.model.BisInspPlanDtlAddvcd;
- import cn.com.goldenwater.dcproj.model.BisInspPlanDtlPtyp;
- import cn.com.goldenwater.dcproj.param.BisInspPlanDtlAddvcdParam;
- import cn.com.goldenwater.dcproj.param.BisInspPlanDtlParam;
- import cn.com.goldenwater.dcproj.param.BisInspPlanDtlPtypParam;
- import cn.com.goldenwater.dcproj.param.BisInspPlandpRlParam;
- import cn.com.goldenwater.dcproj.service.*;
- import cn.com.goldenwater.dcproj.utils.AdLevelUtil;
- import cn.com.goldenwater.dcproj.utils.Constant;
- import cn.com.goldenwater.dcproj.utils.StringUtils;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import org.apache.commons.collections.CollectionUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.util.Assert;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletResponse;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- import java.util.Optional;
- import java.util.stream.Collectors;
- /**
- * @author hjp
- * @date 2022-8-9
- */
- @Api(value = "检查年度计划分解管理", tags = "检查年度计划分解管理")
- @RestController
- @RequestMapping("/bis/insp/plan/dtl")
- public class BisInspPlanDtlController extends BaseController {
- private Logger logger = LoggerFactory.getLogger(getClass());
- @Autowired
- private BisInspPlanDtlService bisInspPlanDtlService;
- @Autowired
- private BisInspPlanDtlAddvcdService bisInspPlanDtlAddvcdService;
- @Autowired
- private BisInspPlanDtlPtypService bisInspPlanDtlPtypService;
- @Autowired
- private BisInspPlandpRlService bisInspPlandpRlService;
- @Autowired
- private BisInspAllRlationPersService bisInspAllRlationPersService;
- @Autowired
- private BisInspPlanDpService bisInspPlanDpService;
- @Autowired
- private AttAdBaseService attAdBaseService;
- @Autowired
- private OlBisInspOrgService olBisInspOrgService;
- @ApiOperation(value = "添加检查年度计划分解")
- @RequestMapping(value = "/", method = RequestMethod.POST)
- public BaseResponse<BisInspPlanDtlDto> insert(@ApiParam(name = "BisInspPlanDtlDto", value = "BisInspPlanDtlDto", required = true) @RequestBody BisInspPlanDtlDto bisInspPlanDtlDto) {
- Assert.notNull(bisInspPlanDtlDto.getPlanId(), "年度计划ID为必填参数");
- List<String> adCodes = bisInspPlanDtlDto.getdAdCodes();
- Assert.notNull(adCodes, "检查区域为必填参数");
- bisInspPlanDtlDto.setPersId(getCurrentPersId());
- bisInspPlanDtlDto.setOrgId(getCurrentOrgId());
- // 把不在列表中的 开展检查实施处室(单位) 保存到详细计划表中
- bisInspPlanDtlDto.setChkImplDept(bisInspPlanDtlDto.getPlanDpRlNames());
- //判断是否重复创建
- if (null != bisInspPlanDtlDto.getDetermine() && !bisInspPlanDtlDto.getDetermine()) {
- // true 表示 有重复计划 false 表示没有
- List<Map<String, String>> byAdCodeAndTm = bisInspPlanDtlAddvcdService.getByAdCodeAndTm(bisInspPlanDtlDto);
- BaseResponse response = buildFailResponse(String.valueOf(CollectionUtils.isNotEmpty(byAdCodeAndTm)));
- if(CollectionUtils.isNotEmpty(byAdCodeAndTm)){
- String hasAdCodes = byAdCodeAndTm.stream().map(m->m.get("AD_CODE").substring(0,4)).collect(Collectors.joining("','","'","'"));
- List<BisInspPlanDtlDto> byAdCodeAndTmList = bisInspPlanDtlAddvcdService.getByAdCodeAndTmList(hasAdCodes, bisInspPlanDtlDto);
- if (StringUtils.isNotBlank(bisInspPlanDtlDto.getId())){
- // 编辑
- if(null !=byAdCodeAndTmList && byAdCodeAndTmList.size()>0){
- // 把自身去掉
- byAdCodeAndTmList = byAdCodeAndTmList.stream().filter(f-> !bisInspPlanDtlDto.getId().equals(f.getId())).collect(Collectors.toList());
- }
- response = buildFailResponse(String.valueOf(CollectionUtils.isNotEmpty(byAdCodeAndTmList)));
- }
- response.setData(byAdCodeAndTmList);
- }
- List<Map<String, String>> byAdCodeAndTmAndPlan = bisInspPlanDtlAddvcdService.getByAdCodeAndTmAndPlan(bisInspPlanDtlDto);
- if(CollectionUtils.isNotEmpty(byAdCodeAndTmAndPlan)){
- response.setSuccess(false);
- response.setCode(500);
- response.setMessage("报错");
- }
- return response;
- }
- if (StringUtils.isBlank(bisInspPlanDtlDto.getId())) {
- bisInspPlanDtlService.insert(bisInspPlanDtlDto);
- } else {
- bisInspPlanDtlService.update(bisInspPlanDtlDto);
- }
- bisInspPlanDtlService.updatePostProcessing(bisInspPlanDtlDto);
- return buildSuccessResponse(bisInspPlanDtlDto);
- }
- /* @ApiOperation(value = "添加检查年度计划分解")
- @RequestMapping(value = "/", method = RequestMethod.POST)
- public BaseResponse<BisInspPlanDtlDto> insert(@ApiParam(name = "BisInspPlanDtlDto", value = "BisInspPlanDtlDto", required = true) @RequestBody BisInspPlanDtlDto bisInspPlanDtlDto) {
- Assert.notNull(bisInspPlanDtlDto.getPlanId(), "年度计划ID为必填参数");
- List<String> adCodes = bisInspPlanDtlDto.getdAdCodes();
- Assert.notNull(adCodes, "检查区域为必填参数");
- bisInspPlanDtlDto.setPersId(getCurrentPersId());
- bisInspPlanDtlDto.setOrgId(getCurrentOrgId());
- // 把不在列表中的 开展检查实施处室(单位) 保存到详细计划表中
- bisInspPlanDtlDto.setChkImplDept(bisInspPlanDtlDto.getPlanDpRlNames());
- // true 表示 有重复计划 false 表示没有
- List<Map<String, String>> byAdCodeAndTmAndPlan = bisInspPlanDtlAddvcdService.getByAdCodeAndTmAndPlan(bisInspPlanDtlDto);
- if(CollectionUtils.isNotEmpty(byAdCodeAndTmAndPlan)){
- BaseResponse resp = new BaseResponse();
- resp.setSuccess(false);
- resp.setCode(500);
- resp.setMessage("报错");
- return resp;
- }
- return null;
- }*/
- @ApiOperation(value = "根据ID删除检查年度计划分解")
- @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
- public BaseResponse<?> delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
- Assert.notNull(id, "主键ID为必填参数");
- int ret = bisInspPlanDtlService.delete(id);
- return buildSuccessResponse();
- }
- @ApiOperation(value = "根据ID获取检查年度计划分解(单表)")
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- public BaseResponse<BisInspPlanDtlDto> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
- BisInspPlanDtl dtl = bisInspPlanDtlService.get(id);
- if (Objects.isNull(dtl)) {
- return buildSuccessResponse(null);
- }
- BisInspPlanDtlDto dto = new BisInspPlanDtlDto();
- BeanUtils.copyProperties(dtl, dto);
- //检查行政区
- Optional.ofNullable(bisInspPlanDtlAddvcdService.findList(new BisInspPlanDtlAddvcdParam(dto.getId()))).ifPresent(a -> {
- dto.setdAdCodes(a.stream().map(BisInspPlanDtlAddvcd::getAdCode).collect(Collectors.toList()));
- dto.setdAdName(a.stream().map(BisInspPlanDtlAddvcd::getAdName).collect(Collectors.joining(",")));
- });
- //督查类型
- Optional.ofNullable(bisInspPlanDtlPtypService.findList(new BisInspPlanDtlPtypParam(dto.getId()))).ifPresent(b -> {
- dto.setPtypIds(b.stream().map(BisInspPlanDtlPtyp::getPtype).collect(Collectors.toList()));
- });
- //参加处室单位
- dto.setPlanDpRlIds(bisInspPlandpRlService.findByPlanDpIdList(new BisInspPlandpRlParam(dto.getPlanId(), Constant.STRING_ONE)));
- return buildSuccessResponse(dto);
- }
- @ApiOperation(value = "获取列表")
- @RequestMapping(value = "/list", method = RequestMethod.POST)
- public BaseResponse<List<BisInspPlanDtlDto>> findPageList(@ApiParam(name = "bisInspPlanDtlParam", value = "bisInspPlanDtlParam", required = true) @RequestBody BisInspPlanDtlParam bisInspPlanDtlParam) {
- BisInspAllRlationPers byId = bisInspAllRlationPersService.getById(getCurrentPersId());
- 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())){
- bisInspPlanDtlParam.setPlanDpId(dp.getId());
- bisInspPlanDtlParam.setDdAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
- }
- });
- return buildSuccessResponse(bisInspPlanDtlService.findDtlList(bisInspPlanDtlParam));
- }
- @ApiOperation(value = "导出详细计划")
- @RequestMapping(value = "/export", method = RequestMethod.POST)
- public void exportExcel(HttpServletResponse response, @ApiParam(name = "bisInspPlanDtlParam", value = "bisInspPlanDtlParam", required = true) @RequestBody BisInspPlanDtlParam bisInspPlanDtlParam){
- BisInspAllRlationPers byId = bisInspAllRlationPersService.getById(getCurrentPersId());
- String planDpId = byId.getPlanDpId();
- if (StringUtils.isBlank(planDpId)){
- return ;
- }
- Optional.ofNullable(bisInspPlanDpService.get(planDpId)).ifPresent(dp ->{
- if (!StringUtils.equals(Constant.STRING_TWO,dp.getDpType())){
- bisInspPlanDtlParam.setPlanDpId(dp.getId());
- bisInspPlanDtlParam.setDdAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
- }
- });
- bisInspPlanDtlService.export(response, bisInspPlanDtlParam);
- }
- }
|