|
|
|
@ -3,7 +3,12 @@ package com.ruoyi.web.controller.manager;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
|
|
import com.ruoyi.common.utils.ShiroUtils;
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
|
import com.ruoyi.common.utils.bean.BeanValidators;
|
|
|
|
|
import com.ruoyi.common.utils.security.Md5Utils;
|
|
|
|
|
import com.ruoyi.system.domain.check.TdCheckReport;
|
|
|
|
|
import com.ruoyi.system.domain.check.TdCheckType;
|
|
|
|
|
import com.ruoyi.system.domain.check.dto.TdCheckReportDTO;
|
|
|
|
@ -11,6 +16,7 @@ import com.ruoyi.system.domain.check.dto.TdCheckTypeDTO;
|
|
|
|
|
import com.ruoyi.system.domain.spost.TdClassifiedPost;
|
|
|
|
|
import com.ruoyi.system.domain.spost.dto.TdClassifiedPostDTO;
|
|
|
|
|
import com.ruoyi.system.service.spost.TdClassifiedPostService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
@ -29,6 +35,7 @@ import java.util.List;
|
|
|
|
|
* @Version 1.0
|
|
|
|
|
*/
|
|
|
|
|
@Component
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class ClassifiedPostManager {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@ -66,4 +73,43 @@ public class ClassifiedPostManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导入数据
|
|
|
|
|
* @param classifiedPosts 数据列表
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
public String importPost(List<TdClassifiedPost> classifiedPosts) {
|
|
|
|
|
if (CollUtil.isEmpty(classifiedPosts)) {
|
|
|
|
|
throw new ServiceException("导入数据不能为空!");
|
|
|
|
|
}
|
|
|
|
|
int successNum = 0;
|
|
|
|
|
int failureNum = 0;
|
|
|
|
|
StringBuilder successMsg = new StringBuilder();
|
|
|
|
|
StringBuilder failureMsg = new StringBuilder();
|
|
|
|
|
for (TdClassifiedPost classifiedPost : classifiedPosts) {
|
|
|
|
|
try {
|
|
|
|
|
classifiedPost.setCreateTime(new Date());
|
|
|
|
|
classifiedPost.setCreateBy(ShiroUtils.getSysUser().getUserName());
|
|
|
|
|
classifiedPost.setDeptId(ShiroUtils.getSysUser().getDeptId());
|
|
|
|
|
classifiedPost.setStatus("0");
|
|
|
|
|
classifiedPostService.save(classifiedPost);
|
|
|
|
|
successNum++;
|
|
|
|
|
successMsg.append("<br/>").append(successNum).append("、账号 ").append(classifiedPost.getPostName()).append(" 导入成功");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
failureNum++;
|
|
|
|
|
String msg = "<br/>" + failureNum + "、账号 " + classifiedPost.getPostName() + " 导入失败:";
|
|
|
|
|
failureMsg.append(msg).append(e.getMessage());
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (failureNum > 0) {
|
|
|
|
|
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
|
|
throw new ServiceException(failureMsg.toString());
|
|
|
|
|
} else {
|
|
|
|
|
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
|
|
}
|
|
|
|
|
return successMsg.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|