Эх сурвалжийг харах

询价明细增加封装和生产日期字段,增加单价预算、截止日期【商城】

hejq 8 жил өмнө
parent
commit
ddaf428745

+ 27 - 0
src/main/java/com/uas/ps/inquiry/CorsConfig.java

@@ -0,0 +1,27 @@
+package com.uas.ps.inquiry;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+/**
+ * @author liusw
+ * @version 2018/1/23 16:53
+ */
+@Configuration
+public class CorsConfig extends WebMvcConfigurerAdapter {
+
+    /**
+     * 跨域问题
+     * @param registry
+     */
+    @Override
+    public void addCorsMappings(final CorsRegistry registry) {
+        registry.addMapping("/**")
+                .allowedOrigins("*")
+                .allowCredentials(true)
+                .allowedMethods("GET", "POST", "DELETE", "PUT")
+                .maxAge(3600);
+    }
+
+}

+ 30 - 0
src/main/java/com/uas/ps/inquiry/RepositoryConfiguration.java

@@ -0,0 +1,30 @@
+package com.uas.ps.inquiry;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+
+import javax.sql.DataSource;
+
+/**
+ * @author sunyj
+ * @since 2018/1/13 16:26
+ */
+@Configuration
+@EnableJpaRepositories
+public class RepositoryConfiguration {
+
+    @Autowired
+    private DataSource dataSource;
+
+    @Bean
+    @Primary
+    public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) {
+        return builder.dataSource(dataSource)
+                .packages("com.uas.ps.entity", "com.uas.ps.inquiry.**.*").build();
+    }
+}

+ 6 - 0
src/main/java/com/uas/ps/inquiry/controller/PublicInquiryController.java

@@ -159,6 +159,12 @@ public class PublicInquiryController {
     public Page<PurcInquiryItemInfo> getInquiry(PageInfo pageInfo, SearchFilter searchFilter) {
         Sort sort = new Sort(Sort.Direction.DESC, "date");
         pageInfo.setSort(sort);
+        if (null != searchFilter.getUserUU()) {
+            pageInfo.filter("userUU", searchFilter.getUserUU());
+        }
+        if (null != searchFilter.getEnUU()) {
+            pageInfo.filter("inquiry.enUU", searchFilter.getEnUU());
+        }
         return publicInquiryService.findTodoByPageInfo(pageInfo, searchFilter);
     }
 

+ 1 - 1
src/main/java/com/uas/ps/inquiry/dao/ProductDao.java

@@ -1,6 +1,6 @@
 package com.uas.ps.inquiry.dao;
 
-import com.uas.ps.inquiry.model.Product;
+import com.uas.ps.entity.Product;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.stereotype.Repository;

+ 0 - 277
src/main/java/com/uas/ps/inquiry/model/Product.java

@@ -1,277 +0,0 @@
-package com.uas.ps.inquiry.model;
-
-import javax.persistence.*;
-import java.io.Serializable;
-
-/**
- * 简单物料信息,询价搜索
- *
- * @author hejq
- * @date 2018-01-17 11:19
- */
-@Entity
-@Table(name = "products")
-public class Product implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    @Column(name = "pr_id")
-    private Long id;
-
-    /**
-     * 商品信息标题
-     */
-    @Column(name = "pr_title")
-    private String title;
-
-    /**
-     * TODO unknown?
-     */
-    @Column(name = "pr_detail")
-    private String detail;
-
-    /**
-     * 产品编号
-     */
-    @Column(name = "pr_code")
-    private String code;
-
-    /**
-     * 产品规格
-     */
-    @Column(name = "pr_spec")
-    private String spec;
-
-    /**
-     * 单位
-     */
-    @Column(name = "pr_unit")
-    private String unit;
-
-    /**
-     * 所属企业UU
-     */
-    @Column(name = "pr_enuu")
-    private Long enUU;
-
-    /**
-     * 个人UU 上传人的UU
-     */
-    @Column(name = "pr_useruu")
-    private Long userUU;
-
-    /**
-     * 品牌(ERP) 上传时的品牌
-     */
-    @Column(name = "pr_brand")
-    private String brand;
-
-    /**
-     * 原厂型号(erp) 用户上传的型号
-     */
-    @Column(name = "pr_cmpcode")
-    private String cmpCode;
-
-    /**
-     * UUID 标准料号
-     */
-    @Column(name = "pr_cmpuuid")
-    private String cmpUuid;
-
-    /**
-     * 类目(平台)(中文)
-     */
-    @Column(name = "pr_kind")
-    private String kind;
-
-    /**
-     * 类目(平台)(英文)
-     */
-    @Column(name = "pr_kinden")
-    private String kindEn;
-
-    /**
-     * 品牌(平台)(中文)
-     */
-    @Column(name = "pr_pbrand")
-    private String pBrand;
-
-    /**
-     * 品牌(平台)(英文)
-     */
-    @Column(name = "pr_pbranden")
-    private String pBrandEn;
-
-    /**
-     * 品牌(平台)(uuid)
-     */
-    @Column(name = "pr_pbranduuid")
-    private String pBrandUuid;
-
-    /**
-     * 型号(平台)
-     */
-    @Column(name = "pr_pcmpcode")
-    private String pCmpCode;
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    public String getTitle() {
-        return title;
-    }
-
-    public void setTitle(String title) {
-        this.title = title;
-    }
-
-    public String getDetail() {
-        return detail;
-    }
-
-    public void setDetail(String detail) {
-        this.detail = detail;
-    }
-
-    public String getCode() {
-        return code;
-    }
-
-    public void setCode(String code) {
-        this.code = code;
-    }
-
-    public String getSpec() {
-        return spec;
-    }
-
-    public void setSpec(String spec) {
-        this.spec = spec;
-    }
-
-    public String getUnit() {
-        return unit;
-    }
-
-    public void setUnit(String unit) {
-        this.unit = unit;
-    }
-
-    public Long getEnUU() {
-        return enUU;
-    }
-
-    public void setEnUU(Long enUU) {
-        this.enUU = enUU;
-    }
-
-    public Long getUserUU() {
-        return userUU;
-    }
-
-    public void setUserUU(Long userUU) {
-        this.userUU = userUU;
-    }
-
-    public String getBrand() {
-        return brand;
-    }
-
-    public void setBrand(String brand) {
-        this.brand = brand;
-    }
-
-    public String getCmpCode() {
-        return cmpCode;
-    }
-
-    public void setCmpCode(String cmpCode) {
-        this.cmpCode = cmpCode;
-    }
-
-    public String getCmpUuid() {
-        return cmpUuid;
-    }
-
-    public void setCmpUuid(String cmpUuid) {
-        this.cmpUuid = cmpUuid;
-    }
-
-    public String getKind() {
-        return kind;
-    }
-
-    public void setKind(String kind) {
-        this.kind = kind;
-    }
-
-    public String getKindEn() {
-        return kindEn;
-    }
-
-    public void setKindEn(String kindEn) {
-        this.kindEn = kindEn;
-    }
-
-    public String getpBrand() {
-        return pBrand;
-    }
-
-    public void setpBrand(String pBrand) {
-        this.pBrand = pBrand;
-    }
-
-    public String getpBrandEn() {
-        return pBrandEn;
-    }
-
-    public void setpBrandEn(String pBrandEn) {
-        this.pBrandEn = pBrandEn;
-    }
-
-    public String getpBrandUuid() {
-        return pBrandUuid;
-    }
-
-    public void setpBrandUuid(String pBrandUuid) {
-        this.pBrandUuid = pBrandUuid;
-    }
-
-    public String getpCmpCode() {
-        return pCmpCode;
-    }
-
-    public void setpCmpCode(String pCmpCode) {
-        this.pCmpCode = pCmpCode;
-    }
-
-    @Override
-    public String toString() {
-        return "Product{" +
-                "id=" + id +
-                ", title='" + title + '\'' +
-                ", detail='" + detail + '\'' +
-                ", code='" + code + '\'' +
-                ", spec='" + spec + '\'' +
-                ", unit='" + unit + '\'' +
-                ", enUU=" + enUU +
-                ", userUU=" + userUU +
-                ", brand='" + brand + '\'' +
-                ", cmpCode='" + cmpCode + '\'' +
-                ", cmpUuid='" + cmpUuid + '\'' +
-                ", kind='" + kind + '\'' +
-                ", kindEn='" + kindEn + '\'' +
-                ", pBrand='" + pBrand + '\'' +
-                ", pBrandEn='" + pBrandEn + '\'' +
-                ", pBrandUuid='" + pBrandUuid + '\'' +
-                ", pCmpCode='" + pCmpCode + '\'' +
-                '}';
-    }
-}

