package com.yeshi.fanli.service.impl.user;
|
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.UUID;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
import org.springframework.web.multipart.MultipartFile;
|
import org.yeshi.utils.tencentcloud.COSManager;
|
|
import com.yeshi.fanli.dao.mybatis.user.UserComplaintMapper;
|
import com.yeshi.fanli.entity.bus.user.UserComplaint;
|
import com.yeshi.fanli.entity.bus.user.UserInfo;
|
import com.yeshi.fanli.exception.user.UserComplaintException;
|
import com.yeshi.fanli.service.inter.user.UserComplaintService;
|
|
import net.sf.json.JSONArray;
|
|
@Service
|
public class UserComplaintServiceImpl implements UserComplaintService {
|
|
@Resource
|
private UserComplaintMapper userComplaintMapper;
|
|
@Override
|
public void addUserComplaint(List<MultipartFile> fileList, Long uid, String content)
|
throws UserComplaintException, IOException, Exception {
|
|
if (content == null || content.trim().length() == 0) {
|
throw new UserComplaintException(1, "吐槽内容不能为空");
|
}
|
|
// 图片最多五张、可以为空
|
if (fileList != null && fileList.size() > 5 ) {
|
throw new UserComplaintException(1, "图片最多可上传五张");
|
}
|
|
// 图片列表
|
String pictureList = null;
|
if (fileList != null && fileList.size() > 0) {
|
|
JSONArray array = new JSONArray();
|
// 文件上传
|
for (MultipartFile file: fileList) {
|
|
InputStream inputStream = file.getInputStream();
|
String contentType = file.getContentType();
|
String type = contentType.substring(contentType.indexOf("/") + 1);
|
// 上传文件相对位置
|
String fileUrl="/img/UserComplaint/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
|
|
String uploadFilePath = COSManager.getInstance().uploadFile(inputStream, fileUrl).getUrl();
|
array.add(uploadFilePath);
|
}
|
|
pictureList = array.toString();
|
}
|
|
UserInfo userInfo = null;
|
if (uid != null) {
|
userInfo = new UserInfo();
|
userInfo.setId(uid);
|
}
|
|
UserComplaint userComplaint = new UserComplaint();
|
userComplaint.setContent(content);
|
userComplaint.setPictureList(pictureList);
|
userComplaint.setUserInfo(userInfo);
|
userComplaint.setCreateTime(new Date());
|
userComplaintMapper.insertSelective(userComplaint);
|
}
|
|
|
}
|