Bläddra i källkod

Merge branch 'yonge' of http://git.dayaedu.com/yonge/mec into yonge

yonge 5 år sedan
förälder
incheckning
be6d985da5

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/GoodsDao.java

@@ -135,4 +135,12 @@ public interface GoodsDao extends BaseDAO<Integer, Goods> {
     List<MusicGroupGoodsAndDiscountDto> getMusicGroupGoodsAndDiscount(@Param("subjectId") Integer subjectId, @Param("type") String type);
 
     List<MusicGroupGoodsAndDiscountDto> getMusicGroupGoodsAndDiscountWithSubjects(@Param("subjectIds") String subjectIds, @Param("type") String type);
+
+    /**
+     * 是否存在已上架的商品编号
+     * @param goodsId
+     * @param status
+     * @return
+     */
+    Boolean findByIdAndStatus(@Param("goodsId") String goodsId, @Param("status") int status);
 }

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentPaymentOrderDao.java

@@ -4,6 +4,7 @@ import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.Organization;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
+import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.GroupType;
 import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;

+ 7 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentPaymentRouteOrderDao.java

@@ -64,4 +64,11 @@ public interface StudentPaymentRouteOrderDao extends BaseDAO<Long, StudentPaymen
     int queryAuditCount(Map<String, Object> params);
     
     List<StudentPaymentRouteOrder> queryAuditPage(Map<String, Object> params);
+
+    /**
+     * 是否有重复到订单号
+     * @param transNos
+     * @return
+     */
+    List<String> countByTransNo(@Param("transNos") List<Object> transNos);
 }

+ 21 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentPaymentRouteOrder.java