+ 10 - 10
src/main/java/com/uas/ps/inquiry/model/PublicInquiryInfo.java

@@ -115,9 +115,9 @@ public class PublicInquiryInfo implements Serializable {
 	/**
 	 * 附件
 	 */
-	@OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
-	@JoinTable(name = "publicinquiry$attach", joinColumns = @JoinColumn(name = "in_id", referencedColumnName = "in_id"), inverseJoinColumns = @JoinColumn(name="at_id", referencedColumnName = "at_id"))
-	private Set<Attach> attachs;
+//	@OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
+//	@JoinTable(name = "publicinquiry$attach", joinColumns = @JoinColumn(name = "in_id", referencedColumnName = "in_id"), inverseJoinColumns = @JoinColumn(name="at_id", referencedColumnName = "at_id"))
+//	private Set<Attach> attachs;
 
 	/**
 	 * 客户已提交
@@ -277,13 +277,13 @@ public class PublicInquiryInfo implements Serializable {
 		this.inquiryItems = inquiryItems;
 	}
 
-	public Set<Attach> getAttachs() {
-		return attachs;
-	}
-
-	public void setAttachs(Set<Attach> attachs) {
-		this.attachs = attachs;
-	}
+//	public Set<Attach> getAttachs() {
+//		return attachs;
+//	}
+//
+//	public void setAttachs(Set<Attach> attachs) {
+//		this.attachs = attachs;
+//	}
 
 	public String getEnvironment() {
 		return environment;

+ 1 - 0
src/main/java/com/uas/ps/inquiry/model/PublicInquiryItem.java

@@ -2,6 +2,7 @@ package com.uas.ps.inquiry.model;
 
 import com.alibaba.fastjson.annotation.JSONField;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.uas.ps.entity.Product;
 import com.uas.ps.entity.Status;
 import com.uas.ps.inquiry.entity.Constant;
 import com.uas.ps.inquiry.util.DateUtils;

+ 140 - 46
src/main/java/com/uas/ps/inquiry/model/PublicInquiryItemInfo.java

@@ -1,6 +1,8 @@
 package com.uas.ps.inquiry.model;
 
 
+import com.uas.ps.entity.Product;
+
 import javax.persistence.*;
 import java.io.Serializable;
 import java.util.*;
@@ -309,6 +311,42 @@ public class PublicInquiryItemInfo implements Serializable {
     @OrderBy("lapQty")
     private List<PublicInquiryReplyInfo> replies;
 
+	/**
+	 * 封装
+	 */
+	@Column(name = "id_encapsulation")
+	private String encapsulation;
+
+    /**
+     * 单价预算
+     */
+    @Column(name = "id_unitprice")
+    private Double unitPrice;
+
+    /**
+     * 封装
+     */
+    @Column(name = "id_sort")
+    private String sort;
+
+    /**
+     * 产品生产日期
+     */
+    @Column(name = "id_producedate")
+    private String produceDate;
+
+    /**
+     * 物料报价数量(记录多少人或企业对该物料进行报价)
+     */
+    @Column(name = "id_offeramount")
+    private Integer offerAmount;
+
+    /**
+     * 截止日期
+     */
+    @Column(name = "id_enddate")
+    private Date endDate;
+
 	public Long getId() {
 		return id;
 	}
@@ -662,51 +700,107 @@ public class PublicInquiryItemInfo implements Serializable {
         this.replies = replies;
     }
 
+    public String getEncapsulation() {
+        return encapsulation;
+    }
+
+    public void setEncapsulation(String encapsulation) {
+        this.encapsulation = encapsulation;
+    }
+
+    public Double getUnitPrice() {
+        return unitPrice;
+    }
+
+    public void setUnitPrice(Double unitPrice) {
+        this.unitPrice = unitPrice;
+    }
+
+    public String getSort() {
+        return sort;
+    }
+
+    public void setSort(String sort) {
+        this.sort = sort;
+    }
+
+    public String getProduceDate() {
+        return produceDate;
+    }
+
+    public void setProduceDate(String produceDate) {
+        this.produceDate = produceDate;
+    }
+
+    public Integer getOfferAmount() {
+        return offerAmount;
+    }
+
+    public void setOfferAmount(Integer offerAmount) {
+        this.offerAmount = offerAmount;
+    }
+
+    public Date getEndDate() {
+        return endDate;
+    }
+
+    public void setEndDate(Date endDate) {
+        this.endDate = endDate;
+    }
+
     @Override
-	public String toString() {
-		return "PublicInquiryItemInfo{" +
-				"id=" + id +
-				", sourceId=" + sourceId +
-				", number=" + number +
-				", inquiry=" + inquiry +
-				", userUU=" + userUU +
-				", productId=" + productId +
-				", product=" + product +
-				", prodCode='" + prodCode + '\'' +
-				", currency='" + currency + '\'' +
-				", taxrate=" + taxrate +
-				", remark='" + remark + '\'' +
-				", vendUU=" + vendUU +
-				", enterprise=" + enterprise +
-				", vendUserUU=" + vendUserUU +
-				", fromDate=" + fromDate +
-				", toDate=" + toDate +
-				", vendFromDate=" + vendFromDate +
-				", vendToDate=" + vendToDate +
-				", minOrderQty=" + minOrderQty +
-				", minPackQty=" + minPackQty +
-				", brand='" + brand + '\'' +
-				", vendorprodcode='" + vendorprodcode + '\'' +
-				", leadtime=" + leadtime +
-				", status=" + status +
-				", sendStatus=" + sendStatus +
-				", backStatus=" + backStatus +
-				", replySendStatus=" + replySendStatus +
-				", agreed=" + agreed +
-				", decideStatus=" + decideStatus +
-				", invalidStatus=" + invalidStatus +
-				", custLap=" + custLap +
-				", erpDate=" + erpDate +
-				", date=" + date +
-				", overdue=" + overdue +
-				", invalid=" + invalid +
-				", source='" + source + '\'' +
-				", needquantity=" + needquantity +
-				", erpstatus=" + erpstatus +
-				", kind='" + kind + '\'' +
-				", vendName='" + vendName + '\'' +
-				", businessCode='" + businessCode + '\'' +
-				", offerTime=" + offerTime +
-				'}';
-	}
+    public String toString() {
+        return "PublicInquiryItemInfo{" +
+                "id=" + id +
+                ", sourceId=" + sourceId +
+                ", number=" + number +
+                ", inquiry=" + inquiry +
+                ", userUU=" + userUU +
+                ", productId=" + productId +
+                ", product=" + product +
+                ", prodCode='" + prodCode + '\'' +
+                ", currency='" + currency + '\'' +
+                ", taxrate=" + taxrate +
+                ", remark='" + remark + '\'' +
+                ", vendUU=" + vendUU +
+                ", enterprise=" + enterprise +
+                ", vendUserUU=" + vendUserUU +
+                ", fromDate=" + fromDate +
+                ", toDate=" + toDate +
+                ", vendFromDate=" + vendFromDate +
+                ", vendToDate=" + vendToDate +
+                ", minOrderQty=" + minOrderQty +
+                ", minPackQty=" + minPackQty +
+                ", brand='" + brand + '\'' +
+                ", vendorprodcode='" + vendorprodcode + '\'' +
+                ", leadtime=" + leadtime +
+                ", status=" + status +
+                ", sendStatus=" + sendStatus +
+                ", backStatus=" + backStatus +
+                ", replySendStatus=" + replySendStatus +
+                ", agreed=" + agreed +
+                ", decideStatus=" + decideStatus +
+                ", invalidStatus=" + invalidStatus +
+                ", custLap=" + custLap +
+                ", erpDate=" + erpDate +
+                ", date=" + date +
+                ", overdue=" + overdue +
+                ", invalid=" + invalid +
+                ", source='" + source + '\'' +
+                ", qutoApp='" + qutoApp + '\'' +
+                ", needquantity=" + needquantity +
+                ", erpstatus=" + erpstatus +
+                ", kind='" + kind + '\'' +
+                ", vendName='" + vendName + '\'' +
+                ", businessCode='" + businessCode + '\'' +
+                ", offerTime=" + offerTime +
+                ", replies=" + replies +
+                ", encapsulation='" + encapsulation + '\'' +
+                ", unitPrice=" + unitPrice +
+                ", sort='" + sort + '\'' +
+                ", produceDate='" + produceDate + '\'' +
+                ", offerAmount=" + offerAmount +
+                ", endDate=" + endDate +
+                '}';
+    }
 }

