Commit 0491ac0c by 章家宝

拍卖需求:偏好设置代码提交

1 parent 788066ea
Showing 38 changed files with 1907 additions and 10 deletions
......@@ -218,6 +218,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<source>17</source> <!-- 对应你的Java版本(8/11/17) -->
<target>17</target>
<!-- 核心:添加-parameters参数,保留参数名 -->
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
<executions>
<execution>
<id>exclude-slf4j-simple</id>
......
package com.glsx.usedcar.export;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.glsx.usedcar.module.account.dto.AccountPreferenceDTO;
import com.glsx.usedcar.module.account.enums.*;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 用户偏好配置Excel导出Bean
* 核心转换逻辑内聚到枚举类,转换器仅做转发
*/
@Data
@NoArgsConstructor
public class AccountPreferenceExportBean {
@ExcelIgnore
private Integer id;
@ExcelProperty("用户ID")
@ColumnWidth(15)
private Integer accountId;
@ExcelProperty("车商手机号")
@ColumnWidth(15)
private String mobile;
@ExcelProperty("车商昵称")
@ColumnWidth(15)
private String nickName;
@ExcelProperty("实名姓名")
@ColumnWidth(15)
private String accountName;
@ExcelProperty(value = "经营模式")
@ColumnWidth(20)
private String businessModel;
@ExcelProperty(value = "注册地区")
@ColumnWidth(20)
private String regAddress;
@ExcelProperty(value = "偏好车况")
@ColumnWidth(25)
private String vehicleCondition;
@ExcelProperty(value = "偏好车龄")
@ColumnWidth(25)
private String vehicleAge;
@ExcelProperty(value = "偏好品牌")
@ColumnWidth(50)
private String brandList;
@ExcelProperty(value = "车辆燃油类型")
@ColumnWidth(20)
private String vehicleFuelType;
@ExcelProperty(value = "车辆类型")
@ColumnWidth(20)
private String vehicleType;
@ExcelProperty(value = "最近更新时间")
@ColumnWidth(20)
private String updateTime;
@ExcelProperty(value = "编辑人")
@ColumnWidth(20)
private String updateBy;
public AccountPreferenceExportBean(AccountPreferenceDTO accountPreference) {
if (accountPreference == null) {
return;
}
this.id = accountPreference.getId();
this.accountId = accountPreference.getAccountId();
this.mobile = accountPreference.getMobile();
this.nickName = accountPreference.getNickName();
this.accountName = accountPreference.getAccountName();
this.vehicleCondition = accountPreference.getVehicleCondition();
// 经营模式:直接调用枚举转中文
this.businessModel = BusinessModelEnum.getDescByCodeStr(accountPreference.getBusinessModel());
this.regAddress = String.format("%s-%s", accountPreference.getProvinceName(), accountPreference.getCityName());
// 车况:编码转中文(按需添加,示例)
this.vehicleCondition = VehicleConditionEnum.getDescByCodeStr(accountPreference.getVehicleCondition());
// 车辆年限:编码转中文(按需添加,示例)
this.vehicleAge = VehicleAgeEnum.getDescByCodeStr(accountPreference.getVehicleAge());
// 燃油类型:编码转中文(按需添加,示例)
this.vehicleFuelType = VehicleFuelTypeEnum.getDescByCodeStr(accountPreference.getVehicleFuelType());
this.brandList = accountPreference.getBrandNameList();
this.vehicleType = VehicleTypeEnum.getDescByCodeStr(accountPreference.getVehicleType());
this.updateTime = accountPreference.getUpdateTime().toString();
this.updateBy = accountPreference.getUpdatedBy();
}
}
\ No newline at end of file
package com.glsx.usedcar.export.converter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 车型Excel转换器(JSON转中文名称)
*/
public class VehicleTypeConverter implements Converter<String> {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@Override
public Class<?> supportJavaTypeKey() {
return String.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public WriteCellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
if (!StringUtils.hasText(value)) {
return new WriteCellData<>("");
}
try {
List<Map<String, Object>> vehicleTypeList = OBJECT_MAPPER.readValue(value, new TypeReference<List<Map<String, Object>>>() {});
String typeNames = vehicleTypeList.stream()
.map(m -> m.get("type_name").toString())
.collect(Collectors.joining(","));
return new WriteCellData<>(typeNames);
} catch (Exception e) {
return new WriteCellData<>(value);
}
}
@Override
public String convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
return cellData.getStringValue();
}
}
\ No newline at end of file
package com.glsx.usedcar.web.rest.account;
import com.glsx.usedcar.export.AccountPreferenceExportBean;
import com.glsx.usedcar.export.ExcelExporter;
import com.glsx.usedcar.module.account.dto.*;
import com.glsx.usedcar.module.account.entity.AccountPreference;
import com.glsx.usedcar.module.account.entity.AccountPreference_;
import com.glsx.usedcar.module.account.service.AccountPreferenceService;
import com.glsx.usedcar.module.security.entity.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.persistence.criteria.JoinType;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import org.summerframework.orm.paging.Pagination;
import java.io.IOException;
import java.util.List;
/**
* 用户偏好配置接口(REST版本)
* 贴合项目分页/导出规范,移除无需传入的登录用户参数
*/
@Tag(name = "用户偏好配置接口", description = "用户车辆偏好的查询、修改等操作")
@RestController
@RequestMapping("/rest/account/preference")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AccountPreferenceController {
private final AccountPreferenceService accountPreferenceService;
@Operation(summary = "分页查询用户偏好", description = "分页查询用户偏好列表,支持车况、经营模式等多条件筛选")
@PostMapping("page")
public Page<AccountPreferenceDTO> pageAccountPreference(@RequestBody Pagination<AccountPreference> pagination) {
// 关联枚举型偏好值表
pagination.addFetch(root -> root.fetch(AccountPreference_.preferenceValues, JoinType.LEFT));
// 关联车型偏好表
pagination.addFetch(root -> root.fetch(AccountPreference_.vehicleTypes, JoinType.LEFT));
// 关联用户表
pagination.addFetch(root -> root.fetch(AccountPreference_.account, JoinType.LEFT));
return accountPreferenceService.pageList(pagination);
}
@Operation(summary = "查询用户偏好导出", description = "导出用户偏好列表为Excel文件")
@PostMapping("export")
public void exportAccountPreference(@RequestBody Pagination<AccountPreference> pagination, HttpServletResponse response) throws IOException {
pagination.setLimit(99999);
List<AccountPreferenceDTO> preferences = accountPreferenceService.pageList(pagination).getContent();
// 实体转导出Bean(需自定义AccountPreferenceExportBean)
List<AccountPreferenceExportBean> exportBeans = preferences.stream().map(AccountPreferenceExportBean::new).toList();
// Excel导出(复用项目的ExcelExporter工具类)
ExcelExporter.exportExcel(response, "用户偏好列表", "用户偏好列表", AccountPreferenceExportBean.class, exportBeans);
}
@Operation(summary = "根据用户偏好id修改用户偏好", description = "根据主键ID修改用户车辆偏好配置")
@PostMapping("/update")
public boolean updateById(@RequestBody AccountPreferenceSaveOrUpdateDTO updateDTO, Authentication authentication) {
User user = (User) authentication.getPrincipal();
String userName = user.getUserName();
if (StringUtils.isBlank(updateDTO.getCityCn())) {
updateDTO.setCityCn(" ");
}
return accountPreferenceService.saveOrUpdate(updateDTO, updateDTO.getAccountId(), userName);
}
@Operation(summary = "用户偏好详情", description = "根据主键ID查询用户偏好配置详情")
@GetMapping("/detail/{id}")
public AccountPreferenceDetailDTO getDetail(
@Parameter(description = "用户偏好ID") @PathVariable Integer id) {
return accountPreferenceService.getDetailById(id);
}
}
\ No newline at end of file
......@@ -198,6 +198,9 @@
<version>${spring.boot.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
......
package com.glsx.usedcar.web.api.account;
import com.glsx.usedcar.module.account.dto.AccountPreferenceGetDTO;
import com.glsx.usedcar.module.account.dto.AccountPreferenceSaveOrUpdateDTO;
import com.glsx.usedcar.module.account.entity.Account;
import com.glsx.usedcar.module.account.service.AccountPreferenceService;
import com.glsx.usedcar.module.account.service.AccountService;
import com.glsx.usedcar.resp.BaseResp;
import io.swagger.v3.oas.annotations.*;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
import static com.glsx.usedcar.web.WebConstants.LOGIN_ACCOUNT;
@Slf4j
@Tag(name = "用户偏好配置接口", description = "用户车辆偏好的查询、修改等操作")
@RestController
@RequestMapping("/api/account/preference")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AccountPreferenceController {
private final AccountPreferenceService accountPreferenceService;
private final AccountService accountService;
@Operation(summary = "查询用户偏好", description = "根据登录的用户查询车辆偏好配置详情")
@PostMapping("/get")
public BaseResp<AccountPreferenceGetDTO> getPreference(@Parameter(hidden = true) @RequestAttribute(LOGIN_ACCOUNT) Account account) {
return BaseResp.success(accountPreferenceService.getPreference(account));
}
@Operation(summary = "7天内不弹窗", description = "用户设置7天内不弹窗")
@PostMapping("/skip.popup.for7days")
public BaseResp<Boolean> skipPopupFor7Days(@Parameter(hidden = true) @RequestAttribute(LOGIN_ACCOUNT) Account account) {
return BaseResp.success(accountService.skipPreferenPopupForceDays(account.getAccountId(), 7));
}
@Operation(summary = "保存偏好", description = "用户偏好")
@PostMapping("/save")
public BaseResp<Boolean> saveOrUpdate(@RequestBody AccountPreferenceSaveOrUpdateDTO dto,
@Parameter(hidden = true) @RequestAttribute(LOGIN_ACCOUNT) Account account) {
if (dto == null || account == null || account.getAccountId() <= 0) {
log.warn("保存/更新用户偏好失败:入参为空或用户ID非法");
return BaseResp.fail("用户ID非法");
}
Integer accountId = account.getAccountId();
String operator = Optional.ofNullable(account.getAccountName()).orElse(account.getMobile());
return BaseResp.success(accountPreferenceService.saveOrUpdate(dto, accountId, operator));
}
}
\ No newline at end of file
......@@ -163,6 +163,11 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
<build>
......
package com.glsx.usedcar.module.account.dao;
import com.glsx.usedcar.module.account.entity.AccountPreference;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.summerframework.orm.BaseRepository;
public interface AccountPreferenceDao extends BaseRepository<AccountPreference, Integer>, JpaSpecificationExecutor<AccountPreference> {
/**
* 根据用户ID查询未删除的偏好
*/
AccountPreference findByAccountIdAndDeletedFlag(Integer accountId, String deletedFlag);
}
\ No newline at end of file
package com.glsx.usedcar.module.account.dao;
import com.glsx.usedcar.module.account.entity.AccountPreferenceOpLog;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.summerframework.orm.BaseRepository;
import java.util.List;
/**
* 用户偏好配置操作日志表 Dao
* 贴合示例风格:继承BaseRepository + JpaSpecificationExecutor
*/
public interface AccountPreferenceOpLogDao extends BaseRepository<AccountPreferenceOpLog, Integer>, JpaSpecificationExecutor<AccountPreferenceOpLog> {
// 可根据业务扩展查询方法,如:按偏好ID查询日志
List<AccountPreferenceOpLog> findByPreferenceIdAndDeletedFlag(Integer preferenceId, String deletedFlag);
/**
* 根据偏好ID查询操作日志,按创建时间倒序
* @param preferenceId 用户偏好ID
* @return 操作日志列表
*/
List<AccountPreferenceOpLog> findByPreferenceIdOrderByCreateTimeDesc(Integer preferenceId);
}
\ No newline at end of file
package com.glsx.usedcar.module.account.dao;
import com.glsx.usedcar.module.account.entity.AccountPreferenceValue;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import org.summerframework.orm.BaseRepository;
import java.util.List;
/**
* 用户偏好-枚举型多值关联表 Dao
*/
public interface AccountPreferenceValueDao extends BaseRepository<AccountPreferenceValue, Integer>, JpaSpecificationExecutor<AccountPreferenceValue> {
@Modifying
@Transactional
@Query("UPDATE AccountPreferenceValue apv SET apv.deletedFlag = ?2 WHERE apv.preferenceId = ?1")
void updateDeletedFlagByPreferenceId(
@Param("preferenceId") Integer preferenceId,
@Param("deletedFlag") String deletedFlag
);
/**
* 根据偏好ID查询未删除的偏好值(查询方法,JPA可自动解析,无需手动写SQL)
*/
List<AccountPreferenceValue> findByPreferenceIdAndDeletedFlag(Integer preferenceId, String deletedFlag);
}
\ No newline at end of file
package com.glsx.usedcar.module.account.dao;
import com.glsx.usedcar.module.account.entity.AccountPreferenceVehicleType;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import org.summerframework.orm.BaseRepository;
import java.util.List;
/**
* 用户偏好-车型关联表 Dao
*/
public interface AccountPreferenceVehicleTypeDao extends BaseRepository<AccountPreferenceVehicleType, Integer>, JpaSpecificationExecutor<AccountPreferenceVehicleType> {
/**
* 根据偏好ID更新删除标识
* @param preferenceId 偏好ID
* @param deletedFlag 删除标识(N:未删除,D:已删除)
*/
@Modifying // 标记为更新操作,告知JPA执行executeUpdate()而非查询
@Transactional // 更新操作必须加事务
@Query("UPDATE AccountPreferenceVehicleType apvt SET apvt.deletedFlag = ?2 WHERE apvt.preferenceId = ?1")
void updateDeletedFlagByPreferenceId(Integer preferenceId, String deletedFlag);
/**
* 根据偏好ID查询未删除的车型
*/
List<AccountPreferenceVehicleType> findByPreferenceIdAndDeletedFlag(Integer preferenceId, String deletedFlag);
}
\ No newline at end of file
package com.glsx.usedcar.module.account.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Size;
import lombok.*;
import org.summerframework.orm.validator.UpdateValidGroup;
import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AccountPreferenceDTO {
@Schema(description = "偏好配置主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
private Integer id;
@Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8888")
private Integer accountId;
@Schema(description = "车况(1-精品 2-瑕疵 3-重大事故 4-报废,多个英文逗号分隔)",
requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2")
@Size(max = 64, groups = UpdateValidGroup.class, message = "车况长度不能超过64字符")
private String vehicleCondition;
@Schema(description = "经营模式(1-批发 2-零售,多个英文逗号分隔)",
requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private String businessModel;
@Schema(description = "车辆年限(1-1-3年 2-3-6年 3-6-10年 4->10年,多个英文逗号分隔)",
requiredMode = Schema.RequiredMode.REQUIRED, example = "2,3")
private String vehicleAge;
@Schema(description = "车辆燃油类型(1-燃油 2-新能源,多个英文逗号分隔)",
requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2")
private String vehicleFuelType;
@Schema(description = "车辆类型",
requiredMode = Schema.RequiredMode.REQUIRED,
example = "1")
private String vehicleType;
@Schema(description = "车辆品牌", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private String brandList;
@Schema(description = "车辆品牌名称列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private String brandNameList;
@Schema(description = "城市邮政编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "110000")
private String cityCode;
@Schema(description = "城市名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "北京市")
private String cityName;
@Schema(description = "城市名称拼音", requiredMode = Schema.RequiredMode.REQUIRED, example = "beijingshi")
private String cityCn;
@Schema(description = "状态:0未提交 1已提交", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
private Byte status;
private String mobile;
private String nickName;
private String accountName;
// 用户名拼音首字母
private String updateNameCnFirst;
private String createdBy;
private LocalDateTime createTime;
private String updatedBy;
private LocalDateTime updateTime;
private LocalDateTime regTime;
private String provinceName;
}
package com.glsx.usedcar.module.account.dto;
import com.glsx.usedcar.module.account.entity.AccountPreference;
import com.glsx.usedcar.module.account.entity.AccountPreferenceOpLog;
import lombok.*;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AccountPreferenceDetailDTO extends AccountPreferenceDTO{
private List<AccountPreferenceOpLogDTO> logList;
}
package com.glsx.usedcar.module.account.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AccountPreferenceGetDTO extends AccountPreferenceDTO {
@Schema(description = "用户类型: 0 老用户 1 新用户", example = "1")
private Integer accountType;
@Schema(description = "是否弹窗", example = "true")
private boolean isPopUp;
}
package com.glsx.usedcar.module.account.dto;
import com.glsx.usedcar.module.account.entity.AccountPreferenceOpLog;
import com.glsx.usedcar.module.account.entity.AccountPreferenceOpLog.OpType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.beans.BeanUtils;
import java.time.LocalDateTime;
/**
* 用户偏好操作日志DTO
* <p>用于封装用户偏好配置的操作日志数据,适配接口返回/入参场景</p>
*
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "用户偏好操作日志DTO")
public class AccountPreferenceOpLogDTO {
/**
* 操作类型
* <p>枚举值:ADD(新增)、MODIFY(修改)、DELETE(删除)等</p>
*/
@Schema(description = "操作类型(ADD-新增,MODIFY-修改,DELETE-删除)", example = "MODIFY")
private OpType opType;
/**
* 操作内容
* <p>记录具体的操作行为,如:修改城市:上海市(310000)→北京市(110000);新增燃油类型:新能源;</p>
*/
@Schema(description = "操作内容(精准描述用户的具体操作)", example = "修改城市:上海市(310000)-shanghashi→北京市(110000)-beijingshi;删除车型:宝马;")
private String opContent;
/**
* 操作人
* <p>操作人的账号/姓名,如:admin、张三</p>
*/
@Schema(description = "操作人(账号/姓名)", example = "admin")
private String opBy;
/**
* 操作时间
* <p>日志创建的时间,精确到秒</p>
*/
@Schema(description = "操作时间", example = "2026-01-26 15:30:20")
private LocalDateTime createTime;
public static AccountPreferenceOpLogDTO convertOpLogToDTO(AccountPreferenceOpLog logEntity) {
if (logEntity == null) {
return null;
}
AccountPreferenceOpLogDTO logDTO = new AccountPreferenceOpLogDTO();
// 复制基础字段
BeanUtils.copyProperties(logEntity, logDTO);
// 补充特殊字段映射(若有枚举/格式转换可在此处理)
logDTO.setOpType(logEntity.getOpType()); // 操作类型枚举直接复制
logDTO.setOpContent(logEntity.getOpContent()); // 操作内容
logDTO.setOpBy(logEntity.getOpBy()); // 操作人
logDTO.setCreateTime(logEntity.getCreateTime()); // 操作时间
return logDTO;
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.summerframework.orm.validator.UpdateValidGroup;
/**
* 用户偏好配置-修改请求DTO
*/
@Data
@Schema(description = "用户偏好配置修改请求参数")
public class AccountPreferenceSaveOrUpdateDTO {
@Schema(description = "偏好配置主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
private Integer id;
@Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8888")
private Integer accountId;
@Schema(description = "车况(1-精品 2-瑕疵 3-重大事故 4-报废,多个英文逗号分隔)",
requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2")
private String vehicleCondition;
@Schema(description = "经营模式(1-批发 2-零售,多个英文逗号分隔)",
requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private String businessModel;
@Schema(description = "车辆年限(1-1-3年 2-3-6年 3-6-10年 4->10年,多个英文逗号分隔)",
requiredMode = Schema.RequiredMode.REQUIRED, example = "2,3")
private String vehicleAge;
@Schema(description = "车辆燃油类型(1-燃油 2-新能源,多个英文逗号分隔)",
requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2")
private String vehicleFuelType;
@Schema(description = "车辆类型",
requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2")
private String vehicleType;
@Schema(description = "车辆类型(JSON格式:[{type_id: 车辆类型id, type_name: 车型名称}])",
requiredMode = Schema.RequiredMode.REQUIRED,
example = "[{\"type_id\":101,\"type_name\":\"小型轿车\"},{\"type_id\":102,\"type_name\":\"SUV\"}]")
private String brandList;
@Schema(description = "城市邮政编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "110000")
private String cityCode;
@Schema(description = "城市名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "北京市")
private String cityName;
@Schema(description = "城市名称拼音", requiredMode = Schema.RequiredMode.REQUIRED, example = "beijingshi")
private String cityCn;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotBlank(groups = UpdateValidGroup.class, message = "状态不能为空")
private Byte status;
}
\ No newline at end of file
......@@ -207,6 +207,13 @@ public class Account extends AuditingTimeEntity implements Serializable {
private String cityCode;
/**
* 偏好弹窗时间
*/
@Column
private LocalDateTime preferencePopTime;
/**
* 是否是超级用户
*/
@Column
......
package com.glsx.usedcar.module.account.entity;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.summerframework.orm.entity.AuditingTimeEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Set;
import static jakarta.persistence.GenerationType.IDENTITY;
/**
* 用户偏好配置主表(AccountPreference)实体类
*
* @since 2026-01-26
*/
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "account_preference", indexes = {
@Index(name = "idx_account_preference_account_id", columnList = "account_id")
})
@EntityListeners(AuditingEntityListener.class)
@Getter
@Setter
@NoArgsConstructor
public class AccountPreference extends AuditingTimeEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
/**
* 用户id
*/
@Column(name = "account_id", nullable = false)
private Integer accountId;
/**
* 城市邮政编码
*/
@Column(name = "city_code", nullable = false, length = 10)
private String cityCode;
/**
* 城市名称
*/
@Column(name = "city_name", nullable = false, length = 50)
private String cityName;
/**
* 城市名称拼音
*/
@Column(name = "city_cn", nullable = false, length = 100)
private String cityCn;
/**
* 创建人
*/
@Column(name = "created_by", nullable = false, length = 64)
private String createdBy;
/**
* 创建时间
*/
@Column(name = "create_time", nullable = false, updatable = false)
private LocalDateTime createTime;
/**
* 修改人
*/
@Column(name = "updated_by", nullable = false, length = 64)
private String updatedBy;
/**
* 修改时间
*/
@Column(name = "update_time", nullable = false)
private LocalDateTime updateTime;
/**
* 0 未提交 1 已提交
*/
@Column(name = "status", nullable = false)
private Byte status;
/**
* 删除标识(D:已删除;N:未删除)
*/
@Column(name = "deleted_flag", nullable = false, length = 1)
private String deletedFlag = "N";
// 关联关系:一个主偏好对应多个枚举值
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch = FetchType.LAZY, mappedBy = "accountPreference")
private Set<AccountPreferenceValue> preferenceValues = new HashSet<>(0);
// 关联关系:一个主偏好对应多个车型
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch = FetchType.LAZY, mappedBy = "accountPreference")
private Set<AccountPreferenceVehicleType> vehicleTypes = new HashSet<>(0);
// 关联关系:一个主偏好对应多条变更日志
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch = FetchType.LAZY, mappedBy = "accountPreference")
private Set<AccountPreferenceOpLog> changeLogs = new HashSet<>(0);
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "account_id", insertable = false, updatable = false)
private Account account;
// 有参构造器(常用)
public AccountPreference(Integer accountId) {
this.accountId = accountId;
}
public AccountPreference(Integer id, Integer accountId) {
this.id = id;
this.accountId = accountId;
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.summerframework.orm.entity.AuditingTimeEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
import static jakarta.persistence.GenerationType.IDENTITY;
/**
* 用户偏好配置操作日志表(AccountPreferenceOpLog)实体类
*
* @since 2026-01-26
*/
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "account_preference_op_log", indexes = {
@Index(name = "idx_preference_id", columnList = "preference_id"),
@Index(name = "idx_account_id", columnList = "account_id"),
@Index(name = "idx_change_time", columnList = "create_time"), // 索引名是idx_change_time,对应字段create_time
@Index(name = "idx_change_type", columnList = "op_type") // 索引名是idx_change_type,对应字段op_type
})
@EntityListeners(AuditingEntityListener.class)
@Getter
@Setter
@NoArgsConstructor
public class AccountPreferenceOpLog extends AuditingTimeEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
/**
* 关联account_preference表的主键ID
*/
@Column(name = "preference_id", nullable = false)
private Integer preferenceId;
/**
* 用户id
*/
@Column(name = "account_id", nullable = false)
private Integer accountId;
/**
* 操作类型:ADD-新增 MODIFY-修改 DELETE-删除
*/
@Enumerated(EnumType.STRING)
@Column(name = "op_type", nullable = false, length = 16)
private OpType opType;
/**
* 操作后内容(JSON格式,存储变更后的全量字段值,删除时为NULL)
*/
@Column(name = "op_content", columnDefinition = "TEXT", nullable = false)
private String opContent;
/**
* 操作人(与原表的created_by/updated_by一致)
*/
@Column(name = "op_by", nullable = false, length = 64)
private String opBy;
/**
* 创建时间(操作时间)
*/
@Column(name = "create_time", nullable = false, updatable = false)
private LocalDateTime createTime;
/**
* 删除标识(D:已删除;N:未删除)
*/
@Column(name = "deleted_flag", nullable = false, length = 1)
private String deletedFlag = "N";
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "preference_id", insertable = false, updatable = false)
private AccountPreference accountPreference;
/**
* 操作类型枚举
*/
public enum OpType {
/**
* 新增
*/
ADD,
/**
* 修改
*/
MODIFY,
/**
* 删除
*/
DELETE;
}
// 有参构造器(常用场景快速实例化)
public AccountPreferenceOpLog(Integer preferenceId, Integer accountId, OpType opType, String opContent, String opBy) {
this.preferenceId = preferenceId;
this.accountId = accountId;
this.opType = opType;
this.opContent = opContent;
this.opBy = opBy;
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.summerframework.orm.entity.AuditingTimeEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
import static jakarta.persistence.GenerationType.IDENTITY;
/**
* 用户偏好-枚举型多值关联表(AccountPreferenceValue)实体类
*
* @since 2026-01-26
*/
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "account_preference_value", indexes = {
@Index(name = "idx_preference_enum_type_value", columnList = "preference_type, preference_value, deleted_flag"),
@Index(name = "idx_preference_enum_preference_id", columnList = "preference_id")
})
@EntityListeners(AuditingEntityListener.class)
@Getter
@Setter
@NoArgsConstructor
public class AccountPreferenceValue extends AuditingTimeEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
/**
* 关联account_preference主键
*/
@Column(name = "preference_id", nullable = false)
private Integer preferenceId;
/**
* 偏好类型
*/
@Enumerated(EnumType.STRING)
@Column(name = "preference_type", nullable = false, length = 32)
private PreferenceType preferenceType;
/**
* 偏好值:如1(精品)、2(瑕疵)等
*/
@Column(name = "preference_value", nullable = false, length = 64)
private String preferenceValue;
/**
* 创建时间
*/
@Column(name = "create_time", nullable = false, updatable = false)
private LocalDateTime createTime;
/**
* 删除标识(D:已删除;N:未删除)
*/
@Column(name = "deleted_flag", nullable = false, length = 1)
private String deletedFlag = "N";
// 关联关系:多对一关联主偏好表
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "preference_id", insertable = false, updatable = false)
private AccountPreference accountPreference;
/**
* 偏好类型枚举
*/
public enum PreferenceType {
/**
* 车况
*/
vehicle_condition,
/**
* 经营模式
*/
business_model,
/**
* 年限
*/
vehicle_age,
/**
* 车辆燃油类型
*/
vehicle_fuel_type,
/**
* 车辆类型
*/
vehicle_type,
;
}
// 有参构造器
public AccountPreferenceValue(Integer preferenceId, PreferenceType preferenceType, String preferenceValue) {
this.preferenceId = preferenceId;
this.preferenceType = preferenceType;
this.preferenceValue = preferenceValue;
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.summerframework.orm.entity.AuditingTimeEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
import static jakarta.persistence.GenerationType.IDENTITY;
/**
* 用户偏好-车型关联表(AccountPreferenceVehicleType)实体类
*
* @since 2026-01-26
*/
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "account_preference_vehicle_type", indexes = {
@Index(name = "idx_preference_vehicle_type_id", columnList = "type_id, deleted_flag"),
@Index(name = "idx_preference_vehicle_type_name", columnList = "type_name, deleted_flag"),
@Index(name = "idx_preference_vehicle_type_preference_id", columnList = "preference_id")
})
@EntityListeners(AuditingEntityListener.class)
@Getter
@Setter
@NoArgsConstructor
public class AccountPreferenceVehicleType extends AuditingTimeEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
/**
* 关联account_preference主键
*/
@Column(name = "preference_id", nullable = false)
private Integer preferenceId;
/**
* 车辆类型id
*/
@Column(name = "type_id", nullable = false)
private Integer typeId;
/**
* 车型名称
*/
@Column(name = "type_name", nullable = false, length = 100)
private String typeName;
/**
* 创建时间
*/
@Column(name = "create_time", nullable = false, updatable = false)
private LocalDateTime createTime;
/**
* 删除标识(D:已删除;N:未删除)
*/
@Column(name = "deleted_flag", nullable = false, length = 1)
private String deletedFlag = "N";
// 关联关系:多对一关联主偏好表
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "preference_id", insertable = false, updatable = false)
private AccountPreference accountPreference;
// 有参构造器
public AccountPreferenceVehicleType(Integer preferenceId, Integer typeId, String typeName) {
this.preferenceId = preferenceId;
this.typeId = typeId;
this.typeName = typeName;
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.entity;
import io.swagger.v3.oas.annotations.media.Schema;
/**
* 偏好配置变更类型枚举
*/
@Schema(description = "偏好配置变更类型")
public enum PreferenceChangeType {
@Schema(description = "新增")
ADD,
@Schema(description = "修改")
MODIFY,
@Schema(description = "删除")
DELETE
}
\ No newline at end of file
package com.glsx.usedcar.module.account.enums;
import lombok.Getter;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* 经营模式枚举
*/
@Getter
public enum BusinessModelEnum {
WHOLESALE("1", "批发"),
RETAIL("2", "零售");
private final String code;
private final String desc;
BusinessModelEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
public static String getDescByCode(String code) {
for (BusinessModelEnum e : values()) {
if (e.getCode().equals(code)) {
return e.getDesc();
}
}
return code;
}
public static java.util.Map<String, String> getCodeDescMap() {
java.util.Map<String, String> map = new java.util.HashMap<>();
for (BusinessModelEnum e : values()) {
map.put(e.getCode(), e.getDesc());
}
return map;
}
/**
* 多编码字符串转中文拼接
*/
public static String getDescByCodeStr(String codeStr) {
if (!StringUtils.hasText(codeStr)) {
return "";
}
return Arrays.stream(codeStr.split(","))
.map(BusinessModelEnum::getDescByCode)
.collect(Collectors.joining(","));
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.enums;
import lombok.Getter;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* 车辆年限枚举
*/
@Getter
public enum VehicleAgeEnum {
ONE_TO_THREE("1", "1-3年"),
THREE_TO_SIX("2", "3-6年"),
SIX_TO_TEN("3", "6-10年"),
MORE_THAN_TEN("4", ">10年");
private final String code;
private final String desc;
VehicleAgeEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
public static String getDescByCode(String code) {
for (VehicleAgeEnum e : values()) {
if (e.getCode().equals(code)) {
return e.getDesc();
}
}
return code;
}
public static java.util.Map<String, String> getCodeDescMap() {
java.util.Map<String, String> map = new java.util.HashMap<>();
for (VehicleAgeEnum e : values()) {
map.put(e.getCode(), e.getDesc());
}
return map;
}
/**
* 多编码字符串转中文拼接
*/
public static String getDescByCodeStr(String codeStr) {
if (!StringUtils.hasText(codeStr)) {
return "";
}
return Arrays.stream(codeStr.split(","))
.map(VehicleAgeEnum::getDescByCode)
.collect(Collectors.joining(","));
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.enums;
import lombok.Getter;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* 车况枚举
*/
@Getter
public enum VehicleConditionEnum {
HIGH_QUALITY("1", "精品"),
FLAW("2", "瑕疵"),
MAJOR_ACCIDENT("3", "重大事故"),
SCRAP("4", "报废");
private final String code;
private final String desc;
VehicleConditionEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
/**
* 根据编码获取描述
*/
public static String getDescByCode(String code) {
for (VehicleConditionEnum e : values()) {
if (e.getCode().equals(code)) {
return e.getDesc();
}
}
return code; // 未匹配到返回原编码
}
/**
* 生成编码→描述的Map
*/
public static java.util.Map<String, String> getCodeDescMap() {
java.util.Map<String, String> map = new java.util.HashMap<>();
for (VehicleConditionEnum e : values()) {
map.put(e.getCode(), e.getDesc());
}
return map;
}
/**
* 核心:多编码字符串转中文拼接(适配Excel导出)
* 示例:"1,2" → "精品,瑕疵"
*/
public static String getDescByCodeStr(String codeStr) {
if (!StringUtils.hasText(codeStr)) {
return "";
}
return Arrays.stream(codeStr.split(","))
.map(VehicleConditionEnum::getDescByCode)
.collect(Collectors.joining(","));
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.enums;
import lombok.Getter;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* 燃油类型枚举
*/
@Getter
public enum VehicleFuelTypeEnum {
FUEL("1", "燃油"),
NEW_ENERGY("2", "新能源");
private final String code;
private final String desc;
VehicleFuelTypeEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
public static String getDescByCode(String code) {
for (VehicleFuelTypeEnum e : values()) {
if (e.getCode().equals(code)) {
return e.getDesc();
}
}
return code;
}
public static java.util.Map<String, String> getCodeDescMap() {
java.util.Map<String, String> map = new java.util.HashMap<>();
for (VehicleFuelTypeEnum e : values()) {
map.put(e.getCode(), e.getDesc());
}
return map;
}
/**
* 多编码字符串转中文拼接
*/
public static String getDescByCodeStr(String codeStr) {
if (!StringUtils.hasText(codeStr)) {
return "";
}
return Arrays.stream(codeStr.split(","))
.map(VehicleFuelTypeEnum::getDescByCode)
.collect(Collectors.joining(","));
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.enums;
import lombok.Getter;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 车型枚举(轿车/SUV/MPV/跑车/皮卡)
*
* @time 2026-01-28
*/
@Getter
public enum VehicleTypeEnum {
/** 轿车 */
SEDAN("1", "轿车"),
/** SUV */
SUV("2", "SUV"),
/** MPV */
MPV("3", "MPV"),
/** 跑车 */
SPORTS_CAR("4", "跑车"),
/** 皮卡 */
PICKUP_TRUCK("5", "皮卡");
/** 编码(对应前端value) */
private final String code;
/** 中文描述(对应前端label) */
private final String desc;
VehicleTypeEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
/**
* 根据编码获取中文描述
* @param code 编码(1/2/3/4/5)
* @return 中文描述,未匹配到返回原编码
*/
public static String getDescByCode(String code) {
for (VehicleTypeEnum e : values()) {
if (e.getCode().equals(code)) {
return e.getDesc();
}
}
return code;
}
/**
* 获取编码-描述的映射Map(用于前端下拉框/数据转换)
* @return key=编码,value=中文描述
*/
public static Map<String, String> getCodeDescMap() {
Map<String, String> map = new HashMap<>();
for (VehicleTypeEnum e : values()) {
map.put(e.getCode(), e.getDesc());
}
return map;
}
/**
* 多编码字符串(逗号分隔)转中文拼接
* 示例:输入"1,2" → 输出"轿车,SUV"
* @param codeStr 逗号分隔的编码字符串(如"1,2,3")
* @return 中文描述拼接串,空值返回空字符串
*/
public static String getDescByCodeStr(String codeStr) {
if (!StringUtils.hasText(codeStr)) {
return "";
}
return Arrays.stream(codeStr.split(","))
.map(VehicleTypeEnum::getDescByCode)
.collect(Collectors.joining(","));
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.service;
import com.glsx.usedcar.module.account.dao.AccountPreferenceOpLogDao;
import com.glsx.usedcar.module.account.entity.AccountPreferenceOpLog;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AccountPreferenceOpLogService {
private final AccountPreferenceOpLogDao accountPreferenceOpLogDao;
// 基础业务方法(按需扩展)
/**
* 保存操作日志
*/
public void saveLog(Integer preferenceId, Integer accountId, AccountPreferenceOpLog.OpType opType, String opContent, String opBy) {
try {
AccountPreferenceOpLog log = new AccountPreferenceOpLog(preferenceId, accountId, opType, opContent, opBy);
log.setDeletedFlag("N");
log.setCreateTime(LocalDateTime.now());
accountPreferenceOpLogDao.save(log);
} catch (Exception e) {
log.error("保存用户偏好操作日志失败", e);
}
}
public List<AccountPreferenceOpLog> findByPreferenceIdOrderByCreateTimeDesc(Integer id) {
return accountPreferenceOpLogDao.findByPreferenceIdOrderByCreateTimeDesc(id);
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.service;
import com.glsx.usedcar.module.account.dao.AccountPreferenceValueDao;
import com.glsx.usedcar.module.account.entity.AccountPreferenceValue;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AccountPreferenceValueService {
private final AccountPreferenceValueDao accountPreferenceValueDao;
// 基础业务方法(按需扩展)
/**
* 批量保存偏好值
*/
public void saveAll(Iterable<AccountPreferenceValue> values) {
accountPreferenceValueDao.saveAll(values);
}
/**
* 根据偏好ID查询未删除的偏好值
*/
public List<AccountPreferenceValue> findByPreferenceId(Integer preferenceId) {
return accountPreferenceValueDao.findByPreferenceIdAndDeletedFlag(preferenceId, "N");
}
/**
* 根据偏好ID逻辑删除
*/
public void deleteByPreferenceId(Integer preferenceId) {
accountPreferenceValueDao.updateDeletedFlagByPreferenceId(preferenceId, "D");
}
}
\ No newline at end of file
package com.glsx.usedcar.module.account.service;
import com.glsx.usedcar.module.account.dao.AccountPreferenceVehicleTypeDao;
import com.glsx.usedcar.module.account.entity.AccountPreferenceVehicleType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AccountPreferenceVehicleTypeService {
private final AccountPreferenceVehicleTypeDao accountPreferenceVehicleTypeDao;
// 基础业务方法(按需扩展)
/**
* 批量保存车型
*/
public List<AccountPreferenceVehicleType> saveAll(Iterable<AccountPreferenceVehicleType> vehicleTypes) {
return accountPreferenceVehicleTypeDao.saveAll(vehicleTypes);
}
/**
* 根据偏好ID查询未删除的车型
*/
public List<AccountPreferenceVehicleType> findByPreferenceId(Integer preferenceId) {
return accountPreferenceVehicleTypeDao.findByPreferenceIdAndDeletedFlag(preferenceId, "N");
}
/**
* 根据偏好ID逻辑删除
*/
public void deleteByPreferenceId(Integer preferenceId) {
accountPreferenceVehicleTypeDao.updateDeletedFlagByPreferenceId(preferenceId, "D");
}
}
\ No newline at end of file
......@@ -32,10 +32,8 @@ import org.summerframework.core.exception.FieldException;
import org.summerframework.orm.UpdateField;
import org.summerframework.orm.paging.Pagination;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.time.*;
import java.util.*;
/**
* 个人账户(Account) 服务实现类
......@@ -413,4 +411,17 @@ public class AccountService extends AbstractAuctionService {
return accountDao.countAndGroupBy(Account_.certifiedState, (Specification<Account>) (root, query, criteriaBuilder) -> criteriaBuilder.isNotNull(root.get(Account_.certifiedState)));
}
public boolean skipPreferenPopupForceDays(int accountId, int day) {
Optional<Account> optionalAccount = accountDao.findById(accountId);
if (optionalAccount.isEmpty()) {
return false;
}
Account account = optionalAccount.get();
LocalDate today = LocalDate.now(ZoneId.of("Asia/Shanghai"));
LocalDate targetDate = today.plusDays(day);
LocalDateTime targetDateTime = LocalDateTime.of(targetDate, LocalTime.MIN);
account.setPreferencePopTime(targetDateTime); // 直接修改字段
accountDao.save(account);
return true;
}
}
\ No newline at end of file
package com.glsx.usedcar.req;
/**
*
*
* @time 2026-01-28 10:59
*/
public class BaseReq {
}
package com.glsx.usedcar.resp;
import lombok.Data;
/**
* 通用返回结果类
* 泛型T为返回数据的类型
*
* @time 2026-01-28 11:00
*/
@Data
public class BaseResp<T> {
/**
* 响应码(成功默认000000,失败可自定义)
*/
private String code;
/**
* 响应数据
*/
private T data;
/**
* 操作是否成功
*/
private boolean success;
/**
* 响应消息(失败时存放错误信息,成功时默认"操作成功")
*/
private String message;
/**
* 默认构造方法:默认设置success=true,code=000000,message=操作成功
*/
public BaseResp() {
this.success = true;
this.code = "000000";
this.message = "操作成功";
}
/**
* 带参构造方法(自定义所有字段)
*/
public BaseResp(String code, T data, boolean success, String message) {
this.code = code;
this.data = data;
this.success = success;
this.message = message;
}
/**
* 成功响应(带返回数据)
* @param data 要返回的业务数据
* @param <T> 数据类型
* @return 通用响应对象
*/
public static <T> BaseResp<T> success(T data) {
BaseResp<T> resp = new BaseResp<>();
resp.setData(data);
return resp;
}
/**
* 成功响应(无返回数据,仅提示成功)
* @param <T> 数据类型(默认Void)
* @return 通用响应对象
*/
public static <T> BaseResp<T> success() {
return success(null);
}
/**
* 成功响应(自定义成功消息+数据)
* @param data 要返回的业务数据
* @param message 自定义成功消息
* @param <T> 数据类型
* @return 通用响应对象
*/
public static <T> BaseResp<T> success(T data, String message) {
BaseResp<T> resp = success(data);
resp.setMessage(message);
return resp;
}
/**
* 失败响应(自定义错误码+错误消息)
* @param code 错误码
* @param message 错误消息
* @param <T> 数据类型(默认Void)
* @return 通用响应对象
*/
public static <T> BaseResp<T> fail(String code, String message) {
BaseResp<T> resp = new BaseResp<>();
resp.setSuccess(false);
resp.setCode(code);
resp.setMessage(message);
resp.setData(null);
return resp;
}
/**
* 失败响应(默认错误码+自定义错误消息)
* 默认错误码:999999(系统异常)
* @param message 错误消息
* @param <T> 数据类型(默认Void)
* @return 通用响应对象
*/
public static <T> BaseResp<T> fail(String message) {
return fail("999999", message);
}
}
\ No newline at end of file
package com.glsx.usedcar.util;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
/**
* 中文转拼音首字母大写工具类
*/
public class ChineseFirstLetterUtil {
// 初始化拼音格式(无声调、大写)
private static final HanyuPinyinOutputFormat PINYIN_FORMAT;
static {
PINYIN_FORMAT = new HanyuPinyinOutputFormat();
PINYIN_FORMAT.setCaseType(HanyuPinyinCaseType.UPPERCASE); // 拼音大写
PINYIN_FORMAT.setToneType(HanyuPinyinToneType.WITHOUT_TONE); // 无声调
}
/**
* 核心方法:输入中文,获取拼音首字母大写(多个字拼接)
* @param chinese 中文文字(单个字/多个字,如"北京"、"中")
* @return 首字母大写字符串(如"BJ"、"Z"),空值/非中文返回空字符串
*/
public static String getFirstLetterUpperCase(String chinese) {
// 1. 空值校验
if (chinese == null || chinese.trim().isEmpty()) {
return "";
}
chinese = chinese.trim();
StringBuilder result = new StringBuilder();
// 2. 遍历每个字符
for (char c : chinese.toCharArray()) {
// 3. 判断是否为中文字符
if (Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) {
try {
// 4. 获取该字的拼音(多音字取第一个)
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, PINYIN_FORMAT);
if (pinyinArray != null && pinyinArray.length > 0) {
String pinyin = pinyinArray[0]; // 多音字默认取第一个拼音
// 5. 提取首字母并拼接
result.append(pinyin.charAt(0));
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
// 拼音格式错误(理论上不会触发,已初始化格式)
e.printStackTrace();
}
}
// 非中文字符(数字/字母/符号):可选择跳过,或保留原字符(根据需求调整)
// 如需保留非中文字符,取消下面注释:
// else {
// result.append(c);
// }
}
return result.toString();
}
/**
* 提取字符串中第一个中文字符的拼音首字母大写
* @param text 输入文字(可空、含中文/非中文)
* @return 第一个中文字符的拼音首字母大写(无中文/空输入返回空字符串)
*/
public static String getFirstChineseCharFirstLetter(String text) {
// 1. 空值/空字符串直接返回空
if (text == null || text.trim().isEmpty()) {
return "";
}
// 2. 初始化拼音格式(大写、无声调)
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
format.setCaseType(HanyuPinyinCaseType.UPPERCASE);
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
// 3. 遍历字符,找到第一个中文字符
for (char c : text.trim().toCharArray()) {
// 仅处理中文字符(Unicode:\u4E00-\u9FA5 是中文汉字范围)
if (Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) {
try {
// 4. 获取该字拼音(多音字取第一个),提取首字母并返回
String[] pinyinArr = PinyinHelper.toHanyuPinyinStringArray(c, format);
if (pinyinArr != null && pinyinArr.length > 0) {
return String.valueOf(pinyinArr[0].charAt(0));
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
// 格式异常(理论上不会触发),返回空
return "";
}
}
// 非中文字符跳过,继续找下一个
}
// 5. 遍历完无中文字符,返回空
return text.substring(0, 1).toUpperCase();
}
// 测试方法(验证效果)
public static void main(String[] args) {
// 单个字测试
System.out.println(getFirstLetterUpperCase("中")); // 输出:Z
// 多个字测试
System.out.println(getFirstLetterUpperCase("北京")); // 输出:BJ
System.out.println(getFirstLetterUpperCase("杭州")); // 输出:HZ
// 包含多音字测试("行"默认取XING)
System.out.println(getFirstLetterUpperCase("银行")); // 输出:YX
// 空值/非中文测试
System.out.println(getFirstLetterUpperCase("")); // 输出:空字符串
System.out.println(getFirstLetterUpperCase("123abc")); // 输出:空字符串(非中文跳过)
}
}
\ No newline at end of file
package com.glsx.usedcar.util;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* 生产级邮政编码转省级行政区工具类(全量映射)
* 覆盖所有省/自治区/直辖市/特别行政区
*/
public class ZipCodeToProvinceUtil {
private ZipCodeToProvinceUtil() {
}
private static final Map<String, String> ZIP_PROVINCE_MAP;
static {
Map<String, String> map = new HashMap<>(100);
// -------------------------- 直辖市 --------------------------
map.put("10", "北京市"); // 100000→北京市
map.put("20", "上海市"); // 200000→上海市
map.put("30", "天津市"); // 300000→天津市
map.put("40", "重庆市"); // 400000→重庆市
map.put("50", "重庆市");
// -------------------------- 华北地区 --------------------------
map.put("03", "山西省");
map.put("05", "河北省");
map.put("06", "河北省");
map.put("07", "河北省");
map.put("11", "辽宁省");
map.put("12", "辽宁省");
map.put("13", "吉林省");
map.put("15", "黑龙江省");
map.put("16", "黑龙江省");
// -------------------------- 华东地区 --------------------------
map.put("21", "江苏省");
map.put("22", "江苏省");
map.put("23", "安徽省");
map.put("24", "安徽省");
map.put("25", "山东省");
map.put("26", "山东省");
map.put("27", "山东省");
map.put("31", "浙江省");
map.put("32", "浙江省");
map.put("33", "江西省");
map.put("34", "江西省");
map.put("35", "福建省");
map.put("36", "福建省");
// -------------------------- 华中地区 --------------------------
map.put("41", "湖南省"); // 410000→长沙
map.put("42", "湖南省"); // 备用邮编段
map.put("43", "湖北省"); // 430000→武汉
map.put("44", "湖北省"); // 备用邮编段
map.put("45", "河南省"); // 450000→郑州
map.put("46", "河南省"); // 备用邮编段
map.put("47", "河南省"); // 备用邮编段
// -------------------------- 华南地区 --------------------------
map.put("51", "广东省"); // 510000→广州、518000→深圳
map.put("52", "广东省"); // 备用邮编段
map.put("53", "广西壮族自治区"); // 530000→南宁
map.put("54", "广西壮族自治区"); // 541000→桂林
map.put("55", "贵州省"); // 550000→贵阳
map.put("56", "贵州省"); // 563000→遵义
map.put("57", "海南省"); // 570000→海口
// -------------------------- 西南地区 --------------------------
map.put("61", "四川省"); // 610000→成都
map.put("62", "四川省"); // 621000→绵阳
map.put("63", "四川省"); // 635000→达州
map.put("64", "四川省"); // 646000→泸州
map.put("65", "云南省"); // 650000→昆明
map.put("66", "云南省"); // 661000→红河
map.put("67", "云南省"); // 671000→大理、674400→怒江
map.put("85", "西藏自治区"); // 850000→拉萨、852000→那曲
map.put("86", "西藏自治区"); // 860000→林芝
// -------------------------- 西北地区 --------------------------
map.put("71", "陕西省"); // 710000→西安
map.put("72", "陕西省"); // 721000→宝鸡、723000→汉中
map.put("73", "甘肃省"); // 730000→兰州
map.put("74", "甘肃省"); // 741000→天水、745000→庆阳
map.put("75", "宁夏回族自治区"); // 750000→银川
map.put("76", "宁夏回族自治区"); // 760000→吴忠
map.put("81", "青海省"); // 810000→西宁
map.put("83", "新疆维吾尔自治区");// 830000→乌鲁木齐
map.put("84", "新疆维吾尔自治区");// 900000→伊犁
map.put("91", "新疆维吾尔自治区");// 备用邮编段
// -------------------------- 特别行政区 --------------------------
map.put("99", "特别行政区"); // 999077→香港、999078→澳门
// 转为不可变Map,确保线程安全与数据不可篡改
ZIP_PROVINCE_MAP = Collections.unmodifiableMap(map);
}
public static String getProvinceByZipCode(String zipCode) {
if (zipCode == null || zipCode.trim().isEmpty()) {
return "未知省份";
}
String zip = zipCode.trim();
if ("999077".equals(zip)) {
return "香港特别行政区";
}
if ("999078".equals(zip)) {
return "澳门特别行政区";
}
if (!zip.matches("^\\d{6}$")) {
return "未知省份";
}
String prefix = zip.substring(0, 2);
String province = ZIP_PROVINCE_MAP.get(prefix);
if ("特别行政区".equals(province)) {
return "香港/澳门特别行政区";
}
return province != null ? province : "未知省份";
}
public static String getProvinceByZipCode(Integer zipCode) {
if (zipCode == null) {
return "未知省份";
}
// 补全6位数字(防止少位数,如10000→010000,避免截取错误)
String zip = String.format("%06d", zipCode);
return getProvinceByZipCode(zip);
}
}
\ No newline at end of file
package org.summerframework.security;
import org.apache.commons.lang3.StringUtils;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.summerframework.core.components.tree.TreeItem;
import jakarta.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;
......@@ -54,7 +52,7 @@ public abstract class AbstractSecurityController {
@GetMapping("getUserAuthentication")
public Authenticity getUserAuthentication(@RequestParam(required = false) String module, Authentication authentication) {
public Authenticity getUserAuthentication(@RequestParam(required = false, name = "module") String module, Authentication authentication) {
List<Privilege> privileges = securityService.loadUserPrivileges(authentication);
if (StringUtils.isNotBlank(module)) {
Optional<Privilege> first = privileges.stream().filter(p -> p.getType() == Privilege.Type.MODULE && p.getCode().equals(module)).findFirst();
......
......@@ -432,6 +432,9 @@
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!