@@ -54,6 +54,10 @@ public class StudentPaymentRouteOrder {
     
     private String memo;
     
+    private String goodsIds;
+
+    private String goodsNums;
+
     private String goodsJson;
     
     private AuditStatusEnum auditStatus;
@@ -76,7 +80,23 @@ public class StudentPaymentRouteOrder {
     
     private Organization organ = new Organization();
 
-    public Long getId() {
+	public String getGoodsIds() {
+		return goodsIds;
+	}
+
+	public void setGoodsIds(String goodsIds) {
+		this.goodsIds = goodsIds;
+	}
+
+	public String getGoodsNums() {
+		return goodsNums;
+	}
+
+	public void setGoodsNums(String goodsNums) {
+		this.goodsNums = goodsNums;
+	}
+
+	public Long getId() {
         return id;
     }
 

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/TemplateTypeEnum.java

@@ -4,6 +4,7 @@ import com.ym.mec.common.enums.BaseEnum;
 
 public enum TemplateTypeEnum implements BaseEnum<String, TemplateTypeEnum> {
     GOODS("GOODS","商品导入模板"),
+    ROUTE_ORDER("ROUTE_ORDER","财务管理导入模板"),
     FINANCIAL_EXPENDITURE("FINANCIAL_EXPENDITURE","财务支出导入模板");
 
     private String code;

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentRouteOrderService.java

@@ -2,6 +2,7 @@ package com.ym.mec.biz.service;
 
 
 import java.math.BigDecimal;
+import java.util.List;
 
 import com.ym.mec.biz.dal.dto.PageInfoOrder;
 import com.ym.mec.biz.dal.dto.StudentPaymentRouteOrderDto;
@@ -11,6 +12,7 @@ import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.QueryInfo;
 import com.ym.mec.common.service.BaseService;
+import org.springframework.web.multipart.MultipartFile;
 
 
 public interface StudentPaymentRouteOrderService extends BaseService<Long, StudentPaymentRouteOrder> {
@@ -64,4 +66,11 @@ public interface StudentPaymentRouteOrderService extends BaseService<Long, Stude
 	 */
 	Boolean deleteRouteOrder(Long orderId);
 
+	/**
+	 * 财务管理订单导入
+	 * @author zouxuan
+	 * @param file
+	 * @return
+	 */
+    List<StudentPaymentRouteOrder> importRouteOrder(MultipartFile file) throws Exception;
 }

+ 132 - 16
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentRouteOrderServiceImpl.java

@@ -1,16 +1,21 @@
 package com.ym.mec.biz.service.impl;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.Map.Entry;
 import java.util.stream.Collectors;
 
+import com.alibaba.fastjson.JSONArray;
+import com.ym.mec.biz.dal.entity.*;
+import com.ym.mec.biz.dal.enums.*;
+import com.ym.mec.util.date.DateUtil;
+import com.ym.mec.util.excel.IniFileUtil;
+import com.ym.mec.util.excel.POIUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
@@ -24,17 +29,6 @@ import com.ym.mec.biz.dal.dao.StudentPaymentRouteOrderDao;
 import com.ym.mec.biz.dal.dao.SysUserCashAccountDao;
 import com.ym.mec.biz.dal.dto.PageInfoOrder;
 import com.ym.mec.biz.dal.dto.StudentPaymentRouteOrderDto;
-import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.SellOrder;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
-import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
-import com.ym.mec.biz.dal.enums.AccountType;
-import com.ym.mec.biz.dal.enums.AuditStatusEnum;
-import com.ym.mec.biz.dal.enums.DealStatusEnum;
-import com.ym.mec.biz.dal.enums.GroupType;
-import com.ym.mec.biz.dal.enums.OrderTypeEnum;
-import com.ym.mec.biz.dal.enums.SellTypeEnum;
-import com.ym.mec.biz.dal.enums.SporadicChargeTypeEnum;
 import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
 import com.ym.mec.biz.service.GoodsService;
 import com.ym.mec.biz.service.SellOrderService;
@@ -46,6 +40,7 @@ import com.ym.mec.common.page.QueryInfo;
 import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.collection.MapUtil;
+import org.springframework.web.multipart.MultipartFile;
 
 @Service
 public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentRouteOrder> implements StudentPaymentRouteOrderService {
@@ -314,4 +309,125 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
         return true;
     }
 
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public List<StudentPaymentRouteOrder> importRouteOrder(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.ROUTE_ORDER.getMsg());
+		List<StudentPaymentRouteOrder> studentPaymentRouteOrders = 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);
+		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;
+			}
+			List<String> list = studentPaymentRouteOrderDao.countByTransNo(collect);
+			if(list != null && list.size() > 0){
+				throw new BizException("导入数据错误  重复的交易流水号:{}",list.get(0));
+			}
+
+			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("transNo")) {
+						if(StringUtils.isEmpty(row.get(s).toString())){
+							continue valueIsNull;
+						}
+					}
+					if (columnValue.equals("merNo")) {
+						if(StringUtils.isEmpty(row.get(s).toString())){
+							continue valueIsNull;
+						}else {
+							objectMap.put("merNo", row.get(s));
+						}
+						continue;
+					}
+					if (columnValue.equals("organName") && StringUtils.isNotEmpty(row.get(s).toString())) {
+						Integer integer = organMap.get(row.get(s));
+						if(integer == null){
+							continue valueIsNull;
+						}else {
+							objectMap.put("routeOrganId", integer);
+						}
+						continue;
+					}
+					if (columnValue.equals("cooperationOrganName") && StringUtils.isNotEmpty(row.get(s).toString())) {
+						Integer integer = cooperationOrganMap.get(row.get(s));
+						if(integer != null){
+							objectMap.put("schoolId", integer);
+						}
+						continue;
+					}
+					if (columnValue.equals("payTime") && 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));
+				}
+				StudentPaymentRouteOrder studentPaymentRouteOrder = JSONObject.parseObject(objectMap.toJSONString(),StudentPaymentRouteOrder.class);
+				//是否有销售金额
+				if(studentPaymentRouteOrder.getSaleAmount() != null && studentPaymentRouteOrder.getSaleAmount().longValue() != 0l){
+					String goodsIds = studentPaymentRouteOrder.getGoodsIds();
+					String goodsNums = studentPaymentRouteOrder.getGoodsNums();
+
+					if(StringUtils.isEmpty(goodsNums)){
+						throw new BizException("导入失败:有销售金额时商品数量必填");
+					}
+					if(StringUtils.isEmpty(goodsIds)){
+						throw new BizException("导入失败:有销售金额时商品编号必填");
+					}
+					List<String> goodsIdList = new ArrayList(Arrays.asList(goodsIds.split(",")));
+					List<String> goodsNumList = new ArrayList(Arrays.asList(goodsNums.split(",")));
+					if(goodsIdList.size() != goodsNumList.size()){
+						throw new BizException("导入失败:商品编号和商品数量不一致");
+					}
+					JSONArray goodsJSON = new JSONArray();
+					for (int i = 0; i < goodsIdList.size(); i++) {
+						if(!goodsDao.findByIdAndStatus(goodsIdList.get(i), 1)){
+							throw new BizException("导入失败:商品编号{}不存在",goodsIdList.get(i));
+						}
+						try {
+							int goodsNum = Integer.parseInt(goodsNumList.get(i));
+							JSONObject jsonObject = new JSONObject();
+							jsonObject.put(goodsIdList.get(i),goodsNum);
+							goodsJSON.add(jsonObject);
+						}catch (Exception e1){
+							throw new BizException("导入失败:商品数量{}填写错误",goodsNumList.get(i));
+						}
+					}
+					studentPaymentRouteOrder.setGoodsJson(goodsJSON.toJSONString());
+				}
+				studentPaymentRouteOrders.add(studentPaymentRouteOrder);
+			}
+		}
+		if(studentPaymentRouteOrders.size() > 0){
+			Map<String, List<StudentPaymentRouteOrder>> stringListMap = studentPaymentRouteOrders.stream().collect(Collectors.groupingBy(StudentPaymentRouteOrder::getTransNo));
+			if(stringListMap.size() != studentPaymentRouteOrders.size()){
+				throw new BizException("导入失败:请勿录入重复的交易流水号");
+			}
+			studentPaymentRouteOrderDao.batchAdd(studentPaymentRouteOrders);
+		}
+		return studentPaymentRouteOrders;
+	}
+
 }

