Administrator
2023-12-27 0fd777e6de7c058accfba355ec419959927e0cb2
2023-12-27 朱宝民 根据条件查询交易汇总记录
4个文件已修改
2个文件已添加
277 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeClientMapper.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoStatistics.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeClientMapper.xml 95 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientSv.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/QueryStatistic.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeClientMapper.java
@@ -4,6 +4,7 @@
import com.dy.pipIrrGlobal.pojoSe.SeClient;
import com.dy.pipIrrGlobal.voSe.VoClient;
import com.dy.pipIrrGlobal.voSe.VoOperate;
import com.dy.pipIrrGlobal.voSe.VoStatistics;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -112,4 +113,25 @@
     * @return 符合条件的交易记录
     */
    List<VoOperate> getOperates(Map<?, ?> params);
    /**
     * 根据指定条件获取交易笔数汇总和交易金额汇总
     * @param params
     * @return
     */
    Map getStatisticSums(Map<?, ?> params);
    /**
     * 根据指定条件获取汇总记录数
     * @param params
     * @return
     */
    Long getStatisticRecordCount(Map<?, ?> params);
    /**
     * 根据指定条件获取统计记录
     * @param params
     * @return
     */
    List<VoStatistics> getStatistics(Map<?, ?> params);
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoStatistics.java
New file
@@ -0,0 +1,42 @@
package com.dy.pipIrrGlobal.voSe;
import com.dy.common.po.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
 * @author ZhuBaoMin
 * @date 2023-12-27 15:01
 * @LastEditTime 2023-12-27 15:01
 * @Description
 */
