1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.CustomerServiceMapper;
import cn.wisenergy.mapper.UsersMapper;
import cn.wisenergy.model.app.CustomerService;
import cn.wisenergy.model.app.User;
import cn.wisenergy.service.app.CustomerServiceService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.yaml.snakeyaml.events.Event;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Service
@Slf4j
public class CustomerServiceServiceImpl implements CustomerServiceService {
@Autowired
private CustomerServiceMapper customerServiceMapper;
@Autowired
private UsersMapper usersMapper;
@Value("${uploadFile.location}")
private String uploadQRImagesLocation;
@Override
public CustomerService getServiceByRand(String userId){
User byUserId = usersMapper.getByUserId(userId);
String customerServiceId = byUserId.getCustomerServiceId();
if (null == customerServiceId){
CustomerService customerService = customerServiceMapper.randService();
String wechatImgUrl = customerService.getWechatId();
byUserId.setCustomerServiceId(wechatImgUrl);
usersMapper.updateById(byUserId);
return customerService;
}else {
CustomerService customerService = customerServiceMapper.selectbyWeChatId(customerServiceId);
return customerService;
}
}
@Override
public void setWeChatQRImg(String wechatId, String wechatImgUrl) {
CustomerService customerService = new CustomerService();
customerService.setWechatId(wechatId);
customerService.setWechatImgUrl(wechatImgUrl);
customerService.setCreateTime(new Date());
customerService.setUpdateTime(new Date());
customerServiceMapper.insert(customerService);
}
/**
* 专属客服二维码图片文件上传
*/
@Override
public R uploadImage(MultipartFile file, HttpServletRequest request, String wechatId) throws IOException {
String basePath = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort();
Long time = System.currentTimeMillis();
String originalFilename = file.getOriginalFilename();//文件原始名称
String suffixName = originalFilename.substring(originalFilename.lastIndexOf("."));//从最后一个.开始截取。截取zxName的后缀名
String newName = time+suffixName; //文件新名称
//设置文件存储路径,可以存放在你想要指定的路径里面
String rootPath="/opt/upload/video/"; //上传图片存放位置
String filePath = rootPath + newName;
File newFile = new File(filePath);
//判断目标文件所在目录是否存在
if(!newFile.getParentFile().exists()){
//如果目标文件所在的目录不存在,则创建父目录
newFile.getParentFile().mkdirs();
}
//将内存中的数据写入磁盘
file.transferTo(newFile);
//入库地址
String serviceUrl = "/upload/" + newName;
CustomerService customerService = new CustomerService();
customerService.setWechatId(wechatId);
customerService.setWechatImgUrl(serviceUrl);
customerServiceMapper.insert(customerService);
return R.ok("上传成功");
}
}