+ 3 - 0
mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml

@@ -387,4 +387,7 @@
             AND g.type_ = #{type}
         </if>
     </select>
+    <select id="findByIdAndStatus" resultType="java.lang.Boolean">
+        SELECT COUNT(0) FROM goods WHERE status_ = #{status} AND id_ = #{goodsId}
+    </select>
 </mapper>

+ 1 - 0
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderMapper.xml

@@ -101,6 +101,7 @@
                 #{classGroupId}, #{payTime})
     </insert>
 
+
     <!-- 根据主键查询一条记录 -->
     <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder">
         UPDATE student_payment_order

+ 15 - 2
mec-biz/src/main/resources/config/mybatis/StudentPaymentRouteOrderMapper.xml

@@ -143,10 +143,17 @@
     <insert id="batchAdd" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id"
             keyProperty="id">
         INSERT INTO student_payment_route_order
-        (order_no_,route_organ_id_, route_amount_,route_balance_amount_, mer_no_,fee_flag_,usre_id_,school_id_,trans_no_,pay_time_,sale_amount_,service_amount_,memo_,goods_json_,audit_status_,audit_comment_,create_time_,update_time_,create_by_,update_by_)
+        (order_no_,route_organ_id_, route_amount_,route_balance_amount_, mer_no_,fee_flag_,user_id_,
+        school_id_,trans_no_,pay_time_,sale_amount_,service_amount_,memo_,goods_json_,audit_status_,
+        audit_comment_,create_time_,update_time_,create_by_,update_by_)
         VALUE
         <foreach collection="routeOrders" item="routeOrder" separator=",">
