|
@@ -18,11 +18,13 @@ import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.security.core.parameters.P;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
@@ -53,9 +55,10 @@ public class AppRedemptionCodeServiceImpl extends ServiceImpl<RedemptionCodeDao,
|
|
|
private final static Logger logger = LoggerFactory.getLogger(AppRedemptionCodeServiceImpl.class);
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public List<AppRedemptionCode> importRedemptionCode(MultipartFile file) throws Exception {
|
|
|
Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(
|
|
|
- new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
|
|
|
+ new ByteArrayInputStream(file.getBytes()), 0, file.getOriginalFilename());
|
|
|
|
|
|
InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
|
|
|
Map<String, String> columns = IniFileUtil.readIniFile(inputStream, TemplateTypeEnum.REDEMPTIONCODE.getMsg());
|
|
@@ -83,13 +86,20 @@ public class AppRedemptionCodeServiceImpl extends ServiceImpl<RedemptionCodeDao,
|
|
|
try {
|
|
|
AppRedemptionCode redemptionCode = JSONObject.parseObject(objectMap.toJSONString(),
|
|
|
AppRedemptionCode.class);
|
|
|
+ if (redemptionCode.getCode() == null) continue;
|
|
|
redemptionCodesList.add(redemptionCode);
|
|
|
- redemptionCodeDao.insert(redemptionCode);
|
|
|
} catch (Exception ex) {
|
|
|
- throw new BizException("导入数据出错", ex);
|
|
|
+ throw new BizException("导入数据出错:" + ex, ex);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ try {
|
|
|
+ redemptionCodeDao.insertBatch(redemptionCodesList);
|
|
|
+ } catch (DuplicateKeyException dupKeyEx) {
|
|
|
+ throw new BizException("数据重复:" + dupKeyEx.getCause(), dupKeyEx);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new BizException("导入数据出错:" + ex, ex);
|
|
|
+ }
|
|
|
return redemptionCodesList;
|
|
|
}
|
|
|
|