Преглед изворни кода

新增订单年份最大公出表

anderx пре 1 година
родитељ
комит
82c926c443

+ 85 - 0
src/main/java/com/goafanti/common/dao/OrderYearMaxDurationMapper.java

@@ -0,0 +1,85 @@
+package com.goafanti.common.dao;
+
+import com.goafanti.common.model.OrderYearMaxDuration;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+
+/**
+ * 订单最大公出表(OrderYearMaxDuration)表数据库访问层
+ *
+ * @author makejava
+ * @since 2024-07-04 16:41:14
+ */
+public interface OrderYearMaxDurationMapper {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    OrderYearMaxDuration queryById(Integer id);
+
+
+    /**
+     * 查询指定行数据
+     *
+     * @param orderYearMaxDuration 查询条件
+     * @param pageable             分页对象
+     * @return 对象列表
+     */
+    List<OrderYearMaxDuration> findOrderYearMaxDurationList(OrderYearMaxDuration orderYearMaxDuration, @Param("pageable") Pageable pageable);
+
+    /**
+     * 统计总行数
+     *
+     * @param orderYearMaxDuration 查询条件
+     * @return 总行数
+     */
+    long queryAllByCount(OrderYearMaxDuration orderYearMaxDuration);
+
+    /**
+     * 新增数据
+     *
+     * @param orderYearMaxDuration 实例对象
+     * @return 影响行数
+     */
+    int insert(OrderYearMaxDuration orderYearMaxDuration);
+
+    /**
+     * 批量新增数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<OrderYearMaxDuration> 实例对象列表
+     * @return 影响行数
+     */
+    int insertBatch(@Param("entities") List<OrderYearMaxDuration> entities);
+
+    /**
+     * 批量新增或按主键更新数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<OrderYearMaxDuration> 实例对象列表
+     * @return 影响行数
+     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
+     */
+    int insertOrUpdateBatch(@Param("entities") List<OrderYearMaxDuration> entities);
+
+    /**
+     * 修改数据
+     *
+     * @param orderYearMaxDuration 实例对象
+     * @return 影响行数
+     */
+    int update(OrderYearMaxDuration orderYearMaxDuration);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+}
+

+ 139 - 0
src/main/java/com/goafanti/common/mapper/OrderYearMaxDurationMapper.xml

