发表于: 2017-11-02 21:54:32
1 726
一.今天完成的主要事情
1.完成上传图片接口
依然使用当时做任务的功能类以及第三方API
/**
* @Description: 上传文件接口
* @param: type 上传文件的类型
* @param: file 上传的文件
* @return: 返回相应的jsp页面
* @throws: Exception
* @author: zhangxin
* @Date: 2017-10-26
*/
@RequestMapping(value = "/a/u/image", method = RequestMethod.POST)
public String uploadFile(HttpServletRequest request,
HttpServletResponse response, ModelMap model, Integer type,
@RequestParam MultipartFile file) {
log.info("uploadFile() parameters: type is :" + type);
Integer validateResult = ImgFileUtil.validateParameterOfUploadFile(type, file);
if (validateResult != ParametersConstant.CORRECT_VALIDATE_RESULT) {
model.addAttribute("code", validateResult);
return "/common/failure";
}
log.info("file name is:" + file.getOriginalFilename());
//获取后缀,生成新的文件名
String extend = FileUtil.getFileExtension(file.getOriginalFilename());
String fileName = UUID.randomUUID().toString() + "." + extend;
String path = "data/img/polyfinance/whodarekillme/" + ImgFileUtil.getFileNameByType(type) + "/" + fileName;
log.info("new file path is : " + path);
try {
//上传文件并返回文件地址链接url
byte[] uploadBytes = file.getBytes();
if (storage.uploadFileByByteArray(uploadBytes, path)) {
log.info("upload file success!");
String imagePath = storage.getFileUrl(path);
model.addAttribute("url", imagePath);
return "/common/img";
}
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage());
log.error("uploadFile() error, type is : " + type);
model.addAttribute("code", InterfaceCodeConstant.System_Exception);
return "/common/failure";
}
return "/common/failure";
}
}
除此之外,还有三个功能类,用于调用第三方API接口
其中一个阿里云存储,一个七牛云存储,还有一个是作为调度,同样,需要在spring的配置文件中配置好相关配置,配置文件如下
<!-- 七牛云存储上传文件模块 -->
<bean id="qiniuStorage" class="com.ptteng.util.storage.QiniuStorageUtil">
<property name="accessKey" value="e8byTKXyt6dfOXrX99iSRpsULtxRwAUK75fpi1xS"></property>
<property name="secretKey" value="voi-hN-bZErW5Ld1e6LlsUiehiz7Yx4dL1z3s1ja"></property>
<property name="endpoint" value="http://ovjf6a85f.bkt.clouddn.com"></property>
<property name="bucket" value="xiaowenhou"></property>
</bean>
<!--阿里云存储上传文件模块-->
<bean id="aliStorage" class="com.ptteng.util.storage.AliStorageUtil">
<property name="accessKeyId" value="LTAInw2uvA9Iiz1u"></property>
<property name="accessKeySecret" value="ZvMYRfBDViHZV5d6Gb20ivESime6XG"></property>
<property name="endpoint" value="http://oss-cn-shenzhen.aliyuncs.com"></property>
<property name="bucketName" value="xiaowenhou"></property>
</bean>
<!--云存储模块,可以通过配置该模块实现文件上传至不同的云存储中-->
<bean id="storage" class="com.ptteng.util.storage.StorageUtil">
<property name="aliStorageUtil" ref="aliStorage"></property>
<property name="qiniuStorage" ref="qiniuStorage"></property>
<!--选择使用哪种云存储方式,该值只有两个, qiniu 和 ali-->
<property name="choice" value="ali"></property>
</bean>
<!--迁移模块,可以通过配置该模块实现数据从一个云存储迁移到另一个云存储中-->
<bean id="transfer" class="com.ptteng.util.storage.TransferUtil">
<property name="aliStorageUtil" ref="aliStorage"></property>
<property name="qiniuStorage" ref="qiniuStorage"></property>
<!--迁移之后是否需要删除原来的存储空间的内容,yes为是,no为不是-->
<property name="isDelete" value="no"></property>
<!--选择从七牛迁移到阿里(qiniu-to-ali)还是从阿里迁移到七牛(ali-to-qiniu)-->
<property name="toOther" value="ali-to-qiniu"></property>
</bean>
2.对etl任务进行重构
主要的改动有两处,
一是将发送短信的模版作为变量通过spring注入的方式传递
二是将角色名作为变量通过spring注入的方式传递,这样如果后续需要修改角色名和短信模版时,就不需要更改源代码,直接更改配置文件即可
如图
3.请师兄进行codereview
codereview之后需要注意的地方如下:
1.在接口中第一步先打印接口路径,方便后续日志中查找
2.通过条件筛选出来的IDList,如果该IDList不为空,再通过该IDList查找出的对象List,此时该对象List中的元素是不需要判空的
二.明天计划完成的事情
1.准备小课堂
2.针对codereview发现的问题,再次进行修改
三.遇到的问题
暂无
四.收获
以上
通过codereview对代码规范和要注意的地方有了更加深入的理解
五,项目进度情况
目前后端的功能基本都做完了,现在就看前端的页面什么时候能写完了
评论