|
@@ -1,11 +1,19 @@
|
|
|
package com.phm.manage.service.impl;
|
|
|
|
|
|
+import com.phm.common.core.domain.entity.SysUser;
|
|
|
+import com.phm.common.exception.ServiceException;
|
|
|
+import com.phm.common.utils.SecurityUtils;
|
|
|
+import com.phm.common.utils.StringUtils;
|
|
|
+import com.phm.common.utils.bean.BeanValidators;
|
|
|
import com.phm.manage.domain.Sortie;
|
|
|
import com.phm.manage.mapper.SortieMapper;
|
|
|
import com.phm.manage.service.ISortieService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.validation.Validator;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -16,9 +24,14 @@ import java.util.List;
|
|
|
*/
|
|
|
@Service
|
|
|
public class SortieServiceImpl implements ISortieService {
|
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(SortieServiceImpl.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
private SortieMapper sortieMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ protected Validator validator;
|
|
|
+
|
|
|
/**
|
|
|
* 查询架次信息
|
|
|
*
|
|
@@ -86,4 +99,57 @@ public class SortieServiceImpl implements ISortieService {
|
|
|
public int deleteSortieById(Long id) {
|
|
|
return sortieMapper.deleteSortieById(id);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入架次数据
|
|
|
+ *
|
|
|
+ * @param sortieList 架次数据列表
|
|
|
+ * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String importSortie(List<Sortie> sortieList, Boolean isUpdateSupport) {
|
|
|
+ if (StringUtils.isNull(sortieList) || sortieList.isEmpty()) {
|
|
|
+ throw new ServiceException("导入架次数据不能为空!");
|
|
|
+ }
|
|
|
+ int successNum = 0;
|
|
|
+ int failureNum = 0;
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ for (Sortie sortie : sortieList) {
|
|
|
+ try {
|
|
|
+ // 验证是否存在这个架次
|
|
|
+ Sortie sor = sortieMapper.selectSortieByNumber(sortie.getSortieNumber());
|
|
|
+ if (StringUtils.isNull(sor)) {
|
|
|
+ BeanValidators.validateWithException(validator, sortie);
|
|
|
+ sortie.initCreatInfo();
|
|
|
+ sortieMapper.insertSortie(sortie);
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>").append(successNum).append("、架次号 ").append(sortie.getSortieNumber()).append(" 导入成功");
|
|
|
+ } else if (isUpdateSupport) {
|
|
|
+ BeanValidators.validateWithException(validator, sortie);
|
|
|
+ sortie.setSortieNumber(sor.getSortieNumber());
|
|
|
+ sortie.initUpdateInfo();
|
|
|
+ sortieMapper.updateSortie(sortie);
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>").append(successNum).append("、架次号 ").append(sortie.getSortieNumber()).append(" 更新成功");
|
|
|
+ } else {
|
|
|
+ failureNum++;
|
|
|
+ failureMsg.append("<br/>").append(failureNum).append("、架次号 ").append(sortie.getSortieNumber()).append(" 已存在");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、架次号 " + sortie.getSortieNumber() + " 导入失败:";
|
|
|
+ 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();
|
|
|
+ }
|
|
|
}
|