收集回报信息
注意:上传图片和提交表单分开
思路
操作1:接收页面上异步上传的图片
@RequestMapping("/create/upload/return/picture.json") public ResultEntityuploadReturnPicture( //接收用户上传图片 @RequestParam("returnPicture") MultipartFile returnPicture ) throws IOException { //1、执行文件上传 ResultEntity uploadReturnPicResultEntity = CrowdUtil.uploadFileToOss( ossProperties.getEndPoint(), ossProperties.getAccessKeyId(), ossProperties.getAccessKeySecret(), returnPicture.getInputStream(), ossProperties.getBucketName(), ossProperties.getBucketDomain(), returnPicture.getOriginalFilename()); //2、返回上传的结果 return uploadReturnPicResultEntity; }
操作2:接收整个回报信息数据
@ResponseBody @RequestMapping("/create/save/return.json") public ResultEntitysaveReturn(ReturnVO returnVO, HttpSession session) { try { //1、从 session域中读取之前缓存的ProjectVO对象 ProjectVO projectVO = (ProjectVO) session.getAttribute(ConstantUtil.ATTR_MANE_TEMPLE_PROJECT); //2、判断projectVO是否为null if (projectVO == null) { return ResultEntity.failed(ConstantUtil.MESSAGE_TEMPLE_PROJECT_MISSING); } //3、从projectVO对象中获取存储回报信息的集合 List returnVOList = projectVO.getReturnVOList(); //4、判断returnVO集合是否有效 if (returnVOList == null || returnVOList.size() == 0) { //5、创建集合对象对returnVOList进行初始化 returnVOList = new ArrayList (); //6、为了让以后能够正常使用这个集合,设置到peojectVO对象中 projectVO.setReturnVOList(returnVOList); } //7、将收集了表单数据的returnVO对象存入集合 returnVOList.add(returnVO); //8、把数据有变化的ProjectVO对象重新存入Session域,以确保新的数据最终能够存入redis session.setAttribute(ConstantUtil.ATTR_MANE_TEMPLE_PROJECT, projectVO); //9、所有操作成功完成返回成功 return ResultEntity.successWithoutData(); } catch (Exception e) { e.printStackTrace(); return ResultEntity.failed(e.getMessage()); } }
跳转页面
从收集回报信息页面跳转到确认信息页面
页面上修改”下一步“按钮
<a th:href="@{/project/create/confirm/page}" class="btn btn-warning btn-lg">下一步a>
添加view-controller
registry.addViewController("/create/confirm/page.html").setViewName("project-confirm");
调整project-comsumer.html页
收集确认信息
点击提交按钮提交表单
修改提交按钮的html标签
<button type="button" id="submitBtn" class="btn btn-warning btn-lg">提交button>
调整表单代码
<form id="confirmFomr" th:action="@{/project/create/confirm}" method="post" role="form"> <div class="form-group"> <label for="exampleInputEmail1">易付宝企业账号:label><input type="email" name="paynum" class="form-control" id="exampleInputEmail1" /> div> <div class="form-group"> <label for="exampleInputPassword1">法人身份证号:label><input type="password" name="cardnum" class="form-control" id="exampleInputPassword1" /> div> form>
给提交按钮绑定单级响应函数
收集表单数据执行保存
Project-consumer
@RequestMapping("/create/confirm") public String saveConfirm(ModelMap modelMap, HttpSession session, MemberConfirmInfoVO memberConfirmInfoVO) { //1、从session域读取之前临时存储的projectVO对象 ProjectVO projectVO = (ProjectVO) session.getAttribute(ConstantUtil.ATTR_MANE_TEMPLE_PROJECT); //2、如果projectVO为null if (projectVO == null) { throw new RuntimeException(ConstantUtil.MESSAGE_TEMPLE_PROJECT_MISSING); } //3、将确认信息数据设置到projectVO对象中 projectVO.setMemberConfirmInfoVO(memberConfirmInfoVO); //4、从session域读取当前登陆的用户 MemberLoginVO memberLoginVO = (MemberLoginVO) session.getAttribute(ConstantUtil.ATTR_NAME_LOGIN_MEMBER); Integer memberId = memberLoginVO.getId(); //5、调用远程方法保存projectVO对象 ResultEntitysaveResultEntity = mySQLRemoteService.saveProjectVORemote(projectVO, memberId); //6、判断远程的保存操作是否成功 String result = saveResultEntity.getResult(); if (ResultEntity.FAILED.equals(result)){ modelMap.addAttribute(ConstantUtil.ATTR_NANE_MESSAGE, saveResultEntity.getMessage()); return "project-confirm"; } //7、将临时的ProjectVO对象从Session域移除 session.removeAttribute(ConstantUtil.MESSAGE_TEMPLE_PROJECT_MISSING); //8、如果远程保存成功则跳转到最终完成页面 return "redirect:http://www.crowd.com/project/create/success"; }
声明mysql-provider的Feign接口
@RequestMapping("/get/memberpo/by/login/acct/remote") ResultEntitygetMemberPOByLoginAcctRemote(@RequestParam("loginAcct") String loginAcct); @RequestMapping("/save/member/remote") ResultEntity saveMember(@RequestBody MemberPO memberPO); @RequestMapping("save/project/vo/remote") ResultEntity saveProjectVORemote(@RequestBody ProjectVO projectVO, @RequestParam("memberId") Integer memberId);
执行数据库保存
需要在保存projectPO之后获取自增主键值
在mysql=provider中执行具体操作
@RequestMapping("save/project/vo/remote") ResultEntitysaveProjectVORemote( @RequestBody ProjectVO projectVO, @RequestParam("memberId") Integer memberId) { try { projectService.saveProject(projectVO, memberId); return ResultEntity.successWithoutData(); } catch (Exception e) { e.printStackTrace(); return ResultEntity.failed(e.getMessage()); } }
在mysql-provider的service方法中执行保存
@Override @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) public void saveProject(ProjectVO projectVO, Integer memberId) { // 一、保存ProjectPO对象 ProjectPO projectPO = new ProjectPO(); BeanUtils.copyProperties(projectVO, projectPO); // 保存ProjectPO projectPOMapper.insertSelective(projectPO); // 获取自增主键 Integer projectId = projectPO.getId(); // 保存项目、分类的关联信息 ListtypeIdList = projectVO.getTypeIdList(); projectPOMapper.insertTypeRelationship(typeIdList, projectId); // 保存项目、标签的关联信息 List tagIdList = projectVO.getTagIdList(); projectPOMapper.insertTagRelationship(tagIdList, projectId); // 保存项目的详情图片路径信息 List detailPicturePathList = projectVO.getDetailPicturePathList(); projectItemPicPOMapper.insertPathList(projectId, detailPicturePathList); // 项目发起人信息 MemberLauchInfoVO memberLauchInfoVO = projectVO.getMemberLauchInfoVO(); MemberLaunchInfoPO memberLaunchInfoPO = new MemberLaunchInfoPO(); BeanUtils.copyProperties(memberLauchInfoVO, memberLaunchInfoPO); memberLaunchInfoPO.setMemberid(memberId); memberLaunchInfoPOMapper.insert(memberLaunchInfoPO); // 回报的信息 List returnVOList = projectVO.getReturnVOList(); List returnPOList = new ArrayList (); for (ReturnVO returnVO : returnVOList) { ReturnPO returnPO = new ReturnPO(); BeanUtils.copyProperties(returnVO, returnPO); returnPOList.add(returnPO); } returnPOMapper.insertReturnPOBatch(returnPOList, projectId); // 保存项目的确认信息 MemberConfirmInfoVO memberConfirmInfoVO = projectVO.getMemberConfirmInfoVO(); MemberConfirmInfoPO memberConfirmInfoPO = new MemberConfirmInfoPO(); BeanUtils.copyProperties(memberConfirmInfoVO, memberConfirmInfoPO); memberConfirmInfoPO.setId(memberId); memberConfirmInfoPOMapper.insert(memberConfirmInfoPO); }
SQL
insert into t_project_type(`projectid`,`typeid`)values (#{projectId},#{typeId}) insert into t_project_tag(`projectid`,`tagid`)values (#{projectId},#{tagId})
insert into t_project_item_pic( projectid, item_pic_path)values (#{projectId},#{detailPath})
insert into t_return ( projectid, type, supportmoney, content, count, signalpurchase, purchase, freight, invoice, returndate, describ_pic_path ) values ( #{projectId}, #{returnPO.type}, #{returnPO.supportmoney}, #{returnPO.content}, #{returnPO.count}, #{returnPO.signalpurchase}, #{returnPO.purchase}, #{returnPO.freight}, #{returnPO.invoice}, #{returnPO.returndate}, #{returnPO.describPicPath} )