文件上传 bast64

This commit is contained in:
haozq 2024-11-13 13:23:42 +08:00
parent c7b8378b78
commit 06c02c5e24
9 changed files with 50 additions and 29 deletions

View File

@ -72,7 +72,6 @@ public class PartApplyController {
/**
* 图片文件上传
* @return

View File

@ -50,7 +50,7 @@ public class PartInputController {
* @return
*/
@PostMapping("addInputData")
public ServerResponse addInputData(HttpServletRequest request, @RequestParam("file[]") MultipartFile[] files) {
public ServerResponse addInputData(HttpServletRequest request, @RequestParam(value = "file[]",required = false) MultipartFile[] files) {
return service.addInputData(request,files);
}
@ -61,7 +61,7 @@ public class PartInputController {
* @return
*/
@PostMapping("updateInputData")
public ServerResponse updateInputData(HttpServletRequest request, @RequestParam("file[]") MultipartFile[] files) {
public ServerResponse updateInputData(HttpServletRequest request, @RequestParam(value = "file[]",required = false) MultipartFile[] files) {
return service.updateInputData(request,files);
}

View File

@ -91,5 +91,20 @@ public class PartInputVo {
* 文件上传 集合
*/
private List<FileUploadVo> fileList;
/**
*
*/
private String type;
/**
*
*/
private String name;
/**
*
*/
private String model;
}

View File

@ -76,7 +76,7 @@ public interface PartInputMapper {
* 修改 入库信息
* @param list
*/
int uploadDetails(List<PartInputDetails> list);
int uploadDetails(PartInputDetails data);
/**
* 更新1数据

View File

@ -48,10 +48,6 @@ public class PartInputServiceImpl implements PartInputService{
public List<PartInputVo> findByPage(PartInputVo data) {
List<PartInputVo> list=new ArrayList<>();
try{
if(StringHelper.isNotEmpty(data.getInputDay())){
data.setStartDay(data.getInputDay().split(" ~ ")[0]);
data.setEndDay(data.getInputDay().split(" ~ ")[1]);
}
list=mapper.findByPage(data);
}catch (Exception e){
@ -177,20 +173,23 @@ public class PartInputServiceImpl implements PartInputService{
detail.setTotalPrice(totalPrice.toString());
});
//修改详情
int num2= mapper.uploadDetails(list);
int num2=0;
for (int i = 0; i <list.size() ; i++) {
int num3= mapper.uploadDetails(list.get(i));
num2=num2+num3;
}
if(num2!=list.size()){
return ServerResponse.createErroe("修改失败");
}else{
list.forEach(detail->{
//更新 -及平准单价
// String pzPrice=mapper.getPzPrice(detail);
mapper.updateTypeNum2(detail.getPartId(),detail.getPartPrice());
});
}
}
//文件上传
if(files!=null || files.length>0){
if(files!=null && files.length>0){
List<FileUploadVo> fileList=uploadService.uploadImage(files,vo.getId(),"t_part_input",null);
if(StringUtils.isEmpty(fileList) || fileList.size()!=files.length){
return ServerResponse.createErroe("入库失败");
@ -198,18 +197,18 @@ public class PartInputServiceImpl implements PartInputService{
}
List<PartInputDetails> childerList=mapper.getInputDetailList(vo);
AtomicReference<String> isFlag= new AtomicReference<>("1");
BigDecimal allPrice = new BigDecimal("0");
final BigDecimal[] allPrice = {new BigDecimal("0")};
childerList.forEach(data->{
BigDecimal price = new BigDecimal(data.getPartPrice());
BigDecimal num = new BigDecimal(data.getInputNum());
BigDecimal totalPrice = price.multiply(num);
allPrice.add(totalPrice);
allPrice[0] = allPrice[0].add(totalPrice);
if("0".equals(data.getPartPrice())){
isFlag.set("0");
}
});
vo.setIsFlag(isFlag.get());
vo.setAllPrice(allPrice.toString());
vo.setAllPrice(allPrice[0].toString());
int num3= mapper.updateInputData(vo);
if(num3>0){
return ServerResponse.createSuccess("修改成功","修改成功");

View File

@ -42,11 +42,11 @@ public class FileUploadService {
try {
for (String bast64 : files) {
String fileName=IDUtils.createID()+".png";
String filePath= DateTimeHelper.getNowYMD()+"/"+ fileName;
String filePath= "/"+DateTimeHelper.getNowYMD()+"/"+ fileName;
String newPath= SystemUtils.getUploadPath()+filePath;
// 解码Base64字符串
byte[] decodedBytes = Base64.getDecoder().decode(bast64);
try (FileOutputStream fileOutputStream = new FileOutputStream(filePath)) {
try (FileOutputStream fileOutputStream = new FileOutputStream(newPath)) {
// 将字节写入文件
fileOutputStream.write(decodedBytes);
} catch (IOException e) {
@ -54,7 +54,7 @@ public class FileUploadService {
}
FileUploadVo vo=new FileUploadVo();
vo.setFileName(fileName);
vo.setFileUrl(newPath);
vo.setFileUrl(filePath);
vo.setOwnId(outId);
vo.setModelTable(table);
vo.setSuffix(".png");
@ -86,7 +86,7 @@ public class FileUploadService {
for (MultipartFile file : files) {
String fileName = file.getOriginalFilename();
String suffix=IDUtils.getSuffix(fileName);
String path= DateTimeHelper.getNowYMD()+"/"+ IDUtils.createID()+suffix;
String path="/"+DateTimeHelper.getNowYMD()+"/"+ IDUtils.createID()+suffix;
String newPath= SystemUtils.getUploadPath()+path;
File uploadFile = new File(newPath);
//生成文件夹

View File

@ -39,7 +39,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
String filePath= SystemUtils.getUploadPath();//获取文件上传路径
/** 本地文件上传路径 */
registry.addResourceHandler("/statics/**")
.addResourceLocations("file:" + filePath);
.addResourceLocations("file:" + filePath+"/");
registry.addResourceHandler("/files/**")
.addResourceLocations("file:"+filePath);
}

View File

@ -40,8 +40,8 @@ zhly:
file:
upload_path:
windows: D://files/zg_gqj/
linux: /home/zg_gqj/files/
windows: D://files/zg_gqj
linux: /home/zg_gqj/files

View File

@ -29,11 +29,9 @@
</update>
<update id="uploadDetails">
<foreach close="" collection="list" index="index" item="item" open="" separator=";">
update t_part_put_details set part_price=#{item.partPrice}, vender_id=#{item.vendId},
total_price=#{item.totalPrice}, set vender_name=#{item.vendName}
where id=#{item.id}
</foreach>
update t_part_put_details set part_price=#{partPrice}, vender_id=#{vendId},
total_price=#{totalPrice},vender_name=#{vendName}
where id=#{id}
</update>
<update id="updateInputData">
update t_part_input set updater=#{updater},update_time=now(),all_price=#{allPrice},
@ -49,15 +47,16 @@
<where>
<if test="keyWord!=null and keyWord!=''">
and (tpi.code like concat('%',#{keyWord},'%') or
tpi.creator like concat('%',#{keyWord},'%') or
tpi.input_user like concat('%',#{keyWord},'%') or
tpi.input_day like concat('%',#{keyWord},'%') or
tpi.remark like concat('%',#{keyWord},'%')
)
</if>
<if test="inputDay!=null and inputDay!='' and startDay!=null and endDay!=null ">
<if test="startDay!=null and startDay!='' and endDay!=null and endDay!='' ">
and STR_TO_DATE(tpi.input_day, '%Y-%m-%d') between STR_TO_DATE(#{startDay} ,'%Y-%m-%d') AND STR_TO_DATE(#{endDay},'%Y-%m-%d')
</if>
</where>
order by tpi.create_time desc
</select>
<!--入库数量-->
<select id="getInputNum" resultType="java.lang.Integer">
@ -87,9 +86,18 @@
select ppd.id, ppd.put_id inputId,ppd.part_id partId, ppd.part_type partType,
ppd.part_name partName, ppd.part_model partModel, ppd.part_unit partUnit, ppd.input_num inputNum,
ppd.part_price partPrice, ppd.total_price totalPrice, ppd.vender_id vendId,
ppd.vender_name vendName
ppd.vender_name vendName,remark
FROM t_part_put_details ppd
where ppd.put_id=#{id}
<if test="type!=null and type!=''">
and ppd.part_type like concat('%',#{type},'%')
</if>
<if test="name!=null and name!=''">
and ppd.part_name like concat('%',#{name},'%')
</if>
<if test="model!=null and model!=''">
and ppd.part_model like concat('%',#{model},'%')
</if>
</select>
<select id="getPzPrice" resultType="java.lang.String">
select ROUND(IFNULL(AVG(part_price),0),2) price