excal导入
@PostMapping("importLeads/{createId}")
public YyptResponse outExcel(@RequestParam("file") MultipartFile[] file, @PathVariable("createId") Integer createId) {
if (createId == null) {
return YyptResponse.failure("导入人不id不能为空!");
}
for (MultipartFile multipartFile : file) {
String s = leadsService.importLeads(multipartFile, createId);
if (s != null) {
return YyptResponse.failure("文件名称:"+multipartFile.getOriginalFilename()+"\n"+"出现异常原因:"+s);
}
}
return YyptResponse.success(null);
}
String importLeads(MultipartFile file,Integer createId);
@Service
@AllArgsConstructor
public class LeadsServiceImpl extends ServiceImpl<LeadsMapper, Leads> implements LeadsService {
private final WechatExternalContactYtyfMapper wechatExternalContactYtyfMapper;
@Override
public String checkPhone(Leads leads) {
if (leads == null || leads.getCreateId() == null) {
return "创建人id不能为空";
}
if (StringUtils.isEmpty(leads.getName())) {
return "用户姓名不能为空";
}
if (StringUtils.isEmpty(leads.getPhone())) {
return "电话不能为空";
}
Integer count = this.getBaseMapper().selectCount(Wrappers.<Leads>lambdaQuery().eq(Leads::getPhone,
leads.getPhone()));
if (count>0){
return SysConstants.REPEATED_CLUES;
}
List<UserDto> userList = wechatExternalContactYtyfMapper.getUserId(leads.getPhone());
if (userList != null && userList.size() > 0) {
UserDto userDto = userList.get(0);
leads.setBuildId(userDto.getUserId());
leads.setBuildDate(userDto.getCreDate());
leads.setStatus(SysConstants.LEADS_STATUS_SUCCESS);
}
this.baseMapper.insert(leads);
return null;
}
@Override
public String importLeads(MultipartFile file,Integer createId){
ImportParams importParams = new ImportParams();
importParams.setTitleRows(1);
importParams.setHeadRows(1);
List<Leads> leadsList = null;
try {
leadsList = ExcelImportUtil.importExcel(file.getInputStream(), Leads.class,importParams);
} catch (Exception e) {
e.printStackTrace();
}
Map<String,String> map=null;
for (int i = 0; i < leadsList.size(); i++) {
Leads leads = leadsList.get(i);
leads.setCreateId(createId);
if (SysConstants.REPEATED_CLUES.equals(checkPhone(leads))) {
if (map==null){
map=new HashMap<>();
}
map.put(leads.getName(),leads.getPhone());
}
}
if (map!=null&&map.size()>0){
return "除已有线索,都已成功导入!\n重复线索列表如下:"+map.toString();
}
return null;
}
package com.yypt.scrm.domain;
import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.List;
import java.util.Set;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
@Data
public class Leads implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.AUTO)
private Integer id;
@Excel(name="线索id")
private String leadsId;
@Excel(name="姓名")
private String name;
@Excel(name="电话")
private String phone;
@Excel(name="所在地")
private String address;
@Excel(name="流量来源")
private String trafficSource;
@Excel(name = "素材内容")
private String content;
@Excel(name="推广链接")
private String sponsoredLinks;
@Excel(name="备注")
private String remark;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
private Integer dockingId;
private LocalDateTime buildDate;
private Integer buildId ;
private Integer createId;
private Integer status;
@TableField(exist = false)
private String dockingName;
@TableField(exist = false)
private String buildName;
@TableField(exist = false)
private String createName;
@TableField(exist = false)
private String roleCodeList;
@TableField(exist = false)
private Integer loginId;
@TableField(exist = false)
private Set<Integer> userSet;
}