手机验证码登录修改

This commit is contained in:
haozq 2025-09-10 15:21:59 +08:00
parent cb06844301
commit 753ab48794
8 changed files with 234 additions and 59 deletions

View File

@ -7,6 +7,9 @@ import com.bonus.common.core.domain.AjaxResult;
import com.bonus.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -19,6 +22,9 @@ public class ProductController extends BaseController {
@Autowired
public ProductService service;
@Autowired
private PlatformTransactionManager transactionManager;
/**
* 查询产品列表集合
* @param product
@ -42,7 +48,16 @@ public class ProductController extends BaseController {
@PreAuthorize("@ss.hasPermi('tb:product:add')")
@PostMapping("/add")
public AjaxResult add(@RequestParam(value = "files")MultipartFile[] file, TbProduct product ){
return service.addProduct(file,product);
TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
try{
AjaxResult ajaxResult=service. addProduct(file,product);
transactionManager.commit(status);
return ajaxResult;
}catch (Exception e){
transactionManager.rollback(status);
}
return AjaxResult.error("新增失败,请求参数不正确");
}

View File

@ -0,0 +1,57 @@
package com.bonus.business.domain;
import com.bonus.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.lang.ref.PhantomReference;
@EqualsAndHashCode(callSuper = true)
@Data
public class ProductCaseImage extends BaseEntity {
private String id;
/**
* ·名称
*/
private String tableId;
/**
* 资源id
*/
private String sourceId;
/**
* 文件名称
*/
private String fileName;
/**
* 文件路径
*/
private String filePath;
/**
* 文件大小
*/
private String fileSize;
/**
* 源文件名称
*/
private String originalName;
/**
* 文件后缀
*/
private String fileSuffix;
/**
* 文件类型
*/
private String fileType;
/**
* 桶名称
*/
private String bucketName;
private String createUser;
}

View File

