浏览代码

陪验开发11

zhoutao 5 年之前
父节点
当前提交
8eb210ea9c

+ 123 - 0
pigx-inventory/pigx-inventory-biz/src/main/java/com/pig4cloud/pigx/qa/controller/InspectionApplyController.java

@@ -0,0 +1,123 @@
+package com.pig4cloud.pigx.qa.controller;
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.pig4cloud.pigx.qa.entity.InspectionApply;
+import com.pig4cloud.pigx.qa.fastdfs.FastDFSClient;
+import com.pig4cloud.pigx.qa.service.InspectionApplyService;
+import com.pig4cloud.pigx.common.core.util.R;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.models.Response;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * 陪验申请
+ *
+ * @author 周涛·
+ * @date 2019-04-15 10:25:32
+ */
+@RestController
+@AllArgsConstructor
+@Api(value = "isnspection",tags = "陪验申请")
+@RequestMapping("/isnspection" )
+public class InspectionApplyController {
+
+	private final InspectionApplyService inspectionApplyService;
+	/**
+	 * 分页查询
+	 *
+	 * @return R
+	 */
+	@GetMapping("/page" )
+	@ApiOperation(value = "陪验列表",produces = "text/plain;charset=UTF-8")
+	public R getInspectionApply(Page page, @RequestParam(required = false) String dateStart,
+                                @RequestParam(required = false) String dateEnd,
+                                @RequestParam(required = false) Integer sId,
+                                @RequestParam(required = false) Integer eId,
+                                @RequestParam(required = false) String scCode,
+                                @RequestParam(required = false) String poCode,
+                                @RequestParam(required = false) String areaCode, Response response)  {
+
+		Page results = inspectionApplyService.getByParm(scCode,poCode,sId,eId,dateStart,dateEnd,null,areaCode,page) ;
+		List<InspectionApply> inspectionApplys = results.getRecords();
+		for (InspectionApply inspectionApply :inspectionApplys ){
+			if (!StrUtil.isBlank( inspectionApply.getInspector())){
+				inspectionApply.setInspector(Base64.encode(inspectionApply.getInspector()));
+			}
+			if (inspectionApply.getCheckResult()!=null){
+				switch (inspectionApply.getCheckResult().intValue()){
+					case 1:inspectionApply.setCheckResultName("Pass");break;
+					case 2:inspectionApply.setCheckResultName("质量问题");break;
+					case 3:inspectionApply.setCheckResultName("Pending");break;
+					case 4:inspectionApply.setCheckResultName("GL");break;
+					case 5:inspectionApply.setCheckResultName("数量不足");break;
+					case 6:inspectionApply.setCheckResultName("客户接受");break;
+				}
+
+			}
+		}
+
+
+		List<String> strings=new ArrayList<>();
+		inspectionApplys.forEach(k->strings.add(JSONObject.toJSONString(k)));
+
+		results.setRecords(strings);
+
+		return R.ok(results);
+	}
+
+	@PostMapping("mobile/picture" )
+	@ApiOperation(value = "陪验员上传图片")
+	public R addSampleDocumentBySdId(@RequestParam("scId" ) Integer scId,
+									 @RequestParam(value = "file",required = false) MultipartFile file) throws IOException {
+		List<String> urls=new ArrayList<>();
+		String filename = file.getOriginalFilename();
+		String fileExt = filename.substring(filename.lastIndexOf(".") + 1);
+		String url = FastDFSClient.upload(file.getBytes(), fileExt);
+		urls.add(url);
+
+
+		//StringBuffer string=new StringBuffer();
+		//for (String file:files){
+			//if (StrUtil.startWith(file,"http://")){
+			//	string.append(file).append(",");
+		//	}else {
+			//	byte[] decode = Base64.decode(file);
+			//	String picture = FastDFSClient.upload(decode, "png");
+			//	string.append(picture).append(",");
+			//}
+		//}
+		List<InspectionApply> inspectionApplies = inspectionApplyService.getbyScIdBetweenThisWeek(scId);
+
+		if (!inspectionApplies.isEmpty()){
+			inspectionApplies.forEach(k->{
+				if (!StrUtil.isBlank(k.getPicture())){
+					List<String> oldUrls = Arrays.asList(k.getPicture().split(","));
+					urls.addAll(oldUrls);
+				}
+				k.setPicture(String.join(",",urls));
+				inspectionApplyService.updateById(k);
+			});
+		}else {
+			InspectionApply inspectionApply = new InspectionApply();
+			inspectionApply.setScId(scId);
+			inspectionApply.setPicture(String.join(",",urls));
+
+			inspectionApplyService.save(inspectionApply);
+		}
+		return R.ok();
+
+
+
+	}
+
+
+}