-            (#{routeOrder.orderNo},#{routeOrder.routeOrganId},#{routeOrder.routeAmount},#{routeOrder.routeBalanceAmount},#{routeOrder.merNo},#{routeOrder.feeFlag},#{routeOrder.userId},#{routeOrder.schoolId},#{routeOrder.transNo},#{routeOrder.payTime},#{routeOrder.saleAmount},#{routeOrder.serviceAmount},#{routeOrder.memo},#{routeOrder.goodsJson},#{routeOrder.auditStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{routeOrder.auditComment},#{routeOrder.createTime},#{routeOrder.updateTime},#{routeOrder.createBy},#{routeOrder.updateBy})
+            (#{routeOrder.orderNo},#{routeOrder.routeOrganId},#{routeOrder.routeAmount},
+            #{routeOrder.routeBalanceAmount},#{routeOrder.merNo},#{routeOrder.feeFlag},
+            #{routeOrder.userId},#{routeOrder.schoolId},#{routeOrder.transNo},#{routeOrder.payTime},
+            #{routeOrder.saleAmount},#{routeOrder.serviceAmount},#{routeOrder.memo},#{routeOrder.goodsJson},
+            #{routeOrder.auditStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{routeOrder.auditComment},
+            #{routeOrder.createTime},#{routeOrder.updateTime},NOW(),NOW())
         </foreach>
     </insert>
 
@@ -286,6 +293,12 @@
         <include refid="queryPaymentOrder"/>
         ORDER BY spo.id_ ASC
     </select>
+    <select id="countByTransNo" resultType="java.lang.String">
+        SELECT order_no_ FROM student_payment_route_order WHERE trans_no_ IN
+        <foreach collection="transNos" open="(" close=")" item="item" separator=",">
+            #{item}
+        </foreach>
+    </select>
 
     <delete id="deleteByOrderNo">
         DELETE

+ 12 - 1
mec-web/src/main/java/com/ym/mec/web/controller/ImportController.java

@@ -4,9 +4,11 @@ import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.entity.FinancialExpenditure;
 import com.ym.mec.biz.dal.entity.Goods;
+import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
 import com.ym.mec.biz.dal.enums.TemplateTypeEnum;
 import com.ym.mec.biz.service.FinancialExpenditureService;
 import com.ym.mec.biz.service.GoodsService;
+import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.util.date.DateUtil;
@@ -37,6 +39,8 @@ public class ImportController extends BaseController {
     private FinancialExpenditureService financialExpenditureService;
     @Autowired
     private SysUserFeignService sysUserFeignService;
+    @Autowired
+    private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
 
     @ApiOperation(value = "导入商品")
     @PostMapping(value = "goods")
@@ -56,11 +60,18 @@ public class ImportController extends BaseController {
         return succeed(financialExpenditureService.importFinancialExpenditure(file));
     }
 
+    @ApiOperation(value = "导入财务管理订单")
+    @PostMapping(value = "routeOrder")
+    @PreAuthorize("@pcs.hasPermissions('import/routeOrder')")
+    public HttpResponseResult<List<StudentPaymentRouteOrder>> importRouteOrder(@RequestParam("file") MultipartFile file) throws Exception {
+        return succeed(studentPaymentRouteOrderService.importRouteOrder(file));
+    }
+
     @ApiOperation(value = "下载导入模板")
     @GetMapping(value = "downloadTemplate")
     @PreAuthorize("@pcs.hasPermissions('import/downloadTemplate')")
     public void getGoodsTemplate(HttpServletResponse response, TemplateTypeEnum templateType) throws IOException {
-        InputStream inputStream = new ClassPathResource("excelTemplate/" + templateType.getMsg() + ".xls").getInputStream();
+        InputStream inputStream = new ClassPathResource("excelTemplate/" + templateType.getMsg() + ".xlsx").getInputStream();
         OutputStream outputStream = response.getOutputStream();
         try {
             response.setContentType("application/octet-stream");

+ 4 - 4
mec-web/src/main/resources/columnMapper.ini

@@ -38,11 +38,11 @@
 [财务管理导入模板]
 所属分部 = organName
 所属学校 = cooperationOrganName
-交易流水号 = orderNo
+交易流水号 = transNo
 收款账户 = merNo
 交易日期 = payTime
-销售金额 = goodsAmount
+销售金额 = saleAmount
 服务金额 = serviceAmount
-商品名称 = goodsId
-商品数量 = goodsNum
+商品编号 = goodsIds
+商品数量 = goodsNums
 备注 = memo

BIN
mec-web/src/main/resources/excelTemplate/财务管理导入模板.xlsx