预案

pom.xml
 

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.8</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-scratchpad</artifactId>
    <version>3.8</version>
</dependency>
@RestController
@RequestMapping("/planInfoController")
@Api(value = "/PlanInfoController", tags = {"预案Api"})
public class PlanInfoController {

@PostMapping
@ApiOperation(value = "新增", httpMethod = "POST", response = Result.class)
public Result insertPlanInfo(@RequestBody PlanInfoDto planInfoDto) {
    try{
        int insertNums = infoService.insert(planInfoDto);
        if(insertNums > 0){
            return Result.build();
        }
        return Result.fail.error("服务器端新增数据失败!");
    }catch (Exception e){
        e.printStackTrace();
        return Result.fail.error("服务器端发生异常!");
    }
}

@RequestMapping("/uploadWord")
@ApiOperation(value = "解析word文件", httpMethod = "POST")
public Result uploadWord(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
    String buffer = "";
    if (!file.isEmpty()) {

        try {
            if (file.getOriginalFilename().endsWith(".doc")) {
                WordExtractor ex = new WordExtractor(file.getInputStream());
                buffer = ex.getText();
            }
            if (file.getOriginalFilename().endsWith(".docx")) {
                XWPFDocument xdoc = new XWPFDocument(file.getInputStream());
                XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc);
                buffer = extractor.getText();
               // extractor.close();
            }
        }catch (FileNotFoundException e){
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return Result.success.msg(buffer);
}

 

@Service
@Transactional
public class PlanInfoServiceImpl implements PlanInfoService {
@Override
public int insert(PlanInfoDto record) {
    record.setPublishDate(new Date());
    //新增预案基本信息
    int planInfoNums = planInfoMapper.insert(record);
    //新增预案数字预案信息
    insertDigitAndCommandSystem(record);
    return planInfoNums;
}
public class PlanInfoDto extends PlanInfo {

    @ApiModelProperty(value = "数字预案集合")
    List<PlanInfoDigit> planInfoDigitList;

    @ApiModelProperty(value = "指挥体系集合")
    List<PlanInfoCommandSystem> commandSystemList;

    public List<PlanInfoCommandSystem> getCommandSystemList() {
        return commandSystemList;
    }

    public void setCommandSystemList(List<PlanInfoCommandSystem> commandSystemList) {
        this.commandSystemList = commandSystemList;
    }

    public List<PlanInfoDigit> getPlanInfoDigitList() {
        return planInfoDigitList;
    }

    public void setPlanInfoDigitList(List<PlanInfoDigit> planInfoDigitList) {
        this.planInfoDigitList = planInfoDigitList;
    }
}
public void insertDigitAndCommandSystem(PlanInfoDto record) {
    //新增数字预案信息
    List<PlanInfoDigit> digitList = record.getPlanInfoDigitList();
    if (digitList != null) {
        for (PlanInfoDigit planInfoDigit : digitList) {
            planInfoDigit.setInfoId(record.getInfoId());
            planInfoDigitMapper.insert(planInfoDigit);
            //新增数字预案的节点信息
            List<PlanInfoDigitNode> planInfoDigitNodeList = planInfoDigit.getPlanInfoDigitNodeList();
            for (PlanInfoDigitNode planInfoDigitNode : planInfoDigitNodeList) {
                planInfoDigitNode.setDigitId(planInfoDigit.getDigitId());
                planInfoDigitNodeMapper.insert(planInfoDigitNode);
            }
        }
    }
    //新增指挥系统信息
    List<PlanInfoCommandSystem> planInfoCommandSystemList = record.getCommandSystemList();
    if (planInfoCommandSystemList != null) {
        for (PlanInfoCommandSystem planInfoCommandSystem : planInfoCommandSystemList) {
            planInfoCommandSystem.setInfoId(record.getInfoId());
            planInfoCommandSystemMapper.insert(planInfoCommandSystem);
            //新增指挥体系节点信息
            List<PlanInfoCommandSystemNode> planInfoCommandSystemNodeList =
                    planInfoCommandSystem.getPlanInfoCommandSystemNodeList();
            for (PlanInfoCommandSystemNode planInfoCommandSystemNode : planInfoCommandSystemNodeList) {
                planInfoCommandSystemNode.setCommandSystemId(planInfoCommandSystem.getCommandSystemId());
                planInfoCommandSystemNodeMapper.insert(planInfoCommandSystemNode);
                //新增指挥体系节点联系人信息
                List<PlanCommandSystemPrincipal> planCommandSystemPrincipalList =
                        planInfoCommandSystemNode.getPlanCommandSystemPrincipalList();
                for (PlanCommandSystemPrincipal planCommandSystemPrincipal : planCommandSystemPrincipalList) {
                    planCommandSystemPrincipal.setTeamId(planInfoCommandSystemNode.getTeamId());
                    planCommandSystemPrincipalMapper.insert(planCommandSystemPrincipal);
                }
            }
        }
    }
}

 

附:

@PutMapping
@ApiOperation(value = "插入", httpMethod = "PUT", response = Result.class)
@Transactional(rollbackFor={RuntimeException.class, Exception.class})
public Result insert(PlanInfo info, PlanInfoDigit planInfoDigit, List<PlanInfoDigitNode> planInfoDigitNodeList,
                     PlanInfoCommandSystem planInfoCommandSystem,
                     Map<PlanInfoCommandSystemNode, Map<PlanCommandSystemPrincipal, List<DutyContacts>>> planInfoCommandSystemNodeList) {
    int res = infoService.insert(info);//
    if(res == 1) {
        long infoId = info.getInfoId();
        planInfoDigit.setInfoId(infoId);
        res = planInfoDigitService.insert(planInfoDigit);
        if (res == 1 && planInfoDigitNodeList != null && planInfoDigitNodeList.size() > 0) {
            long digitId = planInfoDigit.getDigitId();
            for (int i = 0; i < planInfoDigitNodeList.size(); i++) {
                PlanInfoDigitNode pidn = planInfoDigitNodeList.get(i);
                pidn.setDigitId(digitId);
                res = planInfoDigitNodeService.insert(pidn);
                if (res != 1) {
                    return null;
                }
            }
        }

        planInfoCommandSystem.setInfoId(infoId);
        res = planInfoCommandSystemService.insert(planInfoCommandSystem);//指挥体系表
        if (res != 1) {
            return null;
        }


        long commandSystemId = planInfoCommandSystem.getCommandSystemId();
        for (PlanInfoCommandSystemNode picsn : planInfoCommandSystemNodeList.keySet()) {
            picsn.setCommandSystemId(commandSystemId);//指挥体系id
            res = planInfoCommandSystemNodeService.insert(picsn);//指挥体系--节点信息表
            if (res != 1) {
                return null;
            }

            Map<PlanCommandSystemPrincipal, List<DutyContacts>> planCommandSystemPrincipalList = planInfoCommandSystemNodeList.get(picsn);
            for (PlanCommandSystemPrincipal pcsp : planCommandSystemPrincipalList.keySet()) {

                List<DutyContacts> dutyContactsList = planCommandSystemPrincipalList.get(pcsp);
                if (dutyContactsList != null && dutyContactsList.size() > 0) {
                    for (int k = 0; k < dutyContactsList.size(); k++) {
                        pcsp.setNodeId(picsn.getNodeId());
                        DutyContacts dc = dutyContactsList.get(k);
                        pcsp.setDutyContactsId(dc.getId());
                        res = planCommandSystemPrincipalService.insert(pcsp);
                        if (res != 1) {
                            return null;
                        }
                    }
                }


            }
        }
    }
    return null;

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值