From 9f7ec65f772de0d83580bad8655171fda888f197 Mon Sep 17 00:00:00 2001 From: wen <1455474577@qq.com> Date: Thu, 27 Jan 2022 15:03:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=9F=A5=E8=AF=A2=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E5=8D=A1=E5=88=97=E8=A1=A8=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xhpc/card/mapper/TIccardInfoMapper.java | 12 +++ .../java/com/xhpc/card/pojo/TIccardInfo.java | 6 +- .../service/impl/XhpcCardServiceImpl.java | 24 +++--- .../java/com/xhpc/card/utils/MyDateUtil.java | 76 +++++++++++++++++++ .../com/xhpc/card/utils/MyPagingUtil.java | 46 +++++++++++ .../resources/mapper/TIccardInfoMapper.xml | 25 +++++- 6 files changed, 175 insertions(+), 14 deletions(-) create mode 100644 xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/utils/MyDateUtil.java create mode 100644 xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/utils/MyPagingUtil.java diff --git a/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/mapper/TIccardInfoMapper.java b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/mapper/TIccardInfoMapper.java index 9f63374f..eb13b307 100644 --- a/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/mapper/TIccardInfoMapper.java +++ b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/mapper/TIccardInfoMapper.java @@ -1,5 +1,6 @@ package com.xhpc.card.mapper; +import com.xhpc.card.domain.QueryConditions; import com.xhpc.card.pojo.TIccardInfo; import java.util.List; @@ -28,4 +29,15 @@ public interface TIccardInfoMapper { */ List selectAll(); + /** + * 通过查询条件查询所有卡记录信息 + * + * @param queryConditions 查询条件 + * @return 符合条件的所有卡记录信息集合 + * @author WH + * @date 2022/1/27 11:21 + * @since version-1.0 + */ + List selectAllBy(QueryConditions queryConditions); + } \ No newline at end of file diff --git a/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/pojo/TIccardInfo.java b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/pojo/TIccardInfo.java index 85917116..622bc67e 100644 --- a/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/pojo/TIccardInfo.java +++ b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/pojo/TIccardInfo.java @@ -30,12 +30,12 @@ public class TIccardInfo implements Serializable { /** * 0表示平台,1表示运营商 */ - private Byte isPlatform; + private Integer isPlatform; /** * 卡类型。0.离线卡; 1.联网卡 */ - private Byte cardtype; + private Integer cardtype; /** * 卡用户索引 (t_iccard_users 找用户的,没有表示没绑) @@ -65,7 +65,7 @@ public class TIccardInfo implements Serializable { /** * 0.初始化, 1.正常, 2.锁卡, 3.挂失, 4.作废 */ - private Byte status; + private Integer status; /** * 添加日期 diff --git a/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/service/impl/XhpcCardServiceImpl.java b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/service/impl/XhpcCardServiceImpl.java index 672172b5..692c1a10 100644 --- a/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/service/impl/XhpcCardServiceImpl.java +++ b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/service/impl/XhpcCardServiceImpl.java @@ -9,12 +9,12 @@ import com.xhpc.card.pojo.TIccardInfo; import com.xhpc.card.pojo.TIccardUsers; import com.xhpc.card.pojo.XhpcOperator; import com.xhpc.card.service.IXhpcCardService; +import com.xhpc.card.utils.MyPagingUtil; import com.xhpc.common.api.CardHistoryOrderService; import com.xhpc.common.core.constant.Constants; import com.xhpc.common.core.domain.R; import com.xhpc.common.domain.IccardInfo; import com.xhpc.common.domain.XhpcIcCardInfo; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -28,10 +28,10 @@ import java.util.List; @Service public class XhpcCardServiceImpl implements IXhpcCardService { - @Autowired + @Resource private XhpcCardMapper xhpcCardMapper; - @Autowired + @Resource private CardHistoryOrderService cardHistoryOrderService; @Resource private TIccardDeviceMapper tIccardDeviceMapper; @@ -130,16 +130,20 @@ public class XhpcCardServiceImpl implements IXhpcCardService { @Override public R queryCardListBy(QueryConditions queryConditions) { - + //计算分页索引 + long startIndex = MyPagingUtil.calculateStartIndex(queryConditions.getCurrentPage(), queryConditions.getItems()); + queryConditions.setCurrentPage(startIndex); CardList cardList = new CardList(); cardList.setTotalItems(0); cardList.setData(new ArrayList<>()); + List tIccardInfoList2 = tIccardInfoMapper.selectAllBy(queryConditions); List tIccardInfoList = tIccardInfoMapper.selectAll(); if (tIccardInfoList.isEmpty()) { return R.ok(cardList); } + //1.遍历卡记录 for (TIccardInfo tIccardInfo : tIccardInfoList) { - //封装通用数据 + //2.封装通用数据 CardList.DataDTO dataDTO = new CardList.DataDTO(); dataDTO.setCardSerialNumber(tIccardInfo.getCardid()); dataDTO.setCardPhysicalNumber(tIccardInfo.getCardno()); @@ -147,25 +151,25 @@ public class XhpcCardServiceImpl implements IXhpcCardService { String corpno = tIccardInfo.getCorpno(); XhpcOperator xhpcOperator = xhpcOperatorMapper.selectByPrimaryKey(Long.valueOf(corpno)); dataDTO.setGrantOperator(xhpcOperator.getName()); - dataDTO.setClassification(Integer.valueOf(tIccardInfo.getCardtype())); - //判断是否是离线卡,离线卡处理逻辑 + dataDTO.setClassification(tIccardInfo.getCardtype()); + //3.判断是否是离线卡,离线卡处理逻辑 if (dataDTO.getClassification() == 0) { dataDTO.setCardType(1); //获取卡用户索引,为null表示没有该卡没有绑用户 Integer userIndex = tIccardInfo.getUserindex(); if (userIndex == null) { dataDTO.setCardStatus(1); - continue; } else { dataDTO.setCardStatus(0); dataDTO.setUserType(10); TIccardUsers tIccardUsers = tIccardUsersMapper.selectByPrimaryKey(userIndex); dataDTO.setUserAccount(tIccardUsers.getPhone()); - continue; } } else { //联网卡处理逻辑 - + dataDTO.setCardStatus(0); + Integer isPlatform = tIccardInfo.getIsPlatform(); + dataDTO.setCardType(isPlatform); } cardList.getData().add(dataDTO); } diff --git a/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/utils/MyDateUtil.java b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/utils/MyDateUtil.java new file mode 100644 index 00000000..5f654ab0 --- /dev/null +++ b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/utils/MyDateUtil.java @@ -0,0 +1,76 @@ +package com.xhpc.card.utils; + +import cn.hutool.core.date.DateTime; + +import java.util.Calendar; +import java.util.Date; + +/** + * 进行日期处理的工具类 + * + * @author WH + * @date 2022/1/15 15:59 + * @since version-1.0 + */ +@SuppressWarnings("all") +public class MyDateUtil { + + public static final String DATE_FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm:ss"; + + public static void main(String[] args) { + + System.out.println(getCurrentDateStr()); + } + + /** + * 以xxxx年x月xx日 星期x的字符串格式展示当前时间 + * + * @author WH + * @date 2022/1/15 16:15 + * @since version-1.0 + */ + public static String getCurrentDateStr() { + + Calendar now = Calendar.getInstance(); + int year = now.get(Calendar.YEAR); + int month = now.get(Calendar.MONTH) + 1; + int day = now.get(Calendar.DAY_OF_MONTH); + String dayNames[] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; + int dayOfWeek = now.get(Calendar.DAY_OF_WEEK) - 1; + if (dayOfWeek < 0) dayOfWeek = 0; + String week = dayNames[dayOfWeek]; + String nowDateStr = year + "年" + month + "月" + day + "日 " + week; + + return nowDateStr; + + } + + /** + * 获取表示所传入的Date对象的Calendar对象 + * + * @param date 要转换的Date对象 + * @return 表示所传入的Date对象的Calendar对象 + * @author WH + * @date 2022/1/15 16:11 + * @since version-1.0 + */ + public static Calendar getCalendar(Date date) { + + Calendar c = Calendar.getInstance(); + c.setTime(date); + return c; + } + + /** + * 获取一个yyyy-MM-dd HH:mm:ss格式的当前时间字符串 + * + * @author WH + * @date 2022/1/15 16:04 + * @since version-1.0 + */ + public static String getCurrentDateStrInYyyyMmDdHhMmSsFormat() { + + return DateTime.now().toString(DATE_FORMAT_DATE_TIME); + } + +} diff --git a/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/utils/MyPagingUtil.java b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/utils/MyPagingUtil.java new file mode 100644 index 00000000..f335c124 --- /dev/null +++ b/xhpc-modules/xhpc-card/src/main/java/com/xhpc/card/utils/MyPagingUtil.java @@ -0,0 +1,46 @@ +package com.xhpc.card.utils; + +/** + * 用于进行分页的工具类 + * + * @author WH + * @date 2022/1/15 15:25 + * @since version-1.0 + */ +public class MyPagingUtil { + + /** + * 用于计算MySQL数据库中的limit子句的startIndex值 + * + * @param currentPage 当前要显示的记录的页数 + * @param items 当前页要显示多少条记录 + * @return 返回MySQL数据库中的limit子句的startIndex值 + * @throws IllegalArgumentException 传入的参数不符合要求,发生此异常 + * @author WH + * @date 2022/1/15 15:27 + * @since version-1.0 + */ + public static long calculateStartIndex(long currentPage, long items) throws IllegalArgumentException { + + if ((currentPage - 1) < 0) { + throw new IllegalArgumentException("当前页数最小为1"); + } + if (items < 1) { + throw new IllegalArgumentException("当前页要显示的记录数最小为1"); + } + return (currentPage - 1) * items; + } + + /** + * 重写构造方法,遵循工具类不能被实例化的规则 + * + * @author WH + * @date 2022/1/27 11:52 + * @since version-1.0 + */ + private MyPagingUtil() { + + throw new IllegalArgumentException("Utility class don't need to be instantiated"); + } + +} diff --git a/xhpc-modules/xhpc-card/src/main/resources/mapper/TIccardInfoMapper.xml b/xhpc-modules/xhpc-card/src/main/resources/mapper/TIccardInfoMapper.xml index 012b91a9..bc3f8588 100644 --- a/xhpc-modules/xhpc-card/src/main/resources/mapper/TIccardInfoMapper.xml +++ b/xhpc-modules/xhpc-card/src/main/resources/mapper/TIccardInfoMapper.xml @@ -27,11 +27,34 @@ from t_iccard_info where id = #{id,jdbcType=INTEGER} - select from t_iccard_info + delete from t_iccard_info