|
|
|
@ -1,22 +1,29 @@ |
|
|
|
|
package com.dxhy.core.controller.mailGather; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.codec.Base64; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.dxhy.common.controller.AbstractController; |
|
|
|
|
import com.dxhy.common.util.UUIDUtils; |
|
|
|
|
import com.dxhy.common.utils.Base64Encoding; |
|
|
|
|
import com.dxhy.common.utils.R; |
|
|
|
|
import com.dxhy.common.vo.UserInfo; |
|
|
|
|
import com.dxhy.core.model.mailGather.EmailMaintainExcel; |
|
|
|
|
import com.dxhy.core.model.mailGather.EmailMaintainVo; |
|
|
|
|
import com.dxhy.core.service.mailGather.EmailMaintainService; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import lombok.Data; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -110,16 +117,79 @@ public class EmailMaintainController extends AbstractController { |
|
|
|
|
/** |
|
|
|
|
* 编辑数据 |
|
|
|
|
* |
|
|
|
|
* @param emailMaintain 实体 |
|
|
|
|
* @param file 实体 |
|
|
|
|
* @return 编辑结果 |
|
|
|
|
*/ |
|
|
|
|
@PostMapping("/emailUpload") |
|
|
|
|
public ResponseEntity<R> emailUpload(@RequestBody EmailMaintainVo emailMaintain) { |
|
|
|
|
boolean b = emailMaintainService.update(emailMaintain); |
|
|
|
|
if(b){ |
|
|
|
|
return ResponseEntity.ok(R.ok()); |
|
|
|
|
@RequestMapping("/emailUpload") |
|
|
|
|
public ResponseEntity<R> emailUpload(@RequestParam(value = "file") MultipartFile file, |
|
|
|
|
@RequestParam(value = "deptId") String deptId, |
|
|
|
|
@RequestParam(value = "deptName") String deptName) { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
List<EmailMaintainExcel> emailMaintainExcels = |
|
|
|
|
EasyExcel.read(file.getInputStream()).sheet().head(EmailMaintainExcel.class).headRowNumber(1).doReadSync(); |
|
|
|
|
log.info("解析的数据:{}",JSONObject.toJSONString(emailMaintainExcels)); |
|
|
|
|
if (emailMaintainExcels == null || emailMaintainExcels.isEmpty()) { |
|
|
|
|
return ResponseEntity.ok(R.error("数据解析失败")); |
|
|
|
|
} |
|
|
|
|
List<String> errorMsgList = Lists.newArrayList(); |
|
|
|
|
List<EmailMaintainVo> mailList = Lists.newArrayList(); |
|
|
|
|
|
|
|
|
|
int resultIndex = 2; |
|
|
|
|
for (EmailMaintainExcel maintainExcel : emailMaintainExcels) { |
|
|
|
|
String userId = maintainExcel.getUserId(); |
|
|
|
|
if (StringUtils.isBlank(userId)) { |
|
|
|
|
errorMsgList.add("第" + resultIndex + "行,用户编码不能为空"); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
String userName = emailMaintainService.getUserName(userId); |
|
|
|
|
if(StringUtils.isBlank(userName)){ |
|
|
|
|
errorMsgList.add("第" + resultIndex + "行,用户编码在系统中查询不到,请核实!"); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
String address = maintainExcel.getEmailAddress(); |
|
|
|
|
if (StringUtils.isBlank(address)) { |
|
|
|
|
errorMsgList.add("第" + resultIndex + "行,邮箱地址不能为空"); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if(!"@qq.com".equals(address) || !"@163.com".equals(address)){ |
|
|
|
|
errorMsgList.add("第" + resultIndex + "行,不支持该邮箱类型"); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
String password = maintainExcel.getEmailPassword(); |
|
|
|
|
if (StringUtils.isBlank(password)) { |
|
|
|
|
errorMsgList.add("第" + resultIndex + "行,授权码不能为空"); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
EmailMaintainVo maintainVo = new EmailMaintainVo(); |
|
|
|
|
maintainVo.setId(UUIDUtils.generateShortUuid()); |
|
|
|
|
maintainVo.setCompanyCode(deptId); |
|
|
|
|
maintainVo.setDeptName(deptName); |
|
|
|
|
maintainVo.setUsername(userName); |
|
|
|
|
maintainVo.setUserId(userId); |
|
|
|
|
maintainVo.setEmailAddress(address); |
|
|
|
|
String encode = Base64Encoding.encode(password); |
|
|
|
|
maintainVo.setEmailPassword(encode); |
|
|
|
|
maintainVo.setDelStatus("0"); |
|
|
|
|
maintainVo.setCreateUser(getUserInfo().getLoginname()); |
|
|
|
|
maintainVo.setCreateTime(new Date()); |
|
|
|
|
maintainVo.setModifyTime(new Date()); |
|
|
|
|
mailList.add(maintainVo); |
|
|
|
|
resultIndex++; |
|
|
|
|
} |
|
|
|
|
if (ObjectUtil.isNotEmpty(errorMsgList)) { |
|
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
|
json.put("datalist", errorMsgList); |
|
|
|
|
return ResponseEntity.ok(R.ok().put("data",Base64.encode(json.toJSONString()))); |
|
|
|
|
} |
|
|
|
|
int i = emailMaintainService.insertBatch(mailList); |
|
|
|
|
if(i > 0){ |
|
|
|
|
return ResponseEntity.ok(R.ok()); |
|
|
|
|
} |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
return ResponseEntity.ok(R.error()); |
|
|
|
|
return ResponseEntity.ok(R.error("数据解析失败")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|