zengtx преди 2 години
родител
ревизия
9eccb802ef

+ 62 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/report/controller/FabricLossController.java

@@ -19,12 +19,15 @@ import org.jeecg.modules.report.service.IFabricLossService;
 import org.jeecg.modules.report.service.IFabricOmOrderService;
 import org.jeecg.modules.report.service.IFabricPoOrderService;
 import org.jeecg.modules.report.service.ISyFabricLossReportService;
+import org.jeecg.modules.system.controller.CommonController;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.net.URLEncoder;
 import java.util.Collection;
@@ -63,6 +66,9 @@ public class FabricLossController {
 	private IFabricOmOrderService fabricOmOrderService;
 	@Autowired
 	private ISyFabricLossReportService syFabricLossReportService;
+
+	@Autowired
+	CommonController commonController;
 	/**
 	 *面料损耗
 	 * @param csocode 计划号
@@ -137,6 +143,9 @@ public class FabricLossController {
 			builder.header("Content-Disposition",
 					"attacher;filename*=UTF-8''" + filename);
 		}
+
+
+
 		return builder.body(content);
 
 	}
@@ -297,4 +306,57 @@ public class FabricLossController {
 		return result;
 	}
 
+
+	@AutoLog(value = "附件上传直接保存到数据库")
+	@ApiOperation(value="附件上传直接保存到数据库", notes="附件上传直接保存到数据库")
+	@PostMapping(value = "/addFile")
+	public Result<String> addFile(HttpServletRequest request, HttpServletResponse response,
+								 FabricLoss fabricLoss){
+
+		Result<String> result = new Result<String>();
+
+		String fileName = commonController.upload(request,response).getMessage();
+        if(oConvertUtils.isEmpty(fabricLoss.getName())){
+			result.setMessage("没有获取到文件,上传失败!");
+			result.setResult("没有获取到文件,上传失败!");
+			result.setSuccess(false);
+			return result;
+		}
+		int i = fabricLossService.addFile(fabricLoss.getCode(),fileName);
+        if(i>0){
+			result.setMessage("上传成功!");
+			result.setResult(fileName);
+			result.setSuccess(true);
+		}else{
+			result.setMessage("上传失败!");
+			result.setResult(fileName);
+			result.setSuccess(false);
+		}
+
+		return result;
+	}
+
+
+	@AutoLog(value = "附件直接删除")
+	@ApiOperation(value="附件直接删除", notes="附件直接删除")
+	@DeleteMapping(value = "/deleteFile")
+	public Result<String> deleteFile(HttpServletRequest request, HttpServletResponse response,
+								  FabricLoss fabricLoss){
+
+		Result<String> result = new Result<String>();
+
+		int i = fabricLossService.deleteFile(fabricLoss.getCode(),fabricLoss.getName());
+		if(i>0){
+			result.setMessage("删除成功!");
+			result.setResult(fabricLoss.getName());
+			result.setSuccess(true);
+		}else{
+			result.setMessage("删除成功!");
+			result.setResult(fabricLoss.getName());
+			result.setSuccess(false);
+		}
+
+		return result;
+	}
+
 }

+ 3 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/report/entity/FabricLoss.java

@@ -80,4 +80,7 @@ public class FabricLoss {
     // 附件,多个逗号分割
     String attachs;
 
+
+    private String code;
+    private String name;
 }

+ 5 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/report/service/IFabricLossService.java

@@ -34,4 +34,9 @@ public interface IFabricLossService extends IService<FabricLoss> {
 	// 根据文件id,获取文件内容
 	byte[] getFileContent(String fileId);
 
+	//点击上传,直接保存到数据库
+	public int addFile(String code,String name);
+	//点击删除,直接删除数据库附件
+	public int deleteFile(String code,String name);
+
 }

+ 59 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/report/service/impl/FabricLossServiceImpl.java

@@ -13,6 +13,7 @@ import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.constant.CacheConstant;
 import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.api.ISysBaseAPI;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.system.vo.SysUserCacheInfo;
@@ -26,6 +27,7 @@ import org.jeecg.modules.report.mapper.FabricLossMapper;
 import org.jeecg.modules.report.service.IFabricLossService;
 import org.jeecg.modules.report.service.IFabricOmOrderService;
 import org.jeecg.modules.report.service.IFabricPoOrderService;
+import org.jeecg.modules.report.service.ISyFabricLossReportService;
 import org.jeecg.modules.system.entity.*;
 import org.jeecg.modules.system.mapper.*;
 import org.jeecg.modules.system.model.SysUserSysDepartModel;
@@ -66,6 +68,9 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 
 	@Autowired
 	private IFabricOmOrderService fabricOmOrderService;
+
+	@Autowired
+	private ISyFabricLossReportService syFabricLossReportService;
 	/**
 	 * 面料损耗信息接口
 	 * @param code 计划号
@@ -234,6 +239,60 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 		return null;
 	}
 
+	//点击上传,直接保存到数据库
+	@Override
+	public int addFile(String code, String name) {
+
+		StringBuffer sbu = new StringBuffer();
+
+		QueryWrapper<SyFabricLossReport> fbaQueryWrapper = new QueryWrapper<>();
+		fbaQueryWrapper.eq("plan_code",code);
+		List<SyFabricLossReport> list = syFabricLossReportService.list(fbaQueryWrapper);
+		if(list.size() == 0){
+         throw new JeecgBootException("为获取到计划号,请查询!");
+		}
+        SyFabricLossReport entity = list.get(0);
+		if(oConvertUtils.isNotEmpty(entity.getAttachs())){
+			sbu.append(entity.getAttachs()+",temp/"+name);
+
+			entity.setAttachs(sbu.toString());
+		}else{
+			sbu.append(name);
+		}
+		syFabricLossReportService.updateById(entity);
+		return 1;
+	}
+
+	//点击删除,直接删除数据库附件
+	@Override
+	public int deleteFile(String code,String name) {
+
+		StringBuffer sbu = new StringBuffer();
+
+		QueryWrapper<SyFabricLossReport> fbaQueryWrapper = new QueryWrapper<>();
+		fbaQueryWrapper.eq("plan_code",code);
+		List<SyFabricLossReport> list = syFabricLossReportService.list(fbaQueryWrapper);
+		if(list.size() == 0){
+			throw new JeecgBootException("为获取到计划号,请查询!");
+		}
+		SyFabricLossReport entity = list.get(0);
+		String split[] = entity.getAttachs().split(",");
+
+		for(String str:split){
+          if(!str.equals(name)){
+			  sbu.append(str+",");
+		  }
+		}
+		sbu.deleteCharAt(sbu.length() - 1);
+
+		entity.setAttachs(sbu.toString());
+
+		syFabricLossReportService.updateById(entity);
+
+		return 1;
+
+	}
+
 	/**
 	 * 根据委外订单出库价格,设置采购订单-来源余纱,采购订单-其他入库的纱
 	 * @param fabricLoss