@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.goafanti.common.dao.OrderYearMaxDurationMapper">
+
+    <resultMap type="com.goafanti.common.model.OrderYearMaxDuration" id="OrderYearMaxDurationMap">
+        <result property="id" column="id" jdbcType="INTEGER"/>
+        <result property="orderNo" column="order_no" jdbcType="VARCHAR"/>
+        <result property="year" column="year" jdbcType="INTEGER"/>
+        <result property="status" column="status" jdbcType="INTEGER"/>
+        <result property="maxDuration" column="max_duration" jdbcType="VARCHAR"/>
+        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <!--查询单个-->
+    <select id="queryById" resultMap="OrderYearMaxDurationMap">
+        select id,
+               order_no,
+               year,
+               status,
+               max_duration,
+               create_time
+        from order_year_max_duration
+        where id = #{id}
+    </select>
+
+    <!--查询指定行数据-->
+    <select id="findOrderYearMaxDurationCount" resultMap="OrderYearMaxDurationMap">
+        select
+        id, order_no, year, status, max_duration, create_time
+        from order_year_max_duration
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="orderNo != null and orderNo != ''">
+                and order_no = #{orderNo}
+            </if>
+            <if test="year != null">
+                and year = #{year}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+            <if test="maxDuration != null">
+                and max_duration = #{maxDuration}
+            </if>
+            <if test="createTime != null">
+                and create_time = #{createTime}
+            </if>
+        </where>
+        limit #{pageable.offset}, #{pageable.pageSize}
+    </select>
+
+    <!--统计总行数-->
+    <select id="queryAllByCount" resultType="java.lang.Intger">
+        select count(1)
+        from order_year_max_duration
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="orderNo != null and orderNo != ''">
+                and order_no = #{orderNo}
+            </if>
+            <if test="year != null">
+                and year = #{year}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+            <if test="maxDuration != null">
+                and max_duration = #{maxDuration}
+            </if>
+            <if test="createTime != null">
+                and create_time = #{createTime}
+            </if>
+        </where>
+    </select>
+
+    <!--新增所有列-->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        insert into order_year_max_duration(order_no, year, status, max_duration, create_time)
+        values (#{orderNo}, #{year}, #{status}, #{maxDuration}, #{createTime})
+    </insert>
+
+    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
+        insert into order_year_max_duration(order_no, year, status, max_duration, create_time)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{entity.orderNo}, #{entity.year}, #{entity.status}, #{entity.maxDuration}, #{entity.createTime})
+        </foreach>
+    </insert>
+
+    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
+        insert into order_year_max_duration(order_no, year, status, max_duration, create_time)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{entity.orderNo}, #{entity.year}, #{entity.status}, #{entity.maxDuration}, #{entity.createTime})
+        </foreach>
+        on duplicate key update
+        order_no = values(order_no),
+        year = values(year),
+        status = values(status),
+        max_duration = values(max_duration),
+        create_time = values(create_time)
+    </insert>
+
+    <!--通过主键修改数据-->
+    <update id="update">
+        update order_year_max_duration
+        <set>
+            <if test="orderNo != null and orderNo != ''">
+                order_no = #{orderNo},
+            </if>
+            <if test="year != null">
+                year = #{year},
+            </if>
+            <if test="status != null">
+                status = #{status},
+            </if>
+            <if test="maxDuration != null">
+                max_duration = #{maxDuration},
+            </if>
+            <if test="createTime != null">
+                create_time = #{createTime},
+            </if>
+        </set>
+        where id = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete
+        from order_year_max_duration
+        where id = #{id}
+    </delete>
+
+</mapper>
+

+ 89 - 0
src/main/java/com/goafanti/common/model/OrderYearMaxDuration.java

@@ -0,0 +1,89 @@
+package com.goafanti.common.model;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+
+/**
+ * 订单最大公出表(OrderYearMaxDuration)实体类
+ *
+ * @author makejava
+ * @since 2024-07-04 16:41:14
+ */
+public class OrderYearMaxDuration implements Serializable {
+    private static final long serialVersionUID = -31870521635051598L;
+
+    private Integer id;
+    /**
+     * 订单编号
+     */
+    private String orderNo;
+    /**
+     * 年份
+     */
+    private Integer year;
+    /**
+     * 状态 0=限制,1=不限制
+     */
+    private Integer status;
+    /**
+     * 最大公出时间
+     */
+    private BigDecimal maxDuration;
+    /**
+     * 发起时间
+     */
+    private Date createTime;
+
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getOrderNo() {
+        return orderNo;
+    }
+
+    public void setOrderNo(String orderNo) {
+        this.orderNo = orderNo;
+    }
+
+    public Integer getYear() {
+        return year;
+    }
+
+    public void setYear(Integer year) {
+        this.year = year;
+    }
+
+    public Integer getStatus() {
+        return status;
+    }
+
+    public void setStatus(Integer status) {
+        this.status = status;
+    }
+
+    public BigDecimal getMaxDuration() {
+        return maxDuration;
+    }
+
+    public void setMaxDuration(BigDecimal maxDuration) {
+        this.maxDuration = maxDuration;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+}
+

+ 60 - 10
src/main/java/com/goafanti/order/service/impl/OrderNewServiceImpl.java

@@ -49,9 +49,12 @@ import java.io.File;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
@@ -707,9 +710,9 @@ public class OrderNewServiceImpl extends BaseMybatisDao<TOrderNewMapper> impleme
 	 * @param orderNo
 	 */
 	public TOrderPublicReleaseCount pushOrderPublicReleaseCount(String orderNo) {
-		//获取所有公出、订单与会员信息
+		//获取公出信息
 		List<PublicRelease> list = publicReleaseMapper.selectByOrderNo(orderNo);
-		TOrderNewBo t = tOrderNewMapper.getOrderNewDetail(orderNo);
+		TOrderNew orderNew = tOrderNewMapper.selectByPrimaryKey(orderNo);
 		//公出时间统计
 		BigDecimal durationCount = BigDecimal.ZERO;
 		//公出次数
@@ -729,12 +732,64 @@ public class OrderNewServiceImpl extends BaseMybatisDao<TOrderNewMapper> impleme
 		out.setActualDuration(durationCount.doubleValue());
 		out.setPeopleCount(peopleList.size());
 		out.setFrequency(count);
-//		pushMaxDuration(t,out);
+
+		//获取会员信息
+		List<TTaskMember> tTaskMembers = tTaskMemberMapper.selectByOrderNo(orderNo);
+		int yearSum=0;
+		String serviceLife = null;
+		for (TTaskMember e : tTaskMembers) {
+			if (e.getYearSum()!=null&&e.getYearSum()>yearSum){
+				yearSum=e.getYearSum();
+				serviceLife=e.getServiceLife();
+			}
+		}
+		List<String> strings = JSON.parseArray(serviceLife, String.class);
+        List<Integer> collect = null;
+        if (strings != null) {
+            collect = strings.stream().map(this::extractYear).collect(Collectors.toList());
+			int size = collect.size();
+			BigDecimal divide = orderNew.getTotalAmount().divide(new BigDecimal(size), RoundingMode.HALF_EVEN);
+			BigDecimal maxDuration = pushMaxDuration(divide);
+			int i = 1;
+			for (Integer year : collect) {
+				OrderYearMaxDuration orderYearMaxDuration = new OrderYearMaxDuration();
+				orderYearMaxDuration.setYear(year);
+				if (maxDuration.compareTo(new BigDecimal(-1))==0){
+					orderYearMaxDuration.setMaxDuration(BigDecimal.ZERO);
+					orderYearMaxDuration.setStatus(1);
+				}else {
+					orderYearMaxDuration.setMaxDuration(maxDuration.multiply(new BigDecimal(i)));
+					orderYearMaxDuration.setStatus(0);
+				}
+				orderYearMaxDuration.setOrderNo(orderNo);
+				System.out.println(orderYearMaxDuration);
+				i++;
+			}
+
+		}
+
+//
+//		List<String> yearsStrList = Arrays.asList("2019年", "2020年", "2021年(增)");
+//		List<Integer> yearsIntList = yearsStrList.stream()
+//				.map(this::extractYear)
+//				.collect(Collectors.toList());
+//
+//		System.out.println(yearsIntList);
+
 		return out;
 
 
 	}
 
+	private  Integer extractYear(String yearStr) {
+		Pattern pattern = Pattern.compile("(\\d{4})");
+		Matcher matcher = pattern.matcher(yearStr);
+		if (matcher.find()) {
+			return Integer.parseInt(matcher.group(1));
+		}
+		throw new BusinessException("年份提取失败");
+	}
+
 	@Override
 	public List<TOrderNew> selectGetAll() {
 		return tOrderNewMapper.selectgetAll();
@@ -785,12 +840,9 @@ public class OrderNewServiceImpl extends BaseMybatisDao<TOrderNewMapper> impleme
 
 	/**
 	 * 处理订单公出&报销最大公出
-	 * @param t
-	 * @param out
 	 */
-	private void pushMaxDuration(TOrderNewBo t,TOrderPublicReleaseCount out ) {
+	private BigDecimal pushMaxDuration(BigDecimal totalAmount) {
 		BigDecimal res=BigDecimal.ZERO;
-		BigDecimal totalAmount=t.getTotalAmount()==null?BigDecimal.ZERO:t.getTotalAmount();
 		int status=1;
 		if (totalAmount.compareTo(BigDecimal.valueOf(1)) < 0) {
 			res=BigDecimal.ZERO;
@@ -805,10 +857,8 @@ public class OrderNewServiceImpl extends BaseMybatisDao<TOrderNewMapper> impleme
 
 		} else if (totalAmount.compareTo(BigDecimal.valueOf(10))>=0) {
 			res=BigDecimal.valueOf(-1);
-			status=0;
 		}
-		out.setMaxDuration(res.doubleValue());
-		out.setStatus(status);
+		return res;
 	}