1.初始化项目创建操作
用户点击:阅读并同意协议
①检查是否登录
所在工程:distribution-crowd-6-project-manager
所在类:com.rgh.crowd.controller.ProjectController
@RestController
public class ProjectController {
@Autowired
private RedisOperationRemoteService redisOperationRemoteService;
@Autowired
private DataBaseOperationRemoteService dataBaseOperationRemoteService;
@RequestMapping("/project/manager/initCreation")
public ResultEntity initCreation(
@RequestParam("memberSignToken") String memberSignToken) {
// 检查是否登录,也就是检查memberSignToken是否有效
ResultEntity resultEntity = redisOperationRemoteService.retrieveStringValueByStringKey(memberSignToken);
if (ResultEntity.FAILED.equals(resultEntity.getResult())) {
return ResultEntity.failed(resultEntity.getMessage());
}
String memberId = resultEntity.getData();
if (memberId == null) {
return ResultEntity.failed(CrowdConstant.MESSAGE_ACCESS_DENIED);
}
}
②将ProjectVO存入Redis
[1]KEY设计
所在工程:distribution-crowd-1-common
所在类:com.rgh.crowd.constant.CrowdConstant
public static final String REDIS_PROJECT_TEMP_TOKEN_PREFIX = "PROJECT_TEMP_TOKEN_";
前缀后面使用UUID生成。
所在类:com.rgh.crowd.constant.CrowdUtils
/**
* 根据不同前缀生成Redis中保存数据的key
*
* @param prefix
* @return
*/
public static String generateRedisKeyByPrefix(String prefix) {
return prefix + UUID.randomUUID().toString().replaceAll("-", "");
}
[2]VALUE设计
String value = JSON.toJSONString(projectVO);
③project-manager工程中的Controller方法
@RequestMapping("/project/manager/initCreation")
public ResultEntity initCreation(
@RequestParam("memberSignToken") String memberSignToken) {
// 1.检查是否登录,也就是检查memberSignToken是否有效
ResultEntity resultEntity = redisOperationRemoteService.retrieveStringValueByStringKey(memberSignToken);
if(ResultEntity.FAILED.equals(resultEntity.getResult())) {
return ResultEntity.failed(resultEntity.getMessage());
}
String memberId = resultEntity.getData();
if(memberId == null) {
return ResultEntity.failed(CrowdConstant.MESSAGE_ACCESS_DENIED);
}
// 2.创建空ProjectVO对象备用
ProjectVO projectVO = new ProjectVO();
// 3.将memberSignToken存入ProjectVO对象
projectVO.setMemberSignToken(memberSignToken);
// 4.将projectTempToken存入ProjectVO对象
String projectTempToken = CrowdUtils.generateRedisKeyByPrefix(CrowdConstant.REDIS_PROJECT_TEMP_TOKEN_PREFIX);
projectVO.setProjectTempToken(projectTempToken);
// 5.将ProjectVO对象转换成JSON
String jsonString = JSON.toJSONString(projectVO);
// 6.将projectTempToken和jsonString作为key、value存入Redis
// 虽然是临时数据,但是不能指定一个固定的过期时间,在用户操作完成时删除
redisOperationRemoteService.saveNormalStringKeyValue(projectTempToken, jsonString, -1);
return ResultEntity.successWithData(projectVO);
}
测试
登陆方法
创建项目方法
再去Redis中看键与值是否正确
2.上传项目头图
①操作流程
前端工程接收上传图片
上传到OSS
将访问图片的URL地址发送给project-manager工程
-
project-manager工程访问Redis查询ProjectVO对象
- 从Redis查询到JSON字符串
- 将JSON字符串还原成ProjectVO对象
将图片路径存入ProjectVO对象
将ProjectVO对象转换为JSON字符串
将JSON字符串重新存入Redis
②代码
所在工程:distribution-crowd-6-project-manager
所在类:com.rgh.crowd.controller.ProjectController
@RequestMapping("/project/manager/save/head/picture/path")
public ResultEntity saveHeadPicturePath(
@RequestParam("memberSignToken") String memberSignToken,
@RequestParam("projectTempToken") String projectTempToken,
@RequestParam("headerPicturePath") String headerPicturePath
) {
// 检查是否登录,也就是检查memberSignToken是否有效
ResultEntity resultEntity = redisOperationRemoteService.retrieveStringValueByStringKey(memberSignToken);
if(ResultEntity.FAILED.equals(resultEntity.getResult())) {
return ResultEntity.failed(resultEntity.getMessage());
}
// project-manager工程访问Redis查询ProjectVO对象
ResultEntity resultEntityForGetValue = redisOperationRemoteService.retrieveStringValueByStringKey(projectTempToken);
if(ResultEntity.FAILED.equals(resultEntityForGetValue.getResult())) {
return ResultEntity.failed(resultEntityForGetValue.getMessage());
}
// 从Redis查询到JSON字符串
String projectVOJSON = resultEntityForGetValue.getData();
// 将JSON字符串还原成ProjectVO对象
ProjectVO projectVO = JSON.parseObject(projectVOJSON, ProjectVO.class);
// 将图片路径存入ProjectVO对象
projectVO.setHeaderPicturePath(headerPicturePath);
// 将ProjectVO对象转换为JSON字符串
String jsonString = JSON.toJSONString(projectVO);
// 将JSON字符串重新存入Redis
return redisOperationRemoteService.saveNormalStringKeyValue(projectTempToken, jsonString, -1);
}
测试:
-
登陆
-
重新初始化
-
存一个图片路径试试
-
从Redis中看下键对应的值
3.上传项目详情图片
@RequestMapping("/project/manager/save/detail/picture/path/list")
public ResultEntity saveDetailPicturePathList(
@RequestParam("memberSignToken") String memberSignToken,
@RequestParam("projectTempToken") String projectTempToken,
@RequestParam("detailPicturePathList") List detailPicturePathList
) {
// 检查是否登录,也就是检查memberSignToken是否有效
ResultEntity resultEntity = redisOperationRemoteService.retrieveStringValueByStringKey(memberSignToken);
if(ResultEntity.FAILED.equals(resultEntity.getResult())) {
return ResultEntity.failed(resultEntity.getMessage());
}
// project-manager工程访问Redis查询ProjectVO对象
ResultEntity resultEntityForGetValue = redisOperationRemoteService.retrieveStringValueByStringKey(projectTempToken);
if(ResultEntity.FAILED.equals(resultEntityForGetValue.getResult())) {
return ResultEntity.failed(resultEntityForGetValue.getMessage());
}
// 从Redis查询到JSON字符串
String projectVOJSON = resultEntityForGetValue.getData();
// 将JSON字符串还原成ProjectVO对象
ProjectVO projectVO = JSON.parseObject(projectVOJSON, ProjectVO.class);
// 将图片路径存入ProjectVO对象
projectVO.setDetailPicturePathList(detailPicturePathList);
// 将ProjectVO对象转换为JSON字符串
String jsonString = JSON.toJSONString(projectVO);
// 将JSON字符串重新存入Redis
return redisOperationRemoteService.saveNormalStringKeyValue(projectTempToken, jsonString, -1);
}
测试:
4.保存项目信息
@RequestMapping("/project/manager/save/project/information")
public ResultEntity saveProjectInformation(@RequestBody ProjectVO projectVOFront) {
// 获取memberSignToken
String memberSignToken = projectVOFront.getMemberSignToken();
// 检查是否登录,也就是检查memberSignToken是否有效
ResultEntity resultEntity = redisOperationRemoteService.retrieveStringValueByStringKey(memberSignToken);
if(ResultEntity.FAILED.equals(resultEntity.getResult())) {
return ResultEntity.failed(resultEntity.getMessage());
}
// 从projectVOFront中获取projectTempToken
String projectTempToken = projectVOFront.getProjectTempToken();
// project-manager工程访问Redis查询ProjectVO对象
ResultEntity resultEntityForGetValue = redisOperationRemoteService.retrieveStringValueByStringKey(projectTempToken);
if(ResultEntity.FAILED.equals(resultEntityForGetValue.getResult())) {
return ResultEntity.failed(resultEntityForGetValue.getMessage());
}
// 从Redis查询到JSON字符串
String projectVOJSON = resultEntityForGetValue.getData();
// 将JSON字符串还原成ProjectVO对象
ProjectVO projectVOBehind = JSON.parseObject(projectVOJSON, ProjectVO.class);
projectVOFront.setHeaderPicturePath(projectVOBehind.getHeaderPicturePath());
projectVOFront.setDetailPicturePathList(projectVOBehind.getDetailPicturePathList());
// 将projectVOFront对象中的属性复制到projectVOBehind对象
BeanUtils.copyProperties(projectVOFront, projectVOBehind);
// 将projectVOBehind对象转换为JSON字符串
String jsonString = JSON.toJSONString(projectVOBehind);
// 将JSON字符串重新存入Redis
return redisOperationRemoteService.saveNormalStringKeyValue(projectTempToken, jsonString, -1);
}
测试:
JSON格式
查看Redis中是否存入成功
5.保存回报信息
@RequestMapping("/project/manager/save/return/infromation")
public ResultEntity saveReturnInfromation(@RequestBody ReturnVO returnVO) {
// 获取memberSignToken
String memberSignToken = returnVO.getMemberSignToken();
// 检查是否登录,也就是检查memberSignToken是否有效
ResultEntity resultEntity = redisOperationRemoteService.retrieveStringValueByStringKey(memberSignToken);
if (ResultEntity.FAILED.equals(resultEntity.getResult())) {
return ResultEntity.failed(resultEntity.getMessage());
}
// 从projectVOFront中获取projectTempToken
String projectTempToken = returnVO.getProjectTempToken();
// project-manager工程访问Redis查询ProjectVO对象
ResultEntity resultEntityForGetValue = redisOperationRemoteService
.retrieveStringValueByStringKey(projectTempToken);
if (ResultEntity.FAILED.equals(resultEntityForGetValue.getResult())) {
return ResultEntity.failed(resultEntityForGetValue.getMessage());
}
// 从Redis查询到JSON字符串
String projectVOJSON = resultEntityForGetValue.getData();
// 将JSON字符串还原成ProjectVO对象
ProjectVO projectVOBehind = JSON.parseObject(projectVOJSON, ProjectVO.class);
// 获取旧的回报信息集合
List returnVOList = projectVOBehind.getReturnVOList();
// 判断returnVOList是否有数据
if (!CrowdUtils.collectionEffectiveCheck(returnVOList)) {
// 初始化
returnVOList = new ArrayList<>();
projectVOBehind.setReturnVOList(returnVOList);
}
// 将当前回报信息存入List
returnVOList.add(returnVO);
// 重新对ProjectVO对象进行JOSN转换
String jsonString = JSON.toJSONString(projectVOBehind);
// 重新把ProjectVO对象保存Redis
return redisOperationRemoteService.saveNormalStringKeyValue(projectTempToken, jsonString, -1);
}
测试
6.保存确认信息
@RequestMapping("/project/manager/save/confirm/infomation")
public ResultEntity saveConfirmInfomation(@RequestBody MemberConfirmInfoVO memberConfirmInfoVO) {
// 获取memberSignToken
String memberSignToken = memberConfirmInfoVO.getMemberSignToken();
// 检查是否登录,也就是检查memberSignToken是否有效
ResultEntity resultEntity = redisOperationRemoteService.retrieveStringValueByStringKey(memberSignToken);
if (ResultEntity.FAILED.equals(resultEntity.getResult())) {
return ResultEntity.failed(resultEntity.getMessage());
}
// 从projectVOFront中获取projectTempToken
String projectTempToken = memberConfirmInfoVO.getProjectTempToken();
// project-manager工程访问Redis查询ProjectVO对象
ResultEntity resultEntityForGetValue = redisOperationRemoteService
.retrieveStringValueByStringKey(projectTempToken);
if (ResultEntity.FAILED.equals(resultEntityForGetValue.getResult())) {
return ResultEntity.failed(resultEntityForGetValue.getMessage());
}
// 从Redis查询到JSON字符串
String projectVOJSON = resultEntityForGetValue.getData();
// 将JSON字符串还原成ProjectVO对象
ProjectVO projectVOBehind = JSON.parseObject(projectVOJSON, ProjectVO.class);
projectVOBehind.setMemberConfirmInfoVO(memberConfirmInfoVO);
// 重新对ProjectVO对象进行JOSN转换
String jsonString = JSON.toJSONString(projectVOBehind);
// 重新把ProjectVO对象保存Redis
return redisOperationRemoteService.saveNormalStringKeyValue(projectTempToken, jsonString, -1);
}
测试:
7.所有相关数据存入数据库
①执行流程
②project-manager的Controller方法
@RequestMapping("/project/manager/save/whole/project")
public ResultEntity saveWholeProject(
@RequestParam("memberSignToken") String memberSignToken,
@RequestParam("projectTempToken") String projectTempToken) {
// 检查是否登录,也就是检查memberSignToken是否有效
ResultEntity resultEntity = redisOperationRemoteService.retrieveStringValueByStringKey(memberSignToken);
if (ResultEntity.FAILED.equals(resultEntity.getResult())) {
return ResultEntity.failed(resultEntity.getMessage());
}
String memberId = resultEntity.getData();
if (memberId == null) {
return ResultEntity.failed(CrowdConstant.MESSAGE_ACCESS_DENIED);
}
// project-manager工程访问Redis查询ProjectVO对象
ResultEntity resultEntityForGetValue = redisOperationRemoteService
.retrieveStringValueByStringKey(projectTempToken);
if (ResultEntity.FAILED.equals(resultEntityForGetValue.getResult())) {
return ResultEntity.failed(resultEntityForGetValue.getMessage());
}
// 从Redis查询到JSON字符串
String projectVOJSON = resultEntityForGetValue.getData();
// 将JSON字符串还原成ProjectVO对象
ProjectVO projectVO = JSON.parseObject(projectVOJSON, ProjectVO.class);
// 执行保存
ResultEntity resultEntityForSave = dataBaseOperationRemoteService.saveProjectRemote(projectVO, memberId);
if(ResultEntity.FAILED.equals(resultEntityForSave.getResult())) {
return resultEntityForSave;
}
// 删除Redis中的临时数据
return redisOperationRemoteService.removeByKey(projectTempToken);
}
③database-provider的Controller方法
@RequestMapping("/save/project/remote/{memberId}")
public ResultEntity saveProjectRemote(
@RequestBody ProjectVO projectVO,
@PathVariable("memberId") String memberId) {
try {
projectService.saveProject(projectVO, memberId);
return ResultEntity.successNoData();
} catch (Exception e) {
e.printStackTrace();
return ResultEntity.failed(e.getMessage());
}
}
把自增的主键存入id属性中
TypePOMapper接口
void insertRelationshipBatch(
@Param("projectId") Integer projectId,
@Param("typeIdList") List typeIdList);
TypePOMapper.xml
insert into t_project_type(projectid, typeid)
values
(#{projectId},#{typeId})
TagPOMapper接口
void insertRelationshipBatch(
@Param("projectId") Integer projectId,
@Param("tagIdList") List tagIdList);
TagPOMapper.xml
insert into t_project_tag(projectid,tagid)
values
(#{projectId},#{tagId})
ProjectItemPicPOMapper接口
void insertBatch(@Param("projectItemPicPOList") List projectItemPicPOList);
ProjectItemPicPOMapper.xml
INSERT INTO t_project_item_pic (projectid, item_pic_path)
VALUES
(#{projectItemPic.projectid},#{projectItemPic.itemPicPath})
ReturnPOMapper接口
void insertBatch(@Param("returnPOList") List returnPOList);
ReturnPOMapper.xml
insert into t_return (
projectid,
type,
supportmoney,
content,
count,
signalpurchase,
purchase,
freight,
invoice,
returndate,
describ_pic_path
)
values
(
#{returnPO.projectid,jdbcType=INTEGER},
#{returnPO.type,jdbcType=TINYINT},
#{returnPO.supportmoney,jdbcType=INTEGER},
#{returnPO.content,jdbcType=VARCHAR},
#{returnPO.count,jdbcType=INTEGER},
#{returnPO.signalpurchase,jdbcType=INTEGER},
#{returnPO.purchase,jdbcType=INTEGER},
#{returnPO.freight,jdbcType=INTEGER},
#{returnPO.invoice,jdbcType=TINYINT},
#{returnPO.returndate,jdbcType=INTEGER},
#{returnPO.describPicPath,jdbcType=VARCHAR}
)
④database-provider的Service方法
- 1.保存ProjectPO
- 2.获取保存ProjectPO后得到的自增主键
- 在ProjectPOMapper.xml文件中insert方法对应的标签中设置useGeneratedKeys="true" keyProperty="id"
- 3.保存typeIdList
- 4.保存tagIdList
- 5.保存detailPicturePathList
- 6.保存MemberLaunchInfoPO
- 7.根据ReturnVO的List保存ReturnPO
- 8.保存MemberConfirmInfoPO
@Transactional(readOnly=false, propagation=Propagation.REQUIRES_NEW, rollbackFor=Exception.class)
public void saveProject(ProjectVO projectVO, String memberId) {
// 1.保存ProjectPO
ProjectPO projectPO = new ProjectPO();
BeanUtils.copyProperties(projectVO, projectPO);
projectPO.setMemberid(Integer.parseInt(memberId));
projectPOMapper.insert(projectPO);
// 2.获取保存ProjectPO后得到的自增主键
// 在ProjectPOMapper.xml文件中insert方法对应的标签中设置useGeneratedKeys="true" keyProperty="id"
Integer projectId = projectPO.getId();
// 3.保存typeIdList
List typeIdList = projectVO.getTypeIdList();
if(CrowdUtils.collectionEffectiveCheck(typeIdList)) {
typePOMapper.insertRelationshipBatch(projectId, typeIdList);
}
// 4.保存tagIdList
List tagIdList = projectVO.getTagIdList();
if(CrowdUtils.collectionEffectiveCheck(tagIdList)) {
tagPOMapper.insertRelationshipBatch(projectId, tagIdList);
}
// 5.保存detailPicturePathList
// ①从VO对象中获取detailPicturePathList
List detailPicturePathList = projectVO.getDetailPicturePathList();
if(CrowdUtils.collectionEffectiveCheck(detailPicturePathList)) {
// ②创建一个空List集合,用来存储ProjectItemPicPO对象
List projectItemPicPOList = new ArrayList<>();
// ③遍历detailPicturePathList
for (String detailPath : detailPicturePathList) {
// ④创建projectItemPicPO对象
ProjectItemPicPO projectItemPicPO = new ProjectItemPicPO(null, projectId, detailPath);
projectItemPicPOList.add(projectItemPicPO);
}
// ⑤根据projectItemPicPOList执行批量保存
projectItemPicPOMapper.insertBatch(projectItemPicPOList);
}
// 6.保存MemberLaunchInfoPO
MemberLauchInfoVO memberLauchInfoVO = projectVO.getMemberLauchInfoVO();
if(memberLauchInfoVO != null) {
MemberLaunchInfoPO memberLaunchInfoPO = new MemberLaunchInfoPO();
BeanUtils.copyProperties(memberLauchInfoVO, memberLaunchInfoPO);
memberLaunchInfoPO.setMemberid(Integer.parseInt(memberId));
memberLaunchInfoPOMapper.insert(memberLaunchInfoPO);
}
// 7.根据ReturnVO的List保存ReturnPO
List returnVOList = projectVO.getReturnVOList();
if(CrowdUtils.collectionEffectiveCheck(returnVOList)) {
List returnPOList = new ArrayList<>();
for (ReturnVO returnVO : returnVOList) {
ReturnPO returnPO = new ReturnPO();
BeanUtils.copyProperties(returnVO, returnPO);
returnPO.setProjectid(projectId);
returnPOList.add(returnPO);
}
returnPOMapper.insertBatch(returnPOList);
}
// 8.保存MemberConfirmInfoPO
MemberConfirmInfoVO memberConfirmInfoVO = projectVO.getMemberConfirmInfoVO();
if(memberConfirmInfoVO != null) {
MemberConfirmInfoPO memberConfirmInfoPO = new MemberConfirmInfoPO(null, Integer.parseInt(memberId), memberConfirmInfoVO.getPaynum(), memberConfirmInfoVO.getCardnum());
memberConfirmInfoPOMapper.insert(memberConfirmInfoPO);
}
}
把ProjectPO中的maney改为Integer类型
测试:
-
登陆
-
拿到tokenID创建项目
-
上传头图
-
看Redis中是否存入数据
-
上传详情的图片
-
保存项目信息
在t_type和t_tag表中加入测试数据
这里要加上MemberLauchInfoVO信息
记得是JSON格式
-
在Redis中查看数据
-
保存汇报信息
查看Redis中是否存入
-
保存确认的信息
- 保存所有的数据
- 看Redis中的项目tokenId是否删除
为了方便测试可以把在Redis中存的键设置为持久化的键