diff --git a/hiver-core/pom.xml b/hiver-core/pom.xml index 812d8bbe..d7e7fdb6 100644 --- a/hiver-core/pom.xml +++ b/hiver-core/pom.xml @@ -165,5 +165,10 @@ aliyun-java-sdk-dysmsapi 1.0.0 + + com.belerweb + pinyin4j + 2.5.0 + \ No newline at end of file diff --git a/hiver-core/src/main/java/cc/hiver/core/common/utils/PinYinUtils.java b/hiver-core/src/main/java/cc/hiver/core/common/utils/PinYinUtils.java new file mode 100644 index 00000000..ff6a2fea --- /dev/null +++ b/hiver-core/src/main/java/cc/hiver/core/common/utils/PinYinUtils.java @@ -0,0 +1,45 @@ +package cc.hiver.core.common.utils; + +import net.sourceforge.pinyin4j.PinyinHelper; +import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; +import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; +import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; +import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; + +public class PinYinUtils { + /** + * 获取汉字串拼音首字母,英文字符不变 + * @param chinese 汉字串 + * @return 汉语拼音首字母 + */ + public static String getFirstSpell(String chinese) { + if(chinese == null || "".equals(chinese)) { + return ""; + } + StringBuffer pybf = new StringBuffer(); + char[] arr = chinese.toCharArray(); + HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); + defaultFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE); + defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + for (int i = 0; i < arr.length; i++) { + if (arr[i] > 128) { + try { + String[] temp = PinyinHelper.toHanyuPinyinStringArray(arr[i]); + if (temp != null) { + pybf.append(temp[0].charAt(0)); + } + } catch (Exception e) { + e.printStackTrace(); + } + } else { + pybf.append(arr[i]); + } + } + return pybf.toString().replaceAll("\\W", "").trim(); + } + + public static void main(String[] args) { + System.out.println(getFirstSpell("王富康")); + } + +} diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/controller/LogisticsOrderController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/controller/LogisticsOrderController.java index e9328f0f..cfa5bf0a 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/controller/LogisticsOrderController.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/controller/LogisticsOrderController.java @@ -1,11 +1,13 @@ package cc.hiver.mall.logisticsorder.controller; +import cc.hiver.core.common.utils.PinYinUtils; import cc.hiver.core.common.utils.ResultUtil; import cc.hiver.core.common.vo.Result; import cc.hiver.mall.logisticsaddressbook.service.LogisticsAddressBookService; import cc.hiver.mall.logisticsorder.entity.LogisticsOrder; import cc.hiver.mall.logisticsorder.service.LogisticsOrderService; import cc.hiver.mall.logisticsorder.vo.LogisticsOrderQueryVo; +import cc.hiver.mall.utils.DateUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -15,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; +import java.util.Date; + /** * 物流订单控制器 * @@ -37,7 +41,15 @@ public class LogisticsOrderController { @PostMapping(value = "/addLogisticsOrder") @ApiOperation("新增物流订单") public Result addLogisticsOrder(@RequestBody LogisticsOrder logisticsOrder) { - + //单号命名规则 物流公司首字母-yyyyMMdd-递增流水号 + String orderNumber = PinYinUtils.getFirstSpell(logisticsOrder.getCompanyName())+"-"+ DateUtil.COMPAT.getDateText(new Date())+"-"; + //查询一下这个物流公司,今天最后一条数据的单号是多少,如果没有,默认为1 + LogisticsOrder lastOrder = logisticsOrderService.getLogisticsOrderByCompanyId(logisticsOrder); + if(lastOrder != null){ + int newNumber = Integer.parseInt(lastOrder.getOrderNumber().split("-")[2])+1; + orderNumber += newNumber; + } + logisticsOrder.setOrderNumber(orderNumber); final boolean b = logisticsOrderService.saveOrUpdate(logisticsOrder); if (b) { //保存收发货人地址簿 diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/service/LogisticsOrderService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/service/LogisticsOrderService.java index bec47039..e05b9a88 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/service/LogisticsOrderService.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/service/LogisticsOrderService.java @@ -16,4 +16,11 @@ public interface LogisticsOrderService extends IService { * @date 2024/8/24 */ IPage getLogisticsOrderPageList(LogisticsOrderQueryVo logisticsOrderQueryVo); + + + /** + * 根据条件查询物流订单 + */ + LogisticsOrder getLogisticsOrderByCompanyId(LogisticsOrder logisticsOrder); + } diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/service/impl/LogisticsOrderServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/service/impl/LogisticsOrderServiceImpl.java index 11e247a4..a08094f6 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/service/impl/LogisticsOrderServiceImpl.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/logisticsorder/service/impl/LogisticsOrderServiceImpl.java @@ -1,10 +1,12 @@ package cc.hiver.mall.logisticsorder.service.impl; +import cc.hiver.mall.logisticsaddressbook.entity.LogisticsAddressBook; import cc.hiver.mall.logisticsorder.entity.LogisticsOrder; import cc.hiver.mall.logisticsorder.mapper.LogisticsOrderMapper; import cc.hiver.mall.logisticsorder.service.LogisticsOrderService; import cc.hiver.mall.logisticsorder.vo.LogisticsOrderQueryVo; import cc.hiver.mall.utils.DateUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -12,6 +14,8 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Date; + @Service public class LogisticsOrderServiceImpl extends ServiceImpl implements LogisticsOrderService { @@ -35,4 +39,21 @@ public class LogisticsOrderServiceImpl extends ServiceImpl page = new Page<>(logisticsOrderQueryVo.getPageNum(), logisticsOrderQueryVo.getPageSize()); return logisticsOrderMapper.getLogisticsOrderPageList(page, logisticsOrderQueryVo); } + + + /** + * 根据条件查询物流订单 + */ + @Override + public LogisticsOrder getLogisticsOrderByCompanyId(LogisticsOrder logisticsOrder){ + + LambdaQueryWrapper stuQuery = new LambdaQueryWrapper<>(); + stuQuery.eq(LogisticsOrder::getCompanyId, logisticsOrder.getCompanyId()) + .orderByDesc(LogisticsOrder::getCreateTime) + .between(LogisticsOrder::getCreateTime, DateUtil.COMMON.getDateText(new Date())+" 00:00:00", DateUtil.COMMON.getDateText(new Date())+" 23:59:59") + .last("limit 1"); + + return getBaseMapper().selectOne(stuQuery); + } + }