zouxuan 4 роки тому
батько
коміт
bda5c5ae27

+ 118 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/FinancialExpenditureServiceImpl.java

@@ -0,0 +1,118 @@
+package com.ym.mec.biz.service.impl;
+
+
+import com.alibaba.fastjson.JSONObject;
+import com.ym.mec.biz.dal.dao.FinancialExpenditureDao;
+import com.ym.mec.biz.dal.entity.FinancialExpenditure;
+import com.ym.mec.biz.service.FinancialExpenditureService;
+import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.exception.BizException;
+import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.util.excel.IniFileUtil;
+import com.ym.mec.util.excel.POIUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class FinancialExpenditureServiceImpl extends BaseServiceImpl<Long, FinancialExpenditure> implements FinancialExpenditureService {
+	
+	@Autowired
+	private FinancialExpenditureDao financialExpenditureDao;
+
+	@Override
+	public BaseDAO<Long, FinancialExpenditure> getDAO() {
+		return financialExpenditureDao;
+	}
+
+	private static final Logger LOGGER = LoggerFactory.getLogger(FinancialExpenditureServiceImpl.class);
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public List<FinancialExpenditure> importFinancialExpenditure(MultipartFile file) throws IOException {
+		Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(file.getInputStream(), 2, file.getOriginalFilename());
+		String fileName = file.getOriginalFilename().split("\\.")[0];
+		InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
+		Map<String,String> columns = IniFileUtil.readIniFile(inputStream,fileName);
+		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);
+		Map<String, Integer> phoneMap = getMap("sys_user", "phone_", "id_", true, String.class, Integer.class);
+		for (String e : sheetsListMap.keySet()) {
+			List<Map<String, Object>> sheet = sheetsListMap.get(e);
+			valueIsNull: for (Map<String, Object> row : sheet) {
+				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("phone")) {
+						if(StringUtils.isEmpty(row.get(s).toString())){
+							LOGGER.error("商品导入异常:手机号不可为空 param:{}",objectMap);
+							continue valueIsNull;
+						}else {
+							Integer integer = phoneMap.get(row.get(s));
+							if(integer == null){
+								LOGGER.error("商品导入异常:手机号校验失败 param:{}",objectMap);
+								continue valueIsNull;
+							}else {
+								objectMap.put("applyUserId", integer);
+							}
+						}
+					}
+					if (columnValue.equals("amount")) {
+						if(StringUtils.isEmpty(row.get(s).toString())){
+							LOGGER.error("商品导入异常:费用不可为空 param:{}",objectMap);
+							continue valueIsNull;
+						}else {
+							objectMap.put("amount", row.get(s));
+						}
+					}
+					if (columnValue.equals("organName") && StringUtils.isNotEmpty(row.get(s).toString())) {
+						Integer integer = organMap.get(row.get(s));
+						if(integer == null){
+							LOGGER.error("商品导入异常:分部校验失败 param:{}",objectMap);
+						}else {
+							objectMap.put("organId", integer);
+						}
+					}
+					if (columnValue.equals("cooperationOrganName") && StringUtils.isNotEmpty(row.get(s).toString())) {
+						Integer integer = cooperationOrganMap.get(row.get(s));
+						if(integer == null){
+							LOGGER.error("商品导入异常:合作单位校验失败 param:{}",objectMap);
+						}else {
+							objectMap.put("cooperationOrganId", integer);
+						}
+					}
+					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("导入数据出错");
+				}
+			}
+		}
+		if(financialExpenditures.size() != 0){
+			financialExpenditureDao.batchInsert(financialExpenditures);
+		}
+		return financialExpenditures;
+	}
+}

+ 45 - 0
mec-web/src/main/java/com/ym/mec/web/controller/FinancialExpenditureController.java

@@ -0,0 +1,45 @@
+package com.ym.mec.web.controller;
+
+import com.ym.mec.biz.dal.entity.FinancialExpenditure;
+import com.ym.mec.biz.service.FinancialExpenditureService;
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.page.QueryInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+@RequestMapping("financialExpenditure")
+@Api(tags = "财务支出服务")
+@RestController
+public class FinancialExpenditureController extends BaseController {
+
+    @Autowired
+    private FinancialExpenditureService financialExpenditureService;
+
+    @ApiOperation(value = "修改财务支出")
+    @PostMapping("/update")
+    @PreAuthorize("@pcs.hasPermissions('financialExpenditure/update')")
+    public Object upSet(@RequestBody FinancialExpenditure financialExpenditure) {
+        financialExpenditureService.update(financialExpenditure);
+        return succeed();
+    }
+
+    @ApiOperation(value = "删除财务支出")
+    @PostMapping("/del/{id}")
+    @PreAuthorize("@pcs.hasPermissions('financialExpenditure/del')")
+    public Object del(@ApiParam(value = "财务支出编号", required = true) @PathVariable("id") Long id) {
+        financialExpenditureService.delete(id);
+        return succeed();
+    }
+
+    @ApiOperation(value = "分页查询财务支出列表")
+    @GetMapping("/queryPage")
+    @PreAuthorize("@pcs.hasPermissions('financialExpenditure/queryPage')")
+    public Object queryPage(QueryInfo queryInfo) {
+        return succeed(financialExpenditureService.queryPage(queryInfo));
+    }
+
+}

+ 24 - 0
mec-web/src/main/resources/columnMapper.ini

@@ -0,0 +1,24 @@
+[商品导入模板]
+品牌 = brand
+商品名称 = name
+商品类型 = type
+商品分类 = goodsCategoryName
+商品型号 = specification
+商品价格 = marketPrice
+商品团购价 = groupPurchasePrice
+商品采购价 = discountPrice
+商品图片(插入一张图片) = image
+商品描述 = desc
+协议成本价 = agreeCostPrice
+
+[财务支出导入模板]
+批次号 = batchNo
+财务流程编号 = financialProcessNo
+钉钉流程编号 = dingtalkProcessNo
+分部 = organName
+合作单位 = cooperationOrganName
+申请人(手机号) = phone
+费用 = amount
+费用明细 = itemDetail
+支付时间 = paymentTime
+事由 = cause

BIN
mec-web/src/main/resources/excelTemplate/商品导入模板.xls