2024-08-12 朱宝民 指定时间段内注册虚拟卡农户、代码优化(yearMonth)
| | |
| | | |
| | | 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 |
| | |
| | | int updateByPrimaryKeySelective(SeVcOperate record); |
| | | |
| | | int updateByPrimaryKey(SeVcOperate record); |
| | | |
| | | /** |
| | | * 指定时间段内注册虚拟卡的农户记录数量 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | Long getRegisterVcClientsCount(Map<?, ?> params); |
| | | |
| | | /** |
| | | * 指定时间段内注册虚拟卡的农户 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | List<VoClientRegisterVC> getRegisterVcClients(Map<?, ?> params); |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | |
| | | </resultMap> |
| | | <sql id="Base_Column_List"> |
| | | <!--@mbg.generated--> |
| | | id, vc_id, client_id, operate_type, recharge_id, `operator`, operate_time |
| | | 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> |
| | | <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> |
| | | <!--@mbg.generated--> |
| | | delete from se_vc_operate |
| | | delete |
| | | from se_vc_operate |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </delete> |
| | | <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoSe.SeVcOperate"> |
| | |
| | | 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> |
| | |
| | | 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 |
| | |
| | | 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()) ; |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | 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 |
| | |
| | | @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 ; |
| | | } |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | |
| | | 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; |
| | |
| | | * @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); |
| | |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.util.Calendar; |
| | | import java.util.List; |
| | |
| | | * @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); |
| | |
| | | * @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); |