创建项目
This commit is contained in:
24
src/main/java/com/yxt/purchase/PurchaseApplication.java
Normal file
24
src/main/java/com/yxt/purchase/PurchaseApplication.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.yxt.purchase;
|
||||
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* @author dimengzhe
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = {
|
||||
"com.yxt.purchase.config",
|
||||
"com.yxt.common.base.config",
|
||||
"com.yxt.goods"
|
||||
})
|
||||
// 启用自带定时任务
|
||||
@EnableScheduling
|
||||
@EnableFeignClients(basePackages = {})
|
||||
public class PurchaseApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(PurchaseApplication.class, args);
|
||||
}
|
||||
}
|
||||
10
src/main/java/com/yxt/purchase/apiadmin/AdminHomeRest.java
Normal file
10
src/main/java/com/yxt/purchase/apiadmin/AdminHomeRest.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.yxt.purchase.apiadmin;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController("com.yxt.base.apiadmin.AdminHomeRest")
|
||||
@RequestMapping("/apiadmin/home")
|
||||
public class AdminHomeRest {
|
||||
|
||||
}
|
||||
10
src/main/java/com/yxt/purchase/apiwx/WxHomeRest.java
Normal file
10
src/main/java/com/yxt/purchase/apiwx/WxHomeRest.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.yxt.purchase.apiwx;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController("com.yxt.base.apiwx.WxHomeRest")
|
||||
@RequestMapping("/apiwx/home")
|
||||
public class WxHomeRest {
|
||||
|
||||
}
|
||||
4
src/main/java/com/yxt/purchase/biz/package-info.java
Normal file
4
src/main/java/com/yxt/purchase/biz/package-info.java
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 宇信通 仓库管理 项目后台逻辑和接口
|
||||
*/
|
||||
package com.yxt.purchase.biz;
|
||||
114
src/main/java/com/yxt/purchase/config/SaTokenConfigure.java
Normal file
114
src/main/java/com/yxt/purchase/config/SaTokenConfigure.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package com.yxt.purchase.config;//package com.yxt.base.config;
|
||||
//
|
||||
//import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||
//import cn.dev33.satoken.stp.StpUtil;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
//
|
||||
///**
|
||||
// * @author wangpengfei
|
||||
// * @date 2023/5/16 14:43
|
||||
// */
|
||||
//@Configuration
|
||||
//public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
// @Value("${image.url.prefix:http://127.0.0.1:8080/upload/}")
|
||||
// private String urlPrefix;
|
||||
// // 注册 Sa-Token 拦截器
|
||||
// @Override
|
||||
// public void addInterceptors(InterceptorRegistry registry) {
|
||||
// // 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。
|
||||
//
|
||||
// registry.addInterceptor(new SaInterceptor(handler -> StpUtil.checkLogin()))
|
||||
// .addPathPatterns("/**")
|
||||
// .excludePathPatterns("/sysuser/doLogin")
|
||||
// .excludePathPatterns("/lpkgiftcard/gifCardByCustomerSid")
|
||||
// .excludePathPatterns("/empcardgift/gifCardByCustomerSid")
|
||||
// .excludePathPatterns("/empcard/getEmpCardByCustomerSid")
|
||||
// .excludePathPatterns("/lpkgiftcard/getGifCardBySid/**")
|
||||
// .excludePathPatterns("/empcardgift/getGifCardBySid/**")
|
||||
// .excludePathPatterns("/empcard/getEmpCardBySid/**")
|
||||
// .excludePathPatterns("/lpkgiftcard/isSaturAndSun/**")
|
||||
// .excludePathPatterns("/empcardgift/isSaturAndSun/**")
|
||||
// .excludePathPatterns("/empcard/isSaturAndSun/**")
|
||||
// .excludePathPatterns("/lpkgiftcard/getReservationBySid/**")
|
||||
// .excludePathPatterns("/lpksreservoorder/submission")
|
||||
// .excludePathPatterns("/lpksreservoorder/exportExcelByStore")
|
||||
// .excludePathPatterns("/empsreservoorder/createNewUserBagOrder")
|
||||
// .excludePathPatterns("/lpksreservoorders/submission")
|
||||
// .excludePathPatterns("/empsreservoorder/ordersList")
|
||||
// .excludePathPatterns("/empsreservoorder/submission")
|
||||
// .excludePathPatterns("/empsreservoorder/submissionEmp")
|
||||
// .excludePathPatterns("/empcardgift/generateCard")
|
||||
// .excludePathPatterns("/lpkgiftcard/bindCard")
|
||||
// .excludePathPatterns("/empcard/bindCard")
|
||||
// .excludePathPatterns("/lpksreservoorder/orderByCardSid/**")
|
||||
// .excludePathPatterns("/lpksreservoorder/orderListByUserSid/**")
|
||||
// .excludePathPatterns("/lpksreservoorder/orderDetails/**")
|
||||
// .excludePathPatterns("/newcomerrecorecord/recommendNewUsers")
|
||||
// .excludePathPatterns("/newcomerrecorecord/recommendedAssistance")
|
||||
// .excludePathPatterns("/newcomerrecorecord/recordList/**")
|
||||
// .excludePathPatterns("/transferrecords/transferRecordsList")
|
||||
// .excludePathPatterns("/empsreservoorder/createVegeOrder")
|
||||
// .excludePathPatterns("/empsreservoorder/OrderDetails/**")
|
||||
// .excludePathPatterns("/empsreservoorder/changePayState/**")
|
||||
// .excludePathPatterns("/lpkgoods/goodsDetails/**")
|
||||
// .excludePathPatterns("/lpkstore/getAllStoreByQuery")
|
||||
// .excludePathPatterns("/vegetablecellar/receiveTransferGoods")
|
||||
// .excludePathPatterns("/transferrecords/submission")
|
||||
// .excludePathPatterns("/lpkgiftcard/getCardByBank")
|
||||
// .excludePathPatterns("/empcard/getEmpCard")
|
||||
// .excludePathPatterns("/empcardgift/shareEmpCard/**")
|
||||
// .excludePathPatterns("/empcardgift/generateEmpCardGift")
|
||||
// .excludePathPatterns("/empcardgift/generateEmpCard")
|
||||
// .excludePathPatterns("/lpkcustomer/wxSilentLogin")
|
||||
// .excludePathPatterns("/lpkgiftcard/gifCardsByCustomerSid")
|
||||
// .excludePathPatterns("/lpkgoods/getAllGiftBag")
|
||||
// .excludePathPatterns("/appletgiftbag/getGiftBagBySid/**")
|
||||
// .excludePathPatterns("/appletgiftbag/appletGiftBagList")
|
||||
// .excludePathPatterns("/lpkgiftcard/cardShareDetail/**")
|
||||
// .excludePathPatterns("/lpkgiftcard/cardShareGoodsDetail/**")
|
||||
// .excludePathPatterns("/empcardgift/generateTopEmpCard/**")
|
||||
// .excludePathPatterns("/empsreservoorder/createOrder")
|
||||
// .excludePathPatterns("/appletgiftbag/recommendRecord/**")
|
||||
// //2024-01-17
|
||||
// .excludePathPatterns("/lpkgiftcard/getAllGoodsType/**")
|
||||
// .excludePathPatterns("/appletnotice/getNotice")
|
||||
// .excludePathPatterns("/empsreservoorder/getPreOrder")
|
||||
// .excludePathPatterns("/lpkgoods/getAllGoodsType/**")
|
||||
// .excludePathPatterns("/transferrecords/submission")
|
||||
// .excludePathPatterns("/vegetablecellar/receiveTransferGoods")
|
||||
// .excludePathPatterns("/customerstore/isSaturAndSun")
|
||||
// .excludePathPatterns("/lpkgiftcard/getGoodsByType/**")
|
||||
// .excludePathPatterns("/lpkgoods/getGoodsTypeAndBrand")
|
||||
// .excludePathPatterns("/lpkgoods/getGoodsByType")
|
||||
// .excludePathPatterns("/lpksreservoorders/orderListByUserSid")
|
||||
// .excludePathPatterns("/appletgiftbag/newUserQuota")
|
||||
// .excludePathPatterns("/shoppingcart/addShoppingCart")
|
||||
// .excludePathPatterns("/shoppingcart/getGoodsWeight")
|
||||
// .excludePathPatterns("/shoppingcart/shoppingCartList")
|
||||
// .excludePathPatterns("/shoppingcart/delShoppingCart/**")
|
||||
// .excludePathPatterns("/lpkgoods/vegeCellarTypeList")
|
||||
// .excludePathPatterns("/vegetablecellar/addGoods/**")
|
||||
// .excludePathPatterns("/lpkgoods/vegeCellarList")
|
||||
// .excludePathPatterns("/customerstore/getStoreBySid/**")
|
||||
// .excludePathPatterns("/lpkgiftcard/bindAllCard")
|
||||
// .excludePathPatterns("/lpkcustomer/customerInfo/**")
|
||||
// .excludePathPatterns("/vegetablecellar/saveGoods")
|
||||
// .excludePathPatterns("/transferrecords/getTransferByCode/**")
|
||||
// //2024-01-18
|
||||
// .excludePathPatterns("/lpkcustomer/getCustomerInfo/**")
|
||||
// .excludePathPatterns("/lpkcustomer/modifyUserNickName")
|
||||
// .excludePathPatterns("/lpkcustomer/modifyHeadImage")
|
||||
// .excludePathPatterns("/upload/**")
|
||||
// .excludePathPatterns("/lpkcustomer/getPhoneNumber")
|
||||
// .excludePathPatterns("/lpkcustomer/getRealInfo/**")
|
||||
// .excludePathPatterns("/lpkcustomer/saveRealInfo")
|
||||
// .excludePathPatterns("/pms/PmsBrand/getList")
|
||||
// .excludePathPatterns("/LpkCustomerBank/getBankList")
|
||||
// .excludePathPatterns("/lpkcustomer/updateCustomerBank")
|
||||
// .excludePathPatterns("//wxapi/**")
|
||||
// ;
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.yxt.purchase.config;
|
||||
|
||||
import com.yxt.common.base.config.handler.GlobalExceptionHandler;
|
||||
import com.yxt.common.core.result.ResultBean;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.servlet.NoHandlerFoundException;
|
||||
|
||||
/**
|
||||
* @author dimengzhe
|
||||
* @date 2020/9/12 3:23
|
||||
* @description 全局异常处理
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
public class SaTokenGloableException extends GlobalExceptionHandler {
|
||||
|
||||
private static final Logger L = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
|
||||
public SaTokenGloableException() {
|
||||
}
|
||||
@ExceptionHandler({Exception.class})
|
||||
public ResultBean handleException(Exception e) {
|
||||
if(null !=e.getMessage()){
|
||||
if(e.getMessage().contains("token 无效:")){
|
||||
L.error(e.getMessage(), e);
|
||||
return ResultBean.fireFail().setCode("5000").setMsg("系统异常::" + e.getMessage());
|
||||
}
|
||||
if(e.getMessage().contains("未能读取到有效 token")){
|
||||
// L.error(e.getMessage(), e);
|
||||
return ResultBean.fireFail().setMsg("系统异常::" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
L.error(e.getMessage(), e);
|
||||
return ResultBean.fireFail().setMsg("系统异常::" + e.getMessage());
|
||||
}
|
||||
@ExceptionHandler({NoHandlerFoundException.class})
|
||||
public ResultBean handlerNoFoundException(Exception e) {
|
||||
L.error(e.getMessage(), e);
|
||||
return ResultBean.fireFail().setCode("404").setMsg("路径不存在,请检查路径是否正确");
|
||||
}
|
||||
|
||||
// @ExceptionHandler({Exception.class})
|
||||
// public ResultBean handleException(Exception e) {
|
||||
// L.error(e.getMessage(), e);
|
||||
// return ResultBean.fireFail().setMsg("系统异常::" + e.getMessage());
|
||||
// }
|
||||
|
||||
@ExceptionHandler({BindException.class})
|
||||
public ResultBean validatedBindException(BindException e) {
|
||||
L.error(e.getMessage(), e);
|
||||
String message = ((ObjectError)e.getAllErrors().get(0)).getDefaultMessage();
|
||||
return ResultBean.fireFail().setCode("405").setMsg(message);
|
||||
}
|
||||
|
||||
@ExceptionHandler({MethodArgumentNotValidException.class})
|
||||
public ResultBean validExceptionHandler(MethodArgumentNotValidException e) {
|
||||
L.error(e.getMessage(), e);
|
||||
String message = e.getBindingResult().getFieldError().getDefaultMessage();
|
||||
return ResultBean.fireFail().setCode("405").setMsg(message);
|
||||
}
|
||||
}
|
||||
4
src/main/java/com/yxt/purchase/config/package-info.java
Normal file
4
src/main/java/com/yxt/purchase/config/package-info.java
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 宇信通监管项目-光伏(山海新能源)项目后台逻辑和接口-接口声明
|
||||
*/
|
||||
package com.yxt.purchase.config;
|
||||
4
src/main/java/com/yxt/purchase/feign/package-info.java
Normal file
4
src/main/java/com/yxt/purchase/feign/package-info.java
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 宇信通监管项目-光伏(山海新能源)项目后台逻辑和接口-接口声明
|
||||
*/
|
||||
package com.yxt.purchase.feign;
|
||||
93
src/main/java/com/yxt/purchase/utils/DoubleUtils.java
Normal file
93
src/main/java/com/yxt/purchase/utils/DoubleUtils.java
Normal file
@@ -0,0 +1,93 @@
|
||||
package com.yxt.purchase.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author wangpengfei
|
||||
* @date 2024/1/24 8:53
|
||||
*/
|
||||
public class DoubleUtils {
|
||||
|
||||
/**
|
||||
* 对double数据进行取精度.
|
||||
* @param value double数据.
|
||||
* @param scale 精度位数(保留的小数位数).
|
||||
* @param roundingMode 精度取值方式.
|
||||
* @return 精度计算后的数据.
|
||||
*/
|
||||
public static double round(double value, int scale,
|
||||
int roundingMode) {
|
||||
BigDecimal bd = BigDecimal.valueOf(value);
|
||||
bd = bd.setScale(scale, roundingMode);
|
||||
double d = bd.doubleValue();
|
||||
bd = null;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* double 相加
|
||||
* @param d1
|
||||
* @param d2
|
||||
* @return
|
||||
*/
|
||||
public static double sum(double d1,double d2){
|
||||
BigDecimal bd1 = BigDecimal.valueOf(d1);
|
||||
BigDecimal bd2 = BigDecimal.valueOf(d2);
|
||||
return bd1.add(bd2).doubleValue();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* double 相减
|
||||
* @param d1
|
||||
* @param d2
|
||||
* @return
|
||||
*/
|
||||
public static double sub(double d1,double d2){
|
||||
BigDecimal bd1 = BigDecimal.valueOf(d1);
|
||||
BigDecimal bd2 = BigDecimal.valueOf(d2);
|
||||
return bd1.subtract(bd2).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* double 乘法
|
||||
* @param d1
|
||||
* @param d2
|
||||
* @return
|
||||
*/
|
||||
public static double mul(double d1, double d2){
|
||||
BigDecimal bd1 = BigDecimal.valueOf(d1);
|
||||
BigDecimal bd2 = BigDecimal.valueOf(d2);
|
||||
return bd1.multiply(bd2).doubleValue();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* double 除法
|
||||
* @param d1
|
||||
* @param d2
|
||||
* @param scale 四舍五入 小数点位数
|
||||
* @return
|
||||
*/
|
||||
public static double div(double d1,double d2,int scale){
|
||||
BigDecimal bd1 = BigDecimal.valueOf(d1);
|
||||
BigDecimal bd2 = BigDecimal.valueOf(d2);
|
||||
return bd1.divide
|
||||
(bd2,scale,BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
}
|
||||
/**
|
||||
* 去除多余.0
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public static String removeZeros(String num) {
|
||||
if (num.indexOf(".") > 0) {
|
||||
// 去掉多余的0
|
||||
num = num.replaceAll("0+?$", "");
|
||||
// 如果最后一位是. 则去掉
|
||||
num = num.replaceAll("[.]$", "");
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
277
src/main/java/com/yxt/purchase/utils/PinYinUtils.java
Normal file
277
src/main/java/com/yxt/purchase/utils/PinYinUtils.java
Normal file
@@ -0,0 +1,277 @@
|
||||
package com.yxt.purchase.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.HanyuPinyinVCharType;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @Description
|
||||
* @Author liuguohui
|
||||
* @Date 2021/9/16
|
||||
*/
|
||||
public class PinYinUtils {
|
||||
|
||||
private static HanyuPinyinOutputFormat format = null;
|
||||
|
||||
static {
|
||||
format = new HanyuPinyinOutputFormat();
|
||||
//拼音小写
|
||||
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
|
||||
//无音标方式;WITH_TONE_NUMBER:1-4数字表示英标;WITH_TONE_MARK:直接用音标符(必须WITH_U_UNICODE否则异常
|
||||
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
||||
//用v表示ü
|
||||
format.setVCharType(HanyuPinyinVCharType.WITH_V);
|
||||
}
|
||||
|
||||
// 多音字
|
||||
private static final Map<String, Object> DYZMAP = setDYZMap();
|
||||
|
||||
private static Map<String, Object> setDYZMap(){
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("仇","QIU");
|
||||
map.put("柏", "BO");
|
||||
map.put("牟", "MU");
|
||||
map.put("颉", "XIE");
|
||||
map.put("解", "XIE");
|
||||
map.put("尉", "YU");
|
||||
map.put("奇", "JI");
|
||||
map.put("单", "SHAN");
|
||||
map.put("谌", "SHEN");
|
||||
map.put("乐", "YUE");
|
||||
map.put("召", "SHAO");
|
||||
map.put("朴", "PIAO");
|
||||
map.put("区", "OU");
|
||||
map.put("查", "ZHA");
|
||||
map.put("曾", "ZENG");
|
||||
map.put("缪", "MIAO");
|
||||
map.put("晟", "CHENG");
|
||||
map.put("员", "YUN");
|
||||
map.put("贠", "YUN");
|
||||
map.put("黑", "HE");
|
||||
map.put("重", "CHONG");
|
||||
map.put("秘", "BI");
|
||||
map.put("冼", "XIAN");
|
||||
map.put("折", "SHE");
|
||||
map.put("翟", "ZHAI");
|
||||
map.put("盖", "GE");
|
||||
map.put("万俟", "MOQI");
|
||||
map.put("尉迟", "YUCHI");
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 返回字符串的拼音
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String[] getCharPinYinString(String str) {
|
||||
if (str == null || str.length() < 1) {
|
||||
return null;
|
||||
}
|
||||
List<String> result = new ArrayList<String>();
|
||||
//对字符串中的记录逐个分析
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
result = getCharPinYinString(str.charAt(i), result);
|
||||
}
|
||||
return result.toArray(new String[result.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符c的拼音拼接到list中的记录中
|
||||
* @param c
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
private static List<String> getCharPinYinString(char c, List<String> list) {
|
||||
String[] strs = getCharPinYinString(c);
|
||||
List<String> result = new ArrayList<String>();
|
||||
// strs去重(多音字)
|
||||
strs = disdinctStr(strs);
|
||||
|
||||
//如果解析出的拼音为空,判断字符C是否为英文字母,如果是英文字母则添加值拼音结果中
|
||||
if (strs == null) {
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
|
||||
c = c <= 91 ? (char)(c + 32) : c;
|
||||
if (list == null || list.size() == 0) {
|
||||
result.add(c + "");
|
||||
} else {
|
||||
for (String s : list) {
|
||||
result.add(s + c);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
//将字符C的拼音首和已存在的拼音首组合成新的记录
|
||||
for (String str : strs) {
|
||||
if (list == null || list.size() == 0) {
|
||||
result.add(str);
|
||||
} else {
|
||||
for (String s : list) {
|
||||
result.add(s + str);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回汉字的拼音
|
||||
* @param c
|
||||
* @return
|
||||
*/
|
||||
public static String[] getCharPinYinString(char c) {
|
||||
try {
|
||||
//返回字符C的拼音
|
||||
return PinyinHelper.toHanyuPinyinStringArray(c, format);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回字符串的拼音的首字母
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String[] getCharPinYinChar(String str) {
|
||||
if (str == null || str.length() < 1) {
|
||||
return null;
|
||||
}
|
||||
List<String> result = new ArrayList<String>();
|
||||
//对字符串中的记录逐个分析
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
result = getCharPinYinChar(str.charAt(i), result);
|
||||
}
|
||||
return result.toArray(new String[result.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符c的拼音首字母拼接到list中的记录中
|
||||
* @param c
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
private static List<String> getCharPinYinChar(char c, List<String> list) {
|
||||
char[] chars = getCharPinYinChar(c);
|
||||
List<String> result = new ArrayList<String>();
|
||||
//如果解析出的拼音为空,判断字符C是否为英文字母,如果是英文字母则添加值拼音结果中
|
||||
if (chars == null) {
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
|
||||
c = c < 91 ? (char)(c + 32) : c;
|
||||
if (list == null || list.size() == 0) {
|
||||
result.add(c + "");
|
||||
} else {
|
||||
for (String s : list) {
|
||||
result.add(s + c);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
//将字符C的拼音首字母和已存在的拼音首字母组合成新的记录
|
||||
for (char ch : chars) {
|
||||
if (list == null || list.size() == 0) {
|
||||
result.add(ch + "");
|
||||
} else {
|
||||
for (String s : list) {
|
||||
result.add(s + ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回汉字拼音首字母
|
||||
* @param c
|
||||
* @return
|
||||
*/
|
||||
public static char[] getCharPinYinChar(char c) {
|
||||
//字符C的拼音
|
||||
String[] strs = getCharPinYinString(c);
|
||||
if (strs != null) {
|
||||
//截取拼音的首字母
|
||||
char[] chars = new char[strs.length];
|
||||
for(int i = 0; i <chars.length; i++) {
|
||||
chars[i] = strs[i].charAt(0);
|
||||
}
|
||||
return chars;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去重
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
private static String [] disdinctStr(String str[]){
|
||||
Stream<String> arrStream = Arrays.stream(str);
|
||||
List<String> arrList = arrStream.distinct().collect(Collectors.toList());
|
||||
str = new String[arrList.size()];
|
||||
arrList.toArray(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入的字符串是否为中文,将中文的转换为拼音
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static String getPinYinName(String name){
|
||||
char[] nameArray = name.toCharArray();
|
||||
String newName = "";
|
||||
for (int i = 0; i < nameArray.length; i++) {
|
||||
if (Character.toString(nameArray[i]).matches("^[\u4e00-\u9fa5]+$")) { // 如果字符是中文,则将中文转为汉语拼音
|
||||
String[] pinYinString = PinYinUtils.getCharPinYinString(nameArray[i]);
|
||||
// strs去重(多音字)
|
||||
pinYinString = disdinctStr(pinYinString);
|
||||
String pinYinStr = StringUtils.join(pinYinString);
|
||||
newName = newName + pinYinStr;
|
||||
}else {
|
||||
newName = newName + Character.toString(nameArray[i]);
|
||||
}
|
||||
}
|
||||
return newName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回字符串的拼音的首字母(包括多音字)
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String getCharDuoPinYinChar(String str) {
|
||||
if (str == null || str.length() < 1) {
|
||||
return null;
|
||||
}
|
||||
char firstChar = str.toCharArray()[0];
|
||||
if(Character.toString(firstChar).matches("^[\u4e00-\u9fa5]+$")){ // 为中文
|
||||
char[] charPinYinChar = getCharPinYinChar(firstChar);
|
||||
String result = "";
|
||||
if (DYZMAP.containsKey(Character.toString(firstChar))) {
|
||||
result = DYZMAP.get(Character.toString(firstChar)).toString().substring(0, 1);
|
||||
}else {
|
||||
result = StringUtils.join(charPinYinChar[0]);
|
||||
}
|
||||
return result.toUpperCase();
|
||||
}else if(Character.toString(firstChar).matches("^[a-zA-Z]")){ // 为英文字母
|
||||
return Character.toString(firstChar).toUpperCase();
|
||||
}else { // 特殊符号
|
||||
return "#";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
89
src/main/java/com/yxt/purchase/utils/StyleUtils.java
Normal file
89
src/main/java/com/yxt/purchase/utils/StyleUtils.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package com.yxt.purchase.utils;
|
||||
|
||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||
import com.alibaba.excel.write.metadata.style.WriteFont;
|
||||
import org.apache.poi.ss.usermodel.BorderStyle;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
|
||||
/**
|
||||
* @author wangpengfei
|
||||
* @date 2023/12/16 22:14
|
||||
*/
|
||||
public class StyleUtils { /**
|
||||
* 标题样式
|
||||
* @return
|
||||
*/
|
||||
public static WriteCellStyle getHeadStyle(){
|
||||
// 头的策略
|
||||
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
|
||||
// 背景颜色
|
||||
// headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE1.getIndex());
|
||||
// headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
|
||||
|
||||
// 字体
|
||||
WriteFont headWriteFont = new WriteFont();
|
||||
headWriteFont.setFontName("宋体");//设置字体名字
|
||||
headWriteFont.setFontHeightInPoints((short)14);//设置字体大小
|
||||
headWriteFont.setBold(true);//字体加粗
|
||||
headWriteCellStyle.setWriteFont(headWriteFont); //在样式用应用设置的字体;
|
||||
|
||||
// 样式
|
||||
headWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
|
||||
headWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色;
|
||||
headWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框;
|
||||
headWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色;
|
||||
headWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框;
|
||||
headWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色;
|
||||
headWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框;
|
||||
headWriteCellStyle.setTopBorderColor((short) 0); //设置顶边框颜色;
|
||||
|
||||
headWriteCellStyle.setWrapped(true); //设置自动换行;
|
||||
|
||||
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//设置水平对齐的样式为居中对齐;
|
||||
headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐的样式为居中对齐;
|
||||
headWriteCellStyle.setShrinkToFit(true);//设置文本收缩至合适
|
||||
|
||||
return headWriteCellStyle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 内容样式
|
||||
* @return
|
||||
*/
|
||||
public static WriteCellStyle getContentStyle(){
|
||||
// 内容的策略
|
||||
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
|
||||
|
||||
// 背景绿色
|
||||
// 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
|
||||
// contentWriteCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
|
||||
// contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
|
||||
|
||||
// 设置字体
|
||||
WriteFont contentWriteFont = new WriteFont();
|
||||
contentWriteFont.setFontHeightInPoints((short) 12);//设置字体大小
|
||||
contentWriteFont.setFontName("宋体"); //设置字体名字
|
||||
contentWriteCellStyle.setWriteFont(contentWriteFont);//在样式用应用设置的字体;
|
||||
|
||||
//设置样式;
|
||||
contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
|
||||
contentWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色;
|
||||
contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框;
|
||||
contentWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色;
|
||||
contentWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框;
|
||||
contentWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色;
|
||||
contentWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框;
|
||||
contentWriteCellStyle.setTopBorderColor((short) 0); ///设置顶边框颜色;
|
||||
|
||||
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);// 水平居中
|
||||
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中
|
||||
contentWriteCellStyle.setWrapped(true); //设置自动换行;
|
||||
|
||||
// contentWriteCellStyle.setShrinkToFit(true);//设置文本收缩至合适
|
||||
|
||||
return contentWriteCellStyle;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user