@Data
@Schema(title = "交易汇总视图对象")
public class VoStatistics implements BaseEntity {
    private static final long serialVersionUID = 1L;
    @Schema(title = "村庄ID")
    private Long villageId;
    @Schema(title = "村庄")
    private String districtTitle;
    @Schema(title = "业务类型")
    private String operateType;
    @Schema(title = "交易日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date operateDt;
    @Schema(title = "交易笔数")
    private Integer count;
    @Schema(title = "交易金额")
    private Float money;
}
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeClientMapper.xml
@@ -399,6 +399,7 @@
    SELECT id, typeName from se_water_type
  </select>
  <!-- 下列内容为交易明细查询 -->
  <!--根据指定条件获取购水汇总和购卡汇总-->
  <select id="getSums" resultType="java.util.Map">
    SELECT
@@ -477,4 +478,98 @@
    </if>
  </select>
  <!-- 下列内容为交易统计查询 -->
  <!--根据指定条件获取交易笔数汇总和交易金额汇总-->
  <select id="getStatisticSums" resultType="java.util.Map">
    SELECT
    SUM(count) AS count,
    SUM(money) AS money
    FROM
    (
      SELECT
      villageId,
      districtTitle,
      operateType,
      operateDt,
      count(*) AS count,
      (sum(money) + sum(cardCost)) AS money
      FROM v_operate
      <where>
        <if test = "villageId != null and villageId > 0">
          AND villageId = ${villageId}
        </if>
<!--        <if test = "paymentId != null and paymentId >0">-->
<!--          AND paymentId = ${paymentId}-->
<!--        </if>-->
        <if test = "operateTimeStart != null and operateTimeStop != null">
          AND operateDt BETWEEN #{operateTimeStart} AND #{operateTimeStop}
        </if>
      </where>
      GROUP BY villageId, districtTitle, operateType, operateDt
    ) temp
  </select>
  <!--根据指定条件获取汇总记录数-->
  <select id="getStatisticRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">
    SELECT
        COUNT(*) AS recordCount
    FROM
    (
        SELECT
          villageId,
          districtTitle,
          operateType,
          operateDt,
          count(*) AS count,
          (sum(money) + sum(cardCost)) AS money
        FROM v_operate
        <where>
          <if test = "villageId != null and villageId > 0">
            AND villageId = ${villageId}
          </if>
<!--          <if test = "paymentId != null and paymentId >0">-->
<!--            AND paymentId = ${paymentId}-->
<!--          </if>-->
          <if test = "operateTimeStart != null and operateTimeStop != null">
            AND operateDt BETWEEN #{operateTimeStart} AND #{operateTimeStop}
          </if>
        </where>
        GROUP BY villageId, districtTitle, operateType, operateDt
    ) temp
  </select>
  <!--根据指定条件获取统计记录-->
  <select id="getStatistics" resultType="com.dy.pipIrrGlobal.voSe.VoStatistics">
    SELECT
        villageId,
        districtTitle,
        operateType,
        operateDt,
        count(*) AS count,
        (sum(money) + sum(cardCost)) AS money
    FROM v_operate
    <where>
      <if test = "villageId != null and villageId > 0">
        AND villageId = ${villageId}
      </if>
<!--      <if test = "paymentId != null and paymentId >0">-->
<!--        AND paymentId = ${paymentId}-->
<!--      </if>-->
      <if test = "operateTimeStart != null and operateTimeStop != null">
        AND operateDt BETWEEN #{operateTimeStart} AND #{operateTimeStop}
      </if>
    </where>
    GROUP BY villageId, districtTitle, operateType, operateDt
    ORDER BY operateDt
    <if test="pageCurr != null and pageSize != null">
      LIMIT ${pageCurr}, ${pageSize}
    </if>
  </select>
</mapper>
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
@@ -93,6 +93,32 @@
    }
    /**
     * 获取交易汇总记录
     * @param vo
     * @return
     */
    @Operation(summary = "获得一页交易汇总记录", description = "返回一页交易汇总记录")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回一页农户数据(BaseResponse.content:QueryResultVo[{}])",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = BaClient.class))}
            )
    })
    @GetMapping(path = "getStatistics")
    @SsoAop()
    public BaseResponse<Map> getStatistics(QueryStatistic vo){
        try {
            Map res = clientSv.getStatistics(vo);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询交易汇总记录异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
    /**
     * 根据主键获取一个农户对象
     * @param id
     * @return
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientSv.java
@@ -6,6 +6,7 @@
import com.dy.pipIrrGlobal.pojoSe.SeClient;
import com.dy.pipIrrGlobal.voSe.VoClient;
import com.dy.pipIrrGlobal.voSe.VoOperate;
import com.dy.pipIrrGlobal.voSe.VoStatistics;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -120,6 +121,64 @@
    }
    /**
     * 根据指定条件获取统计记录
     * @param vo 交易汇总查询条件
     * @return 交易汇总记录
     */
    public Map getStatistics(QueryStatistic vo){
        // 补齐查询时间
        String operateTimeStart = vo.operateTimeStart;
        String operateTimeStop = vo.operateTimeStop;
        if(operateTimeStart != null) {
            operateTimeStart = operateTimeStart + " 00:00:00";
            vo.setOperateTimeStart(operateTimeStart);
        }
        if(operateTimeStop != null) {
            operateTimeStop = operateTimeStop + " 23:59:59";
            vo.setOperateTimeStop(operateTimeStop);
        }
        // 生成查询参数
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo) ;
        // 获取汇总的交易笔数、交易金额
        Integer count = 0;
        Float money = 0f;
        Map map_sum = Optional.ofNullable(seClientMapper.getStatisticSums(params)).orElse(new HashMap());
        if(map_sum.size() > 0) {
            count = Integer.parseInt(map_sum.get("count").toString());
            money = Float.parseFloat(map_sum.get("money").toString());
        }
        // 获取符合条件的记录数
        Long itemTotal = seClientMapper.getStatisticRecordCount(params);
        Integer pageSize = vo.getPageSize();
        // 计算总页数
        Integer pageTotal ;
        pageTotal = (int)Math.ceil((itemTotal==null?0.0D:itemTotal.doubleValue())/pageSize);
        // 根据当前页码及每页数量计算偏移量
        Integer pageCurr = (Integer.parseInt(params.get("pageCurr").toString()) - 1) * Integer.parseInt(params.get("pageSize").toString());
        params.put("pageCurr", pageCurr);
        List<VoStatistics> lit = seClientMapper.getStatistics(params);
        Map map_record = new HashMap();
        map_record.put("itemTotal", itemTotal);
        map_record.put("pageCurr", vo.pageCurr);
        map_record.put("pageSize", pageSize);
        map_record.put("pageTotal", pageTotal);
        map_record.put("list", lit);
        Map map_result = new HashMap();
        map_result.put("count", count);
        map_result.put("money", money);
        map_result.put("records", map_record);
        return map_result;
    }
    /**
     * 根据主键获取农户对象
     * @param id 农户主键
     * @return 农户对象
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/QueryStatistic.java
New file
@@ -0,0 +1,33 @@
package com.dy.pipIrrSell.client;
import com.dy.common.webUtil.QueryConditionVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
/**
 * @author ZhuBaoMin
 * @date 2023-12-27 15:33
 * @LastEditTime 2023-12-27 15:33
 * @Description
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ToString(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Schema(name = "交易汇总查询条件")
public class QueryStatistic extends QueryConditionVo {
    @Schema(description = "村ID")
    public Long villageId;
    //@Schema(description = "支付方式编号")
    //public Long paymentId;
    @Schema(description = "交易查询起始时间")
    public String operateTimeStart;
    @Schema(description = "交易查询截止时间")
    public String operateTimeStop;
}