소스 검색

1.新增导出功能

WoNiu 4 년 전
부모
커밋
b5f2dec0f9

+ 22 - 10
src/main/java/com/galaxis/manatee/controller/ExcelController.java

@@ -1,6 +1,8 @@
 package com.galaxis.manatee.controller;
 
+import com.galaxis.manatee.dao.ChuanyunProjectAttachmentDao;
 import com.galaxis.manatee.dao.ChuanyunUserDao;
+import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunProjectAttachmentDO;
 import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunUserDO;
 import com.galaxis.manatee.util.ExcelUtils;
 import lombok.extern.slf4j.Slf4j;
@@ -12,7 +14,6 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
@@ -23,27 +24,38 @@ import java.util.List;
 public class ExcelController {
 
     private final ChuanyunUserDao chuanyunUserDao;
+    private final ChuanyunProjectAttachmentDao chuanyunProjectAttachmentDao;
 
-    public ExcelController(ChuanyunUserDao chuanyunUserDao) {
+    public ExcelController(ChuanyunUserDao chuanyunUserDao, ChuanyunProjectAttachmentDao chuanyunProjectAttachmentDao) {
         this.chuanyunUserDao = chuanyunUserDao;
+        this.chuanyunProjectAttachmentDao = chuanyunProjectAttachmentDao;
     }
 
 
     @ResponseBody
     @RequestMapping(value = "/test/exportExcel", method = RequestMethod.GET)
     public void exportExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
-        List<ChuanyunUserDO> list = chuanyunUserDao.findAll();
-        String[] title = {"ID", "姓名", "头像", "工号", "钉钉号"};
+        List<ChuanyunProjectAttachmentDO> list = chuanyunProjectAttachmentDao.findAll();
+        String[] title = {"项目名称", "项目编号", "物料名称", "图片", "英文名","零件归属","数量","单位","未税单价","易耗件","系数","汇率","总价","备注"};
         String filename = "testRecord.xls";
         String sheetName = "sheet1";
-        String[][] content = new String[list.size()][7];
+        String[][] content = new String[list.size()][20];
         try {
             for (int i = 0; i < list.size(); i++) {
-                content[i][0] = String.valueOf(list.get(i).getObjectId());
-                content[i][1] = list.get(i).getName();
-                content[i][2] = list.get(i).getPhoto();
-                content[i][3] = list.get(i).getEmployeeNumber();
-                content[i][4] = list.get(i).getDingTalkAccount();
+                content[i][0] = list.get(i).getProjectName();
+                content[i][1] = list.get(i).getProjectCode();
+                content[i][2] = list.get(i).getMaterialName();
+                content[i][3] = list.get(i).getEnclosureId();
+                content[i][4] = list.get(i).getEnglishName();
+                content[i][5] = list.get(i).getPartsOwnership();
+                content[i][6] = String.valueOf(list.get(i).getQty());
+                content[i][7] = list.get(i).getUnit();
+                content[i][8] = String.valueOf(list.get(i).getUnitPricewithoutTax());
+                content[i][9] = list.get(i).getConsumableParts();
+                content[i][10] = String.valueOf(list.get(i).getCoefficient());
+                content[i][11] = String.valueOf(list.get(i).getExchangeRate());
+                content[i][12] = String.valueOf(list.get(i).getTotalPrice());
+                content[i][13] = list.get(i).getRemarks();
             }
         } catch (Exception e) {
             e.printStackTrace();

+ 10 - 0
src/main/java/com/galaxis/manatee/dao/ChuanyunAttachmentDao.java

@@ -0,0 +1,10 @@
+package com.galaxis.manatee.dao;
+
+import com.galaxis.capsule.util.GalaxisRepository;
+import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunAttachmentDO;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ChuanyunAttachmentDao extends GalaxisRepository<ChuanyunAttachmentDO,String> {
+
+}

+ 7 - 0
src/main/java/com/galaxis/manatee/dao/ChuanyunMaterialDao.java

@@ -30,6 +30,13 @@ public interface ChuanyunMaterialDao extends GalaxisRepository<ChuanyunMaterialD
     List<ChuanyunMaterialDO> findAllByCode(String code);
 
     /**
+     * 根据Id获取物料
+     * @param objectId
+     * @return
+     */
+    ChuanyunMaterialDO findByObjectId(String objectId);
+
+    /**
      * 根据物料编码和版本号获得物料对象
      * @param code  物料编码
      * @param version   版本

+ 11 - 0
src/main/java/com/galaxis/manatee/dao/ChuanyunProjectAttachmentDao.java

@@ -0,0 +1,11 @@
+package com.galaxis.manatee.dao;
+
+import com.galaxis.capsule.util.GalaxisRepository;
+import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunAttachmentDO;
+import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunProjectAttachmentDO;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ChuanyunProjectAttachmentDao extends GalaxisRepository<ChuanyunProjectAttachmentDO,String> {
+
+}

+ 35 - 0
src/main/java/com/galaxis/manatee/entity/chuanyun/data/object/ChuanyunAttachmentDO.java

@@ -0,0 +1,35 @@
+package com.galaxis.manatee.entity.chuanyun.data.object;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.extern.slf4j.Slf4j;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import java.util.List;
+
+@Slf4j
+@EqualsAndHashCode(callSuper = true)
+@Data
+@Entity(name = "CHUANYUN_ATTACHMENT")
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ChuanyunAttachmentDO extends BasicDO{
+
+    /**
+     * 表名
+     */
+    public static final String SCHEMA_CODE ="D001789cea86f1498ff41609385ef7390053e56";
+
+    @JsonProperty("F0000001")
+    private String projectId;
+
+    @JsonProperty("F0000011")
+    private String projectCode;
+
+    @JsonProperty("D001789F04b79f0c4b174fa6b482dc624c8124ae")
+    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
+    List<ChuanyunAttachmentDetailDO> list;
+}

+ 68 - 0
src/main/java/com/galaxis/manatee/entity/chuanyun/data/object/ChuanyunAttachmentDetailDO.java

@@ -0,0 +1,68 @@
+package com.galaxis.manatee.entity.chuanyun.data.object;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.extern.slf4j.Slf4j;
+
+import javax.persistence.Entity;
+import java.math.BigDecimal;
+
+@Slf4j
+@EqualsAndHashCode(callSuper = true)
+@Data
+@Entity(name = "CHUANYUN_ATTACHMENT_DETAIL")
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ChuanyunAttachmentDetailDO extends BasicSubDO{
+
+    /**
+     * 表名
+     */
+    public static final String SCHEMA_CODE ="D001789F04b79f0c4b174fa6b482dc624c8124ae";
+
+
+    @JsonProperty("F0000002")
+    private String materialCode;
+
+    @JsonProperty("F0000008")
+    private String photo;
+
+    @JsonProperty("F0000016")
+    private String materialName;
+
+    @JsonProperty("F0000009")
+    private String englishName;
+
+    @JsonProperty("F0000006")
+    private String PartsOwnership;
+
+    @JsonProperty("F0000003")
+    private BigDecimal qty;
+
+    @JsonProperty("F0000005")
+    private String unit;
+
+    @JsonProperty("F0000004")
+    private BigDecimal UnitPricewithoutTax;
+
+    @JsonProperty("F0000010")
+    private String consumableParts;
+
+    @JsonProperty("F0000007")
+    private String remarks;
+
+    @JsonProperty("F0000012")
+    private String enclosureId;
+
+    @JsonProperty("F0000013")
+    private BigDecimal coefficient;
+
+    @JsonProperty("F0000014")
+    private BigDecimal exchangeRate;
+
+    @JsonProperty("F0000015")
+    private BigDecimal totalPrice;
+
+
+}

+ 54 - 0
src/main/java/com/galaxis/manatee/entity/chuanyun/data/object/ChuanyunProjectAttachmentDO.java

@@ -0,0 +1,54 @@
+package com.galaxis.manatee.entity.chuanyun.data.object;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import java.math.BigDecimal;
+
+@Slf4j
+@Data
+@Entity(name = "CHUANYUN_PROJECT_ATTACHMENT")
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ChuanyunProjectAttachmentDO {
+
+    @Id
+    @GeneratedValue(generator = "idGeneratorUser")
+    @GenericGenerator(name ="idGeneratorUser" ,strategy="com.galaxis.capsule.util.GalaxisIdGenerator")
+    private Long objectId;
+
+    private String projectName;
+
+    private String projectCode;
+
+    private String materialCode;
+
+    private String materialName;
+
+    private String enclosureId;
+
+    private String englishName;
+
+    private String PartsOwnership;
+
+    private BigDecimal qty;
+
+    private String unit;
+
+    private BigDecimal UnitPricewithoutTax;
+
+    private String consumableParts;
+
+    private String remarks;
+
+    private BigDecimal coefficient;
+
+    private BigDecimal exchangeRate;
+
+    private BigDecimal totalPrice;
+}

+ 0 - 3
src/main/java/com/galaxis/manatee/entity/chuanyun/data/object/ChuanyunUserDO.java

@@ -38,9 +38,6 @@ public class ChuanyunUserDO extends BasicDO{
      */
     @JsonProperty(value = "Title")
     private String title;
-    
-    
-    private String photo;
 
     /**
      * 工号

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 63 - 1
src/main/java/com/galaxis/manatee/task/ChuanyunBasicDataScheduledTask.java


+ 53 - 41
src/main/java/com/galaxis/manatee/util/ExcelUtils.java

@@ -5,16 +5,8 @@ import java.io.*;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.net.*;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -22,6 +14,7 @@ import java.util.stream.Stream;
 import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.galaxis.manatee.entity.chuanyun.dto.ExcelColumn;
 import org.apache.commons.collections.CollectionUtils;
 
@@ -29,6 +22,21 @@ import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.CharUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
+import org.apache.http.*;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.client.utils.URIUtils;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
 import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.usermodel.Picture;
@@ -89,51 +97,30 @@ public class ExcelUtils {
             row = sheet.createRow(i + 1);
             for (int j = 0; j < values[i].length; j++) {
                 //生成图片
-                if (j==2){
-//                    URL url = new URL(values[i][j]);
-//                    //打开链接
-//                    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
-//                    //设置请求方式为"GET"
-//                    conn.setRequestMethod("GET");
-//                    //超时响应时间为5秒
-//                    conn.setConnectTimeout(5 * 1000);
-//                    //通过输入流获取图片数据
-//                    InputStream inStream = conn.getInputStream();
-//                    //得到图片的二进制数据,以二进制封装得到数据,具有通用性
-//                    byte[] data = readInputStream(inStream);
-//                    log.warn(data.toString());
-//                    //anchor主要用于设置图片的属性
-//                    HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 1023, 250,(short) 2, i, (short) 3, i+1);
-//                    //Sets the anchor type (图片在单元格的位置)
-//                    //0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
-//                    anchor.setAnchorType(0);
-//                    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
-//                    patriarch.createPicture(anchor, wb.addPicture(data, HSSFWorkbook.PICTURE_TYPE_PNG));
-//                    Sheet first=wb.createSheet("first");
+                if (j==3){
+
                     Drawing drawing=sheet.createDrawingPatriarch();
 
                     CreationHelper creationHelper=wb.getCreationHelper();
 
                     ClientAnchor clientAnchor=creationHelper.createClientAnchor();
-                    clientAnchor.setCol1(2);
+                    clientAnchor.setCol1(3);
                     clientAnchor.setRow1(i);
-                    //获取图片
-                    BufferedInputStream in = new BufferedInputStream(new URL("https://lmichelin.fr/content/images/size/w2000/2019/05/5c1bb7dd5e7cc9678fcdc39f_Hello-World-Header.png").openStream());
-                    BufferedImage bufferedImage= ImageIO.read(in);
-
-
-                    InputStream inputStream=new BufferedInputStream(new URL("https://lmichelin.fr/content/images/size/w2000/2019/05/5c1bb7dd5e7cc9678fcdc39f_Hello-World-Header.png").openStream());
+//                    //获取图片
+//                    BufferedInputStream in = new BufferedInputStream(new URL("https://lmichelin.fr/content/images/size/w2000/2019/05/5c1bb7dd5e7cc9678fcdc39f_Hello-World-Header.png").openStream());
+//                    BufferedImage bufferedImage= ImageIO.read(in);
+//                    sendRequest(values[i][j]);
+                    InputStream inputStream=new FileInputStream("save.jpg");
                     byte[] bytes= IOUtils.toByteArray(inputStream);
                     int helloWorldIndex=wb.addPicture(bytes,Workbook.PICTURE_TYPE_PNG);
                     inputStream.close();
 
                     //获取图片尺寸,用于修改单元格大小
-//                    int width=bufferedImage.getWidth();
-                    int height=bufferedImage.getHeight();
+//                    int height=bufferedImage.getHeight();
                     inputStream.close();
                     Picture picture = drawing.createPicture(clientAnchor,helloWorldIndex);
                     picture.resize();
-                    row.setHeight((short)(height*15));
+//                    row.setHeight((short)(height*15));
                 }else{
                     //将内容按顺序赋给对应的列对象
                     row.createCell(j).setCellValue(values[i][j]);
@@ -143,6 +130,31 @@ public class ExcelUtils {
         return wb;
     }
 
+
+    public static void sendRequest() throws URISyntaxException, IOException {
+        HttpClient httpClient = new DefaultHttpClient();
+
+        String url = "https://www.h3yun.com/Api/DownloadBizObjectFile";
+
+        URIBuilder uriBuilder = new URIBuilder(url);
+        List<NameValuePair> list = new LinkedList<>();
+        BasicNameValuePair param1 = new BasicNameValuePair("attachmentId", "fc6abff0-4914-4eda-a0fa-c481094f0d79");
+        BasicNameValuePair param2 = new BasicNameValuePair("EngineCode", "qgvjpgbs50powyd6xyzxzakg3");
+        list.add(param1);
+        list.add(param2);
+        uriBuilder.setParameters(list);
+        HttpUriRequest request = new HttpPost(uriBuilder.build());
+        request.setHeader("EngineCode","qgvjpgbs50powyd6xyzxzakg3");
+        request.setHeader("EngineSecret","BsuPomgoblb0gDdrCBmzkq5KcWlz+2OXgetN1gFgnZgXmdgHdDpGgA==");
+        HttpResponse response = httpClient.execute(request);
+        InputStream stream = response.getEntity().getContent();
+        BufferedImage bufferedImage= ImageIO.read(stream);
+        File outputfile  = new File("save.jpg");
+        ImageIO.write(bufferedImage,"jpeg",outputfile);
+    }
+
+
+
     /**
      * 导入Excel
      * @param path