+ 46 - 0
src/main/java/com/uas/ps/inquiry/model/PurcInquiryItem.java

@@ -2,6 +2,7 @@ package com.uas.ps.inquiry.model;
 
 import com.alibaba.fastjson.annotation.JSONField;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.uas.ps.entity.Product;
 
 import javax.persistence.*;
 import java.util.*;
@@ -292,6 +293,24 @@ public class PurcInquiryItem {
 	@Column(name = "id_producedate")
 	private String produceDate;
 
+    /**
+     * 物料报价数量(记录多少人或企业对该物料进行报价)
+     */
+	@Column(name = "id_offeramount")
+    private Integer offerAmount;
+
+    /**
+     * 封装
+     */
+	@Column(name = "id_encapsulation")
+    private String encapsulation;
+
+    /**
+     * 截止日期
+     */
+	@Column(name = "id_enddate")
+    private Date endDate;
+
 	public Long getId() {
 		return id;
 	}
@@ -646,6 +665,30 @@ public class PurcInquiryItem {
         this.produceDate = produceDate;
     }
 
+    public Integer getOfferAmount() {
+        return offerAmount;
+    }
+
+    public void setOfferAmount(Integer offerAmount) {
+        this.offerAmount = offerAmount;
+    }
+
+    public String getEncapsulation() {
+        return encapsulation;
+    }
+
+    public void setEncapsulation(String encapsulation) {
+        this.encapsulation = encapsulation;
+    }
+
+    public Date getEndDate() {
+        return endDate;
+    }
+
+    public void setEndDate(Date endDate) {
+        this.endDate = endDate;
+    }
+
     public static List<PurcInquiry> distinct(List<PurcInquiryItem> inquiryItems) {
 		List<PurcInquiry> inquiries = new ArrayList<>();
 		Set<Long> keys = new HashSet<>();
@@ -705,6 +748,9 @@ public class PurcInquiryItem {
                 ", offerTime=" + offerTime +
                 ", sort='" + sort + '\'' +
                 ", produceDate='" + produceDate + '\'' +
+                ", offerAmount=" + offerAmount +
+                ", encapsulation='" + encapsulation + '\'' +
+                ", endDate=" + endDate +
                 '}';
     }
 }

+ 17 - 1
src/main/java/com/uas/ps/inquiry/model/PurcInquiryItemInfo.java

@@ -1,6 +1,8 @@
 package com.uas.ps.inquiry.model;
 
 
+import com.uas.ps.entity.Product;
+
 import javax.persistence.*;
 import java.util.*;
 
@@ -291,6 +293,12 @@ public class PurcInquiryItemInfo {
 	@Column(name = "id_producedate")
 	private String produceDate;
 
+    /**
+     * 封装
+     */
+    @Column(name = "id_encapsulation")
+    private String encapsulation;
+
 	public Long getId() {
 		return id;
 	}
@@ -643,7 +651,15 @@ public class PurcInquiryItemInfo {
 		this.produceDate = produceDate;
 	}
 
-	public static List<PurcInquiryInfo> distinct(List<PurcInquiryItemInfo> inquiryItems) {
+    public String getEncapsulation() {
+        return encapsulation;
+    }
+
+    public void setEncapsulation(String encapsulation) {
+        this.encapsulation = encapsulation;
+    }
+
+    public static List<PurcInquiryInfo> distinct(List<PurcInquiryItemInfo> inquiryItems) {
 		List<PurcInquiryInfo> inquiries = new ArrayList<>();
 		Set<Long> keys = new HashSet<>();
 		for (PurcInquiryItemInfo item : inquiryItems) {

+ 26 - 3
src/main/java/com/uas/ps/inquiry/service/impl/InquiryServiceImpl.java

@@ -1,6 +1,7 @@
 package com.uas.ps.inquiry.service.impl;
 
 import com.uas.ps.core.util.CollectionUtils;
+import com.uas.ps.entity.Product;
 import com.uas.ps.inquiry.dao.*;
 import com.uas.ps.inquiry.entity.InquiryDetailInfo;
 import com.uas.ps.inquiry.entity.InquiryProductInfo;
@@ -11,6 +12,7 @@ import com.uas.ps.inquiry.page.criteria.CriterionExpression;
 import com.uas.ps.inquiry.page.criteria.LogicalExpression;
 import com.uas.ps.inquiry.page.criteria.PredicateUtils;
 import com.uas.ps.inquiry.page.criteria.SimpleExpression;
+import com.uas.ps.inquiry.page.exception.IllegalOperatorException;
 import com.uas.ps.inquiry.service.InquiryService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -48,6 +50,9 @@ public class InquiryServiceImpl implements InquiryService {
     @Autowired
     private ProductDao productDao;
 
+    @Autowired
+    private PurcInquiryItemDao purcInquiryItemDao;
+
     /**
      * 查询公共询价列表信息
      *
@@ -87,11 +92,29 @@ public class InquiryServiceImpl implements InquiryService {
     /**
      * 保存公共询价
      *
-     * @param inquiry 询价信息
+     * @param currentInquiry 询价信息
      */
     @Override
-    public PurcInquiry saveInquiry(PurcInquiry inquiry) {
-        return purcInquiryDao.save(inquiry);
+    public PurcInquiry saveInquiry(PurcInquiry currentInquiry) {
+        PurcInquiry existInquiry = purcInquiryDao.findByCodeAndEnUU(currentInquiry.getCode(), currentInquiry.getEnUU());
+        if (null != existInquiry) {
+            throw new IllegalOperatorException("单号重复");
+        } else {
+            PurcInquiry inquiry = purcInquiryDao.save(currentInquiry);
+            if (!CollectionUtils.isEmpty(currentInquiry.getInquiryItems())) {
+                List<PurcInquiryItem> items = new ArrayList<PurcInquiryItem>();
+                for (PurcInquiryItem item : currentInquiry.getInquiryItems()) {
+                    item.setInquiry(inquiry);
+                    if (null == item.getDate()) {
+                        item.setDate(new Date(System.currentTimeMillis()));
+                    }
+                    items.add(item);
+                }
+                items = purcInquiryItemDao.save(items);
+                System.out.println(items);
+            }
+            return inquiry;
+        }
     }
 
     /**

+ 5 - 3
src/main/java/com/uas/ps/inquiry/service/impl/PublicInquiryServiceImpl.java

@@ -1,8 +1,7 @@
 package com.uas.ps.inquiry.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
-import com.uas.ps.core.util.HttpUtil;
-import com.uas.ps.core.util.exception.FlexJsonUtils;
+import com.uas.ps.entity.Product;
 import com.uas.ps.entity.ProductUsers;
 import com.uas.ps.entity.Status;
 import com.uas.ps.inquiry.dao.*;
@@ -15,6 +14,8 @@ import com.uas.ps.inquiry.page.criteria.LogicalExpression;
 import com.uas.ps.inquiry.page.criteria.PredicateUtils;
 import com.uas.ps.inquiry.page.criteria.SimpleExpression;
 import com.uas.ps.inquiry.service.PublicInquiryService;
+import com.uas.ps.inquiry.util.FlexJsonUtils;
+import com.uas.ps.inquiry.util.HttpUtil;
 import com.uas.ps.inquiry.util.IRunnable;
 import com.uas.ps.inquiry.util.ThreadUtils;
 import javassist.NotFoundException;
@@ -115,7 +116,7 @@ public class PublicInquiryServiceImpl implements PublicInquiryService {
     /**
      * 接收应用
      */
-    private final String CONSUMERAPP = "B2B,MALL";
+    private final String CONSUMERAPP = "B2B,MALL,ERP";
 
     /**
      * 保存公共询价信息
@@ -184,6 +185,7 @@ public class PublicInquiryServiceImpl implements PublicInquiryService {
                             model.setConsumeType(CUST_TYPE);
                             model.setConsumerApp(CONSUMERAPP);
                             model.setContent(content);
+                            model.setRemark("公共询价消息精准推送");
                             model.setReceiverEnuu(user.getEnuu());
                             model.setReceiverUu(u.getUserUU());
                             model.setSenderEnuu(item.getInquiry().getEnUU());

+ 32 - 0
src/main/java/com/uas/ps/inquiry/test/MessageTest.java

@@ -0,0 +1,32 @@
+package com.uas.ps.inquiry.test;
+
+import com.uas.ps.core.util.HttpUtil;
+import com.uas.ps.core.util.exception.FlexJsonUtils;
+import com.uas.ps.inquiry.entity.MessageModel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by hejq on 2018-01-24.
+ */
+public class MessageTest {
+    public static void main(String[] args) throws Exception {
+        MessageModel model = new MessageModel();
+        model.setProducerApp("ERP");
+        model.setConsumeType("MULTI");
+        model.setConsumerApp("B2B,MALL");
+        model.setContent("发布公共询价信息,邀请您参与报价");
+        model.setReceiverEnuu(10041559l);
+        model.setReceiverUu(1000003217l);
+        model.setSenderEnuu(10041166l);
+        model.setSenderUu(1000003217l);
+        model.setSmsType("MAIL_AND_SM_AND_IM");
+        model.setMailTemplate("d94e931b-b699-46d7-8bb2-94604a3352c0");
+        model.setSmTemplate("8cf71d56-09bb-4d60-993e-ed87ce72ec3b");
+        List<MessageModel> modelList = new ArrayList<>();
+        modelList.add(model);
+        String response = HttpUtil.doPost("http://192.168.253.12:24000/message/messages", FlexJsonUtils.toJsonDeep(modelList));
+        System.out.println(response);
+    }
+}

+ 46 - 0
src/main/java/com/uas/ps/inquiry/util/FlexJsonUtils.java

@@ -0,0 +1,46 @@
+package com.uas.ps.inquiry.util;
+
+import flexjson.JSONDeserializer;
+import flexjson.JSONSerializer;
+
+import java.util.*;
+
+public abstract class FlexJsonUtils {
+	public static <T> T fromJson(String json, Class<T> cls) {
+		return new JSONDeserializer<T>().use(null, cls).deserialize(json);
+	}
+
+	public static <K, V> Map<K, V> fromJson(String json) {
+		Map<K, V> map = new HashMap<K, V>();
+		return new JSONDeserializer<Map<K, V>>().use(null, map.getClass()).deserialize(json);
+	}
+
+	public static <K, V> LinkedHashMap<K, V> fromLinkedJson(String json) {
+		Map<K, V> map = new LinkedHashMap<K, V>();
+		return new JSONDeserializer<LinkedHashMap<K, V>>().use(null, map.getClass()).deserialize(json);
+	}
+
+	public String toJson() {
+		return new JSONSerializer().exclude("*.class").serialize(this);
+	}
+
+	public static String toJson(Object obj) {
+		return new JSONSerializer().exclude("*.class").serialize(obj);
+	}
+	
+	public static String toJsonDeep(Object obj) {
+		return new JSONSerializer().exclude("*.class").deepSerialize(obj);
+	}
+
+	public static <T> String toJsonArray(Collection<?> collection) {
+		return new JSONSerializer().exclude("*.class").serialize(collection);
+	}
+	
+	public static <T> List<T> fromJsonArray(String json, Class<?> cls) {
+		return new JSONDeserializer<List<T>>().use(null, ArrayList.class).use("values", cls).deserialize(json);
+	}
+	
+	public static <T> Map<String,T> fromJsonHashMap(String json, Class<?> cls) {
+		return new JSONDeserializer<Map<String,T>>().use(null, HashMap.class).use("values", cls).deserialize(json);
+	}
+}

+ 614 - 0
src/main/java/com/uas/ps/inquiry/util/HttpUtil.java

@@ -0,0 +1,614 @@
+package com.uas.ps.inquiry.util;
+
+import org.apache.http.Consts;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+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.*;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.apache.http.entity.mime.content.FileBody;
+import org.apache.http.entity.mime.content.StringBody;
+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.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
+import org.springframework.http.HttpStatus;
+import org.springframework.util.StreamUtils;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * HTTP工具类,封装http请求
+ * 
+ * @author suntg
+ * @date 2015年3月5日14:20:40
+ */
+public class HttpUtil {
+
+	/**
+	 * 发送GET请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendGetRequest(String url, Map<String, ?> params) throws Exception {
+		return sendGetRequest(url, params, false);
+	}
+
+	/**
+	 * 发送GET请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	@SuppressWarnings("unchecked")
+	public static Response sendGetRequest(String url, Map<String, ?> params, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.GET, url, (Map<String, Object>) params, sign, false);
+	}
+
+	/**
+	 * 暂时先使用这种方法(短信接口调用)
+	 */
+	public static String sendPost(String url, String param) {
+		PrintWriter out = null;
+		BufferedReader in = null;
+		String result = "";
+		try {
+			URL realUrl = new URL(url);
+			// 打开和URL之间的连接
+			URLConnection conn = realUrl.openConnection();
+			// 设置通用的请求属性
+			conn.setRequestProperty("content-type", "application/json");
+			conn.setRequestProperty("accept", "*/*");
+			conn.setRequestProperty("connection", "Keep-Alive");
+			conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+			// 发送POST请求必须设置如下两行
+			conn.setDoOutput(true);
+			conn.setDoInput(true);
+			// 获取URLConnection对象对应的输出流
+			out = new PrintWriter(conn.getOutputStream());
+			// 发送请求参数
+			out.print(param);
+			// flush输出流的缓冲
+			out.flush();
+			// 定义BufferedReader输入流来读取URL的响应
+			in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+			String line;
+			while ((line = in.readLine()) != null) {
+				result += line;
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		// 使用finally块来关闭输出流、输入流
+		finally {
+			try {
+				if (out != null) {
+					out.close();
+				}
+				if (in != null) {
+					in.close();
+				}
+			} catch (IOException ex) {
+				ex.printStackTrace();
+			}
+		}
+		return result;
+	}
+
+	/**
+	 * 发送POST请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPostRequest(String url, Map<String, ?> params) throws Exception {
+		return sendPostRequest(url, params, false);
+	}
+
+	/**
+	 * 发送POST请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	@SuppressWarnings("unchecked")
+	public static Response sendPostRequest(String url, Map<String, ?> params, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.POST, url, (Map<String, Object>) params, sign, true);
+	}
+
+	/**
+	 * 发送POST请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @param encode
+	 *            是否使用URLEncode
+	 * @return
+	 * @throws Exception
+	 */
+	@SuppressWarnings("unchecked")
+	public static Response sendPostRequest(String url, Map<String, ?> params, boolean sign, boolean encode)
+			throws Exception {
+		return sendRequest(RequestMethod.POST, url, (Map<String, Object>) params, sign, encode);
+	}
+
+	/**
+	 * 发送Post请求,直接将List类型放入其中
+	 *
+	 * @param postUrl
+	 * @param formData
+	 * @return
+	 * @throws Exception
+	 */
+	public static String doPost(String postUrl, String formData) throws Exception {
+		HttpClient httpClient = new DefaultHttpClient();
+		HttpPost post = new HttpPost(postUrl);
+		StringEntity postingString = new StringEntity(formData,  HTTP.UTF_8);
+		post.setEntity(postingString);
+		post.setHeader("Content-type", "application/json");
+		HttpResponse response = httpClient.execute(post);
+		String content = EntityUtils.toString(response.getEntity());
+		return content;
+	}
+
+	/**
+	 * 发送DELETE请求
+	 * 
+	 * @param url
+	 * @param params
+	 * 
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendDeleteRequest(String url, Map<String, ?> params) throws Exception {
+		return sendDeleteRequest(url, params, false);
+	}
+
+	/**
+	 * 发送DELETE请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	@SuppressWarnings("unchecked")
+	public static Response sendDeleteRequest(String url, Map<String, ?> params, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.DELETE, url, (Map<String, Object>) params, sign, false);
+	}
+
+	/**
+	 * 发起http请求
+	 *
+	 * @param method
+	 *            请求方法GET、POST、PUT、DELETE
+	 * @param url
+	 *            请求链接
+	 * @param params
+	 *            参数
+	 * @param sign
+	 *            是否签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendRequest(RequestMethod method, String url, Map<String, Object> params, boolean sign,
+                                       boolean encode) throws Exception {
+		switch (method) {
+		case GET:
+			return sendHttpUriRequest(new HttpGet(getRequestUrl(url, params, sign)));
+		case POST:
+			return sendHttpEntityEnclosingRequest(new HttpPost(getRequestUrl(url, sign)), params, encode);
+		case PUT:
+			return sendHttpEntityEnclosingRequest(new HttpPut(getRequestUrl(url, sign)), params, encode);
+		case DELETE:
+			return sendHttpUriRequest(new HttpDelete(getRequestUrl(url, params, sign)));
+		default:
+			return sendHttpUriRequest(new HttpGet(getRequestUrl(url, params, sign)));
+		}
+	}
+
+	/**
+	 * 发起GET、DELETE请求
+	 * 
+	 * @param request
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendHttpUriRequest(HttpRequestBase request) throws Exception {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		CloseableHttpResponse response = null;
+		try {
+			response = httpClient.execute(request);
+			return Response.getResponse(response);
+		} finally {
+			try {
+				httpClient.close();
+			} catch (IOException e) {
+			}
+			if (response != null) {
+				try {
+					response.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+	}
+
+	/**
+	 * 发起POST、PUT请求
+	 * 
+	 * @param request
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendHttpEntityEnclosingRequest(HttpEntityEnclosingRequestBase request,
+                                                          Map<String, Object> params, boolean encode) throws Exception {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		CloseableHttpResponse response = null;
+		try {
+			if (!encode) {
+				request.setEntity(new StringEntity(FlexJsonUtils.toJson(params), ContentType.APPLICATION_JSON));
+			} else {
+				List<NameValuePair> nvps = new ArrayList<NameValuePair>();
+				if (params != null && !params.isEmpty()) {
+					Set<Entry<String, Object>> entrys = params.entrySet();
+					for (Map.Entry<String, Object> entry : entrys) {
+						Object entryValue = entry.getValue();
+						String entryValueStr = null;
+						if (entryValue instanceof String) {
+							entryValueStr = entryValue.toString();
+						} else {
+							entryValueStr = FlexJsonUtils.toJson(entry.getValue());
+						}
+						nvps.add(new BasicNameValuePair(entry.getKey(), URLEncoder.encode(entryValueStr, "UTF-8")));
+					}
+				}
+				request.setEntity(new UrlEncodedFormEntity(nvps));
+			}
+			response = httpClient.execute(request);
+			return Response.getResponse(response);
+		} finally {
+			request.releaseConnection();
+			try {
+				httpClient.close();
+			} catch (IOException e) {
+			}
+			if (response != null) {
+				try {
+					response.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+	}
+
+	/**
+	 * 将请求参数添加到链接中
+	 *
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否签名
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 */
+	public static String getRequestUrl(String url, Map<String, Object> params, boolean sign)
+			throws UnsupportedEncodingException {
+		StringBuilder buf = new StringBuilder(url);
+		if (url.indexOf("?") == -1)
+			buf.append("?");
+		else if (!url.endsWith("&"))
+			buf.append("&");
+		// 如果是GET请求,则请求参数在URL中
+		if (params != null && !params.isEmpty()) {
+			Set<Entry<String, Object>> entrys = params.entrySet();
+			for (Map.Entry<String, Object> entry : entrys) {
+				buf.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue().toString(), "UTF-8"))
+						.append("&");
+			}
+		}
+		if (sign) {
+			// 加时间戳,保持相同请求每次签名均不一样
+			buf.append("_timestamp=").append(System.currentTimeMillis());
+			String message = buf.toString();
+			// 对请求串进行签名
+//			buf.append("&_signature=").append(HmacUtils.encode(message));
+		} else
+			buf.deleteCharAt(buf.length() - 1);
+		return buf.toString();
+	}
+
+	/**
+	 * 将签名信息添加到链接中
+	 *
+	 * @param url
+	 * @param sign
+	 *            是否签名
+	 * @return
+	 */
+	public static String getRequestUrl(String url, boolean sign) {
+		try {
+			return getRequestUrl(url, null, sign);
+		} catch (UnsupportedEncodingException e) {
+		}
+		return null;
+	}
+
+	/**
+	 * 将输入流转为字节数组
+	 * 
+	 * @param inStream
+	 * @return
+	 * @throws Exception
+	 */
+	public static byte[] read2Byte(InputStream inStream) throws Exception {
+		ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
+		byte[] buffer = new byte[1024];
+		int len = 0;
+		while ((len = inStream.read(buffer)) != -1) {
+			outSteam.write(buffer, 0, len);
+		}
+		outSteam.close();
+		inStream.close();
+		return outSteam.toByteArray();
+	}
+
+	/**
+	 * 将输入流转为字符串
+	 * 
+	 * @param inStream
+	 * @return
+	 * @throws Exception
+	 */
+	public static String read2String(InputStream inStream) throws Exception {
+		ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
+		byte[] buffer = new byte[1024];
+		int len = 0;
+		while ((len = inStream.read(buffer)) != -1) {
+			outSteam.write(buffer, 0, len);
+		}
+		try {
+			outSteam.close();
+			inStream.close();
+		} catch (Exception e) {
+
+		}
+		return new String(outSteam.toByteArray(), "UTF-8");
+	}
+
+	/**
+	 * 发送xml数据
+	 * 
+	 * @param path
+	 *            请求地址
+	 * @param xml
+	 *            xml数据
+	 * @param encoding
+	 *            编码
+	 * @return
+	 * @throws Exception
+	 */
+	public static byte[] postXml(String path, String xml, String encoding) throws Exception {
+		byte[] data = xml.getBytes(encoding);
+		URL url = new URL(path);
+		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+		conn.setRequestMethod("POST");
+		conn.setDoOutput(true);
+		conn.setRequestProperty("Content-Type", "text/xml; charset=" + encoding);
+		conn.setRequestProperty("Content-Length", String.valueOf(data.length));
+		conn.setConnectTimeout(5 * 1000);
+		OutputStream outStream = conn.getOutputStream();
+		outStream.write(data);
+		outStream.flush();
+		outStream.close();
+		if (conn.getResponseCode() == HttpStatus.OK.value()) {
+			return read2Byte(conn.getInputStream());
+		}
+		return null;
+	}
+
+	/**
+	 * http上传文件
+	 * 
+	 * @param postUrl
+	 *            请求地址
+	 * @param filePath
+	 *            附件路径
+	 * @param params
+	 *            参数
+	 * @return
+	 * @throws Exception
+	 * @throws IOException
+	 * @throws IllegalStateException
+	 */
+	public static Response upload(String postUrl, String filePath, Map<String, String> params)
+			throws IllegalStateException, IOException, Exception {
+		CloseableHttpClient httpClient = null;
+		CloseableHttpResponse response = null;
+		try {
+			httpClient = HttpClients.createDefault();
+			HttpPost httpPost = new HttpPost(postUrl);
+			FileBody fileBody = new FileBody(new File(filePath));
+			MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+			builder.addPart("file", fileBody);
+			if (params != null) {
+				for (String paramKey : params.keySet()) {
+					StringBody body = new StringBody(params.get(paramKey), ContentType.create("text/plain",
+							Consts.UTF_8));
+					builder.addPart(paramKey, body);
+				}
+			}
+			HttpEntity reqEntity = builder.build();
+			httpPost.setEntity(reqEntity);
+			response = httpClient.execute(httpPost);
+		} finally {
+			try {
+				if (response != null) {
+					response.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+			try {
+				if (httpClient != null) {
+					httpClient.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		return Response.getResponse(response);
+	}
+
+	/**
+	 * 下载
+	 * 
+	 * @param postUrl
+	 * @return
+	 * @throws ClientProtocolException
+	 * @throws IOException
+	 */
+	public static InputStream download(String postUrl) throws ClientProtocolException, IOException {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		HttpGet httpGet = new HttpGet(postUrl);
+		CloseableHttpResponse response = httpClient.execute(httpGet);
+		return response.getEntity().getContent();
+	}
+
+	/**
+	 * 获取请求客户端的IP地址
+	 * 
+	 * @param request
+	 * @return
+	 * @throws Exception
+	 */
+	public static String getIpAddr(HttpServletRequest request) {
+		String ip = request.getHeader("x-forwarded-for");
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getHeader("Proxy-Client-IP");
+		}
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getHeader("WL-Proxy-Client-IP");
+		}
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getHeader("HTTP_CLIENT_IP");
+		}
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+		}
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getRemoteAddr();
+		}
+		return ip;
+	}
+	
+	/**
+	 * POST发送
+	 * 
+	 * @param url
+	 * @param data
+	 * @throws Exception
+	 */
+	public static String post(String url, String data) throws Exception {
+		URL urls = new URL(url);
+		HttpURLConnection http = (HttpURLConnection) urls.openConnection();
+		http.setRequestMethod("POST");
+		http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+		http.setDoOutput(true);
+		http.setDoInput(true);
+		System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
+		System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
+		http.connect();
+		OutputStream os = http.getOutputStream();
+		os.write(data.getBytes("UTF-8"));// 传入参数
+		os.flush();
+		os.close();
+		// 从服务器读取响应
+		String encoding = http.getContentEncoding();
+		if (encoding == null)
+			encoding = "UTF-8";
+		return StreamUtils.copyToString(http.getInputStream(), Charset.forName(encoding));
+	}
+
+	public static class Response {
+		private int statusCode;
+		private String responseText;
+		private HttpResponse response;
+
+		public int getStatusCode() {
+			return statusCode;
+		}
+
+		public void setStatusCode(int statusCode) {
+			this.statusCode = statusCode;
+		}
+
+		public String getResponseText() {
+			return responseText;
+		}
+
+		public void setResponseText(String responseText) {
+			this.responseText = responseText;
+		}
+
+		public HttpResponse getResponse() {
+			return response;
+		}
+
+		public void setResponse(HttpResponse response) {
+			this.response = response;
+		}
+
+		public Response() {
+		}
+
+		public Response(HttpResponse response) throws IllegalStateException, IOException, Exception {
+			this.statusCode = response.getStatusLine().getStatusCode();
+			this.responseText = HttpUtil.read2String(response.getEntity().getContent());
+			this.response = response;
+		}
+
+		public static Response getResponse(HttpResponse response) throws IllegalStateException, IOException, Exception {
+			if (response != null)
+				return new Response(response);
+			return null;
+		}
+	}
+}