添加线索导入与新增
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
package com.cool.store.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 自定义导出Excel数据注解
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface Excel
|
||||
{
|
||||
/**
|
||||
* 导出时在excel中排序
|
||||
*/
|
||||
int sort() default Integer.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* 导出到Excel中的名字.
|
||||
*/
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* 日期格式, 如: yyyy-MM-dd
|
||||
*/
|
||||
String dateFormat() default "";
|
||||
|
||||
/**
|
||||
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
|
||||
*/
|
||||
String readConverterExp() default "";
|
||||
|
||||
/**
|
||||
* 分隔符,读取字符串组内容
|
||||
*/
|
||||
String separator() default ",";
|
||||
|
||||
/**
|
||||
* BigDecimal 精度 默认:-1(默认不开启BigDecimal格式化)
|
||||
*/
|
||||
int scale() default -1;
|
||||
|
||||
/**
|
||||
* BigDecimal 舍入规则 默认:BigDecimal.ROUND_HALF_EVEN
|
||||
*/
|
||||
int roundingMode() default BigDecimal.ROUND_HALF_EVEN;
|
||||
|
||||
/**
|
||||
* 导出类型(0数字 1字符串)
|
||||
*/
|
||||
ColumnType cellType() default ColumnType.STRING;
|
||||
|
||||
/**
|
||||
* 导出时在excel中每个列的高度 单位为字符
|
||||
*/
|
||||
double height() default 14;
|
||||
|
||||
/**
|
||||
* 导出时在excel中每个列的宽 单位为字符
|
||||
*/
|
||||
double width() default 16;
|
||||
|
||||
/**
|
||||
* 文字后缀,如% 90 变成90%
|
||||
*/
|
||||
String suffix() default "";
|
||||
|
||||
/**
|
||||
* 当值为空时,字段的默认值
|
||||
*/
|
||||
String defaultValue() default "";
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
*/
|
||||
String prompt() default "";
|
||||
|
||||
/**
|
||||
* 设置只能选择不能输入的列内容.
|
||||
*/
|
||||
String[] combo() default {};
|
||||
|
||||
/**
|
||||
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
|
||||
*/
|
||||
boolean isExport() default true;
|
||||
|
||||
/**
|
||||
* 另一个类中的属性名称,支持多级获取,以小数点隔开
|
||||
*/
|
||||
String targetAttr() default "";
|
||||
|
||||
/**
|
||||
* 是否自动统计数据,在最后追加一行统计数据总和
|
||||
*/
|
||||
boolean isStatistics() default false;
|
||||
/**
|
||||
* 列颜色(列头与列内容) IndexedColors.SKY_BLUE.getIndex()
|
||||
*/
|
||||
short columnsColor() default 0;
|
||||
|
||||
/**
|
||||
* 须比较列 注解所在列顺序与比较列属性的值进行比较
|
||||
*/
|
||||
String compareColName() default "";
|
||||
/**
|
||||
* 导出错误信息
|
||||
*/
|
||||
String compareExportInfo() default "";
|
||||
/**
|
||||
* 字段类型(0:导出导入;1:仅导出;2:仅导入)
|
||||
*/
|
||||
Type type() default Type.ALL;
|
||||
|
||||
enum Type
|
||||
{
|
||||
/**
|
||||
* 导出导入
|
||||
*/
|
||||
ALL(0),
|
||||
/**
|
||||
* 仅导出
|
||||
*/
|
||||
EXPORT(1),
|
||||
/**
|
||||
* 仅导入
|
||||
*/
|
||||
IMPORT(2);
|
||||
private final int value;
|
||||
|
||||
Type(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int value()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
enum ColumnType
|
||||
{
|
||||
/**
|
||||
* 数字
|
||||
*/
|
||||
NUMERIC(0),
|
||||
/**
|
||||
* 字符串
|
||||
*/
|
||||
STRING(1);
|
||||
private final int value;
|
||||
|
||||
ColumnType(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int value()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.cool.store.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Excel注解集
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Excels
|
||||
{
|
||||
Excel[] value();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.cool.store.constants;
|
||||
|
||||
/**
|
||||
* hxd
|
||||
*/
|
||||
public class ExcelErrorConstants {
|
||||
|
||||
public static final String NAME_LOSE = "姓名缺失";
|
||||
|
||||
public static final String MOBILE_LOSE= "手机号缺失";
|
||||
|
||||
public static final String MOBILE_ERROR= "手机号有误";
|
||||
|
||||
public static final String MOBILE_EXIST= "手机号已存在";
|
||||
|
||||
public static final String LIVEAREA_LOSE= "常驻区域缺失";
|
||||
|
||||
public static final String LIVEAREA_FORMAT_ERROR= "常驻区域格式错误";
|
||||
|
||||
public static final String WANTSHOPAREA_LOSE= "意向区域缺失";
|
||||
|
||||
public static final String WANTSHOPAREA_FORMAT_ERROR= "意向区域格式错误";
|
||||
|
||||
public static final String ACCEPTADJUSTTYPE_LOSE= "是否接受调剂缺失";
|
||||
|
||||
public static final String INVESTMENTMANAGER_LOSE= "未找到此招商经理,请核实";
|
||||
|
||||
}
|
||||
@@ -34,4 +34,30 @@ public enum AcceptAdjustTypeEnum {
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
public String getMessage(String enums) {
|
||||
return AcceptAdjustTypeEnum.valueOf(enums).getMessage();
|
||||
}
|
||||
|
||||
|
||||
public Integer getCode(String enums) {
|
||||
return AcceptAdjustTypeEnum.valueOf(enums).getCode();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据name查找
|
||||
* @param message 枚举message
|
||||
* @return 枚举对象
|
||||
*/
|
||||
public static Integer findEnumByName(String message) {
|
||||
for (AcceptAdjustTypeEnum statusEnum : AcceptAdjustTypeEnum.values()) {
|
||||
if (statusEnum.getMessage().equals(message)) {
|
||||
//如果需要直接返回code则更改返回类型为String,return statusEnum.code;
|
||||
return statusEnum.getCode();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ public enum ErrorCodeEnum {
|
||||
INTENT_AREA_NOT_BING_ZONE(500007, "意向区域没有绑定战区 分配招商经理失败!", null),
|
||||
PUBLIC_LINE_NOT_OPERATE(500008, "公海线索不允许操作!", null),
|
||||
PARTNER_BASE_INFO_NOT_EXIST(500009, "加盟商信息不存在!", null),
|
||||
PARTNER_MOBILE_EXIST(500010, "手机号码已存在,请核实!", null),
|
||||
|
||||
INTERVIEW_ENTER_FAIL(1021101, "进入面试间失败", null),
|
||||
DINGDING_USER_NOT_EXIST(1021102, "用户钉钉信息不存在,无法发起资质审核!", null),
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.cool.store.dao;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.mapper.EnterpriseUserMapper;
|
||||
import com.cool.store.utils.StringUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -129,4 +130,11 @@ public class EnterpriseUserDAO {
|
||||
EnterpriseUserDO userInfo = getUserInfoById(userId);
|
||||
return Optional.ofNullable(userInfo).map(EnterpriseUserDO::getName).orElse(StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
public EnterpriseUserDO selectByInvestmentManager(String investmentManager) {
|
||||
if (StringUtil.isEmpty(investmentManager)) {
|
||||
return null;
|
||||
}
|
||||
return enterpriseUserMapper.selectByInvestmentManager(investmentManager);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.cool.store.dto.partner.ApplyReservationProvinceDTO;
|
||||
import com.cool.store.entity.HyOpenAreaInfoDO;
|
||||
import com.cool.store.entity.HyPartnerBaseInfoDO;
|
||||
import com.cool.store.mapper.HyOpenAreaInfoMapper;
|
||||
import com.cool.store.utils.StringUtil;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
@@ -148,4 +149,11 @@ public class HyOpenAreaInfoDAO {
|
||||
return provinceCodeList;
|
||||
}
|
||||
}
|
||||
|
||||
public HyOpenAreaInfoDO selectByAreaPath(String areaPath) {
|
||||
if (StringUtil.isEmpty(areaPath)) {
|
||||
return null;
|
||||
}
|
||||
return hyOpenAreaInfoMapper.selectByAreaPath(areaPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,4 +93,6 @@ public interface EnterpriseUserMapper {
|
||||
|
||||
String selectByMobile(@Param("mobile") String mobile);
|
||||
|
||||
EnterpriseUserDO selectByInvestmentManager(@Param("investmentManager") String investmentManager);
|
||||
|
||||
}
|
||||
@@ -121,4 +121,6 @@ public interface HyOpenAreaInfoMapper {
|
||||
List<HyOpenAreaInfoDO> getSonArea(@Param("id") String id);
|
||||
|
||||
List<HyOpenAreaInfoDO> getProvinceAllCode(@Param("id") String id);
|
||||
|
||||
HyOpenAreaInfoDO selectByAreaPath(@Param("areaPath") String areaPath);
|
||||
}
|
||||
@@ -311,4 +311,9 @@
|
||||
<select id="selectByMobile" resultType="java.lang.String">
|
||||
SELECT user_id FROM enterprise_user WHERE mobile =#{mobile} LIMIT 1
|
||||
</select>
|
||||
<select id="selectByInvestmentManager" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM enterprise_user WHERE mobile like #{investmentManager} or `name` like #{investmentManager} LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -303,5 +303,11 @@
|
||||
SELECT b.* FROM `hy_open_area_info` a inner join hy_open_area_info b on a.`id`=b.`parent_id`
|
||||
WHERE a.parent_id=#{id} ORDER BY b.id desc
|
||||
</select>
|
||||
<select id="selectByAreaPath" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"></include>
|
||||
FROM `hy_open_area_info`
|
||||
WHERE area_path= concat('/',#{areaPath},'/') and deleted=0
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.cool.store.entity;
|
||||
|
||||
import com.cool.store.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hxd
|
||||
* @date 2023-05-29 03:52
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class HyPartnerLineDO implements Serializable {
|
||||
|
||||
@Excel(name = "*姓名(必填)")
|
||||
@ApiModelProperty("姓名")
|
||||
private String partnerName;
|
||||
|
||||
@Excel(name = "*手机号(必填)")
|
||||
@ApiModelProperty("手机号")
|
||||
private String mobile;
|
||||
|
||||
@Excel(name = "*常驻区域(必填)")
|
||||
@ApiModelProperty("常驻区域")
|
||||
private String liveAreaReplace;
|
||||
|
||||
private String liveArea;
|
||||
|
||||
@Excel(name = "*意向区域(必填)")
|
||||
@ApiModelProperty("意向区域")
|
||||
private String wantShopAreaReplace;
|
||||
|
||||
private Long wantShopArea;
|
||||
|
||||
@Excel(name = "*是否接受调剂(必填)")
|
||||
@ApiModelProperty("是否接受调剂")
|
||||
private String acceptAdjustTypeReplace;
|
||||
|
||||
private Integer acceptAdjustType;
|
||||
|
||||
@Excel(name = "分配招商经理")
|
||||
@ApiModelProperty("分配招商经理")
|
||||
private String investmentManagerReplace;
|
||||
|
||||
private String investmentManager;
|
||||
|
||||
|
||||
|
||||
@Excel(name = "错误信息")
|
||||
@ApiModelProperty("错误信息")
|
||||
private String errorInfo;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.cool.store.request;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author hxd
|
||||
* @Date 2023/5/31 11:19
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
@ApiModel
|
||||
@Accessors(chain = true)
|
||||
public class AddLineRequest {
|
||||
|
||||
|
||||
@NotBlank(message = "姓名不能为空")
|
||||
@ApiModelProperty("姓名")
|
||||
private String partnerName;
|
||||
|
||||
@Pattern(regexp = "(?:0|86|\\+86)?1[3-9]\\d{9}",message = "手机号码不正确,请检查后重试")
|
||||
@ApiModelProperty("手机号")
|
||||
private String mobile;
|
||||
|
||||
@NotBlank(message = "常驻区域为空")
|
||||
@ApiModelProperty("常驻区域")
|
||||
private String liveArea;
|
||||
|
||||
@NotBlank(message = "意向区域不能为空")
|
||||
@ApiModelProperty("意向区域")
|
||||
private String wantShopArea;
|
||||
|
||||
|
||||
/**
|
||||
* (0不接受调剂、1全国调剂、2省内调剂、3市内调剂)*
|
||||
*/
|
||||
@NotBlank(message = "是否接受调剂不能为空")
|
||||
@ApiModelProperty("是否接受调剂")
|
||||
private Integer acceptAdjustType;
|
||||
|
||||
|
||||
@ApiModelProperty("分配招商经理")
|
||||
private String investmentManager;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.cool.store.response.error;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author hxd
|
||||
* @FileName: ErrorExcelResponse
|
||||
* @Description:
|
||||
* @date 2023-08-13 19:43
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ErrorExcelResponse {
|
||||
|
||||
private Integer total;
|
||||
|
||||
private Integer errorNum;
|
||||
|
||||
private String file;
|
||||
|
||||
public ErrorExcelResponse(Integer total,Integer errorNum,String file){
|
||||
this.total=total;
|
||||
this.errorNum=errorNum;
|
||||
this.file=file;
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,15 @@
|
||||
<artifactId>dysmsapi20170525</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
<!-- excel工具 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.request.AddLineRequest;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface LineHighSeasService {
|
||||
|
||||
Boolean addLine(AddLineRequest request);
|
||||
|
||||
ResponseResult importLine(MultipartFile file);
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cool.store.constants.ExcelErrorConstants;
|
||||
import com.cool.store.dao.*;
|
||||
import com.cool.store.entity.*;
|
||||
import com.cool.store.enums.AcceptAdjustTypeEnum;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.enums.LineStatusEnum;
|
||||
import com.cool.store.enums.WorkflowStatusEnum;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.oss.OSSServer;
|
||||
import com.cool.store.request.AddLineRequest;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.response.error.ErrorExcelResponse;
|
||||
import com.cool.store.service.HyPartnerLineInfoService;
|
||||
import com.cool.store.service.LineHighSeasService;
|
||||
import com.cool.store.utils.StringUtil;
|
||||
import com.cool.store.utils.UUIDUtils;
|
||||
import com.cool.store.utils.poi.ExcelUtil;
|
||||
import com.cool.store.utils.poi.constant.Constants;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Service
|
||||
public class LineHighSeasServiceImpl implements LineHighSeasService {
|
||||
|
||||
|
||||
@Resource
|
||||
private HyPartnerUserInfoDAO hyPartnerUserInfoDAO;
|
||||
|
||||
@Resource
|
||||
private EnterpriseUserDAO enterpriseUserDAO;
|
||||
|
||||
@Resource
|
||||
private HyOpenAreaInfoDAO hyOpenAreaInfoDAO;
|
||||
|
||||
@Resource
|
||||
private HyPartnerLineInfoDAO hyPartnerLineInfoDAO;
|
||||
|
||||
@Resource
|
||||
private HyPartnerBaseInfoDAO hyPartnerBaseInfoDAO;
|
||||
|
||||
@Resource
|
||||
HyPartnerLineInfoService hyPartnerLineInfoService;
|
||||
|
||||
@Resource
|
||||
private OSSServer ossServer;
|
||||
|
||||
private final int excelMaxSize = 500;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean addLine(AddLineRequest request) {
|
||||
HyPartnerUserInfoDO hyPartnerUserInfoDO = hyPartnerUserInfoDAO.selectByMobile(request.getMobile());
|
||||
if (ObjectUtil.isNotNull(hyPartnerUserInfoDO)) {
|
||||
throw new ServiceException(ErrorCodeEnum.PARTNER_MOBILE_EXIST);
|
||||
}
|
||||
add(request);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增线索
|
||||
* @param request
|
||||
*/
|
||||
public void add(AddLineRequest request) {
|
||||
String partnerId = UUIDUtils.get32UUID();
|
||||
HyPartnerUserInfoDO resultUser = new HyPartnerUserInfoDO();
|
||||
resultUser.setUsername(request.getPartnerName()).setMobile(request.getMobile()).setPartnerId(partnerId).setCreateTime(new Date()).setAcceptAdjustType(request.getAcceptAdjustType())
|
||||
.setLiveArea(request.getLiveArea()).setWantShopArea(request.getWantShopArea());
|
||||
hyPartnerUserInfoDAO.insertSelective(resultUser);
|
||||
|
||||
HyPartnerLineInfoDO resultLine = new HyPartnerLineInfoDO();
|
||||
resultLine.setPartnerId(partnerId).setCreateTime(new Date());
|
||||
|
||||
//判断招商经理是否为空
|
||||
if (StringUtil.isNotEmpty(request.getInvestmentManager())) {
|
||||
resultLine.setInvestmentManager(request.getInvestmentManager()).setLineStatus(LineStatusEnum.PRIVATE_SEAS.getCode());
|
||||
} else {
|
||||
//是否分配跟进人
|
||||
Boolean flag = hyPartnerLineInfoService.assignFollowUser(partnerId, request.getWantShopArea(), request.getAcceptAdjustType(), Boolean.TRUE);
|
||||
if (flag) {
|
||||
//查询跟进人
|
||||
String investmentManager = hyPartnerLineInfoService.getAssignFollowUser(partnerId, "intent");
|
||||
resultLine.setInvestmentManager(investmentManager).setLineStatus(LineStatusEnum.PRIVATE_SEAS.getCode());
|
||||
} else {
|
||||
//直接放公海
|
||||
resultLine.setLineStatus(LineStatusEnum.PUBLIC_SEAS.getCode());
|
||||
}
|
||||
}
|
||||
hyPartnerLineInfoDAO.insertSelective(resultLine);
|
||||
|
||||
HyPartnerBaseInfoDO resultBase = new HyPartnerBaseInfoDO();
|
||||
resultBase.setPartnerId(partnerId).setPartnerLineId(resultLine.getId()).setStatus(Integer.valueOf(WorkflowStatusEnum.INTENT_0.getCode())).
|
||||
setCreateTime(new Date()).setUsername(request.getPartnerName()).setMobile(request.getMobile());
|
||||
hyPartnerBaseInfoDAO.insertSelective(resultBase);
|
||||
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseResult importLine(MultipartFile file) {
|
||||
ExcelUtil<HyPartnerLineDO> util = new ExcelUtil<HyPartnerLineDO>(HyPartnerLineDO.class);
|
||||
List<HyPartnerLineDO> lineDOList = util.importExcel(file.getInputStream());
|
||||
if (lineDOList.size() > excelMaxSize) {
|
||||
|
||||
//上传文件到oss
|
||||
// ossServer.uploadFileServer()
|
||||
return new ResponseResult(500, "", new ErrorExcelResponse(lineDOList.size(), excelMaxSize, ""));
|
||||
}
|
||||
Map<Integer, Map<Integer, List<String>>> styleCells = new HashMap<>(4);
|
||||
for (int i = 0; i < lineDOList.size(); i++) {
|
||||
HyPartnerLineDO hyPartnerLineDO = lineDOList.get(i);
|
||||
if (StringUtil.isEmpty(hyPartnerLineDO.getPartnerName())) {
|
||||
hyPartnerLineDO.setErrorInfo(hyPartnerLineDO.getErrorInfo().concat(Constants.SEMICOLON).concat(ExcelErrorConstants.NAME_LOSE));
|
||||
ExcelUtil.setStyleMap(styleCells, i, 1, new String[]{ExcelUtil.FONT_RED});
|
||||
}
|
||||
String mobile = hyPartnerLineDO.getMobile();
|
||||
//手机号为空
|
||||
if (StringUtil.isEmpty(mobile)) {
|
||||
hyPartnerLineDO.setErrorInfo(hyPartnerLineDO.getErrorInfo().concat(Constants.SEMICOLON).concat(ExcelErrorConstants.MOBILE_LOSE));
|
||||
ExcelUtil.setStyleMap(styleCells, i, 2, new String[]{ExcelUtil.FONT_RED});
|
||||
} else {
|
||||
//手机号格式判断
|
||||
if (!isPhone(mobile)) {
|
||||
hyPartnerLineDO.setErrorInfo(hyPartnerLineDO.getErrorInfo().concat(Constants.SEMICOLON).concat(ExcelErrorConstants.MOBILE_ERROR));
|
||||
ExcelUtil.setStyleMap(styleCells, i, 2, new String[]{ExcelUtil.FONT_RED});
|
||||
}
|
||||
//手机号是否已存在
|
||||
HyPartnerUserInfoDO hyPartnerUserInfoDO = hyPartnerUserInfoDAO.selectByMobile(mobile);
|
||||
if (ObjectUtil.isNotNull(hyPartnerUserInfoDO)) {
|
||||
hyPartnerLineDO.setErrorInfo(hyPartnerLineDO.getErrorInfo().concat(Constants.SEMICOLON).concat(ExcelErrorConstants.MOBILE_EXIST));
|
||||
ExcelUtil.setStyleMap(styleCells, i, 2, new String[]{ExcelUtil.FONT_RED});
|
||||
}
|
||||
}
|
||||
//常驻区域为空
|
||||
String liveArea = hyPartnerLineDO.getLiveAreaReplace();
|
||||
if (StringUtil.isEmpty(liveArea)) {
|
||||
hyPartnerLineDO.setErrorInfo(hyPartnerLineDO.getErrorInfo().concat(Constants.SEMICOLON).concat(ExcelErrorConstants.LIVEAREA_LOSE));
|
||||
ExcelUtil.setStyleMap(styleCells, i, 3, new String[]{ExcelUtil.FONT_RED});
|
||||
} else {
|
||||
//判断格式是否为错
|
||||
if (ObjectUtil.isNull(hyOpenAreaInfoDAO.selectByAreaPath(liveArea))) {
|
||||
hyPartnerLineDO.setErrorInfo(hyPartnerLineDO.getErrorInfo().concat(Constants.SEMICOLON).concat(ExcelErrorConstants.LIVEAREA_FORMAT_ERROR));
|
||||
ExcelUtil.setStyleMap(styleCells, i, 3, new String[]{ExcelUtil.FONT_RED});
|
||||
}else {
|
||||
hyPartnerLineDO.setLiveArea(liveArea.replace(Constants.FORWARD_SLASH, Constants.SPACE));
|
||||
}
|
||||
}
|
||||
//意向区域
|
||||
String wantShopArea = hyPartnerLineDO.getWantShopAreaReplace();
|
||||
if (StringUtil.isEmpty(wantShopArea)) {
|
||||
hyPartnerLineDO.setErrorInfo(hyPartnerLineDO.getErrorInfo().concat(Constants.SEMICOLON).concat(ExcelErrorConstants.WANTSHOPAREA_LOSE));
|
||||
ExcelUtil.setStyleMap(styleCells, i, 4, new String[]{ExcelUtil.FONT_RED});
|
||||
} else {
|
||||
//判断格式是否为错
|
||||
HyOpenAreaInfoDO hyOpenAreaInfoDO = hyOpenAreaInfoDAO.selectByAreaPath(wantShopArea);
|
||||
if (ObjectUtil.isNull(hyOpenAreaInfoDO)) {
|
||||
hyPartnerLineDO.setErrorInfo(hyPartnerLineDO.getErrorInfo().concat(Constants.SEMICOLON).concat(ExcelErrorConstants.WANTSHOPAREA_FORMAT_ERROR));
|
||||
ExcelUtil.setStyleMap(styleCells, i, 4, new String[]{ExcelUtil.FONT_RED});
|
||||
}else {
|
||||
hyPartnerLineDO.setWantShopArea(hyOpenAreaInfoDO.getId());
|
||||
}
|
||||
}
|
||||
//是否接受调剂
|
||||
String acceptAdjustType = hyPartnerLineDO.getAcceptAdjustTypeReplace();
|
||||
if (StringUtil.isEmpty(acceptAdjustType)) {
|
||||
Integer enumByName = AcceptAdjustTypeEnum.findEnumByName(acceptAdjustType);
|
||||
if(ObjectUtil.isNull(enumByName)){
|
||||
hyPartnerLineDO.setErrorInfo(hyPartnerLineDO.getErrorInfo().concat(Constants.SEMICOLON).concat(ExcelErrorConstants.ACCEPTADJUSTTYPE_LOSE));
|
||||
ExcelUtil.setStyleMap(styleCells, i, 5, new String[]{ExcelUtil.FONT_RED});
|
||||
}else {
|
||||
hyPartnerLineDO.setAcceptAdjustType(enumByName);
|
||||
}
|
||||
}
|
||||
//分配招商经理
|
||||
String investmentManager = hyPartnerLineDO.getInvestmentManagerReplace();
|
||||
if (StringUtil.isNotEmpty(investmentManager)) {
|
||||
//判断是否能够查询的到
|
||||
EnterpriseUserDO enterpriseUserDO = enterpriseUserDAO.selectByInvestmentManager(investmentManager);
|
||||
if (ObjectUtil.isNull(enterpriseUserDO)) {
|
||||
hyPartnerLineDO.setErrorInfo(hyPartnerLineDO.getErrorInfo().concat(Constants.SEMICOLON).concat(ExcelErrorConstants.INVESTMENTMANAGER_LOSE));
|
||||
ExcelUtil.setStyleMap(styleCells, i, 6, new String[]{ExcelUtil.FONT_RED});
|
||||
}else {
|
||||
hyPartnerLineDO.setInvestmentManager(enterpriseUserDO.getUserId());
|
||||
}
|
||||
}
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
util.exportExcel(outputStream, lineDOList, "", styleCells);
|
||||
InputStream stream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||
String fileStr = ossServer.uploadFileServer(stream, "");
|
||||
if (styleCells.size() != 0) {
|
||||
return new ResponseResult(500, "", new ErrorExcelResponse(lineDOList.size(), styleCells.size(), fileStr));
|
||||
}
|
||||
for (HyPartnerLineDO hyPartnerLineDO : lineDOList) {
|
||||
AddLineRequest addLineRequest = new AddLineRequest();
|
||||
BeanUtil.copyProperties(addLineRequest,hyPartnerLineDO);
|
||||
addLineRequest.setWantShopArea(hyPartnerLineDO.getWantShopArea().toString());
|
||||
add(addLineRequest);
|
||||
}
|
||||
return new ResponseResult(200, "", new ErrorExcelResponse(lineDOList.size(), styleCells.size(), fileStr));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param phone 字符串类型的手机号
|
||||
* 传入手机号,判断后返回
|
||||
* true为手机号,false相反
|
||||
*/
|
||||
private boolean isPhone(String phone) {
|
||||
String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
|
||||
if (phone.length() != 11) {
|
||||
return false;
|
||||
} else {
|
||||
Pattern p = Pattern.compile(regex);
|
||||
Matcher m = p.matcher(phone);
|
||||
return m.matches();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
package com.cool.store.utils.poi;
|
||||
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 时间工具类
|
||||
*
|
||||
* @author fanlyun
|
||||
*/
|
||||
public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
{
|
||||
public static String YYYY = "yyyy";
|
||||
|
||||
public static String YYYY_MM = "yyyy-MM";
|
||||
|
||||
public static String YYYY_MM_DD = "yyyy-MM-dd";
|
||||
|
||||
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
||||
|
||||
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
private static String[] parsePatterns = {
|
||||
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
||||
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
||||
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
|
||||
|
||||
/**
|
||||
* 获取当前Date型日期
|
||||
*
|
||||
* @return Date() 当前日期
|
||||
*/
|
||||
public static Date getNowDate()
|
||||
{
|
||||
return new Date();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期, 默认格式为yyyy-MM-dd
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String getDate()
|
||||
{
|
||||
return dateTimeNow(YYYY_MM_DD);
|
||||
}
|
||||
|
||||
public static String getTime()
|
||||
{
|
||||
return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
|
||||
}
|
||||
|
||||
public static String dateTimeNow()
|
||||
{
|
||||
return dateTimeNow(YYYYMMDDHHMMSS);
|
||||
}
|
||||
|
||||
public static String dateTimeNow(final String format)
|
||||
{
|
||||
return parseDateToStr(format, new Date());
|
||||
}
|
||||
|
||||
public static String dateTime(final Date date)
|
||||
{
|
||||
return parseDateToStr(YYYY_MM_DD, date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期
|
||||
* @param format 格式化规则
|
||||
* @param date 日期
|
||||
* @return 格式化完毕的日期
|
||||
*/
|
||||
public static String parseDateToStr(final String format, final Date date)
|
||||
{
|
||||
return new SimpleDateFormat(format).format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以规则解析时间字符串
|
||||
* @param format 格式化规则
|
||||
* @param ts 时间字符串
|
||||
* @return 解析后时间
|
||||
*/
|
||||
public static Date dateTime(final String format, final String ts)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new SimpleDateFormat(format).parse(ts);
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期路径 即年/月/日 如2018/08/08
|
||||
*/
|
||||
public static String datePath()
|
||||
{
|
||||
Date now = new Date();
|
||||
return DateFormatUtils.format(now, "yyyy/MM/dd");
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期路径 即年/月/日 如20180808
|
||||
*/
|
||||
public static String dateTime()
|
||||
{
|
||||
Date now = new Date();
|
||||
return DateFormatUtils.format(now, "yyyyMMdd");
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期型字符串转化为日期 格式
|
||||
*/
|
||||
public static Date parseDate(Object str)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
return parseDate(str.toString(), parsePatterns);
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务器启动时间
|
||||
*/
|
||||
public static Date getServerStartDate()
|
||||
{
|
||||
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
|
||||
return new Date(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算两个时间差
|
||||
*/
|
||||
public static String getDatePoor(Date endDate, Date nowDate)
|
||||
{
|
||||
long nd = 1000 * 24 * 60 * 60;
|
||||
long nh = 1000 * 60 * 60;
|
||||
long nm = 1000 * 60;
|
||||
// long ns = 1000;
|
||||
// 获得两个时间的毫秒时间差异
|
||||
long diff = endDate.getTime() - nowDate.getTime();
|
||||
// 计算差多少天
|
||||
long day = diff / nd;
|
||||
// 计算差多少小时
|
||||
long hour = diff % nd / nh;
|
||||
// 计算差多少分钟
|
||||
long min = diff % nd % nh / nm;
|
||||
// 计算差多少秒//输出结果
|
||||
// long sec = diff % nd % nh % nm / ns;
|
||||
return day + "天" + hour + "小时" + min + "分钟";
|
||||
}
|
||||
|
||||
/**
|
||||
* 以规则解析时间字符串
|
||||
* @param strDate 时间字符串
|
||||
* @param pattern 格式化规则
|
||||
* @return 解析后时间
|
||||
*/
|
||||
public static Date strToDate(String strDate, String pattern) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
return formatter.parse(strDate, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据毫秒数获取时间
|
||||
* @param millis 毫秒数
|
||||
* @return 时间
|
||||
*/
|
||||
public static String getDateByMillis(long millis) {
|
||||
//12小时制
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
|
||||
Date date = new Date();
|
||||
date.setTime(millis);
|
||||
return simpleDateFormat.format(date);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
|
||||
|
||||
/**
|
||||
* 返回11个月之前的月,从月的第一天开始,如当前是2020-05-03 返回的是2019-06-01 00:00:00
|
||||
* @return Date
|
||||
*/
|
||||
public static Date getNestOneYear() {
|
||||
LocalDate minusDays = LocalDate.now().minusMonths(11).with(TemporalAdjusters.firstDayOfMonth());
|
||||
return fromDate(minusDays);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从1.8新增的{@link LocalDate}转换为{@link Date}
|
||||
* @param localDate {@link LocalDate}
|
||||
* @return 时间
|
||||
*/
|
||||
private static Date fromDate(LocalDate localDate) {
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
|
||||
return Date.from(instant);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,522 @@
|
||||
package com.cool.store.utils.poi;
|
||||
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字符串工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
{
|
||||
/** 空字符串 */
|
||||
private static final String NULLSTR = "";
|
||||
|
||||
/** 下划线 */
|
||||
private static final char SEPARATOR = '_';
|
||||
|
||||
/** 星号 */
|
||||
private static final String START = "*";
|
||||
|
||||
/**
|
||||
* 获取参数不为空值
|
||||
*
|
||||
* @param value defaultValue 要判断的value
|
||||
* @return value 返回值
|
||||
*/
|
||||
public static <T> T nvl(T value, T defaultValue)
|
||||
{
|
||||
return value != null ? value : defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Collection是否为空, 包含List,Set,Queue
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Collection<?> coll)
|
||||
{
|
||||
return isNull(coll) || coll.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Collection是否非空,包含List,Set,Queue
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Collection<?> coll)
|
||||
{
|
||||
return !isEmpty(coll);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象数组是否为空
|
||||
*
|
||||
* @param objects 要判断的对象数组
|
||||
** @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Object[] objects)
|
||||
{
|
||||
return isNull(objects) || (objects.length == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象数组是否非空
|
||||
*
|
||||
* @param objects 要判断的对象数组
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Object[] objects)
|
||||
{
|
||||
return !isEmpty(objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Map是否为空
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Map<?, ?> map)
|
||||
{
|
||||
return isNull(map) || map.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Map是否为空
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Map<?, ?> map)
|
||||
{
|
||||
return !isEmpty(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个字符串是否为空串
|
||||
*
|
||||
* @param str String
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(String str)
|
||||
{
|
||||
return isNull(str) || NULLSTR.equals(str.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个字符串是否为非空串
|
||||
*
|
||||
* @param str String
|
||||
* @return true:非空串 false:空串
|
||||
*/
|
||||
public static boolean isNotEmpty(String str)
|
||||
{
|
||||
return !isEmpty(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否为空
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isNull(Object object)
|
||||
{
|
||||
return object == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否非空
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotNull(Object object)
|
||||
{
|
||||
return !isNull(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否是数组类型(Java基本型别的数组)
|
||||
*
|
||||
* @param object 对象
|
||||
* @return true:是数组 false:不是数组
|
||||
*/
|
||||
public static boolean isArray(Object object)
|
||||
{
|
||||
return isNotNull(object) && object.getClass().isArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 去空格
|
||||
*/
|
||||
public static String trim(String str)
|
||||
{
|
||||
return (str == null ? "" : str.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取字符串
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param start 开始
|
||||
* @return 结果
|
||||
*/
|
||||
public static String substring(final String str, int start)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
start = str.length() + start;
|
||||
}
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
start = 0;
|
||||
}
|
||||
if (start > str.length())
|
||||
{
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
return str.substring(start);
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取字符串
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param start 开始
|
||||
* @param end 结束
|
||||
* @return 结果
|
||||
*/
|
||||
public static String substring(final String str, int start, int end)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
if (end < 0)
|
||||
{
|
||||
end = str.length() + end;
|
||||
}
|
||||
if (start < 0)
|
||||
{
|
||||
start = str.length() + start;
|
||||
}
|
||||
|
||||
if (end > str.length())
|
||||
{
|
||||
end = str.length();
|
||||
}
|
||||
|
||||
if (start > end)
|
||||
{
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
start = 0;
|
||||
}
|
||||
if (end < 0)
|
||||
{
|
||||
end = 0;
|
||||
}
|
||||
|
||||
return str.substring(start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化文本, {} 表示占位符<br>
|
||||
* 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
|
||||
* 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br>
|
||||
* 例:<br>
|
||||
* 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br>
|
||||
* 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
|
||||
* 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
|
||||
*
|
||||
* @param template 文本模板,被替换的部分用 {} 表示
|
||||
* @param params 参数值
|
||||
* @return 格式化后的文本
|
||||
*/
|
||||
public static String format(String template, Object... params)
|
||||
{
|
||||
if (isEmpty(params) || isEmpty(template))
|
||||
{
|
||||
return template;
|
||||
}
|
||||
return StrFormatter.format(template, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下划线转驼峰命名
|
||||
*/
|
||||
public static String toUnderScoreCase(String str)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// 前置字符是否大写
|
||||
boolean preCharIsUpperCase = true;
|
||||
// 当前字符是否大写
|
||||
boolean curreCharIsUpperCase = true;
|
||||
// 下一字符是否大写
|
||||
boolean nexteCharIsUpperCase = true;
|
||||
for (int i = 0; i < str.length(); i++)
|
||||
{
|
||||
char c = str.charAt(i);
|
||||
if (i > 0)
|
||||
{
|
||||
preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
preCharIsUpperCase = false;
|
||||
}
|
||||
|
||||
curreCharIsUpperCase = Character.isUpperCase(c);
|
||||
|
||||
if (i < (str.length() - 1))
|
||||
{
|
||||
nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
|
||||
}
|
||||
|
||||
// 分词
|
||||
boolean participles = (i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase;
|
||||
if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase)
|
||||
{
|
||||
sb.append(SEPARATOR);
|
||||
}
|
||||
else if (participles)
|
||||
{
|
||||
sb.append(SEPARATOR);
|
||||
}
|
||||
sb.append(Character.toLowerCase(c));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否包含字符串
|
||||
*
|
||||
* @param str 验证字符串
|
||||
* @param strs 字符串组
|
||||
* @return 包含返回true
|
||||
*/
|
||||
public static boolean inStringIgnoreCase(String str, String... strs)
|
||||
{
|
||||
if (str != null && strs != null)
|
||||
{
|
||||
for (String s : strs)
|
||||
{
|
||||
if (str.equalsIgnoreCase(trim(s)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 驼峰式命名法 例如:user_name->userName
|
||||
*/
|
||||
public static String toCamelCase(String s)
|
||||
{
|
||||
if (s == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
s = s.toLowerCase();
|
||||
StringBuilder sb = new StringBuilder(s.length());
|
||||
boolean upperCase = false;
|
||||
for (int i = 0; i < s.length(); i++)
|
||||
{
|
||||
char c = s.charAt(i);
|
||||
|
||||
if (c == SEPARATOR)
|
||||
{
|
||||
upperCase = true;
|
||||
}
|
||||
else if (upperCase)
|
||||
{
|
||||
sb.append(Character.toUpperCase(c));
|
||||
upperCase = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
|
||||
*
|
||||
* @param str 指定字符串
|
||||
* @param strs 需要检查的字符串数组
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public static boolean matches(String str, List<String> strs)
|
||||
{
|
||||
if (isEmpty(str) || isEmpty(strs))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (String testStr : strs)
|
||||
{
|
||||
if (matches(str, testStr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找指定字符串是否匹配指定字符串数组中的任意一个字符串
|
||||
*
|
||||
* @param str 指定字符串
|
||||
* @param strs 需要检查的字符串数组
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public static boolean matches(String str, String... strs)
|
||||
{
|
||||
if (isEmpty(str) || isEmpty(strs))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (String testStr : strs)
|
||||
{
|
||||
if (matches(str, testStr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找指定字符串是否匹配
|
||||
*
|
||||
* @param str 指定字符串
|
||||
* @param pattern 需要检查的字符串
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public static boolean matches(String str, String pattern)
|
||||
{
|
||||
if (isEmpty(pattern) || isEmpty(str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 替换空格
|
||||
pattern = pattern.replaceAll("\\s*", "");
|
||||
// pattern截取开始位置
|
||||
int beginOffset = 0;
|
||||
// 前星号的偏移位置
|
||||
int formerStarOffset;
|
||||
// 后星号的偏移位置
|
||||
int latterStarOffset;
|
||||
|
||||
String remainingUri = str;
|
||||
String prefixPattern;
|
||||
String suffixPattern;
|
||||
|
||||
boolean result;
|
||||
do
|
||||
{
|
||||
formerStarOffset = indexOf(pattern, START, beginOffset);
|
||||
prefixPattern = substring(pattern, beginOffset, formerStarOffset > -1 ? formerStarOffset : pattern.length());
|
||||
|
||||
// 匹配前缀Pattern
|
||||
result = remainingUri.contains(prefixPattern);
|
||||
// 已经没有星号,直接返回
|
||||
if (formerStarOffset == -1)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
// 匹配失败,直接返回
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isEmpty(prefixPattern))
|
||||
{
|
||||
remainingUri = substringAfter(str, prefixPattern);
|
||||
}
|
||||
|
||||
// 匹配后缀Pattern
|
||||
latterStarOffset = indexOf(pattern, START, formerStarOffset + 1);
|
||||
suffixPattern = substring(pattern, formerStarOffset + 1, latterStarOffset > -1 ? latterStarOffset : pattern.length());
|
||||
|
||||
result = remainingUri.contains(suffixPattern);
|
||||
// 匹配失败,直接返回
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isEmpty(suffixPattern))
|
||||
{
|
||||
remainingUri = substringAfter(str, suffixPattern);
|
||||
}
|
||||
|
||||
// 移动指针
|
||||
beginOffset = latterStarOffset + 1;
|
||||
|
||||
}
|
||||
while (!isEmpty(suffixPattern) && !isEmpty(remainingUri));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T cast(Object obj)
|
||||
{
|
||||
return (T) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否非空
|
||||
* @param values 待校验的字符串
|
||||
* @return 是否所有非空
|
||||
*/
|
||||
public static boolean areNotEmpty(String... values) {
|
||||
boolean result = true;
|
||||
if ((values == null) || (values.length == 0)) {
|
||||
result = false;
|
||||
} else {
|
||||
for (String value : values) {
|
||||
result &= !isEmpty(value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 首字母转小写 */
|
||||
public static String toLowerCaseFirstOne(String s) {
|
||||
if(Character.isLowerCase(s.charAt(0))) {
|
||||
return s;
|
||||
} else {
|
||||
return Character.toLowerCase(s.charAt(0)) + s.substring(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package com.cool.store.utils.poi.constant;
|
||||
|
||||
/**
|
||||
* 通用常量信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class Constants
|
||||
{
|
||||
/**
|
||||
* UTF-8 字符集
|
||||
*/
|
||||
public static final String UTF8 = "UTF-8";
|
||||
|
||||
/**
|
||||
* GBK 字符集
|
||||
*/
|
||||
public static final String GBK = "GBK";
|
||||
|
||||
/**
|
||||
* http请求
|
||||
*/
|
||||
public static final String HTTP = "http://";
|
||||
|
||||
/**
|
||||
* info 信息
|
||||
*/
|
||||
public static final String INFO = "INFO:";
|
||||
|
||||
/**
|
||||
* https请求
|
||||
*/
|
||||
public static final String HTTPS = "https://";
|
||||
|
||||
/**
|
||||
* 成功标记
|
||||
*/
|
||||
public static final Integer SUCCESS = 200;
|
||||
|
||||
/**
|
||||
* 失败标记
|
||||
*/
|
||||
public static final Integer FAIL = 500;
|
||||
|
||||
|
||||
/**
|
||||
* 登录失败
|
||||
*/
|
||||
public static final String LOGIN_FAIL = "Error";
|
||||
|
||||
/**
|
||||
* 等号
|
||||
*/
|
||||
public static final String EQUAL_SIGN = "=";
|
||||
/**
|
||||
* 逗号
|
||||
*/
|
||||
public static final String COMMA = ",";
|
||||
|
||||
/**
|
||||
* 单引号
|
||||
*/
|
||||
public static final String SINGLE_QUOTES = "'";
|
||||
/**
|
||||
* 小数点
|
||||
*/
|
||||
public static final String POMINT = ".";
|
||||
/**
|
||||
* 冒号
|
||||
*/
|
||||
public static final String COLON = ":";
|
||||
/**
|
||||
* 分号
|
||||
*/
|
||||
public static final String SEMICOLON = ";";
|
||||
|
||||
/**
|
||||
* 空格
|
||||
*/
|
||||
public static final String SPACE = " ";
|
||||
/**
|
||||
* 横线
|
||||
*/
|
||||
public static final String M_LINE = "-";
|
||||
/**
|
||||
* 下划线
|
||||
*/
|
||||
public static final String D_LINE = "_";
|
||||
|
||||
|
||||
public static final String SEPARATOR= "\\|";
|
||||
|
||||
|
||||
public static final String FORWARD_SLASH = "/";
|
||||
|
||||
/**
|
||||
* 图片格式
|
||||
*/
|
||||
public static final String IMAGE_PNG = "png";
|
||||
|
||||
/**
|
||||
* 图片格式
|
||||
*/
|
||||
public static final String IMAGE_JPG = "jpg";
|
||||
/**
|
||||
* 图片格式
|
||||
*/
|
||||
public static final String IMAGE_POINT_PNG = ".png";
|
||||
|
||||
/**
|
||||
* 图片格式
|
||||
*/
|
||||
public static final String IMAGE_POINT_JPG = ".jpg";
|
||||
|
||||
/**
|
||||
* 删除标识-0
|
||||
*/
|
||||
public static final String DEL_FLAG_0 = "0";
|
||||
/**
|
||||
* 删除标识-1
|
||||
*/
|
||||
public static final String STR_WITH = "&";
|
||||
|
||||
/**
|
||||
* 删除标识-1
|
||||
*/
|
||||
public static final String DEL_FLAG_1 = "1";
|
||||
|
||||
|
||||
/**
|
||||
* 字符串-未知
|
||||
*/
|
||||
public static final String UNKNOWN = "unknown";
|
||||
|
||||
/**
|
||||
* 美元
|
||||
*/
|
||||
public static final String USD = "$";
|
||||
|
||||
/**
|
||||
* 人民币 全角
|
||||
*/
|
||||
public static final String RMB_FULL = "¥";
|
||||
|
||||
/**
|
||||
* 人民币 半角
|
||||
*/
|
||||
public static final String RMB_HALF = "¥";
|
||||
|
||||
/**
|
||||
* 欧元
|
||||
*/
|
||||
public static final String EUR = "€";
|
||||
|
||||
/**
|
||||
* 小写MD5
|
||||
*/
|
||||
public static final String MD5 = "md5";
|
||||
|
||||
/**
|
||||
* 请求头 Content-Encoding
|
||||
*/
|
||||
public static final String CONTENT_ENCODING = "Content-Encoding";
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
package com.cool.store.utils.poi.reflect;
|
||||
|
||||
import com.cool.store.utils.poi.DateUtils;
|
||||
import com.cool.store.utils.poi.constant.Constants;
|
||||
import com.cool.store.utils.poi.text.Convert;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.poi.ss.usermodel.DateUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 反射工具类. 提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class, 被AOP过的真实类等工具函数.
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class ReflectUtils
|
||||
{
|
||||
private static final String SETTER_PREFIX = "set";
|
||||
|
||||
private static final String GETTER_PREFIX = "get";
|
||||
|
||||
private static final String CGLIB_CLASS_SEPARATOR = "$$";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ReflectUtils.class);
|
||||
|
||||
/**
|
||||
* 调用Getter方法.
|
||||
* 支持多级,如:对象名.对象名.方法
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <E> E invokeGetter(Object obj, String propertyName)
|
||||
{
|
||||
Object object = obj;
|
||||
for (String name : StringUtils.split(propertyName, Constants.POMINT))
|
||||
{
|
||||
String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
|
||||
object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
|
||||
}
|
||||
return (E) object;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用Setter方法, 仅匹配方法名。
|
||||
* 支持多级,如:对象名.对象名.方法
|
||||
*/
|
||||
public static <E> void invokeSetter(Object obj, String propertyName, E value)
|
||||
{
|
||||
Object object = obj;
|
||||
String[] names = StringUtils.split(propertyName, ".");
|
||||
for (int i = 0; i < names.length; i++)
|
||||
{
|
||||
if (i < names.length - 1)
|
||||
{
|
||||
String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]);
|
||||
object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
|
||||
}
|
||||
else
|
||||
{
|
||||
String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]);
|
||||
invokeMethodByName(object, setterMethodName, new Object[] { value });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接读取对象属性值, 无视private/protected修饰符, 不经过getter函数.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <E> E getFieldValue(final Object obj, final String fieldName)
|
||||
{
|
||||
Field field = getAccessibleField(obj, fieldName);
|
||||
if (field == null)
|
||||
{
|
||||
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
|
||||
return null;
|
||||
}
|
||||
E result = null;
|
||||
try
|
||||
{
|
||||
result = (E) field.get(obj);
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
logger.error("不可能抛出的异常{}", e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接设置对象属性值, 无视private/protected修饰符, 不经过setter函数.
|
||||
*/
|
||||
public static <E> void setFieldValue(final Object obj, final String fieldName, final E value)
|
||||
{
|
||||
Field field = getAccessibleField(obj, fieldName);
|
||||
if (field == null)
|
||||
{
|
||||
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
field.set(obj, value);
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
logger.error("不可能抛出的异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接调用对象方法, 无视private/protected修饰符.
|
||||
* 用于一次性调用的情况,否则应使用getAccessibleMethod()函数获得Method后反复调用.
|
||||
* 同时匹配方法名+参数类型,
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <E> E invokeMethod(final Object obj, final String methodName, final Class<?>[] parameterTypes,
|
||||
final Object[] args)
|
||||
{
|
||||
if (obj == null || methodName == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Method method = getAccessibleMethod(obj, methodName, parameterTypes);
|
||||
if (method == null)
|
||||
{
|
||||
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 ");
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
return (E) method.invoke(obj, args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
String msg = "method: " + method + ", obj: " + obj + ", args: " + args + "";
|
||||
throw convertReflectionExceptionToUnchecked(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接调用对象方法, 无视private/protected修饰符,
|
||||
* 用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用.
|
||||
* 只匹配函数名,如果有多个同名函数调用第一个。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <E> E invokeMethodByName(final Object obj, final String methodName, final Object[] args)
|
||||
{
|
||||
Method method = getAccessibleMethodByName(obj, methodName, args.length);
|
||||
if (method == null)
|
||||
{
|
||||
// 如果为空不报错,直接返回空。
|
||||
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 ");
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
// 类型转换(将参数数据类型转换为目标方法参数类型)
|
||||
Class<?>[] cs = method.getParameterTypes();
|
||||
for (int i = 0; i < cs.length; i++)
|
||||
{
|
||||
if (args[i] != null && !args[i].getClass().equals(cs[i]))
|
||||
{
|
||||
if (cs[i] == String.class)
|
||||
{
|
||||
args[i] = Convert.toStr(args[i]);
|
||||
if (StringUtils.endsWith((String) args[i], ".0"))
|
||||
{
|
||||
args[i] = StringUtils.substringBefore((String) args[i], ".0");
|
||||
}
|
||||
}
|
||||
else if (cs[i] == Integer.class)
|
||||
{
|
||||
args[i] = Convert.toInt(args[i]);
|
||||
}
|
||||
else if (cs[i] == Long.class)
|
||||
{
|
||||
args[i] = Convert.toLong(args[i]);
|
||||
}
|
||||
else if (cs[i] == Double.class)
|
||||
{
|
||||
args[i] = Convert.toDouble(args[i]);
|
||||
}
|
||||
else if (cs[i] == Float.class)
|
||||
{
|
||||
args[i] = Convert.toFloat(args[i]);
|
||||
}
|
||||
else if (cs[i] == Date.class)
|
||||
{
|
||||
if (args[i] instanceof String)
|
||||
{
|
||||
args[i] = DateUtils.parseDate(args[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
args[i] = DateUtil.getJavaDate((Double) args[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (E) method.invoke(obj, args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
String msg = "method: " + method + ", obj: " + obj + ", args: " + Arrays.toString(args) + "";
|
||||
throw convertReflectionExceptionToUnchecked(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环向上转型, 获取对象的DeclaredField, 并强制设置为可访问.
|
||||
* 如向上转型到Object仍无法找到, 返回null.
|
||||
*/
|
||||
public static Field getAccessibleField(final Object obj, final String fieldName)
|
||||
{
|
||||
// 为空不报错。直接返回 null
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Validate.notBlank(fieldName, "fieldName can't be blank");
|
||||
for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass())
|
||||
{
|
||||
try
|
||||
{
|
||||
Field field = superClass.getDeclaredField(fieldName);
|
||||
makeAccessible(field);
|
||||
return field;
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
|
||||
* 如向上转型到Object仍无法找到, 返回null.
|
||||
* 匹配函数名+参数类型。
|
||||
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
|
||||
*/
|
||||
public static Method getAccessibleMethod(final Object obj, final String methodName,
|
||||
final Class<?>... parameterTypes)
|
||||
{
|
||||
// 为空不报错。直接返回 null
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Validate.notBlank(methodName, "methodName can't be blank");
|
||||
for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass())
|
||||
{
|
||||
try
|
||||
{
|
||||
Method method = searchType.getDeclaredMethod(methodName, parameterTypes);
|
||||
makeAccessible(method);
|
||||
return method;
|
||||
}
|
||||
catch (NoSuchMethodException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
|
||||
* 如向上转型到Object仍无法找到, 返回null.
|
||||
* 只匹配函数名。
|
||||
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
|
||||
*/
|
||||
public static Method getAccessibleMethodByName(final Object obj, final String methodName, int argsNum)
|
||||
{
|
||||
// 为空不报错。直接返回 null
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Validate.notBlank(methodName, "methodName can't be blank");
|
||||
for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass())
|
||||
{
|
||||
Method[] methods = searchType.getDeclaredMethods();
|
||||
for (Method method : methods)
|
||||
{
|
||||
if (method.getName().equals(methodName) && method.getParameterTypes().length == argsNum)
|
||||
{
|
||||
makeAccessible(method);
|
||||
return method;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 改变private/protected的方法为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
|
||||
*/
|
||||
public static void makeAccessible(Method method)
|
||||
{
|
||||
boolean notAccessible = (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
|
||||
&& !method.isAccessible();
|
||||
if (notAccessible) {
|
||||
method.setAccessible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 改变private/protected的成员变量为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
|
||||
*/
|
||||
public static void makeAccessible(Field field)
|
||||
{
|
||||
boolean notAccessible = (!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
|
||||
|| Modifier.isFinal(field.getModifiers())) && !field.isAccessible();
|
||||
if (notAccessible) {
|
||||
field.setAccessible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过反射, 获得Class定义中声明的泛型参数的类型, 注意泛型必须定义在父类处
|
||||
* 如无法找到, 返回Object.class.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Class<T> getClassGenricType(final Class clazz)
|
||||
{
|
||||
return getClassGenricType(clazz, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过反射, 获得Class定义中声明的父类的泛型参数的类型.
|
||||
* 如无法找到, 返回Object.class.
|
||||
*/
|
||||
public static Class getClassGenricType(final Class clazz, final int index)
|
||||
{
|
||||
Type genType = clazz.getGenericSuperclass();
|
||||
|
||||
if (!(genType instanceof ParameterizedType))
|
||||
{
|
||||
logger.debug(clazz.getSimpleName() + "'s superclass not ParameterizedType");
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
|
||||
|
||||
if (index >= params.length || index < 0)
|
||||
{
|
||||
logger.debug("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
|
||||
+ params.length);
|
||||
return Object.class;
|
||||
}
|
||||
if (!(params[index] instanceof Class))
|
||||
{
|
||||
logger.debug(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
return (Class) params[index];
|
||||
}
|
||||
|
||||
public static Class<?> getUserClass(Object instance)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new RuntimeException("Instance must not be null");
|
||||
}
|
||||
Class clazz = instance.getClass();
|
||||
if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR))
|
||||
{
|
||||
Class<?> superClass = clazz.getSuperclass();
|
||||
if (superClass != null && !Object.class.equals(superClass))
|
||||
{
|
||||
return superClass;
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 将反射时的checked exception转换为unchecked exception.
|
||||
*/
|
||||
public static RuntimeException convertReflectionExceptionToUnchecked(String msg, Exception e)
|
||||
{
|
||||
if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException
|
||||
|| e instanceof NoSuchMethodException)
|
||||
{
|
||||
return new IllegalArgumentException(msg, e);
|
||||
}
|
||||
else if (e instanceof InvocationTargetException)
|
||||
{
|
||||
return new RuntimeException(msg, ((InvocationTargetException) e).getTargetException());
|
||||
}
|
||||
return new RuntimeException(msg, e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,998 @@
|
||||
package com.cool.store.utils.poi.text;
|
||||
|
||||
|
||||
import com.cool.store.utils.poi.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 类型转换器
|
||||
*
|
||||
* @author fanlyun
|
||||
*/
|
||||
public class Convert
|
||||
{
|
||||
/**
|
||||
* 转换为字符串<br>
|
||||
* 如果给定的值为null,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String toStr(Object value, String defaultValue)
|
||||
{
|
||||
if (null == value)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof String)
|
||||
{
|
||||
return (String) value;
|
||||
}
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为字符串<br>
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String toStr(Object value)
|
||||
{
|
||||
return toStr(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为字符<br>
|
||||
* 如果给定的值为null,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Character toChar(Object value, Character defaultValue)
|
||||
{
|
||||
if (null == value)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Character)
|
||||
{
|
||||
return (Character) value;
|
||||
}
|
||||
|
||||
final String valueStr = toStr(value, null);
|
||||
return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为字符<br>
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Character toChar(Object value)
|
||||
{
|
||||
return toChar(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为byte<br>
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Byte toByte(Object value, Byte defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Byte)
|
||||
{
|
||||
return (Byte) value;
|
||||
}
|
||||
if (value instanceof Number)
|
||||
{
|
||||
return ((Number) value).byteValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
return Byte.parseByte(valueStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为byte<br>
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Byte toByte(Object value)
|
||||
{
|
||||
return toByte(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Short<br>
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Short toShort(Object value, Short defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Short)
|
||||
{
|
||||
return (Short) value;
|
||||
}
|
||||
if (value instanceof Number)
|
||||
{
|
||||
return ((Number) value).shortValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
return Short.parseShort(valueStr.trim());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Short<br>
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Short toShort(Object value)
|
||||
{
|
||||
return toShort(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Number<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Number toNumber(Object value, Number defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Number)
|
||||
{
|
||||
return (Number) value;
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
return NumberFormat.getInstance().parse(valueStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Number<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Number toNumber(Object value)
|
||||
{
|
||||
return toNumber(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为int<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer toInt(Object value, Integer defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Integer)
|
||||
{
|
||||
return (Integer) value;
|
||||
}
|
||||
if (value instanceof Number)
|
||||
{
|
||||
return ((Number) value).intValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
return Integer.parseInt(valueStr.trim());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为int<br>
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer toInt(Object value)
|
||||
{
|
||||
return toInt(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Integer数组<br>
|
||||
*
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer[] toIntArray(String str)
|
||||
{
|
||||
return toIntArray(",", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Long数组<br>
|
||||
*
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long[] toLongArray(String str)
|
||||
{
|
||||
return toLongArray(",", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Integer数组<br>
|
||||
*
|
||||
* @param split 分隔符
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer[] toIntArray(String split, String str)
|
||||
{
|
||||
if (StringUtils.isEmpty(str))
|
||||
{
|
||||
return new Integer[] {};
|
||||
}
|
||||
String[] arr = str.split(split);
|
||||
final Integer[] ints = new Integer[arr.length];
|
||||
for (int i = 0; i < arr.length; i++)
|
||||
{
|
||||
final Integer v = toInt(arr[i], 0);
|
||||
ints[i] = v;
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Long数组<br>
|
||||
*
|
||||
* @param split 分隔符
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long[] toLongArray(String split, String str)
|
||||
{
|
||||
if (StringUtils.isEmpty(str))
|
||||
{
|
||||
return new Long[] {};
|
||||
}
|
||||
String[] arr = str.split(split);
|
||||
final Long[] longs = new Long[arr.length];
|
||||
for (int i = 0; i < arr.length; i++)
|
||||
{
|
||||
final Long v = toLong(arr[i], null);
|
||||
longs[i] = v;
|
||||
}
|
||||
return longs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为String数组<br>
|
||||
*
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String[] toStrArray(String str)
|
||||
{
|
||||
return toStrArray(",", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为String数组<br>
|
||||
*
|
||||
* @param split 分隔符
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String[] toStrArray(String split, String str)
|
||||
{
|
||||
return str.split(split);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为long<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long toLong(Object value, Long defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Long)
|
||||
{
|
||||
return (Long) value;
|
||||
}
|
||||
if (value instanceof Number)
|
||||
{
|
||||
return ((Number) value).longValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
// 支持科学计数法
|
||||
return new BigDecimal(valueStr.trim()).longValue();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为long<br>
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long toLong(Object value)
|
||||
{
|
||||
return toLong(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为double<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Double toDouble(Object value, Double defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Double)
|
||||
{
|
||||
return (Double) value;
|
||||
}
|
||||
if (value instanceof Number)
|
||||
{
|
||||
return ((Number) value).doubleValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
// 支持科学计数法
|
||||
return new BigDecimal(valueStr.trim()).doubleValue();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为double<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Double toDouble(Object value)
|
||||
{
|
||||
return toDouble(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Float<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Float toFloat(Object value, Float defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Float)
|
||||
{
|
||||
return (Float) value;
|
||||
}
|
||||
if (value instanceof Number)
|
||||
{
|
||||
return ((Number) value).floatValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
return Float.parseFloat(valueStr.trim());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Float<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Float toFloat(Object value)
|
||||
{
|
||||
return toFloat(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为boolean<br>
|
||||
* String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Boolean toBool(Object value, Boolean defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Boolean)
|
||||
{
|
||||
return (Boolean) value;
|
||||
}
|
||||
String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
valueStr = valueStr.trim().toLowerCase();
|
||||
switch (valueStr)
|
||||
{
|
||||
// 为 true、yes、ok、1 时均认为 true
|
||||
case "true":
|
||||
case "yes":
|
||||
case "ok":
|
||||
case "1":
|
||||
return true;
|
||||
//否则认为 false
|
||||
case "false":
|
||||
case "no":
|
||||
case "0":
|
||||
return false;
|
||||
default:
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为boolean<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Boolean toBool(Object value)
|
||||
{
|
||||
return toBool(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Enum对象<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
*
|
||||
* @param clazz Enum的Class
|
||||
* @param value 值
|
||||
* @param defaultValue 默认值
|
||||
* @return Enum
|
||||
*/
|
||||
public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (clazz.isAssignableFrom(value.getClass()))
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
E myE = (E) value;
|
||||
return myE;
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
return Enum.valueOf(clazz, valueStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Enum对象<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
|
||||
*
|
||||
* @param clazz Enum的Class
|
||||
* @param value 值
|
||||
* @return Enum
|
||||
*/
|
||||
public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value)
|
||||
{
|
||||
return toEnum(clazz, value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为BigInteger<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static BigInteger toBigInteger(Object value, BigInteger defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof BigInteger)
|
||||
{
|
||||
return (BigInteger) value;
|
||||
}
|
||||
if (value instanceof Long)
|
||||
{
|
||||
return BigInteger.valueOf((Long) value);
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
return new BigInteger(valueStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为BigInteger<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static BigInteger toBigInteger(Object value)
|
||||
{
|
||||
return toBigInteger(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为BigDecimal<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof BigDecimal)
|
||||
{
|
||||
return (BigDecimal) value;
|
||||
}
|
||||
if (value instanceof Long)
|
||||
{
|
||||
return new BigDecimal((Long) value);
|
||||
}
|
||||
if (value instanceof Double)
|
||||
{
|
||||
return BigDecimal.valueOf((Double) value);
|
||||
}
|
||||
if (value instanceof Integer)
|
||||
{
|
||||
return new BigDecimal((Integer) value);
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
return new BigDecimal(valueStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为BigDecimal<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static BigDecimal toBigDecimal(Object value)
|
||||
{
|
||||
return toBigDecimal(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转为字符串<br>
|
||||
* 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
|
||||
*
|
||||
* @param obj 对象
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String utf8Str(Object obj)
|
||||
{
|
||||
return str(obj, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转为字符串<br>
|
||||
* 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
|
||||
*
|
||||
* @param obj 对象
|
||||
* @param charsetName 字符集
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(Object obj, String charsetName)
|
||||
{
|
||||
return str(obj, Charset.forName(charsetName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转为字符串<br>
|
||||
* 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
|
||||
*
|
||||
* @param obj 对象
|
||||
* @param charset 字符集
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(Object obj, Charset charset)
|
||||
{
|
||||
if (null == obj)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (obj instanceof String)
|
||||
{
|
||||
return (String) obj;
|
||||
}
|
||||
else if (obj instanceof byte[] || obj instanceof Byte[])
|
||||
{
|
||||
return str(obj, charset);
|
||||
}
|
||||
else if (obj instanceof ByteBuffer)
|
||||
{
|
||||
return str((ByteBuffer) obj, charset);
|
||||
}
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将byte数组转为字符串
|
||||
*
|
||||
* @param bytes byte数组
|
||||
* @param charset 字符集
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(byte[] bytes, String charset)
|
||||
{
|
||||
return str(bytes, StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码字节码
|
||||
*
|
||||
* @param data 字符串
|
||||
* @param charset 字符集,如果此字段为空,则解码的结果取决于平台
|
||||
* @return 解码后的字符串
|
||||
*/
|
||||
public static String str(byte[] data, Charset charset)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (null == charset)
|
||||
{
|
||||
return new String(data);
|
||||
}
|
||||
return new String(data, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将编码的byteBuffer数据转换为字符串
|
||||
*
|
||||
* @param data 数据
|
||||
* @param charset 字符集,如果为空使用当前系统字符集
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(ByteBuffer data, String charset)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return str(data, Charset.forName(charset));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将编码的byteBuffer数据转换为字符串
|
||||
*
|
||||
* @param data 数据
|
||||
* @param charset 字符集,如果为空使用当前系统字符集
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(ByteBuffer data, Charset charset)
|
||||
{
|
||||
if (null == charset)
|
||||
{
|
||||
charset = Charset.defaultCharset();
|
||||
}
|
||||
return charset.decode(data).toString();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- 全角半角转换
|
||||
/**
|
||||
* 半角转全角
|
||||
*
|
||||
* @param input String.
|
||||
* @return 全角字符串.
|
||||
*/
|
||||
public static String toSBC(String input)
|
||||
{
|
||||
return toSBC(input, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 半角转全角
|
||||
*
|
||||
* @param input String
|
||||
* @param notConvertSet 不替换的字符集合
|
||||
* @return 全角字符串.
|
||||
*/
|
||||
public static String toSBC(String input, Set<Character> notConvertSet)
|
||||
{
|
||||
char[] c = input.toCharArray();
|
||||
for (int i = 0; i < c.length; i++)
|
||||
{
|
||||
if (null != notConvertSet && notConvertSet.contains(c[i]))
|
||||
{
|
||||
// 跳过不替换的字符
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c[i] == ' ')
|
||||
{
|
||||
c[i] = '\u3000';
|
||||
}
|
||||
else if (c[i] < '\177')
|
||||
{
|
||||
c[i] = (char) (c[i] + 65248);
|
||||
|
||||
}
|
||||
}
|
||||
return new String(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* 全角转半角
|
||||
*
|
||||
* @param input String.
|
||||
* @return 半角字符串
|
||||
*/
|
||||
public static String toDBC(String input)
|
||||
{
|
||||
return toDBC(input, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换全角为半角
|
||||
*
|
||||
* @param text 文本
|
||||
* @param notConvertSet 不替换的字符集合
|
||||
* @return 替换后的字符
|
||||
*/
|
||||
public static String toDBC(String text, Set<Character> notConvertSet)
|
||||
{
|
||||
char[] c = text.toCharArray();
|
||||
for (int i = 0; i < c.length; i++)
|
||||
{
|
||||
if (null != notConvertSet && notConvertSet.contains(c[i]))
|
||||
{
|
||||
// 跳过不替换的字符
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c[i] == '\u3000')
|
||||
{
|
||||
c[i] = ' ';
|
||||
}
|
||||
else if (c[i] > '\uFF00' && c[i] < '\uFF5F')
|
||||
{
|
||||
c[i] = (char) (c[i] - 65248);
|
||||
}
|
||||
}
|
||||
|
||||
return new String(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字金额大写转换 先写个完整的然后将如零拾替换成零
|
||||
*
|
||||
* @param n 数字
|
||||
* @return 中文大写数字
|
||||
*/
|
||||
public static String digitUppercase(double n)
|
||||
{
|
||||
String[] fraction = { "角", "分" };
|
||||
String[] digit = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
|
||||
String[][] unit = { { "元", "万", "亿" }, { "", "拾", "佰", "仟" } };
|
||||
|
||||
String head = n < 0 ? "负" : "";
|
||||
n = Math.abs(n);
|
||||
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (int i = 0; i < fraction.length; i++)
|
||||
{
|
||||
s.append((digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", ""));
|
||||
}
|
||||
if (s.length() < 1)
|
||||
{
|
||||
s = new StringBuilder("整");
|
||||
}
|
||||
int integerPart = (int) Math.floor(n);
|
||||
|
||||
for (int i = 0; i < unit[0].length && integerPart > 0; i++)
|
||||
{
|
||||
StringBuilder p = new StringBuilder();
|
||||
for (int j = 0; j < unit[1].length && n > 0; j++)
|
||||
{
|
||||
p.insert(0, digit[integerPart % 10] + unit[1][j]);
|
||||
integerPart = integerPart / 10;
|
||||
}
|
||||
s.insert(0, p.toString().replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i]);
|
||||
}
|
||||
return head + s.toString().replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.cool.store.controller;
|
||||
|
||||
|
||||
import com.cool.store.entity.HyPartnerLineDO;
|
||||
import com.cool.store.exception.ApiException;
|
||||
import com.cool.store.request.AddLineRequest;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.service.LineHighSeasService;
|
||||
import com.cool.store.utils.poi.ExcelUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: hxd
|
||||
* @Date: 2023-06-06 15:22
|
||||
* @Description:
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/line/highSeas")
|
||||
public class LineHighSeasController {
|
||||
|
||||
|
||||
@Resource
|
||||
private LineHighSeasService lineHighSeasService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新建线索")
|
||||
public ResponseResult addLine(@RequestBody @Valid AddLineRequest request) throws ApiException {
|
||||
|
||||
return ResponseResult.success(lineHighSeasService.addLine(request));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/import")
|
||||
@ApiOperation("批量导入线索")
|
||||
public ResponseResult importLine(MultipartFile file) throws Exception {
|
||||
return lineHighSeasService.importLine(file);
|
||||
}
|
||||
}
|
||||
11
pom.xml
11
pom.xml
@@ -213,6 +213,17 @@
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- excel工具 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
<version>2.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>3.17</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user