@ -13,6 +13,7 @@ import com.bonus.common.annotation.Excel;
* @author ruoyi
* @date 2025-09-10
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class TbComponentInfo extends BaseEntity
{

View File

@ -1,6 +1,8 @@
package com.bonus.business.mapper;
import com.bonus.business.domain.ProductCaseImage;
import com.bonus.business.domain.TbProduct;
import com.bonus.business.domain.TbProductCase;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@ -14,4 +16,23 @@ public interface ProductMapper {
* @return
*/
List<TbProduct> selectProductList(TbProduct product);
/**
* 新增产品数据
* @param product
* @return
*/
int addProduct(TbProduct product);
/**
* 新增产品方案
* @param productCase
*/
int addProductCase(TbProductCase productCase);
/**
* 新增图片库
* @param productCaseImage
*/
int insertCaseImage(ProductCaseImage productCaseImage);
}

View File

@ -1,20 +1,27 @@
package com.bonus.business.service.impl;
import com.bonus.business.domain.ProductCaseImage;
import com.bonus.business.domain.TbProduct;
import com.bonus.business.domain.TbProductCase;
import com.bonus.business.mapper.ProductMapper;
import com.bonus.business.service.ProductService;
import com.bonus.common.core.domain.AjaxResult;
import com.bonus.common.utils.DateUtils;
import com.bonus.common.utils.SecurityUtils;
import com.bonus.common.utils.StringUtils;
import com.bonus.file.service.FileUploadService;
import com.google.common.collect.Maps;
import com.google.common.collect.Table;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@Service
@ -26,6 +33,12 @@ public class ProductServiceImpl implements ProductService {
@Autowired
private FileUploadService service;
public String day= DateUtils.getCurrentYear();
public String month=DateUtils.getCurrentMonth();
public String year=DateUtils.getCurrentYear();
/**
* 分页查询 产品列表
* @param product
@ -44,33 +57,114 @@ public class ProductServiceImpl implements ProductService {
@Override
public AjaxResult addProduct(MultipartFile[] file, TbProduct product) {
if(file==null){
try{
if(file==null || file.length==0){
return AjaxResult.error("请上传封面图片");
}
// String originFileName = file.getOriginalFilename();
// String contentType = file.getContentType();
// if(contentType == null || !(contentType.startsWith("image/"))){
// return AjaxResult.error("附件只能上传图片");
// }
// String day= DateUtils.getCurrentYear();
// String month=DateUtils.getCurrentMonth();
// String year=DateUtils.getCurrentYear();
// String uuid = StringUtils.randomUUID();
// String suffix=StringUtils.substringAfterLast(originFileName, ".");
// //产品封面
// String sb = "product" + "/" +
// year + "/" + month + "/" + day + "/" + uuid + "." + suffix;
// String path=service.uploadFile(file, sb);
// if(path==null){
// return AjaxResult.error("文件上传失败");
// }
Map<String,List<MultipartFile>> map= Maps.newHashMap();
String fileType=product.getFileType();
if(StringUtils.isEmpty(fileType)){
return AjaxResult.error("请上传图片类型");
}
String[] fileTypes=fileType.split(",");
if(fileTypes.length!=file.length){
return AjaxResult.error("图片类型参数不正确");
}
for (int i = 0; i <file.length ; i++) {
String type=fileTypes[i];
List<MultipartFile> multipartFileList=map.get(type);
if(StringUtils.isEmpty(multipartFileList)){
multipartFileList=new ArrayList<>();
multipartFileList.add(file[i]);
map.put(type,multipartFileList);
}else {
multipartFileList.add(file[i]);
map.replace(type,multipartFileList);
}
}
int num=mapper.addProduct(product);
List<MultipartFile> prFile=map.get("s");
AjaxResult ajaxResult1=uploadFile(prFile,"tb_product",product.getId(),"产品案例");
if(ajaxResult1.isError()){
return ajaxResult1;
}
if(num<1){
return AjaxResult.error("产品新增失败");
}else{
List<TbProductCase> list=product.getList();
for (int i = 0; i < list.size(); i++) {
TbProductCase productCase=list.get(i);
List<MultipartFile> multipartFileList=map.get(i+"");
productCase.setProductId(product.getId());
int nums=mapper.addProductCase(productCase);
if(nums<1){
return AjaxResult.error("产品案例新增失败");
}else{
AjaxResult ajaxResult=uploadFile(multipartFileList,"tb_product_case",productCase.getId(),"产品案例");
if(ajaxResult.isError()){
return ajaxResult;
}
}
}
}
}catch (Exception e){
log.error(e.toString(),e);
throw new RuntimeException("新增失败");
}
return AjaxResult.success("新增成功");
return null;
}
/**
* 上传附件
* @param
* @return
*/
public AjaxResult uploadFile(List<MultipartFile> multipartFileList,String tableId,String sourceId,String fileType){
for (MultipartFile file: multipartFileList) {
String contentType = file.getContentType();
if(contentType == null || !(contentType.startsWith("image/"))){
return AjaxResult.error("附件只能上传图片");
}
String uuid = StringUtils.randomUUID();
String originFileName = file.getOriginalFilename();
String suffix=StringUtils.substringAfterLast(originFileName, ".");
//产品 封面
String filePath = "product" + "/" +
year + "/" + month + "/" + day + "/" + uuid + "." + suffix;
String path=service.uploadFile(file, filePath);
if(path==null){
return AjaxResult.error("文件上传失败");
}
ProductCaseImage productCaseImage=new ProductCaseImage();
productCaseImage.setTableId(tableId);
productCaseImage.setSourceId(sourceId);
productCaseImage.setFileType(fileType);
productCaseImage.setFileName(uuid+"." + suffix);
productCaseImage.setFilePath(path+"/"+filePath);
productCaseImage.setBucketName(path);
productCaseImage.setOriginalName(originFileName);
productCaseImage.setFileSuffix(suffix);
productCaseImage.setCreateUser(SecurityUtils.getUserId().toString());
// 获取文件大小字节
long sizeInBytes = file.getSize();
// 转换为可读格式如KB/MB
String humanReadableSize = convertToHumanReadable(sizeInBytes);
productCaseImage.setFileSize(humanReadableSize);
mapper.insertCaseImage(productCaseImage);
}
return AjaxResult.success();
}
// 辅助方法字节转可读格式
private String convertToHumanReadable(long bytes) {
if (bytes < 1024) return bytes + " B";
else if (bytes < 1024 * 1024) return String.format("%.2f KB", bytes / 1024.0);
else return String.format("%.2f MB", bytes / (1024 * 1024.0));
}
}

View File

@ -3,37 +3,8 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.business.mapper.ProductMapper">
<resultMap type="TbProduct" id="TbProductResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="typeId" column="type_id" />
<result property="typeName" column="type_name" />
<result property="linkUrl" column="link_url" />
<result property="linkImage" column="link_image" />
<result property="linkUser" column="link_user" />
<result property="linkPassword" column="link_password" />
<result property="isLink" column="is_link" />
<result property="introduction" column="introduction" />
<result property="createTime" column="create_time" />
<result property="createUser" column="create_user" />
<result property="updateTime" column="update_time" />
<result property="updateUser" column="update_user" />
<result property="delFlag" column="del_flag" />
</resultMap>
<sql id="selectTbProductVo">
</sql>
<select id="selectTbProductList" parameterType="TbProduct" resultMap="TbProductResult">
<include refid="selectTbProductVo"/>
</select>
<select id="selectTbProductById" parameterType="Long" resultMap="TbProductResult">
<include refid="selectTbProductVo"/>
where id = #{id}
</select>
<select id="selectProductList" resultType="com.bonus.business.domain.TbProduct">
select tpt.id, tpt.name, tpt.type_id typeId, sdd.dict_label typeName,
tpt.link_url linkUrl, tpt.link_image linkImage, tpt.link_user linkUser, tpt.link_password linkPassword, tpt.is_link isLink,
@ -50,10 +21,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createUser != null "> and su.nick_name like concat('%', #{typeName},'%')</if>
</select>
<insert id="insertTbProduct" parameterType="TbProduct">
<insert id="addProduct" parameterType="com.bonus.business.domain.TbProduct" keyProperty="id" useGeneratedKeys="true" >
insert into tb_product
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="name != null">name,</if>
<if test="typeId != null">type_id,</if>
<if test="typeName != null">type_name,</if>
@ -67,10 +37,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createUser != null">create_user,</if>
<if test="updateTime != null">update_time,</if>
<if test="updateUser != null">update_user,</if>
<if test="delFlag != null">del_flag,</if>
<if test="updateUser != null">is_access,</if>
del_flag
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="name != null">#{name},</if>
<if test="typeId != null">#{typeId},</if>
<if test="typeName != null">#{typeName},</if>
@ -84,9 +54,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createUser != null">#{createUser},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="updateUser != null">#{updateUser},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="updateUser != null">#{isAccess},</if>
0
</trim>
</insert>
<insert id="addProductCase" useGeneratedKeys="true" keyProperty="id">
insert into tb_product_case(
product_id, case_company, case_introduction,case_sort, del_flag,create_user, create_time, update_user, update_time,
)values (#{productId},#{caseCompany},#{caseIntroduction},#{caseSort},0,#{createUser},now(),#{updateUser},now())
</insert>
<insert id="insertCaseImage">
insert into tb_product_image( table_id, source_id, file_name, file_path,
file_suffix, file_size, original_name, bucket_name,
create_time, create_user, file_type
)values (#{tableId},#{sourceId},#{fileName},#{filePath},#{fileSuffix},#{fileSize},#{originalName},#{bucketName},now(),#{createUser},#{fileType})
</insert>
<update id="updateTbProduct" parameterType="TbProduct">
update tb_product

View File

@ -7,6 +7,7 @@ import java.util.Map;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
/**
* Entity基类

View File

@ -29,7 +29,7 @@ public class FileUploadService {
public String uploadFile(MultipartFile file,String path) {
try{
minioUtil.uploadFile(minioConfig.getBucketName(), file,path);
return path;
return minioConfig.getBucketName();
}catch (Exception e){
log.error(e.toString(),e);
}
@ -37,4 +37,5 @@ public class FileUploadService {
}
}