zhubaomin
2024-08-12 10a200a9efc54e2a3c756882d8da3aaf1305aa44
2024-08-12 朱宝民 指定时间段内注册虚拟卡农户、代码优化(yearMonth)
6个文件已修改
2个文件已添加
443 ■■■■ 已修改文件
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeVcOperateMapper.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSt/VoClientRegisterVC.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeVcOperateMapper.xml 268 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/card/VirtualCardCtrl.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/card/VirtualCardSv.java 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/card/qo/CommonQO.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientSv.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntakeSv.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeVcOperateMapper.java
@@ -2,7 +2,11 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dy.pipIrrGlobal.pojoSe.SeVcOperate;
import com.dy.pipIrrGlobal.voSt.VoClientRegisterVC;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
/**
 * @author ZhuBaoMin
@@ -24,4 +28,18 @@
    int updateByPrimaryKeySelective(SeVcOperate record);
    int updateByPrimaryKey(SeVcOperate record);
    /**
     * 指定时间段内注册虚拟卡的农户记录数量
     * @param params
     * @return
     */
    Long getRegisterVcClientsCount(Map<?, ?> params);
    /**
     * 指定时间段内注册虚拟卡的农户
     * @param params
     * @return
     */
    List<VoClientRegisterVC> getRegisterVcClients(Map<?, ?> params);
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSt/VoClientRegisterVC.java
New file
@@ -0,0 +1,27 @@
package com.dy.pipIrrGlobal.voSt;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Data;
/**
 * @author ZhuBaoMin
 * @date 2024-08-12 14:37
 * @LastEditTime 2024-08-12 14:37
 * @Description 农户注册虚拟卡视图
 */
