|
|
@@ -1,11 +1,20 @@
|
|
|
package com.uas.erp.schedular.publicinquiry.task;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.uas.erp.schedular.b2b.domain.QuotationDownDecide;
|
|
|
import com.uas.erp.schedular.database.RestJdbcTemplate;
|
|
|
+import com.uas.erp.schedular.publicinquiry.domain.PublicInquiryItem;
|
|
|
+import com.uas.erp.schedular.publicinquiry.domain.PublicInquiryReply;
|
|
|
import com.uas.erp.schedular.task.support.TaskMapping;
|
|
|
+import com.uas.erp.schedular.util.CollectionUtil;
|
|
|
+import com.uas.erp.schedular.util.ContextHolder;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.InputStreamReader;
|
|
|
@@ -16,11 +25,221 @@ import java.util.*;
|
|
|
|
|
|
@Component
|
|
|
@TaskMapping(title = "商机")
|
|
|
-public class EnterInquiryTask {
|
|
|
+public class EnterInquiryTask extends AbstractTask{
|
|
|
|
|
|
@Autowired
|
|
|
private RestJdbcTemplate jdbcTemplate;
|
|
|
|
|
|
+ @TaskMapping(title = "从公共服务下载买家对报价信息是否采纳的决策", fixedDelay = 60000)
|
|
|
+ public void dowmInquiryDecide(){
|
|
|
+ int enUU = jdbcTemplate.getInt("select en_uu from enterprise");
|
|
|
+ List<PublicInquiryItem> downs = getForList("/inquiry/public/down/decide?enUU="+enUU, PublicInquiryItem.class);
|
|
|
+ if(!CollectionUtils.isEmpty(downs)){
|
|
|
+ ContextHolder.setDataSize(downs.size());
|
|
|
+ saveQuotationDecide(downs);
|
|
|
+ // 回执
|
|
|
+ onDownloadReplyDecide(downs, enUU);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存从公共服务下载的采纳结果
|
|
|
+ */
|
|
|
+ private void saveQuotationDecide(List<PublicInquiryItem> downs) {
|
|
|
+ List<String> sqls = new ArrayList<String>();
|
|
|
+ for (PublicInquiryItem decide : downs) {
|
|
|
+ Integer id = jdbcTemplate.getInt("select * from quotationdown where b2b_id_id = ?", decide.getId());
|
|
|
+ if (null != id) {
|
|
|
+ sqls.add("update QuotationDown set qu_agreed=" + decide.getAgreed() + " where qu_id=" + id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jdbcTemplate.batchExecute(sqls);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将从公共服务下载的采纳结果保存成功之后,回执给平台
|
|
|
+ * @param downs
|
|
|
+ */
|
|
|
+ private void onDownloadReplyDecide(List<PublicInquiryItem> downs, Integer enUU) {
|
|
|
+ String idStr = CollectionUtil.getKeyString(downs, new CollectionUtil.KeyIterator<PublicInquiryItem>() {
|
|
|
+ @Override
|
|
|
+ public Object getKey(PublicInquiryItem obj) {
|
|
|
+ return obj.getId();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
|
|
+ map.set("enUU", String.valueOf(enUU));
|
|
|
+ map.set("ids", idStr);
|
|
|
+ post("/inquiry/public/down/decide/back", map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将报价方在商城(或B2B)报价的单据同步到报价方UAS
|
|
|
+ */
|
|
|
+ @TaskMapping(title = "将报价方在商城(或B2B)报价的单据同步到报价方UAS", fixedDelay = 60000)
|
|
|
+ public void downInquiryReply(){
|
|
|
+ String enUU = jdbcTemplate.getString("select en_uu from enterprise");
|
|
|
+ String userUU = jdbcTemplate.getString("select en_adminuu from enterprise");
|
|
|
+ List<PublicInquiryItem> data = getForList("/inquiry/public/down/reply?enUU="+enUU, PublicInquiryItem.class);
|
|
|
+ for(PublicInquiryItem publicInquiryItem : data){
|
|
|
+ int count = jdbcTemplate.getInt("select count(*) from businesschance where bc_fromid = ?", publicInquiryItem.getSourceId());
|
|
|
+ if(count == 0){ //若UAS未转企业商机
|
|
|
+ turnBusinesschange(publicInquiryItem, enUU, userUU);
|
|
|
+ //回传给平台,进行商机分配
|
|
|
+ MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
|
|
+ map.set("userUU", userUU);
|
|
|
+ map.set("enUU", enUU);
|
|
|
+ map.set("itemId", String.valueOf(publicInquiryItem.getId()));
|
|
|
+ post("inquiry/sale/allot/enremind", map);
|
|
|
+ }else{ //若UAS已转企业商机
|
|
|
+ Map<String, Object> userMap = jdbcTemplate.queryForMap("select em_code,em_name from employee where em_uu=?", publicInquiryItem.getVendUserUU());
|
|
|
+ if(userMap != null){
|
|
|
+ count = jdbcTemplate.getInt("select count(*) from businesschance where bc_fromid = ? and bc_domancode=? and bc_doman=?",
|
|
|
+ publicInquiryItem.getSourceId(),userMap.get("EM_CODE"),userMap.get("EM_NAME"));
|
|
|
+ if(count == 0){ //商机跟进人不同
|
|
|
+ turnBusinesschange(publicInquiryItem, enUU, userUU);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //生成UAS的客户采购询价单
|
|
|
+ count = jdbcTemplate.getInt("select count(*) from QuotationDown where b2b_id_id=?", data.get(0).getSourceId());
|
|
|
+ if(count == 0){
|
|
|
+ turnQuotationDown(publicInquiryItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成UAS的客户采购询价单
|
|
|
+ * @param publicInquiryItem
|
|
|
+ */
|
|
|
+ private void turnQuotationDown(PublicInquiryItem publicInquiryItem) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ int id = jdbcTemplate.generate("QuotationDown_seq");
|
|
|
+ String code = jdbcTemplate.generateCode("QuotationDown", 2);
|
|
|
+ String taxrate = String.valueOf(publicInquiryItem.getTaxrate());
|
|
|
+ if(taxrate == null || "null".equals(taxrate) || "".equals(taxrate)){
|
|
|
+ taxrate = "0.0";
|
|
|
+ }
|
|
|
+ String prodTitle = publicInquiryItem.getProdTitle();
|
|
|
+ String prodCode = publicInquiryItem.getProdCode();
|
|
|
+ String prodSpec = publicInquiryItem.getSpec();
|
|
|
+ String custLap = String.valueOf(publicInquiryItem.getCustLap());
|
|
|
+ String fromDate = "to_date('"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(publicInquiryItem.getFromDate())+"','YYYY-MM-DD HH24:MI:SS')";
|
|
|
+ String endDate = "to_date('"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(publicInquiryItem.getToDate())+"','YYYY-MM-DD HH24:MI:SS')";
|
|
|
+ String custCode = jdbcTemplate.getString("select cu_code from customer where cu_uu=?", publicInquiryItem.getInquiry().getEnUU());
|
|
|
+ sb.append("insert into QuotationDown(qu_id,b2b_id_id,qu_code,qu_detno,qu_date,qu_enddate,qu_custuu,qu_custcode,qu_custname,qu_status,qu_statuscode,qu_custprodcode,qu_custproddetail,qu_custprodspec,qu_custlap," +
|
|
|
+ "qu_currency,qu_taxrate,qu_source,qu_isreplace,qu_prodcode) values("+id+","+publicInquiryItem.getSourceId()+","+code+",1,"+fromDate+","+endDate+",'"+publicInquiryItem.getInquiry().getEnUU()+"'," +
|
|
|
+ "'"+custCode+"','"+publicInquiryItem.getInquiry().getEnName()+"','已审核','AUDITED',");
|
|
|
+ if(prodCode == null || "null".equals(prodCode)){
|
|
|
+ sb.append("null,");
|
|
|
+ }else{
|
|
|
+ sb.append("'"+prodCode+"',");
|
|
|
+ }
|
|
|
+ if(prodTitle == null || "null".equals(prodTitle)){
|
|
|
+ sb.append("null,");
|
|
|
+ }else{
|
|
|
+ sb.append("'"+prodTitle+"',");
|
|
|
+ }
|
|
|
+ if(prodSpec == null || "null".equals(prodSpec)){
|
|
|
+ sb.append("null,");
|
|
|
+ }else{
|
|
|
+ sb.append("'"+prodSpec+"',");
|
|
|
+ }
|
|
|
+ if(custLap == null || "null".equals(custLap)){
|
|
|
+ sb.append("null,");
|
|
|
+ }else{
|
|
|
+ sb.append("'"+custLap+"',");
|
|
|
+ }
|
|
|
+ String vendorProdCode = publicInquiryItem.getVendorprodcode();
|
|
|
+ sb.append("'"+publicInquiryItem.getCurrency()+"',"+taxrate+",'平台商机',0,");
|
|
|
+ if(vendorProdCode == null || "null".equals(vendorProdCode)){
|
|
|
+ sb.append("null)");
|
|
|
+ }else{
|
|
|
+ sb.append("'"+vendorProdCode+"')");
|
|
|
+ }
|
|
|
+ //System.out.println(sb.toString());
|
|
|
+ jdbcTemplate.execute(sb.toString());
|
|
|
+ //插入报价明细
|
|
|
+ List<PublicInquiryReply> replies = publicInquiryItem.getReplies();
|
|
|
+ List<String> sqls = new ArrayList<String>();
|
|
|
+ for(PublicInquiryReply reply : replies){
|
|
|
+ String sql = "insert into QuotationDownDetail(qd_id,qd_quid,qd_lapqty,qd_price) values(QuotationDownDetail_seq.nextval,"+id+",'"+reply.getLapQty()+"','"+reply.getPrice()+"')";
|
|
|
+ sqls.add(sql);
|
|
|
+ }
|
|
|
+ //System.out.println(sqls);
|
|
|
+ jdbcTemplate.batchExecute(sqls);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成企业内部商机
|
|
|
+ * @param publicInquiryItem
|
|
|
+ * @param enUU
|
|
|
+ * @param userUU
|
|
|
+ */
|
|
|
+ private void turnBusinesschange(PublicInquiryItem publicInquiryItem, String enUU, String userUU) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ String code = jdbcTemplate.generateCode("businesschance",2);
|
|
|
+ String needQty ="";
|
|
|
+ String inbrand = "";
|
|
|
+ inbrand = publicInquiryItem.getInbrand();
|
|
|
+ needQty = String.valueOf(publicInquiryItem.getNeedquantity());
|
|
|
+ if(needQty == null || "null".equals(needQty)){
|
|
|
+ needQty = "";
|
|
|
+ }
|
|
|
+ if(inbrand == null || "null".equals(inbrand)){
|
|
|
+ inbrand = "";
|
|
|
+ }
|
|
|
+ //商机名称
|
|
|
+ String description = "";
|
|
|
+ String prodTitle = publicInquiryItem.getProdTitle();
|
|
|
+ if(prodTitle != null && !"null".equals(prodTitle) && !"".equals(prodTitle)){
|
|
|
+ prodTitle = prodTitle.replaceAll("'","''").replaceAll("&","'||'&'||'");
|
|
|
+ description += publicInquiryItem.getProdTitle();
|
|
|
+ }else{
|
|
|
+ prodTitle = "";
|
|
|
+ }
|
|
|
+ String cmpCode = publicInquiryItem.getCmpCode();
|
|
|
+ if(cmpCode != null && !"null".equals(cmpCode) && !"".equals(cmpCode)){
|
|
|
+ cmpCode = cmpCode.replaceAll("&","'||'&'||'");
|
|
|
+ description += publicInquiryItem.getCmpCode();
|
|
|
+ }else{
|
|
|
+ cmpCode = "";
|
|
|
+ }
|
|
|
+ if(publicInquiryItem.getSpec() != null && !"null".equals(publicInquiryItem.getSpec()) && !"".equals(publicInquiryItem.getSpec())){
|
|
|
+ description += publicInquiryItem.getSpec() +" ";
|
|
|
+ }else{
|
|
|
+ publicInquiryItem.setSpec("");
|
|
|
+ }
|
|
|
+ description += inbrand;
|
|
|
+ if(needQty != null && !"null".equals(needQty) && !"".equals(needQty)){
|
|
|
+ description += ",需求:"+needQty;
|
|
|
+ }
|
|
|
+ //客户编号、客户uu
|
|
|
+ Long cuUU = publicInquiryItem.getInquiry().getEnUU();
|
|
|
+ String custCode = jdbcTemplate.getString("select cu_code from customer where cu_uu=?", cuUU);
|
|
|
+ if(custCode == null || "null".equals(custCode)){
|
|
|
+ custCode = "";
|
|
|
+ }
|
|
|
+ String date = "to_date('" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(publicInquiryItem.getFromDate()) + "','YYYY-MM-DD HH24:MI:SS')";
|
|
|
+ String endDate = "to_date('" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(publicInquiryItem.getToDate()) + "','YYYY-MM-DD HH24:MI:SS')";
|
|
|
+ //跟进人、跟进人编号
|
|
|
+ Map<String, Object> userMap = jdbcTemplate.queryForMap("select em_code,em_name from employee where em_uu=?", publicInquiryItem.getVendUserUU());
|
|
|
+ sb.append("insert into businesschance(bc_id,bc_fromid,bc_code,bc_description,bc_from,bc_nichehouse,bc_currentprocess,bc_date7,bc_status,bc_statuscode,bc_recorder,bc_recorddate,"
|
|
|
+ + "bc_custname,bc_contact,bc_tel,bc_desc7,bc_desc9,bc_desc10,bc_desc11,bc_desc13,bc_date13,bc_desc14,bc_custcode,bc_domancode,bc_doman) values(businesschance_seq.nextval,"+publicInquiryItem.getSourceId()+",'"+code+"','"+description.replaceAll("'","''").replaceAll("&","'||'&'||'")+"','平台商机','平台商机库','样品报价',"+date+","
|
|
|
+ + "'已审核','AUDITED','自动转入',sysdate,'"+publicInquiryItem.getInquiry().getEnName()+"','"+publicInquiryItem.getInquiry().getRecorder()+"',null,'"+prodTitle+"','"+publicInquiryItem.getSpec()+"',"
|
|
|
+ + "'"+cmpCode+"','"+inbrand+"','"+needQty+"',"+endDate+",'"+cuUU+"','"+custCode);
|
|
|
+ if(userMap != null){
|
|
|
+ sb.append("','"+userMap.get("EM_CODE")+"','"+userMap.get("EM_NAME")+"')");
|
|
|
+ }else{
|
|
|
+ sb.append("',null,null)");
|
|
|
+ }
|
|
|
+ jdbcTemplate.execute(sb.toString());
|
|
|
+ //System.out.println(sb.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@TaskMapping(title = "商机下载", fixedDelay = 60000)
|
|
|
public void downloadInquiry(){
|
|
|
long total = 0L;
|
|
|
@@ -112,6 +331,10 @@ public class EnterInquiryTask {
|
|
|
inbrand = "";
|
|
|
}
|
|
|
//商机名称
|
|
|
+ String prodTitle = json.getString("prodTitle");
|
|
|
+ if(prodTitle != null && !"null".equals(prodTitle) && !"".equals(prodTitle)){
|
|
|
+ prodTitle = prodTitle.replaceAll("'","''").replaceAll("&","'||'&'||'");
|
|
|
+ }
|
|
|
String description = json.getString("prodTitle")+" "+ json.getString("cmpCode")+" ";
|
|
|
if(json.getString("spec") != null && !"null".equals(json.getString("spec")) && !"".equals(json.getString("spec"))){
|
|
|
description += json.getString("spec") +" ";
|
|
|
@@ -123,14 +346,17 @@ public class EnterInquiryTask {
|
|
|
//客户编号、客户uu
|
|
|
String cuUU = json.getString("enUU");
|
|
|
String custCode = jdbcTemplate.getString("select cu_code from customer where cu_uu=?", cuUU);
|
|
|
+ if(custCode == null || "null".equals(custCode)){
|
|
|
+ custCode = "";
|
|
|
+ }
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
c.setTime(new Date(json.getLong("date")));
|
|
|
c.add(Calendar.MONTH, 2);
|
|
|
String date = "to_date('" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime())+"','YYYY-MM-DD HH24:MI:SS')";
|
|
|
String endDate = "to_date('"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(json.getLong("endDate")))+"','YYYY-MM-DD HH24:MI:SS')";
|
|
|
sb.append("insert into businesschance(bc_id,bc_fromid,bc_code,bc_description,bc_from,bc_nichehouse,bc_currentprocess,bc_date7,bc_status,bc_statuscode,bc_recorder,bc_recorddate,"
|
|
|
- + "bc_custname,bc_contact,bc_tel,bc_desc7,bc_desc9,bc_desc10,bc_desc11,bc_desc13,bc_date13,bc_desc14,bc_custcode) values(businesschance_seq.nextval,"+json.getInteger("id")+",'"+code+"','"+description.replaceAll("'","''").replaceAll("&","'||'&'||'")+"','平台商机','"+bdName+"','"+bsName+"',"+date+","
|
|
|
- + "'已审核','AUDITED','自动转入',sysdate,'"+json.getString("enName")+"','"+json.getString("userName")+"','"+json.getString("userTel")+"','"+json.getString("prodTitle").replaceAll("'","''").replaceAll("&","'||'&'||'")+"','"+json.getString("spec")+"',"
|
|
|
+ + "bc_custname,bc_contact,bc_tel,bc_desc7,bc_desc9,bc_desc10,bc_desc11,bc_desc13,bc_date13,bc_desc14,bc_custcode) values(businesschance_seq.nextval,"+json.getInteger("itemId")+",'"+code+"','"+description.replaceAll("'","''").replaceAll("&","'||'&'||'")+"','平台商机','"+bdName+"','"+bsName+"',"+date+","
|
|
|
+ + "'已审核','AUDITED','自动转入',sysdate,'"+json.getString("enName")+"','"+json.getString("userName")+"','"+json.getString("userTel")+"','"+prodTitle+"','"+json.getString("spec")+"',"
|
|
|
+ "'"+json.getString("cmpCode").replaceAll("&","'||'&'||'")+"','"+json.getString("inbrand")+"','"+needQty+"',"+endDate+",'"+cuUU+"','"+custCode+"');");
|
|
|
sb.append(" end if;");
|
|
|
}
|