|
@@ -37,157 +37,166 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class FinancialExpenditureServiceImpl extends BaseServiceImpl<Long, FinancialExpenditure> implements FinancialExpenditureService {
|
|
public class FinancialExpenditureServiceImpl extends BaseServiceImpl<Long, FinancialExpenditure> implements FinancialExpenditureService {
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private FinancialExpenditureDao financialExpenditureDao;
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
- public BaseDAO<Long, FinancialExpenditure> getDAO() {
|
|
|
|
- return financialExpenditureDao;
|
|
|
|
- }
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private FinancialExpenditureDao financialExpenditureDao;
|
|
|
|
|
|
- private static final Logger LOGGER = LoggerFactory.getLogger(FinancialExpenditureServiceImpl.class);
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public BaseDAO<Long, FinancialExpenditure> getDAO() {
|
|
|
|
+ return financialExpenditureDao;
|
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
- public List<FinancialExpenditure> importFinancialExpenditure(MultipartFile file) throws Exception {
|
|
|
|
- Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
|
|
|
|
- InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
|
|
|
|
- Map<String,String> columns = IniFileUtil.readIniFile(inputStream,TemplateTypeEnum.FINANCIAL_EXPENDITURE.getMsg());
|
|
|
|
- List<FinancialExpenditure> financialExpenditures = new ArrayList<>();
|
|
|
|
- Map<String, Integer> organMap = getMap("organization", "name_", "id_", true, String.class, Integer.class);
|
|
|
|
- Map<String, Integer> cooperationOrganMap = getMap("cooperation_organ", "name_", "id_", true, String.class, Integer.class);
|
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
|
- for (String e : sheetsListMap.keySet()) {
|
|
|
|
- List<Map<String, Object>> sheet = sheetsListMap.get(e);
|
|
|
|
- List<Object> collect = sheet.stream().map(m -> m.get("钉钉流程编号")).collect(Collectors.toList());
|
|
|
|
- if(collect == null || collect.size() == 0){
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- valueIsNull: for (int j = 0; j < sheet.size(); j++) {
|
|
|
|
- int rowNum = j + 2;
|
|
|
|
- Map<String, Object> row = sheet.get(j);
|
|
|
|
- if (row.size() == 0) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- JSONObject objectMap = new JSONObject();
|
|
|
|
- for (String s : row.keySet()) {
|
|
|
|
- if(!columns.containsKey(s)){
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- String columnValue = columns.get(s);
|
|
|
|
- if (columnValue.equals("type")) {
|
|
|
|
- for (ExpenditureTypeEnum expenditureType : ExpenditureTypeEnum.values()) {
|
|
|
|
- if (expenditureType.getDesc().equals(row.get(s).toString())) {
|
|
|
|
- objectMap.put(columnValue, expenditureType);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if (columnValue.equals("dingtalkProcessNo")) {
|
|
|
|
- if (StringUtils.isEmpty(row.get(s).toString())) {
|
|
|
|
- sb.append("第" + rowNum).append("行数据导入失败:钉钉流程编号不可为空;");
|
|
|
|
- continue valueIsNull;
|
|
|
|
- } else {
|
|
|
|
- objectMap.put("incomeType", row.get(s));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (columnValue.equals("feeProject")) {
|
|
|
|
- for (FeeProjectEnum feeProject : FeeProjectEnum.values()) {
|
|
|
|
- if (feeProject.getDesc().equals(row.get(s).toString())) {
|
|
|
|
- objectMap.put(columnValue, feeProject);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if (columnValue.equals("amount")) {
|
|
|
|
- if(StringUtils.isEmpty(row.get(s).toString())){
|
|
|
|
- sb.append("第" + rowNum).append("行数据导入失败:费用不可为空;");
|
|
|
|
- continue valueIsNull;
|
|
|
|
- }else {
|
|
|
|
- objectMap.put("amount", row.get(s));
|
|
|
|
- }
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if (columnValue.equals("organName") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
|
- Integer integer = organMap.get(row.get(s));
|
|
|
|
- if(integer == null){
|
|
|
|
- sb.append("第" + rowNum).append("行数据导入失败:分部校验失败;");
|
|
|
|
- continue valueIsNull;
|
|
|
|
- }else {
|
|
|
|
- objectMap.put("organId", integer);
|
|
|
|
- }
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if (columnValue.equals("cooperationOrganName") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
|
- Integer integer = cooperationOrganMap.get(row.get(s));
|
|
|
|
- if(integer == null){
|
|
|
|
- sb.append("第" + rowNum).append("行数据导入失败:合作单位校验失败;");
|
|
|
|
- continue valueIsNull;
|
|
|
|
- }else {
|
|
|
|
- objectMap.put("cooperationOrganId", integer);
|
|
|
|
- }
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if (columnValue.equals("paymentTime") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
|
- String toString = row.get(s).toString();
|
|
|
|
- if(StringUtils.isNotEmpty(toString)){
|
|
|
|
- Date date = DateUtil.stringToDate(toString, DateUtil.DEFAULT_PATTERN);
|
|
|
|
- if(date == null){
|
|
|
|
- throw new BizException("导入数据错误 付款时间格式错误");
|
|
|
|
- }else {
|
|
|
|
- objectMap.put(columnValue, DateUtil.format(date,DateUtil.DEFAULT_PATTERN));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- objectMap.put(columnValue, row.get(s));
|
|
|
|
- }
|
|
|
|
- FinancialExpenditure financialExpenditure = null;
|
|
|
|
- try {
|
|
|
|
- financialExpenditure = JSONObject.parseObject(objectMap.toJSONString(),FinancialExpenditure.class);
|
|
|
|
- financialExpenditures.add(financialExpenditure);
|
|
|
|
- } catch (Exception ex) {
|
|
|
|
- throw new BizException("导入数据出错,请检查Excel表格");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if(sb.length() > 0){
|
|
|
|
- throw new BizException(sb.toString());
|
|
|
|
- }
|
|
|
|
- if(financialExpenditures.size() != 0){
|
|
|
|
- financialExpenditureDao.batchInsert(financialExpenditures);
|
|
|
|
- }
|
|
|
|
- return financialExpenditures;
|
|
|
|
- }
|
|
|
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(FinancialExpenditureServiceImpl.class);
|
|
|
|
|
|
- @Override
|
|
|
|
- public PageInfo<FinancialExpenditureDto> queryFinancialExpenditurePage(FinancialExpenditureQueryInfo queryInfo){
|
|
|
|
- PageInfo<FinancialExpenditureDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
|
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
|
- MapUtil.populateMap(params, queryInfo);
|
|
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public List<FinancialExpenditure> importFinancialExpenditure(MultipartFile file) throws Exception {
|
|
|
|
+ Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
|
|
|
|
+ InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
|
|
|
|
+ Map<String, String> columns = IniFileUtil.readIniFile(inputStream, TemplateTypeEnum.FINANCIAL_EXPENDITURE.getMsg());
|
|
|
|
+ List<FinancialExpenditure> financialExpenditures = new ArrayList<>();
|
|
|
|
+ Map<String, Integer> organMap = getMap("organization", "name_", "id_", true, String.class, Integer.class);
|
|
|
|
+ Map<String, Integer> cooperationOrganMap = getMap("cooperation_organ", "name_", "id_", true, String.class, Integer.class);
|
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
|
+ for (String e : sheetsListMap.keySet()) {
|
|
|
|
+ List<Map<String, Object>> sheet = sheetsListMap.get(e);
|
|
|
|
+ List<Object> collect = sheet.stream().map(m -> m.get("钉钉流程编号")).collect(Collectors.toList());
|
|
|
|
+ if (collect == null || collect.size() == 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ valueIsNull:
|
|
|
|
+ for (int j = 0; j < sheet.size(); j++) {
|
|
|
|
+ int rowNum = j + 2;
|
|
|
|
+ Map<String, Object> row = sheet.get(j);
|
|
|
|
+ if (row.size() == 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ JSONObject objectMap = new JSONObject();
|
|
|
|
+ for (String s : row.keySet()) {
|
|
|
|
+ if (!columns.containsKey(s)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ String columnValue = columns.get(s);
|
|
|
|
+ if (columnValue.equals("type")) {
|
|
|
|
+ for (ExpenditureTypeEnum expenditureType : ExpenditureTypeEnum.values()) {
|
|
|
|
+ if (expenditureType.getDesc().equals(row.get(s).toString())) {
|
|
|
|
+ objectMap.put(columnValue, expenditureType);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (columnValue.equals("dingtalkProcessNo")) {
|
|
|
|
+ if (StringUtils.isEmpty(row.get(s).toString())) {
|
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:钉钉流程编号不可为空;");
|
|
|
|
+ continue valueIsNull;
|
|
|
|
+ } else {
|
|
|
|
+ objectMap.put("incomeType", row.get(s));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (columnValue.equals("feeProject")) {
|
|
|
|
+ for (FeeProjectEnum feeProject : FeeProjectEnum.values()) {
|
|
|
|
+ if (feeProject.getDesc().equals(row.get(s).toString())) {
|
|
|
|
+ objectMap.put(columnValue, feeProject);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (columnValue.equals("amount")) {
|
|
|
|
+ if (StringUtils.isEmpty(row.get(s).toString())) {
|
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:费用不可为空;");
|
|
|
|
+ continue valueIsNull;
|
|
|
|
+ } else {
|
|
|
|
+ objectMap.put("amount", row.get(s));
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (columnValue.equals("organName") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
|
+ Integer integer = organMap.get(row.get(s));
|
|
|
|
+ if (integer == null) {
|
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:分部校验失败;");
|
|
|
|
+ continue valueIsNull;
|
|
|
|
+ } else {
|
|
|
|
+ objectMap.put("organId", integer);
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (columnValue.equals("cooperationOrganName") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
|
+ Integer integer = cooperationOrganMap.get(row.get(s));
|
|
|
|
+ if (integer == null) {
|
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:合作单位校验失败;");
|
|
|
|
+ continue valueIsNull;
|
|
|
|
+ } else {
|
|
|
|
+ objectMap.put("cooperationOrganId", integer);
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (columnValue.equals("paymentTime") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
|
+ String toString = row.get(s).toString();
|
|
|
|
+ if (StringUtils.isNotEmpty(toString)) {
|
|
|
|
+ Date date = DateUtil.stringToDate(toString, DateUtil.DEFAULT_PATTERN);
|
|
|
|
+ if (date == null) {
|
|
|
|
+ throw new BizException("导入数据错误 付款时间格式错误");
|
|
|
|
+ } else {
|
|
|
|
+ objectMap.put(columnValue, DateUtil.format(date, DateUtil.DEFAULT_PATTERN));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ objectMap.put(columnValue, row.get(s));
|
|
|
|
+ }
|
|
|
|
+ FinancialExpenditure financialExpenditure = null;
|
|
|
|
+ try {
|
|
|
|
+ financialExpenditure = JSONObject.parseObject(objectMap.toJSONString(), FinancialExpenditure.class);
|
|
|
|
+ financialExpenditures.add(financialExpenditure);
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ throw new BizException("导入数据出错,请检查Excel表格");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (sb.length() > 0) {
|
|
|
|
+ throw new BizException(sb.toString());
|
|
|
|
+ }
|
|
|
|
+ if (financialExpenditures.size() != 0) {
|
|
|
|
+ financialExpenditureDao.batchInsert(financialExpenditures);
|
|
|
|
+ }
|
|
|
|
+ return financialExpenditures;
|
|
|
|
+ }
|
|
|
|
|
|
- List<FinancialExpenditureDto> dataList = null;
|
|
|
|
- int count = financialExpenditureDao.findFinancialExpenditureCount(params);
|
|
|
|
- if (count > 0) {
|
|
|
|
- pageInfo.setTotal(count);
|
|
|
|
- params.put("offset", pageInfo.getOffset());
|
|
|
|
- dataList = financialExpenditureDao.queryFinancialExpenditurePage(params);
|
|
|
|
- }
|
|
|
|
- if (count == 0) {
|
|
|
|
- dataList = new ArrayList<>();
|
|
|
|
- }
|
|
|
|
- pageInfo.setRows(dataList);
|
|
|
|
- return pageInfo;
|
|
|
|
- }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public PageInfo<FinancialExpenditureDto> queryFinancialExpenditurePage(FinancialExpenditureQueryInfo queryInfo) {
|
|
|
|
+ PageInfo<FinancialExpenditureDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ MapUtil.populateMap(params, queryInfo);
|
|
|
|
|
|
- @Override
|
|
|
|
- public void batchDel(String ids) {
|
|
|
|
- if(StringUtils.isEmpty(ids)){
|
|
|
|
- throw new BizException("参数校验失败");
|
|
|
|
- }
|
|
|
|
- financialExpenditureDao.batchDel(ids);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ List<FinancialExpenditureDto> dataList = null;
|
|
|
|
+ int count = financialExpenditureDao.findFinancialExpenditureCount(params);
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ pageInfo.setTotal(count);
|
|
|
|
+ params.put("offset", pageInfo.getOffset());
|
|
|
|
+ dataList = financialExpenditureDao.queryFinancialExpenditurePage(params);
|
|
|
|
+ }
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ dataList = new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ pageInfo.setRows(dataList);
|
|
|
|
+ return pageInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void batchDel(String ids) {
|
|
|
|
+ if (StringUtils.isEmpty(ids)) {
|
|
|
|
+ throw new BizException("参数校验失败");
|
|
|
|
+ }
|
|
|
|
+ financialExpenditureDao.batchDel(ids);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<FinancialExpenditure> batchAdd(List<FinancialExpenditure> financialExpenditures) {
|
|
|
|
+ financialExpenditureDao.batchInsert(financialExpenditures);
|
|
|
|
+ return financialExpenditures;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|