@Data
@JsonPropertyOrder({"clientId","clientName"})
public class VoClientRegisterVC {
    private static final long serialVersionUID = 202408121438001L;
    /**
     * 农户ID
     */
    private Long clientId;
    /**
     * 农户姓名
     */
    private String clientName;
}
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeVcOperateMapper.xml
@@ -1,126 +1,162 @@
<?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.dy.pipIrrGlobal.daoSe.SeVcOperateMapper">
  <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoSe.SeVcOperate">
    <!--@mbg.generated-->
    <!--@Table se_vc_operate-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="vc_id" jdbcType="BIGINT" property="vcId" />
    <result column="client_id" jdbcType="BIGINT" property="clientId" />
    <result column="operate_type" jdbcType="TINYINT" property="operateType" />
    <result column="recharge_id" jdbcType="BIGINT" property="rechargeId" />
    <result column="operator" jdbcType="BIGINT" property="operator" />
    <result column="operate_time" jdbcType="TIMESTAMP" property="operateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, vc_id, client_id, operate_type, recharge_id, `operator`, operate_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select
    <include refid="Base_Column_List" />
    from se_vc_operate
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from se_vc_operate
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoSe.SeVcOperate">
    <!--@mbg.generated-->
    insert into se_vc_operate (id, vc_id, client_id,
      operate_type, recharge_id, `operator`,
      operate_time)
    values (#{id,jdbcType=BIGINT}, #{vcId,jdbcType=BIGINT}, #{clientId,jdbcType=BIGINT},
      #{operateType,jdbcType=TINYINT}, #{rechargeId,jdbcType=BIGINT}, #{operator,jdbcType=BIGINT},
      #{operateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoSe.SeVcOperate">
    <!--@mbg.generated-->
    insert into se_vc_operate
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
    <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoSe.SeVcOperate">
        <!--@mbg.generated-->
        <!--@Table se_vc_operate-->
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="vc_id" jdbcType="BIGINT" property="vcId"/>
        <result column="client_id" jdbcType="BIGINT" property="clientId"/>
        <result column="operate_type" jdbcType="TINYINT" property="operateType"/>
        <result column="recharge_id" jdbcType="BIGINT" property="rechargeId"/>
        <result column="operator" jdbcType="BIGINT" property="operator"/>
        <result column="operate_time" jdbcType="TIMESTAMP" property="operateTime"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        id,
      </if>
      <if test="vcId != null">
        vc_id,
      </if>
      <if test="clientId != null">
        client_id,
      </if>
      <if test="operateType != null">
        operate_type,
      </if>
      <if test="rechargeId != null">
        recharge_id,
      </if>
      <if test="operator != null">
        `operator`,
      </if>
      <if test="operateTime != null">
        operate_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="vcId != null">
        #{vcId,jdbcType=BIGINT},
      </if>
      <if test="clientId != null">
        #{clientId,jdbcType=BIGINT},
      </if>
      <if test="operateType != null">
        #{operateType,jdbcType=TINYINT},
      </if>
      <if test="rechargeId != null">
        #{rechargeId,jdbcType=BIGINT},
      </if>
      <if test="operator != null">
        #{operator,jdbcType=BIGINT},
      </if>
      <if test="operateTime != null">
        #{operateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoSe.SeVcOperate">
    <!--@mbg.generated-->
    update se_vc_operate
    <set>
      <if test="vcId != null">
        vc_id = #{vcId,jdbcType=BIGINT},
      </if>
      <if test="clientId != null">
        client_id = #{clientId,jdbcType=BIGINT},
      </if>
      <if test="operateType != null">
        operate_type = #{operateType,jdbcType=TINYINT},
      </if>
      <if test="rechargeId != null">
        recharge_id = #{rechargeId,jdbcType=BIGINT},
      </if>
      <if test="operator != null">
        `operator` = #{operator,jdbcType=BIGINT},
      </if>
      <if test="operateTime != null">
        operate_time = #{operateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoSe.SeVcOperate">
    <!--@mbg.generated-->
    update se_vc_operate
    set vc_id = #{vcId,jdbcType=BIGINT},
      client_id = #{clientId,jdbcType=BIGINT},
      operate_type = #{operateType,jdbcType=TINYINT},
      recharge_id = #{rechargeId,jdbcType=BIGINT},
      `operator` = #{operator,jdbcType=BIGINT},
      operate_time = #{operateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
        operate_time
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        <!--@mbg.generated-->
        select
        <include refid="Base_Column_List"/>
        from se_vc_operate
        where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        <!--@mbg.generated-->
        delete
        from se_vc_operate
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoSe.SeVcOperate">
        <!--@mbg.generated-->
        insert into se_vc_operate (id, vc_id, client_id,
                                   operate_type, recharge_id, `operator`,
                                   operate_time)
        values (#{id,jdbcType=BIGINT}, #{vcId,jdbcType=BIGINT}, #{clientId,jdbcType=BIGINT},
                #{operateType,jdbcType=TINYINT}, #{rechargeId,jdbcType=BIGINT}, #{operator,jdbcType=BIGINT},
                #{operateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoSe.SeVcOperate">
        <!--@mbg.generated-->
        insert into se_vc_operate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="vcId != null">
                vc_id,
            </if>
            <if test="clientId != null">
                client_id,
            </if>
            <if test="operateType != null">
                operate_type,
            </if>
            <if test="rechargeId != null">
                recharge_id,
            </if>
            <if test="operator != null">
                `operator`,
            </if>
            <if test="operateTime != null">
                operate_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=BIGINT},
            </if>
            <if test="vcId != null">
                #{vcId,jdbcType=BIGINT},
            </if>
            <if test="clientId != null">
                #{clientId,jdbcType=BIGINT},
            </if>
            <if test="operateType != null">
                #{operateType,jdbcType=TINYINT},
            </if>
            <if test="rechargeId != null">
                #{rechargeId,jdbcType=BIGINT},
            </if>
            <if test="operator != null">
                #{operator,jdbcType=BIGINT},
            </if>
            <if test="operateTime != null">
                #{operateTime,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoSe.SeVcOperate">
        <!--@mbg.generated-->
        update se_vc_operate
        <set>
            <if test="vcId != null">
                vc_id = #{vcId,jdbcType=BIGINT},
            </if>
            <if test="clientId != null">
                client_id = #{clientId,jdbcType=BIGINT},
            </if>
            <if test="operateType != null">
                operate_type = #{operateType,jdbcType=TINYINT},
            </if>
            <if test="rechargeId != null">
                recharge_id = #{rechargeId,jdbcType=BIGINT},
            </if>
            <if test="operator != null">
                `operator` = #{operator,jdbcType=BIGINT},
            </if>
            <if test="operateTime != null">
                operate_time = #{operateTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoSe.SeVcOperate">
        <!--@mbg.generated-->
        update se_vc_operate
        set vc_id        = #{vcId,jdbcType=BIGINT},
            client_id    = #{clientId,jdbcType=BIGINT},
            operate_type = #{operateType,jdbcType=TINYINT},
            recharge_id  = #{rechargeId,jdbcType=BIGINT},
            `operator`   = #{operator,jdbcType=BIGINT},
            operate_time = #{operateTime,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=BIGINT}
    </update>
    <!--指定时间段内注册虚拟卡的农户记录数量-->
    <select id="getRegisterVcClientsCount" resultType="java.lang.Long">
        SELECT COUNT(*) AS recordCount
        FROM se_client cli
        WHERE EXISTS(SELECT *
                     FROM se_vc_operate ope
                     WHERE ope.client_id = cli.id
                       AND ope.operate_type = 1
                       AND ope.operate_time BETWEEN #{timeStart} AND #{timeStop})
    </select>
    <!--指定时间段内注册虚拟卡的农户-->
    <select id="getRegisterVcClients" resultType="com.dy.pipIrrGlobal.voSt.VoClientRegisterVC">
        SELECT cli.id   AS clientId,
               cli.name AS clientName
        FROM se_client cli
        WHERE EXISTS(SELECT *
                     FROM se_vc_operate ope
                     WHERE ope.client_id = cli.id
                       AND ope.operate_type = 1
                       AND ope.operate_time BETWEEN #{timeStart} AND #{timeStop})
        ORDER BY cli.id
        <trim prefix="limit ">
            <if test="start != null and count != null">
                #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
            </if>
        </trim>
    </select>
</mapper>
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/card/VirtualCardCtrl.java
@@ -1,9 +1,21 @@
package com.dy.pipIrrStatistics.card;
import com.dy.common.aop.SsoAop;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.voSt.VoClientRegisterVC;
import com.dy.pipIrrStatistics.card.qo.CommonQO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Objects;
/**
 * @author ZhuBaoMin
@@ -19,4 +31,25 @@
public class VirtualCardCtrl {
    private final VirtualCardSv virtualCardSv;
    /**
     * 指定时间段内注册虚拟卡的农户
     * @param qo
     * @param bindingResult
     * @return
     */
    @GetMapping(path = "/getRegisterVcClients")
    @SsoAop()
    public BaseResponse<QueryResultVo<List<VoClientRegisterVC>>> getRegisterVcClients(@Valid CommonQO qo, BindingResult bindingResult) {
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        try {
            return BaseResponseUtils.buildSuccess(virtualCardSv.getRegisterVcClients(qo));
        } catch (Exception e) {
            log.error("获取开卡记录异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/card/VirtualCardSv.java
@@ -1,7 +1,18 @@
package com.dy.pipIrrStatistics.card;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoSe.SeVcOperateMapper;
import com.dy.pipIrrGlobal.voSt.VoClientRegisterVC;
import com.dy.pipIrrStatistics.card.qo.CommonQO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
 * @author ZhuBaoMin
@@ -13,4 +24,44 @@
@Slf4j
@Service
public class VirtualCardSv {
    @Autowired
    private SeVcOperateMapper seVcOperateMapper;
    /**
     * 指定时间段内注册虚拟卡的农户
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoClientRegisterVC>> getRegisterVcClients(CommonQO qo) {
        /**
         * 补齐起止时间,如果开始时间为空,则默认为当前日期
         */
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null) {
            timeStart = timeStart + " 00:00:00";
        }else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        if(timeStop != null) {
            timeStop = timeStop + " 23:59:59";
        }
        qo.setTimeStart(timeStart);
        qo.setTimeStop(timeStop);
        // 生成查询参数
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo) ;
        // 获取符合条件的记录数
        Long itemTotal = Optional.ofNullable(seVcOperateMapper.getRegisterVcClientsCount(params)).orElse(0L);
        QueryResultVo<List<VoClientRegisterVC>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = qo.pageSize ;
        rsVo.pageCurr = qo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = seVcOperateMapper.getRegisterVcClients(params);
        return rsVo ;
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/card/qo/CommonQO.java
New file
@@ -0,0 +1,31 @@
package com.dy.pipIrrStatistics.card.qo;
import com.dy.common.webUtil.QueryConditionVo;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
 * @author ZhuBaoMin
 * @date 2024-08-12 14:54
 * @LastEditTime 2024-08-12 14:54
 * @Description
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class CommonQO extends QueryConditionVo {
    /**
     * 开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private String timeStart;
    /**
     * 结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @NotBlank(message = "结束时间不能为空")
    private String timeStop;
}
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/client/ClientSv.java
@@ -13,6 +13,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Calendar;
@@ -342,8 +344,11 @@
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoDayClient>> getDayAmountAndMoney(ClientAmountQO qo) {
    public QueryResultVo<List<VoDayClient>> getDayAmountAndMoney(ClientAmountQO qo) throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String yearMonth = qo.getYearMonth();
        yearMonth = yearMonth + "-01";
        yearMonth = dateFormat.format(dateFormat.parse(yearMonth));
        Integer year = Integer.parseInt(yearMonth.substring(0,4));
        Integer month = Integer.parseInt(yearMonth.substring(5,7));
        qo.setYear(year);
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntakeSv.java
@@ -12,6 +12,7 @@
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.List;
@@ -644,7 +645,11 @@
     * @return
     */
    public QueryResultVo<List<VoDayIntakeAmount>> getDayIntakeAmount(IntakeAmountQO qo) throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String yearMonth = qo.getYearMonth();
        yearMonth = yearMonth + "-01";
        yearMonth = dateFormat.format(dateFormat.parse(yearMonth));
        Integer year = Integer.parseInt(yearMonth.substring(0,4));
        Integer month = Integer.parseInt(yearMonth.substring(5,7));
        qo.setYear(year);
@@ -698,7 +703,10 @@
     * @return
     */
    public QueryResultVo<List<VoDayLoss>> getDayLossAmount(IntakeAmountQO qo) throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String yearMonth = qo.getYearMonth();
        yearMonth = yearMonth + "-01";
        yearMonth = dateFormat.format(dateFormat.parse(yearMonth));
        Integer year = Integer.parseInt(yearMonth.substring(0,4));
        Integer month = Integer.parseInt(yearMonth.substring(5,7));
        qo.setYear(year);