fs-danaus
2021-06-17 5e6d268612d15a91dfe21bf4a38e0c15b4c36ad2
完善内部对接功能
2个文件已删除
3个文件已添加
19个文件已修改
1242 ■■■■■ 已修改文件
src/com/yc/action/panval/PanelCommitAction.java 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/controller/MutualController.java 218 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/AttachmentEntity.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/BaseEntity.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/CallBack120201Entity.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/Push120201Entity.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/T110203VO.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/T110302.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/T110503Data.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/T120201Entity.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/T121501Entity.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/T121501HeadEntity.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/T130301Entity.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/T140201Entity.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/entity/T210610Entity.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/schedule/DeleteThread.java 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/schedule/PushDataSchedule.java 485 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/schedule/T120201PushDataThread.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/schedule/T120201Thread.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/schedule/T130301PushDataThread.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/schedule/T130301Thread.java 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/schedule/T210610Thread.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/service/MutualServiceIfc.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/service/MutualServiceImpl.java 234 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/action/panval/PanelCommitAction.java
@@ -1,34 +1,31 @@
package com.yc.action.panval;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.yc.action.BaseAction;
import com.yc.exception.CallBackMessage;
import com.yc.multiData.SpObserver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.yc.factory.FactoryBean;
import com.yc.multiData.SpObserver;
import com.yc.open.mutual.entity.T120201Entity;
import com.yc.open.mutual.schedule.DeleteThread;
import com.yc.open.mutual.service.MutualServiceIfc;
import com.yc.service.BaseService;
import com.yc.service.impl.DBHelper;
import com.yc.service.panel.SqlDBHelperIfc;
import com.yc.service.panel.SystemSettingsDao;
import com.yc.utils.SessionKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.sql.SQLException;
import java.util.*;
/**
 * 
@@ -42,6 +39,10 @@
    SystemSettingsDao sDao;
    @Autowired
    SqlDBHelperIfc sDbHelperIfc;
    @Autowired
    ThreadPoolTaskExecutor threadPoolExecutor;
    @Autowired
    MutualServiceIfc mutualServiceIfc;
    /**
     * 判断凭证状态
     * 
@@ -299,7 +300,10 @@
                    //执行删除单据
                    //sql = deletesql + sql;
                    SpObserver.setDBtoInstance("_"+dbid);
                    final T120201Entity entity = mutualServiceIfc.getT120201ByDistributor(doccode);
                    sDbHelperIfc.doSql(listSql);
                    //----增加内部对接推送处理,删除销售订单同时需要把推送到总部的销售订单也要删除  by danaus 2021/6/16 10:47
                    threadPoolExecutor.execute(new DeleteThread(Integer.parseInt(formid), formType_int, entity, dbid));
                    return callBackMessage.sendSuccessMessage("成功");
                } catch (DataAccessException e2) {
                    return callBackMessage.sendErrorMessage(e2.getCause().getMessage());
src/com/yc/open/mutual/controller/MutualController.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.yc.action.grid.GridUtils;
import com.yc.entity.AttachmentConfig;
import com.yc.entity.DataSourceEntity;
import com.yc.entity.attachment.AttachmentEntity;
import com.yc.entity.attachment.AttachmentWhereEntity;
@@ -15,7 +16,6 @@
import com.yc.open.mutual.entity.*;
import com.yc.open.mutual.schedule.MutualLogThread;
import com.yc.open.mutual.schedule.MutualSchedule;
import com.yc.open.mutual.schedule.T120201PushDataThread;
import com.yc.open.mutual.service.MutualServiceIfc;
import com.yc.sdk.WebSocketMessage.entity.MessageType;
import com.yc.sdk.jedis.RedisKey;
@@ -485,7 +485,7 @@
    }
    /**
     * 接收销售订单回写状态
     * 接收销售订单回写状态及更新采购价格
     *
     * @return
     */
@@ -495,18 +495,18 @@
        //验证已在filter里面做,这里只需要处理业务逻辑
        CallBackMessage callBackMessage = new CallBackMessage();
        String data = null;
        T120201Entity t120201Entity = new T120201Entity();
        List<T120201Entity> list =null;
        try {
            String dbid = request.getAttribute(SessionKey.SHOPPING_DBID) + "";
            data = URLDecoder.decode(request.getParameter("data"), "utf-8");
            t120201Entity = JSON.parseObject(data, T120201Entity.class);
            list = JSON.parseArray(data, T120201Entity.class);
            SpObserver.setDBtoInstance("_" + dbid);
            mutualServiceIfc.do130301(t120201Entity);
            mutualServiceIfc.do130301(list);
            callBackMessage.sendSuccessMessageByDefault();
            return callBackMessage.toJSONObject();
        } catch (Exception e) {
            //写错误日志
            this.sendErrorLog(130301, t120201Entity.getDocCode(), e);
            this.sendErrorLog(130301, (list!=null&&list.size()>0)?list.get(0).getDistributorPoDocCode():null, e);
            callBackMessage.sendErrorMessage(e.getCause() != null ? (e.getCause().getMessage()).trim() : e.getMessage());
            return callBackMessage.toJSONObject();
        } finally {
@@ -634,8 +634,8 @@
        try {
            data = URLDecoder.decode(request.getParameter("data"), "utf-8");
            t120201Entity = JSON.parseObject(data, T120201Entity.class);
            if (t120201Entity != null && StringUtils.isNotBlank(t120201Entity.getDbId())) {
                SpObserver.setDBtoInstance("_" + t120201Entity.getDbId());
            if (t120201Entity != null && StringUtils.isNotBlank(t120201Entity.getCltDbid())) {
                SpObserver.setDBtoInstance("_" + t120201Entity.getCltDbid());
                //执行还原销售订单
                final Map map = mutualServiceIfc.reduction120201(t120201Entity);
                callBackMessage.sendSuccessMessageByDefault();
@@ -647,14 +647,41 @@
            }
        } catch (Exception e) {
            //写错误日志
            threadPoolExecutor.execute(new MutualLogThread(120201, t120201Entity.getDocCode(), e.getMessage(), t120201Entity.getDbId()));
            threadPoolExecutor.execute(new MutualLogThread(120201, t120201Entity.getDocCode(), e.getMessage(), t120201Entity.getCltDbid()));
            callBackMessage.sendErrorMessage(e.getCause() != null ? (e.getCause().getMessage()).trim() : e.getMessage());
            return callBackMessage.toJSONObject();
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 接收经销商推送过来删除121501指令
     *
     * @return
     */
    @RequestMapping(value = "/open/mutual/del121501.do")
    @ResponseBody
    public Object del121501(HttpServletRequest request, HttpServletResponse response) {
        //验证已在filter里面做,这里只需要处理业务逻辑
        CallBackMessage callBackMessage = new CallBackMessage();
        String data = null;
        T120201Entity t120201Entity = new T120201Entity();
        try {
            data = URLDecoder.decode(request.getParameter("data"), "utf-8");
            t120201Entity = JSON.parseObject(data, T120201Entity.class);
                SpObserver.setDBtoInstance("_" + t120201Entity.getVndDbid());
                final Integer integer = mutualServiceIfc.del121501(t120201Entity);
                    callBackMessage.sendSuccessMessageByDefault();
                return callBackMessage.toJSONObject();
        } catch (Exception e) {
            //写错误日志
            this.sendErrorLog(121501, t120201Entity.getDocCode(), e);
            callBackMessage.sendErrorMessage(e.getCause() != null ? (e.getCause().getMessage()).trim() : e.getMessage());
            return callBackMessage.toJSONObject();
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 接收删除销售订单指令
     *
@@ -670,11 +697,11 @@
        try {
            data = URLDecoder.decode(request.getParameter("data"), "utf-8");
            t120201Entity = JSON.parseObject(data, T120201Entity.class);
            if (t120201Entity != null && StringUtils.isNotBlank(t120201Entity.getDbId())) {
                SpObserver.setDBtoInstance("_" + t120201Entity.getDbId());
            if (t120201Entity != null && StringUtils.isNotBlank(t120201Entity.getCltDbid())) {
                SpObserver.setDBtoInstance("_" + t120201Entity.getCltDbid());
                //执行未确认的删单
                final Integer integer = mutualServiceIfc.del120201(t120201Entity);
                final DataSourceEntity dataSourceMap = MultiDataSource.getDataSourceMap(t120201Entity.getDbId());
                final DataSourceEntity dataSourceMap = MultiDataSource.getDataSourceMap(t120201Entity.getCltDbid());
                if (integer.intValue() == -2) {
                    callBackMessage.sendErrorMessage("内部推送的【" + dataSourceMap.getSystemDescribe() + "】销售订单:" + t120201Entity.getDocCode() + "已审核,不能执行取消确认操作");
                    callBackMessage.setState(-2);
@@ -689,45 +716,14 @@
            }
        } catch (Exception e) {
            //写错误日志
            threadPoolExecutor.execute(new MutualLogThread(120201, t120201Entity.getDocCode(), e.getMessage(), t120201Entity.getDbId()));
            this.sendErrorLog(120201, t120201Entity.getDocCode(), e);
            callBackMessage.sendErrorMessage(e.getCause() != null ? (e.getCause().getMessage()).trim() : e.getMessage());
            return callBackMessage.toJSONObject();
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 接收销售数据
     *
     * @return
     */
    @RequestMapping(value = "/open/mutual/push120201.do")
    @ResponseBody
    public Object push120201(HttpServletRequest request, HttpServletResponse response) {
        //验证已在filter里面做,这里只需要处理业务逻辑
        CallBackMessage callBackMessage = new CallBackMessage();
        String data = null;
        String dbid = request.getAttribute(SessionKey.SHOPPING_DBID) + "";
        try {
            data = URLDecoder.decode(request.getParameter("data"), "utf-8");
            Push120201Entity  entity= JSON.parseObject(data, Push120201Entity.class);
            SpObserver.setDBtoInstance("_" + dbid);
            String result = mutualServiceIfc.do12021All(entity);
            //回写单据状态
            entity.setList(null);
            entity.setPullSalesOrderToHeadqLastDateTime(result);
            this.createDataAndPush(entity.getCustomerDbid()+"",120201,null,"getLastDateTime.do",entity);
            callBackMessage.sendSuccessMessageByDefault();
            return callBackMessage.toJSONObject();
        } catch (Exception e) {
            //写错误日志
            threadPoolExecutor.execute(new MutualLogThread(12150, null, e.getMessage(), dbid));
            callBackMessage.sendErrorMessage(e.getCause() != null ? (e.getCause().getMessage()).trim() : e.getMessage());
            return callBackMessage.toJSONObject();
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 接收各经销商的通知消息回调 210610
     *
@@ -749,7 +745,35 @@
            return callBackMessage.toJSONObject();
        } catch (Exception e) {
            //写错误日志
            threadPoolExecutor.execute(new MutualLogThread(210610, null, e.getMessage(), dbid));
            this.sendErrorLog(210610, null, e);
            callBackMessage.sendErrorMessage(e.getCause() != null ? (e.getCause().getMessage()).trim() : e.getMessage());
            return callBackMessage.toJSONObject();
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 更新总部拉取经销商销售订单成功回写状态
     *
     * @return
     */
    @RequestMapping(value = "/open/mutual/update120201.do")
    @ResponseBody
    public Object update120201(HttpServletRequest request, HttpServletResponse response) {
        //验证已在filter里面做,这里只需要处理业务逻辑
        CallBackMessage callBackMessage = new CallBackMessage();
        String data = null;
        String dbid = request.getAttribute(SessionKey.SHOPPING_DBID) + "";
        try {
            data = URLDecoder.decode(request.getParameter("data"), "utf-8");
            CallBack120201Entity  entity= JSON.parseObject(data, CallBack120201Entity.class);
            SpObserver.setDBtoInstance("_" + dbid);
            Integer result = mutualServiceIfc.update120201ByVndCode(entity);
            callBackMessage.sendSuccessMessageByDefault();
            return callBackMessage.toJSONObject();
        } catch (Exception e) {
            //写错误日志
            this.sendErrorLog(120201, null, e);
            callBackMessage.sendErrorMessage(e.getCause() != null ? (e.getCause().getMessage()).trim() : e.getMessage());
            return callBackMessage.toJSONObject();
        } finally {
@@ -800,6 +824,18 @@
            data = URLDecoder.decode(request.getParameter("data"), "utf-8");
            T110503Entity  entity= JSON.parseObject(data, T110503Entity.class);
            SpObserver.setDBtoInstance("_" + dbid);
            //--处理附件,把附件拼接url,通过下载方式取得附件
            if(entity.getList()!=null&&entity.getList().size()>0) {
                entity.getList().stream().forEach(x->{
                    try {
                        String unid = this.saveAttachment(entity.getVndDbid() + "", x.getAttachmentHostUrl(), x.getAttachmentList());
                        x.setPhotoPath(unid);
                    }catch (Exception e){
                        e.printStackTrace();
                        threadPoolExecutor.execute(new MutualLogThread(110503, null, e.getMessage(), dbid));
                    }
                });
            }
             mutualServiceIfc.do110503(entity);
            //--回调给总部更新推送时间
            entity.setList(null);
@@ -865,14 +901,12 @@
        conn.disconnect();
        return  bytes;
    }
    private  String saveAttachment(String dbid,String domain,List<com.yc.open.mutual.entity.AttachmentEntity> list) throws Exception{
    public   String saveAttachment(String dbid,String domain,List<com.yc.open.mutual.entity.AttachmentEntity> list) throws Exception{
        if(list==null||list.size()==0) return "";
        String uuid=UUID.randomUUID().toString().toUpperCase();
        String seqString="";
            //存在附件需要处理
            List<String> urls= new ArrayList<>();
          int index=0;
          for(com.yc.open.mutual.entity.AttachmentEntity entity:list){
             String url="/uploads/attachment/"+dbid+"/"+entity.getFormid()+ "/"+entity.getUnid()+"@p@"+entity.getSeq()+"."+entity.getFileType();
@@ -896,7 +930,7 @@
              UploadFiles uploadFiles = new UploadFiles();
              uploadFiles.setOrgBinaryimages(orgBinaryimages);
              uploadFiles.setSmallBinaryimages(orgBinaryimages);
              AttachmentWhereEntity attachmentWhereEntity = attachmentIfc.saveAttachment(uploadFiles, attachmentEntity, list.size()>1?null:"0");
              AttachmentWhereEntity attachmentWhereEntity = attachmentIfc.saveAttachment(uploadFiles, attachmentEntity, entity.getAttachemntType());
              index++;
              if (index == list.size())
                  seqString += attachmentWhereEntity.getSeq();
@@ -924,7 +958,7 @@
            T210610Entity  entity= JSON.parseObject(data, T210610Entity.class);
            SpObserver.setDBtoInstance("_" + dbid);
            //--处理附件,把附件拼接url,通过下载方式取得附件
            String unid =this.saveAttachment(entity.getVndDbid()+"",entity.getUploadUrl(),entity.getUploadList());
            String unid =this.saveAttachment(entity.getVndDbid()+"",entity.getAttachmentHostUrl(),entity.getAttachmentList());
            entity.setUpload(unid);
            Integer result = mutualServiceIfc.do210610(entity);
@@ -946,27 +980,70 @@
        }
    }
    /**
     * 接收销售数据返回推送时间状态
     * 拉取经销商销售数据
     *
     * @return
     */
    @RequestMapping(value = "/open/mutual/getLastDateTime.do")
    @RequestMapping(value = "/open/mutual/pull120201.do")
    @ResponseBody
    public Object getLastDateTime(HttpServletRequest request, HttpServletResponse response) {
    public Object pull120201(HttpServletRequest request, HttpServletResponse response) {
        //验证已在filter里面做,这里只需要处理业务逻辑
        CallBackMessage callBackMessage = new CallBackMessage();
        String data = null;
        String dbid = request.getAttribute(SessionKey.SHOPPING_DBID) + "";
        try {
            data = URLDecoder.decode(request.getParameter("data"), "utf-8");
            Push120201Entity  entity= JSON.parseObject(data, Push120201Entity.class);
            T110203VO t110203= JSON.parseObject(data, T110203VO.class);
            SpObserver.setDBtoInstance("_" + dbid);
            Integer result = mutualServiceIfc.updatePullSalesOrderToHeadqLastDateTime(entity);
            T110302 t110302 =new T110302();
            t110302.setBrands(t110203.getBrands());
            t110302.setPullSalesOrderFromDistributorLastDateTime(t110203.getPullSalesOrderFromDistributorLastDateTime());
            final List<T121501Entity> list = mutualServiceIfc.get120201List(t110302);
            if(list!=null&&list.size()>0) {
                list.stream().forEach(x->{
                    //取出附件拼接url需要的数据
                    final List<com.yc.open.mutual.entity.AttachmentEntity> attachmentInfo = mutualServiceIfc.getAttachmentInfo(x.getHead().getUploads(),120201,"uploads",0);
                    if(attachmentInfo!=null&&attachmentInfo.size()>0){
                        x.setAttachmentHostUrl(AttachmentConfig.get("attachment.server"));
                        x.setAttachmentList(attachmentInfo);
                    }
                });
                callBackMessage.setInfo(list);
            }
            callBackMessage.sendSuccessMessageByDefault();
            return callBackMessage.toJSONObject();
        } catch (Exception e) {
            //写错误日志
            threadPoolExecutor.execute(new MutualLogThread(12150, null, e.getMessage(), dbid));
            threadPoolExecutor.execute(new MutualLogThread(120201, null, e.getMessage(), dbid));
            callBackMessage.sendErrorMessage(e.getCause() != null ? (e.getCause().getMessage()).trim() : e.getMessage());
            return callBackMessage.toJSONObject();
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 拉取经销商库存数据
     *
     * @return
     */
    @RequestMapping(value = "/open/mutual/pull140902.do")
    @ResponseBody
    public Object pull140902(HttpServletRequest request, HttpServletResponse response) {
        //验证已在filter里面做,这里只需要处理业务逻辑
        CallBackMessage callBackMessage = new CallBackMessage();
        String data = null;
        String dbid = request.getAttribute(SessionKey.SHOPPING_DBID) + "";
        try {
            data = URLDecoder.decode(request.getParameter("data"), "utf-8");
            T110203VO t110203= JSON.parseObject(data, T110203VO.class);
            SpObserver.setDBtoInstance("_" + dbid);
            final List<T140902> t140902List = mutualServiceIfc.get140902(t110203.getBrands());
            callBackMessage.setInfo(t140902List);
            callBackMessage.sendSuccessMessageByDefault();
            return callBackMessage.toJSONObject();
        } catch (Exception e) {
            //写错误日志
            threadPoolExecutor.execute(new MutualLogThread(141002, null, e.getMessage(), dbid));
            callBackMessage.sendErrorMessage(e.getCause() != null ? (e.getCause().getMessage()).trim() : e.getMessage());
            return callBackMessage.toJSONObject();
        } finally {
@@ -1014,18 +1091,21 @@
        //验证已在filter里面做,这里只需要处理业务逻辑
        CallBackMessage callBackMessage = new CallBackMessage();
        String data = null;
        T130301Entity t130301Entity = new T130301Entity();
        String dbid = request.getAttribute(SessionKey.SHOPPING_DBID) + "";
        T130301Entity  t130301Entity =new T130301Entity();
        try {
            log.info("/open/mutual/get130301.do.........1");
            data = URLDecoder.decode(request.getParameter("data"), "utf-8");
            t130301Entity = JSON.parseObject(data, T130301Entity.class);
             t130301Entity = JSON.parseObject(data, T130301Entity.class);
            SpObserver.setDBtoInstance("_" + dbid);
            //--处理附件,把附件拼接url,通过下载方式取得附件
            String unid =this.saveAttachment(t130301Entity.getCltDbid()+"",t130301Entity.getAttachmentHostUrl(),t130301Entity.getAttachmentList());
            t130301Entity.setUploads(unid);
            //由refDbId取得对应的客户资料,生成销售订单
            T120201Entity t120201Entity = mutualServiceIfc.do120201(t130301Entity);
            t120201Entity.setRefDbId(dbid);
            //回写单据状态
            threadPoolExecutor.execute(new T120201PushDataThread(t120201Entity, this, baseController));
            log.info("/open/mutual/get130301.do.........2");
             mutualServiceIfc.do120201(t130301Entity);
            callBackMessage.sendSuccessMessageByDefault();
            log.info("/open/mutual/get130301.do.........3");
            return callBackMessage.toJSONObject();
        } catch (Exception e) {
            //写错误日志
@@ -1215,7 +1295,7 @@
    /**
     * 执行取消确认前先删除对方的单据
     * 如:采购订单取消确认,则需要把对方未确认的销售订单删除,如果已确认则不能删除,提示已审核需要对方取消确认
     * 如:采购订单取消确认,则需要把对方未确认的销售订单删除,如果已确认则不能删除,提示已审核需要对方手动取消确认
     */
    public void proccessCanelProc(String dbId, int formid, String docCode, String action) throws Exception {
        //暂时只有130301
@@ -1225,7 +1305,7 @@
                Integer actionType = "del120201.do".equalsIgnoreCase(action) ? 1 : 0;
                final T120201Entity t120201Entity = mutualServiceIfc.checkDocPushSuccess130301(formid, docCode, actionType);
                if (t120201Entity != null && StringUtils.isNotBlank(t120201Entity.getDocCode())) {
                    final String msg = this.createDataAndPush(t120201Entity.getDbId(), 130301, t120201Entity.getDocCode(), action, t120201Entity);
                    final String msg = this.createDataAndPush(t120201Entity.getCltDbid(), 130301, t120201Entity.getDocCode(), action, t120201Entity);
                    Map map = JSON.parseObject(msg, Map.class);
                    int erroCode = GridUtils.prossRowSetDataType_Int(map, "state");
                    if (erroCode != 0) {
@@ -1250,7 +1330,7 @@
                if (dbidList != null&&dbidList.size()>0) {
                    for(T110203VO t110203VO:dbidList) {
                        T210610Entity entity =new T210610Entity();
                        entity.setCltDbid(t110203VO.getDbid());
                        entity.setCltDbid(t110203VO.getCltDbid());
                        entity.setVndDbid(Integer.parseInt(dbId));
                        entity.setDocCode(docCode);
                        //--分发到各经销商系统
@@ -1288,7 +1368,7 @@
        //url="http://localhost:9001";
        String data = JSON.toJSONString(object);
        url += "/open/mutual/" + action + baseController.getSignV2(data, dbId);
        log.info("内部推送url:"+url);
        //log.info("内部推送url:"+url);
        //log.info("内部推送data:"+data);
        return baseController.doPostByParameter(url, URLEncoder.encode(data,"UTF-8"));
src/com/yc/open/mutual/entity/AttachmentEntity.java
@@ -13,4 +13,5 @@
    String fieldid;
    Long fileSize;
    String originalFileName;
    String attachemntType;//0表示单附件
}
src/com/yc/open/mutual/entity/BaseEntity.java
New file
@@ -0,0 +1,14 @@
package com.yc.open.mutual.entity;
import lombok.Data;
import java.util.List;
@Data
public class BaseEntity {
    List<AttachmentEntity> attachmentList;
    String attachmentHostUrl;//总部附件下载URl的域名
    Integer vndDbid;//总部的dbid
    String docCode;//总部的通知的docCode
    Integer cltDbid;
}
src/com/yc/open/mutual/entity/CallBack120201Entity.java
New file
@@ -0,0 +1,16 @@
package com.yc.open.mutual.entity;
import lombok.Data;
import java.io.Serializable;
/**
 * 销售订单回写实体类
 */
@Data
public class CallBack120201Entity implements Serializable {
    private String  docCodeList;//客户采购订单号
    private String cltDbid;//客户dbid
    private String vndDbid;//自身dbid
}
src/com/yc/open/mutual/entity/Push120201Entity.java
@@ -10,6 +10,6 @@
    Integer customerDbid;
    Integer vndDbid;
    List<T121501Entity> list;
    String pullSalesOrderToHeadqLastDateTime;
    String pullSalesOrderFromDistributorLastDateTime;
}
src/com/yc/open/mutual/entity/T110203VO.java
@@ -9,6 +9,11 @@
 */
@Data
public class T110203VO implements Serializable {
    Integer cltDbid;
    Integer vndDbid;
    Integer dbid;
    String pushMatCodeToDistributorLastDateTime;//最后一次推送物料数据时间
    String brands;
    String pullStockFromDistributorLastDateTime;
    String pullSalesOrderFromDistributorLastDateTime;//最后一次拉取销售数据
}
src/com/yc/open/mutual/entity/T110302.java
@@ -14,6 +14,6 @@
   String companyName;
   String brands;
   Integer dbid;
   String pullStockToHeadqLastDateTime;
   String pullSalesOrderToHeadqLastDateTime;
   String pullStockFromDistributorLastDateTime;
   String pullSalesOrderFromDistributorLastDateTime;
}
src/com/yc/open/mutual/entity/T110503Data.java
@@ -8,7 +8,7 @@
 * 通知消息
 */
@Data
public class T110503Data implements Serializable {
public class T110503Data extends  BaseEntity implements Serializable {
    String matGroup ;
    String matGroupName ;
    String parentRowId;
@@ -26,5 +26,6 @@
    String calCostType;
    String matType;
    String qrCode;
    String photoPath;
    Integer baseuomrate;
}
src/com/yc/open/mutual/entity/T120201Entity.java
@@ -10,8 +10,11 @@
@Data
public class T120201Entity implements Serializable {
    private String docCode;//客户采购订单号
    private String dbId;//客户dbid
    private String refDocCode;//销售订单号
    private String refDbId;//自身dbid
    private String cltDbid;//客户dbid
    private String vndDbid;//自身dbid
    private String matCode;
    private String refRowid;
    private Double price;
    private String distributorPoDocCode;//销售单引用推送过来的采购单号,有值则表示需要回写销售价格到采购单的采购价格
}
src/com/yc/open/mutual/entity/T121501Entity.java
@@ -9,7 +9,7 @@
 * 订单实体
 */
@Data
public class T121501Entity {
public class T121501Entity extends BaseEntity{
    private T110203Entity customer;
    private T121501HeadEntity head;
src/com/yc/open/mutual/entity/T121501HeadEntity.java
@@ -36,7 +36,7 @@
     String enterDate;
     String modifyName;
     String modifyDate;
     Integer caiGouStatus;
     String caiGouStatus;
     String caiGouDoccode;
     Integer caiGouFormid ;
     Integer caiGouFormType;
src/com/yc/open/mutual/entity/T130301Entity.java
@@ -9,9 +9,10 @@
 * 采购单实体类
 */
@Data
public class T130301Entity implements Serializable {
public class T130301Entity extends  BaseEntity implements Serializable {
    private String refCode;
    private String refDbId;
    private String uploads;//附件
    private String hDMemo;//附件
    private List<T130301DetailEntity> details;
}
src/com/yc/open/mutual/entity/T140201Entity.java
@@ -17,6 +17,7 @@
    private String shipperCode;//物流公司编号
    private String shipperName;//物流公司名称
    private String logisticsCodeState;//物流状态
    private String receipterTelephone  ;//收货人电话
}
src/com/yc/open/mutual/entity/T210610Entity.java
@@ -3,20 +3,13 @@
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
 * 通知消息
 */
@Data
public class T210610Entity implements Serializable {
public class T210610Entity extends BaseEntity implements Serializable {
    String theme;
    String content;
    String upload;
    List<AttachmentEntity> uploadList;
    String uploadUrl;//总部附件下载URl的域名
    Integer vndDbid;//总部的dbid
    String docCode;//总部的通知的docCode
    Integer cltDbid;
}
src/com/yc/open/mutual/schedule/DeleteThread.java
New file
@@ -0,0 +1,55 @@
package com.yc.open.mutual.schedule;
import com.yc.factory.FactoryBean;
import com.yc.multiData.SpObserver;
import com.yc.open.mutual.controller.MutualController;
import com.yc.open.mutual.entity.T120201Entity;
import com.yc.open.mutual.service.MutualServiceIfc;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * 统一删除处理
 */
public class DeleteThread implements Runnable {
    protected final Logger log = LoggerFactory.getLogger(this.getClass());
    MutualServiceIfc mutualServiceIfc;
    MutualController mutualController;
    int formId;
    int type;
    Object obj;
    String dbId;
    public DeleteThread(int formId, int type, Object obj, String dbId) {
        this.formId = formId;
        this.type = type;
        this.obj = obj;
        this.dbId = dbId;
        mutualServiceIfc = (MutualServiceIfc) FactoryBean.getBean("mutualServiceImpl");
        mutualController = (MutualController) FactoryBean.getBean("mutualController");
    }
    @Override
    public void run() {
        try {
            SpObserver.setDBtoInstance("_" +dbId);
            if ((",120201,").contains("," + formId + ",")) {
                T120201Entity entity=(T120201Entity)obj;
                if (entity != null&&StringUtils.isNotBlank(entity.getVndDbid())) {
                    //推送到总部
                        entity.setCltDbid(dbId);
                        mutualController.createDataAndPush(entity.getVndDbid(), 121501, entity.getDocCode(), "del121501.do", entity);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            mutualController.sendErrorLog(formId, null, ex);
            log.error(ex.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
}
src/com/yc/open/mutual/schedule/PushDataSchedule.java
@@ -1,8 +1,11 @@
package com.yc.open.mutual.schedule;
import com.alibaba.fastjson.JSON;
import com.yc.api.schedule.ScheduleUtils;
import com.yc.entity.AttachmentConfig;
import com.yc.entity.DataSourceEntity;
import com.yc.exception.ApplicationException;
import com.yc.exception.CallBackMessage;
import com.yc.factory.FactoryBean;
import com.yc.multiData.MultiDataSource;
import com.yc.multiData.SpObserver;
@@ -22,6 +25,7 @@
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -53,20 +57,22 @@
        String isMutualRunSchedule = AttachmentConfig.get("isMutualRunSchedule");//只在设置了定时任务的服务器上运行
        if ("1".equals(isMutualRunSchedule)) {
            threadPoolTaskScheduler=(ThreadPoolTaskScheduler)FactoryBean.getBean("threadPoolTaskScheduler");
            threadPoolExecutor=(ThreadPoolTaskExecutor)FactoryBean.getBean("threadPoolExecutor");
            mutualServiceIfc=(MutualServiceIfc)FactoryBean.getBean("mutualServiceImpl");
            mutualController=(MutualController)FactoryBean.getBean("mutualController");
//--拉取库存数据
            threadPoolTaskScheduler = (ThreadPoolTaskScheduler) FactoryBean.getBean("threadPoolTaskScheduler");
            threadPoolExecutor = (ThreadPoolTaskExecutor) FactoryBean.getBean("threadPoolExecutor");
            mutualServiceIfc = (MutualServiceIfc) FactoryBean.getBean("mutualServiceImpl");
            mutualController = (MutualController) FactoryBean.getBean("mutualController");
//--库存数据
//            threadPoolTaskScheduler.schedule(new PushStoreData(), new Trigger() {
//                @Override
//                public Date nextExecutionTime(TriggerContext triggerContext) {
//                    return new CronTrigger("0 39 15 * * ?").nextExecutionTime(triggerContext);//每天执行一次
//                }
//            });
            //TODO 测试用
            threadPoolTaskScheduler.scheduleWithFixedDelay(new PushStoreData(), Instant.now().plusMillis(TimeUnit.MINUTES.toMillis(2)), Duration.ofMinutes(5));
//---拉取销售数据
            //TODO 测试用  经销商推送
            //threadPoolTaskScheduler.scheduleWithFixedDelay(new PushStoreData(), Instant.now().plusMillis(TimeUnit.MINUTES.toMillis(2)), Duration.ofMinutes(5));
            //TODO ---总部拉取
            threadPoolTaskScheduler.scheduleWithFixedDelay(new PullStoreData(), Instant.now().plusMillis(TimeUnit.MINUTES.toMillis(2)), Duration.ofMinutes(5));
//---销售数据
//            threadPoolTaskScheduler.schedule(new PushSalesData(),
//                    new Trigger() {
//                        @Override
@@ -74,10 +80,12 @@
//                            return new CronTrigger("0 56 21 * * ?").nextExecutionTime(triggerContext);//每天执行一次
//                        }
//                    });
           //TODO 测试用
            threadPoolTaskScheduler.scheduleWithFixedDelay(new PushSalesData(), Instant.now().plusMillis(TimeUnit.MINUTES.toMillis(3)), Duration.ofMinutes(3));
            //TODO 测试用 经销商推送
            //threadPoolTaskScheduler.scheduleWithFixedDelay(new PushSalesData(), Instant.now().plusMillis(TimeUnit.MINUTES.toMillis(3)), Duration.ofMinutes(3));
            //TODO ---总部拉取
            threadPoolTaskScheduler.scheduleWithFixedDelay(new PullSalesData(), Instant.now().plusMillis(TimeUnit.MINUTES.toMillis(3)), Duration.ofMinutes(3));
            //---拉基础物料数据
            //---基础物料主数据
            //            threadPoolTaskScheduler.schedule(new PushMatCodeData(),
//                    new Trigger() {
//                        @Override
@@ -93,7 +101,76 @@
    /**
     * 经销商推送销售数据
     */
    private class PushSalesData implements Runnable {
//    private class PushSalesData implements Runnable {
//
//        @Override
//        public void run() {
//            Map<String, DataSourceEntity> infoList = MultiDataSource.getDataSourceMaps();
//            log.info("启动定时拉取销售数据.....[" + (infoList != null ? infoList.size() : 0) + "]");
//            for (Map.Entry<String, DataSourceEntity> entry : infoList.entrySet()) {
//                DataSourceEntity dataSourceEntity = entry.getValue();
//                //非托管系统跳过执行
//                if (ScheduleUtils.isOnbusPlatform(dataSourceEntity)) {
//                    continue;
//                }
//                try {
//                    //一个系统开一个线程
//                    //if(dataSourceEntity.getDbId()!=532) continue;
//                    // threadPoolExecutor.execute(new FormSalesThread(dataSourceEntity));
//                    //  Thread.sleep(10000);//暂停10秒,避免过多的并发
//
//                    String dbid = dataSourceEntity.getDbId() + "";
//                    SpObserver.setDBtoInstance("_" + dbid);
//                    //---取出已认证的供应商
//                    final List<T110302> byBrand = mutualServiceIfc.get110302ByBrand();
//                    for (T110302 t110302 : byBrand) {
//
//                        if (StringUtils.isBlank(t110302.getBrands())) {
//                            //没有品牌,跳过
//                            continue;
//                        }
//                        if (StringUtils.isBlank(t110302.getPullSalesOrderToHeadqLastDateTime())) {
//                            //为空则默认取2000年开始的单
//                            t110302.setPullSalesOrderToHeadqLastDateTime("2000-01-01 00:00:00");
//                        }
//                        final List<T121501Entity> list = mutualServiceIfc.get120201List(t110302);
//                        if (list != null && list.size() > 0) {
//
//                            Push120201Entity entity = new Push120201Entity();
//                            entity.setCustomerDbid(Integer.parseInt(dbid));
//                            entity.setList(list);
//                            entity.setVndDbid(t110302.getDbid());
//                            threadPoolExecutor.execute(new Runnable() {
//                                @Override
//                                public void run() {
//                                    try {
//                                        log.info("销售-" + dataSourceEntity.getSystemDescribe() + "销售数据" + list.size() + "条推送给:" + t110302.getDbid());
//                                        mutualController.createDataAndPush(entity.getVndDbid() + "", 120201, null, "push120201.do", entity);
//                                    } catch (Exception e) {
//                                        e.printStackTrace();
//                                    }
//                                }
//                            });
//
//
//                        }
//                    }
//
//                } catch (Exception e) {
//                    e.printStackTrace();
//                } finally {
//                    SpObserver.setDBtoInstance();
//                }
//
//            }
//            log.info("............推送销售数据完成....");
//        }
//    }
    /**
     * 拉取经销商销售数据
     */
    private class PullSalesData implements Runnable {
        @Override
        public void run() {
@@ -108,44 +185,24 @@
                try {
                    //一个系统开一个线程
                    //if(dataSourceEntity.getDbId()!=532) continue;
                   // threadPoolExecutor.execute(new FormSalesThread(dataSourceEntity));
                  //  Thread.sleep(10000);//暂停10秒,避免过多的并发
                    // threadPoolExecutor.execute(new FormSalesThread(dataSourceEntity));
                    //  Thread.sleep(10000);//暂停10秒,避免过多的并发
                    String dbid = dataSourceEntity.getDbId() + "";
                    SpObserver.setDBtoInstance("_" + dbid);
                    //---取出已认证的供应商
                    final List<T110302> byBrand = mutualServiceIfc.get110302ByBrand();
                    for(T110302 t110302:byBrand) {
                    final List<T110203VO> byBrand = mutualServiceIfc.get110203ByDbid();
                    for (T110203VO t110203 : byBrand) {
                        if(StringUtils.isBlank(t110302.getBrands())){
                        if (StringUtils.isBlank(t110203.getBrands())) {
                            //没有品牌,跳过
                            continue;
                        }
                        if(StringUtils.isBlank(t110302.getPullSalesOrderToHeadqLastDateTime())){
                            //为空则默认取2000年开始的单
                            t110302.setPullSalesOrderToHeadqLastDateTime("2000-01-01 00:00:00");
                        }
                        final List<T121501Entity> list = mutualServiceIfc.get120201List(t110302);
                        if (list != null && list.size() > 0) {
                            Push120201Entity entity = new Push120201Entity();
                            entity.setCustomerDbid(Integer.parseInt(dbid));
                            entity.setList(list);
                            entity.setVndDbid(t110302.getDbid());
                            threadPoolExecutor.execute(new Runnable() {
                                @Override
                                public void run() {
                                    try {
                                        log.info("销售-"+dataSourceEntity.getSystemDescribe()+"销售数据"+list.size()+"条推送给:"+t110302.getDbid());
                                        mutualController.createDataAndPush(entity.getVndDbid() + "", 120201, null, "push120201.do", entity);
                                    }catch (Exception e){
                                        e.printStackTrace();
                                    }
                                }
                            });
                        t110203.setVndDbid(Integer.parseInt(dbid));
                        t110203.setCltDbid(t110203.getDbid());
                        threadPoolExecutor.execute(new pullSalesThread(dataSourceEntity, t110203));
                        }
                    }
                } catch (Exception e) {
@@ -159,11 +216,13 @@
        }
    }
    private class FormSalesThread implements Runnable {
    private class pullSalesThread implements Runnable {
        final DataSourceEntity dataSourceEntity;
        final T110203VO t110203;
        public FormSalesThread(DataSourceEntity dataSourceEntity) {
        public pullSalesThread(DataSourceEntity dataSourceEntity, T110203VO t110203) {
            this.dataSourceEntity = dataSourceEntity;
            this.t110203 = t110203;
        }
        @Override
@@ -172,28 +231,38 @@
                String dbid = dataSourceEntity.getDbId() + "";
                log.info(dataSourceEntity.getSystemDescribe() + "开始执行");
                SpObserver.setDBtoInstance("_" + dbid);
                //---取出已认证的供应商
                final List<T110302> byBrand = mutualServiceIfc.get110302ByBrand();
                for(T110302 t110302:byBrand) {
                    if(StringUtils.isBlank(t110302.getBrands())){
                        //没有品牌,跳过
                        continue;
                    }
                    if(StringUtils.isBlank(t110302.getPullSalesOrderToHeadqLastDateTime())){
                        //为空则默认取2000年开始的单
                        t110302.setPullSalesOrderToHeadqLastDateTime("2000-01-01 00:00:00");
                    }
                    final List<T121501Entity> list = mutualServiceIfc.get120201List(t110302);
                    if (list != null && list.size() > 0) {
                        log.info(dataSourceEntity.getSystemDescribe()+"销售数据"+list.size()+"条推送给:"+t110302.getDbid());
                        Push120201Entity entity = new Push120201Entity();
                        entity.setCustomerDbid(Integer.parseInt(dbid));
                        entity.setList(list);
                        entity.setVndDbid(t110302.getDbid());
                        mutualController.createDataAndPush(entity.getVndDbid() + "", 120201, null, "push120201.do", entity);
                    }
                Push120201Entity entity = new Push120201Entity();
                //把最后更新时间设置前一些
                entity.setPullSalesOrderFromDistributorLastDateTime(DateUtil.toDay());
                String result = mutualController.createDataAndPush(t110203.getCltDbid() + "", 120201, null, "pull120201.do", t110203);
                //---处理拉取回来的销售数据
                CallBackMessage callBackMessage = JSON.parseObject(result, CallBackMessage.class);
                if(callBackMessage.getState()==0) {
                    List<T121501Entity> list = JSON.parseArray(callBackMessage.getData(), T121501Entity.class);
                    List<String> docCodeList=new ArrayList<>();
                   if(list!=null&&list.size()>0) {
                       list.stream().forEach(x->{
                           try{
                           String unid = mutualController.saveAttachment(t110203.getCltDbid() + "", x.getAttachmentHostUrl(), x.getAttachmentList());
                           x.getHead().setUploads(unid);
                           docCodeList.add(x.getHead().getDocCode());
                           }catch (Exception e){
                               e.printStackTrace();
                               threadPoolExecutor.execute(new MutualLogThread(110503, null, e.getMessage(), dbid));
                           }
                               });
                       entity.setList(list);
                       entity.setCustomerDbid(t110203.getCltDbid());
                       mutualServiceIfc.do120201All(entity);
                       //--回写总部vndCode到经销商的销售订单
                       CallBack120201Entity callBack120201Entity=new CallBack120201Entity();
                       callBack120201Entity.setDocCodeList(String.join(",",docCodeList));
                       callBack120201Entity.setCltDbid(t110203.getCltDbid()+"");
                       callBack120201Entity.setVndDbid(dbid);
                       mutualController.createDataAndPush(callBack120201Entity.getCltDbid(),121501,null,"update120201.do",callBack120201Entity);
                   }
                }else{
                    throw new ApplicationException(callBackMessage.getMsg());
                }
            } catch (Exception ex) {
                ex.printStackTrace();
@@ -204,6 +273,7 @@
        }
    }
    /**
     * 拉取经销商库存数据到总部
     */
@@ -227,38 +297,22 @@
                    String dbid = dataSourceEntity.getDbId() + "";
                    SpObserver.setDBtoInstance("_" + dbid);
                    //---取出已认证的供应商
                    final List<T110302> byBrand = mutualServiceIfc.get110302ByBrand();
                    for(T110302 t110302:byBrand) {
                    //---取出已认证的经销商
                    final List<T110203VO> byBrand = mutualServiceIfc.get110203ByDbid();
                    for (T110203VO t110203 : byBrand) {
                        if(StringUtils.isBlank(t110302.getBrands())){
                        if (StringUtils.isBlank(t110203.getBrands())) {
                            //没有品牌,跳过
                            continue;
                        }
                        final List<T140902> t140902List = mutualServiceIfc.get140902(t110302.getBrands());
                        if (t140902List != null && t140902List.size() > 0) {
                            T140902Entity entity = new T140902Entity();
                            entity.setCustomerDbid(Integer.parseInt(dbid));
                            entity.setList(t140902List);
                            entity.setVndDbid(t110302.getDbid());
                            threadPoolExecutor.execute(new Runnable() {
                                @Override
                                public void run() {
                                    try {
                                        log.info("库存-"+dataSourceEntity.getSystemDescribe() + "开始执行");
                                        mutualController.createDataAndPush(entity.getVndDbid() + "", 140902, null, "get140902.do", entity);
                                    }catch (Exception e){
                                        e.printStackTrace();
                                    }
                                }
                            });
                        }
                        t110203.setVndDbid(Integer.parseInt(dbid));
                        t110203.setCltDbid(t110203.getDbid());
                        threadPoolExecutor.execute(new pullStoreThread(dataSourceEntity, t110203));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }finally {
                    log.error(dataSourceEntity.getSystemDescribe() + ":" + e.getMessage());
                } finally {
                    SpObserver.setDBtoInstance();
                }
@@ -270,99 +324,98 @@
    /**
     * 推送库存数据到总部
     */
    private class PushStoreData implements Runnable {
//    private class PushStoreData implements Runnable {
//
//        @Override
//        public void run() {
//            Map<String, DataSourceEntity> infoList = MultiDataSource.getDataSourceMaps();
//            log.info("启动定时拉取库存.....[" + (infoList != null ? infoList.size() : 0) + "]");
//            for (Map.Entry<String, DataSourceEntity> entry : infoList.entrySet()) {
//                DataSourceEntity dataSourceEntity = entry.getValue();
//                //非托管系统跳过执行
//                if (ScheduleUtils.isOnbusPlatform(dataSourceEntity)) {
//                    continue;
//                }
//                try {
//                    //一个系统开一个线程
//                    // if(dataSourceEntity.getDbId()!=532) continue;
//                    //  threadPoolExecutor.execute(new FormThread(dataSourceEntity));
//                    // Thread.sleep(10000);//暂停10秒,避免过多的并发
//                    String dbid = dataSourceEntity.getDbId() + "";
//
//                    SpObserver.setDBtoInstance("_" + dbid);
//                    //---取出已认证的供应商
//                    final List<T110302> byBrand = mutualServiceIfc.get110302ByBrand();
//                    for (T110302 t110302 : byBrand) {
//
//                        if (StringUtils.isBlank(t110302.getBrands())) {
//                            //没有品牌,跳过
//                            continue;
//                        }
//                        final List<T140902> t140902List = mutualServiceIfc.get140902(t110302.getBrands());
//                        if (t140902List != null && t140902List.size() > 0) {
//                            T140902Entity entity = new T140902Entity();
//                            entity.setCustomerDbid(Integer.parseInt(dbid));
//                            entity.setList(t140902List);
//                            entity.setVndDbid(t110302.getDbid());
//                            threadPoolExecutor.execute(new Runnable() {
//                                @Override
//                                public void run() {
//                                    try {
//                                        log.info("库存-" + dataSourceEntity.getSystemDescribe() + "开始执行");
//                                        mutualController.createDataAndPush(entity.getVndDbid() + "", 140902, null, "get140902.do", entity);
//                                    } catch (Exception e) {
//                                        e.printStackTrace();
//                                    }
//                                }
//                            });
//
//
//                        }
//                    }
//                } catch (Exception e) {
//                    e.printStackTrace();
//                } finally {
//                    SpObserver.setDBtoInstance();
//                }
//
//            }
//            log.info(".........库存推送完成...........");
//        }
//    }
        @Override
        public void run() {
            Map<String, DataSourceEntity> infoList = MultiDataSource.getDataSourceMaps();
            log.info("启动定时拉取库存.....[" + (infoList != null ? infoList.size() : 0) + "]");
            for (Map.Entry<String, DataSourceEntity> entry : infoList.entrySet()) {
                DataSourceEntity dataSourceEntity = entry.getValue();
                //非托管系统跳过执行
                if (ScheduleUtils.isOnbusPlatform(dataSourceEntity)) {
                    continue;
                }
                try {
                    //一个系统开一个线程
                   // if(dataSourceEntity.getDbId()!=532) continue;
                  //  threadPoolExecutor.execute(new FormThread(dataSourceEntity));
                   // Thread.sleep(10000);//暂停10秒,避免过多的并发
                    String dbid = dataSourceEntity.getDbId() + "";
                    SpObserver.setDBtoInstance("_" + dbid);
                    //---取出已认证的供应商
                    final List<T110302> byBrand = mutualServiceIfc.get110302ByBrand();
                    for(T110302 t110302:byBrand) {
                        if(StringUtils.isBlank(t110302.getBrands())){
                            //没有品牌,跳过
                            continue;
                        }
                        final List<T140902> t140902List = mutualServiceIfc.get140902(t110302.getBrands());
                        if (t140902List != null && t140902List.size() > 0) {
                            T140902Entity entity = new T140902Entity();
                            entity.setCustomerDbid(Integer.parseInt(dbid));
                            entity.setList(t140902List);
                            entity.setVndDbid(t110302.getDbid());
                            threadPoolExecutor.execute(new Runnable() {
                                @Override
                                public void run() {
                                    try {
                                        log.info("库存-"+dataSourceEntity.getSystemDescribe() + "开始执行");
                                        mutualController.createDataAndPush(entity.getVndDbid() + "", 140902, null, "get140902.do", entity);
                                    }catch (Exception e){
                                        e.printStackTrace();
                                    }
                                }
                            });
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }finally {
                    SpObserver.setDBtoInstance();
                }
            }
            log.info(".........库存推送完成...........");
        }
    }
    private class FormThread implements Runnable {
    private class pullStoreThread implements Runnable {
        final DataSourceEntity dataSourceEntity;
        final T110203VO t110203;
        public FormThread(DataSourceEntity dataSourceEntity) {
        public pullStoreThread(DataSourceEntity dataSourceEntity, T110203VO t110203VO) {
            this.dataSourceEntity = dataSourceEntity;
            this.t110203 = t110203VO;
        }
        @Override
        public void run() {
            try {
                String dbid = dataSourceEntity.getDbId() + "";
                log.info(dataSourceEntity.getSystemDescribe() + "开始执行");
                SpObserver.setDBtoInstance("_" + dbid);
                //---取出已认证的供应商
                final List<T110302> byBrand = mutualServiceIfc.get110302ByBrand();
                for(T110302 t110302:byBrand) {
                    if(StringUtils.isBlank(t110302.getBrands())){
                        //没有品牌,跳过
                        continue;
                log.info("拉取库存-" + dataSourceEntity.getSystemDescribe() + "开始执行");
                String result = mutualController.createDataAndPush(t110203.getCltDbid() + "", 140902, null, "pull140902.do", t110203);
                //---处理拉取回来的库存数据
                CallBackMessage callBackMessage = JSON.parseObject(result, CallBackMessage.class);
                if(callBackMessage.getState()==0) {
                    List<T140902> list = JSON.parseArray(callBackMessage.getData() + "", T140902.class);
                    if(list!=null&&list.size()>0) {
                        T140902Entity t140902Entity = new T140902Entity();
                        t140902Entity.setList(list);
                        t140902Entity.setCustomerDbid(t110203.getCltDbid());
                        mutualServiceIfc.do140902(t140902Entity);
                    }
                    final List<T140902> t140902List = mutualServiceIfc.get140902(t110302.getBrands());
                    if (t140902List != null && t140902List.size() > 0) {
                            T140902Entity entity = new T140902Entity();
                            entity.setCustomerDbid(Integer.parseInt(dbid));
                            entity.setList(t140902List);
                            entity.setVndDbid(t110302.getDbid());
                        mutualController.createDataAndPush(entity.getVndDbid() + "", 140902, null, "get140902.do", entity);
                    }
                }else {
                    throw new ApplicationException(callBackMessage.getMsg());
                }
            } catch (Exception ex) {
                log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage());
            } catch (Exception e) {
                e.printStackTrace();
                log.error(dataSourceEntity.getSystemDescribe() + ":" + e.getMessage());
            } finally {
                SpObserver.setDBtoInstance();
            }
@@ -378,7 +431,7 @@
        @Override
        public void run() {
            Map<String, DataSourceEntity> infoList = MultiDataSource.getDataSourceMaps();
            log.info("...............启动总部定时推送物料数据.....[" + (infoList != null ? infoList.size() : 0) + "]");
            log.info("...............启动总部定时推送物料主数据.....");
            for (Map.Entry<String, DataSourceEntity> entry : infoList.entrySet()) {
                DataSourceEntity dataSourceEntity = entry.getValue();
                //非托管系统跳过执行
@@ -388,16 +441,14 @@
                try {
                    //一个系统开一个线程
                    if(dataSourceEntity.getDbId()!=82&&dataSourceEntity.getDbId()!=583
                            &&dataSourceEntity.getDbId()!=532
                    if (dataSourceEntity.getDbId() != 82 && dataSourceEntity.getDbId() != 583
                            && dataSourceEntity.getDbId() != 532
                    ) continue;
                    //threadPoolExecutor.execute(new FormMatCodeThread(dataSourceEntity));
                    //Thread.sleep(10000);//暂停10秒,避免过多的并发
                    int dbid = dataSourceEntity.getDbId();
                    SpObserver.setDBtoInstance("_" + dbid);
                    //---取出已认证的经销商
                    final List<T110203VO> dbidList = mutualServiceIfc.get110203ByDbid();
                    if(dbidList!=null&&dbidList.size()>0) {
                    if (dbidList != null && dbidList.size() > 0) {
                        for (T110203VO t110203VO : dbidList) {
                            T110503Entity entity = new T110503Entity();
                            entity.setCltDbid(t110203VO.getDbid());
@@ -406,6 +457,14 @@
                            //--取最后一次更新时间之后的数据
                            final List<T110503Data> list = mutualServiceIfc.get110503List(t110203VO.getPushMatCodeToDistributorLastDateTime());
                            if (list != null && list.size() > 0) {
                                list.stream().forEach(x->{
                                    //取出附件拼接url需要的数据
                                    final List<AttachmentEntity> attachmentInfo = mutualServiceIfc.getAttachmentInfo(x.getPhotoPath(),110503,"photoPath",0);
                                    if(attachmentInfo!=null&&attachmentInfo.size()>0){
                                        x.setAttachmentHostUrl(AttachmentConfig.get("attachment.server"));
                                        x.setAttachmentList(attachmentInfo);
                                    }
                                });
                                entity.setList(list);
                                entity.setPushLastDateTime(t110203VO.getPushMatCodeToDistributorLastDateTime());
                                threadPoolExecutor.execute(new Runnable() {
@@ -424,7 +483,7 @@
                        }
                    }
                } catch (Exception e) {
                    mutualController.sendErrorLog(110503,null,e);
                    mutualController.sendErrorLog(110503, null, e);
                    log.error(dataSourceEntity.getSystemDescribe() + ":" + e.getMessage());
                    //e.printStackTrace();
                } finally {
@@ -436,43 +495,43 @@
        }
    }
    private class FormMatCodeThread implements Runnable {
        final DataSourceEntity dataSourceEntity;
        public FormMatCodeThread(DataSourceEntity dataSourceEntity) {
            this.dataSourceEntity = dataSourceEntity;
        }
        @Override
        public void run() {
            try {
                int dbid = dataSourceEntity.getDbId();
                log.info(dataSourceEntity.getSystemDescribe() + "开始执行");
                SpObserver.setDBtoInstance("_" + dbid);
                //---取出已认证的经销商
                final List<T110203VO> dbidList = mutualServiceIfc.get110203ByDbid();
                for(T110203VO t110203VO:dbidList) {
                    T110503Entity entity =new T110503Entity();
                    entity.setCltDbid(t110203VO.getDbid());
                    entity.setVndDbid(dbid);
                    entity.setNowDateTime(DateUtil.toDay());
                    //--取最后一次更新时间之后的数据
                    final List<T110503Data> list = mutualServiceIfc.get110503List(t110203VO.getPushMatCodeToDistributorLastDateTime());
                    if(list!=null&&list.size()>0) {
                        entity.setList(list);
                        entity.setPushLastDateTime(t110203VO.getPushMatCodeToDistributorLastDateTime());
                        mutualController.createDataAndPush(entity.getCltDbid() + "", 110503, null, "get110503.do", entity);
                    }
                }
            } catch (Exception ex) {
                mutualController.sendErrorLog(110503,null,ex);
                log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage());
            } finally {
                SpObserver.setDBtoInstance();
            }
        }
    }
//    private class FormMatCodeThread implements Runnable {
//        final DataSourceEntity dataSourceEntity;
//
//        public FormMatCodeThread(DataSourceEntity dataSourceEntity) {
//            this.dataSourceEntity = dataSourceEntity;
//        }
//
//        @Override
//        public void run() {
//            try {
//                int dbid = dataSourceEntity.getDbId();
//                log.info(dataSourceEntity.getSystemDescribe() + "开始执行");
//                SpObserver.setDBtoInstance("_" + dbid);
//                //---取出已认证的经销商
//                final List<T110203VO> dbidList = mutualServiceIfc.get110203ByDbid();
//                for (T110203VO t110203VO : dbidList) {
//                    T110503Entity entity = new T110503Entity();
//                    entity.setCltDbid(t110203VO.getCltDbid());
//                    entity.setVndDbid(dbid);
//                    entity.setNowDateTime(DateUtil.toDay());
//                    //--取最后一次更新时间之后的数据
//                    final List<T110503Data> list = mutualServiceIfc.get110503List(t110203VO.getPushMatCodeToDistributorLastDateTime());
//                    if (list != null && list.size() > 0) {
//                        entity.setList(list);
//                        entity.setPushLastDateTime(t110203VO.getPushMatCodeToDistributorLastDateTime());
//                        mutualController.createDataAndPush(entity.getCltDbid() + "", 110503, null, "get110503.do", entity);
//                    }
//                }
//            } catch (Exception ex) {
//                mutualController.sendErrorLog(110503, null, ex);
//                log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage());
//            } finally {
//                SpObserver.setDBtoInstance();
//            }
//        }
//
//    }
}
src/com/yc/open/mutual/schedule/T120201PushDataThread.java
File was deleted
src/com/yc/open/mutual/schedule/T120201Thread.java
@@ -6,9 +6,12 @@
import com.yc.open.mutual.entity.PushEntity;
import com.yc.open.mutual.entity.T120201Entity;
import com.yc.open.mutual.service.MutualServiceIfc;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.List;
/**
 * 推送120201销售订单
@@ -33,11 +36,15 @@
    public void run() {
        try {
            SpObserver.setDBtoInstance("_" + pushEntity.getDbId());
            final T120201Entity t120201 = mutualServiceIfc.getT120201(pushEntity.getDocCode());
            if (t120201 != null && t120201.getDocCode() != null) {
            final List<T120201Entity> list = mutualServiceIfc.getT120201(pushEntity.getDocCode());
            //---t120201.getDistributorPoDocCode()不为空表示销售订单是推送过来,当确认时需要回写销售价格到采购订单的采购价格
            if (list != null &&list.size()>0) {
                //自身dbid,传给经销商系统
                t120201.setRefDbId(pushEntity.getDbId());
                threadPoolExecutor.execute(new T120201PushDataThread(t120201, mutualController, baseController));
                T120201Entity entity =list.get(0);
                if(StringUtils.isNotBlank(entity.getDistributorPoDocCode())) {
                    entity.setVndDbid(pushEntity.getDbId());
                    mutualController.createDataAndPush(entity.getCltDbid(), 120201, null, "get120201.do", list);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
src/com/yc/open/mutual/schedule/T130301PushDataThread.java
File was deleted
src/com/yc/open/mutual/schedule/T130301Thread.java
@@ -1,14 +1,18 @@
package com.yc.open.mutual.schedule;
import com.yc.entity.AttachmentConfig;
import com.yc.multiData.SpObserver;
import com.yc.open.controller.BaseController;
import com.yc.open.mutual.controller.MutualController;
import com.yc.open.mutual.entity.AttachmentEntity;
import com.yc.open.mutual.entity.PushEntity;
import com.yc.open.mutual.entity.T130301Entity;
import com.yc.open.mutual.service.MutualServiceIfc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.List;
/**
 * 推送130301采购订单
@@ -44,8 +48,18 @@
//                    threadPoolExecutor.execute(new T130301PushDataThread(t130301List, dbId + "", pushEntity.getDbId(), t130301Entity.getRefCode(), mutualController, baseController));
//                }
                //--默认都是属于一个供应商,不需要上面的处理,直接推送
               // final List<AttachmentEntity> attachmentInfo = mutualServiceIfc.getAttachmentInfo(entity.getUpload());
                threadPoolExecutor.execute(new T130301PushDataThread(t130301Entity.getDetails(), t130301Entity.getDetails().get(0).getDbId()+"", pushEntity.getDbId(), t130301Entity.getRefCode(), mutualController, baseController));
                //--取附件
                final List<AttachmentEntity> attachmentInfo = mutualServiceIfc.getAttachmentInfo(t130301Entity.getUploads(),130301,"Uploads",0);
                if(attachmentInfo!=null&&attachmentInfo.size()>0) {
                    t130301Entity.setAttachmentList(attachmentInfo);
                    t130301Entity.setAttachmentHostUrl(AttachmentConfig.get("attachment.server"));
                }
                t130301Entity.setVndDbid(t130301Entity.getDetails().get(0).getDbId());
                t130301Entity.setCltDbid(Integer.parseInt(pushEntity.getDbId()));
                t130301Entity.setRefCode(pushEntity.getDocCode());
                mutualController.createDataAndPush(t130301Entity.getVndDbid()+"",130301,t130301Entity.getRefCode(),"get130301.do",t130301Entity);
              //  threadPoolExecutor.execute(new T130301PushDataThread(t130301Entity, t130301Entity.getDetails().get(0).getDbId()+"", pushEntity.getDbId(), t130301Entity.getRefCode(), mutualController, baseController));
            }
        } catch (Exception ex) {
src/com/yc/open/mutual/schedule/T210610Thread.java
@@ -42,11 +42,11 @@
                for(T210610Entity entity:list) {
                    //--分发到各经销商系统
                    if(entity.getCltDbid()!=null) {
                        final List<AttachmentEntity> attachmentInfo = mutualServiceIfc.getAttachmentInfo(entity.getUpload());
                        final List<AttachmentEntity> attachmentInfo = mutualServiceIfc.getAttachmentInfo(entity.getUpload(),210610,"upload",0);
                        if(attachmentInfo!=null){
                            //附件服务器域名
                            entity.setUploadUrl( AttachmentConfig.get("attachment.server"));
                            entity.setUploadList(attachmentInfo);
                            entity.setAttachmentHostUrl( AttachmentConfig.get("attachment.server"));
                            entity.setAttachmentList(attachmentInfo);
                        }
                        entity.setVndDbid(Integer.parseInt(pushEntity.getDbId()));//总部dbid
                        mutualController.createDataAndPush(entity.getCltDbid() + "", pushEntity.getFormId(), pushEntity.getDocCode(), "get210610.do", entity);
src/com/yc/open/mutual/service/MutualServiceIfc.java
@@ -100,16 +100,16 @@
     * @param t130301Entity
     * @return
     */
    T120201Entity do120201(T130301Entity t130301Entity);
    void do120201(T130301Entity t130301Entity);
    Map getCompanyInfo();
    List getDepartmentInfo(String companyId);
    T120201Entity getT120201(String docCode);
    List<T120201Entity> getT120201(String docCode);
    T140201Entity getT140201(String docCode);
    Integer do130301(T120201Entity t120201Entity);
    void do130301(List<T120201Entity> list);
    /**
     * 回写物流信息状态到采购订单130301
@@ -148,11 +148,8 @@
    Integer do140902(T140902Entity t140902Entity);
    List<T110302> get110302ByBrand();
    String do12021All(Push120201Entity entity);
    Integer updatePullSalesOrderToHeadqLastDateTime(Push120201Entity  entity);
    void do120201All(Push120201Entity entity);
    List<T210610Entity> getT210610(String docCode);
@@ -170,5 +167,11 @@
    Integer updateLastDateTimeBy110503(T110503Entity entity);
    List<AttachmentEntity> getAttachmentInfo(String uuid);
    List<AttachmentEntity> getAttachmentInfo(String uuid,Integer formid,String fieldid,int headflag);
    T120201Entity getT120201ByDistributor   (String docCode);
    Integer del121501(T120201Entity t120201Entity);
    Integer update120201ByVndCode(CallBack120201Entity entity);
}
src/com/yc/open/mutual/service/MutualServiceImpl.java
@@ -1,6 +1,7 @@
package com.yc.open.mutual.service;
import com.yc.action.grid.GridUtils;
import com.yc.exception.ApplicationException;
import com.yc.open.deli.entity.T110203Entity;
import com.yc.open.deli.entity.T110562Entity;
import com.yc.open.mutual.entity.*;
@@ -140,7 +141,7 @@
                "  ItemMemo varchar(400),soDocCode varchar(20),canceldigit money, \n" +
                "  brand varchar(20),cv2 varchar(80), \n" +
                "  packingQuantity varchar(100),weight money,totalWeight money, \n" +
                "  unsubscribeDoccode varchar(20),sORowid varchar(20),errMsg varchar(500),dbId int )  \n" +
                "  unsubscribeDoccode varchar(20),sORowid varchar(20),errMsg varchar(500),dbId int,uploads varchar(200) )  \n" +
                "  declare @docCode varchar(20), \n" +
                "  @cvenCode varchar(50),@cvenName varchar(80),\n" +
@@ -150,7 +151,7 @@
                "  @ItemMemo varchar(400),@soDocCode varchar(20),@canceldigit money, \n" +
                "  @brand varchar(20),@cv2 varchar(80), \n" +
                "  @packingQuantity varchar(100),@weight money,@totalWeight money, \n" +
                "  @unsubscribeDoccode varchar(20),@soRowid varchar(20) ,@soCcCode varchar(20),@soCcName varchar(50),@dbId int    \n" +
                "  @unsubscribeDoccode varchar(20),@soRowid varchar(20) ,@soCcCode varchar(20),@soCcName varchar(50),@dbId int,@uploads varchar(200)    \n" +
                " declare @ObjMatCode varchar(50),@ObjMatName varchar(120) ,@ObjSpecial varchar(120) ,@FormId int = 130301 \n" +
/*
                " select top 1 @DefaultVndCode = a.DefaultVndCode ,@DefaultVndName = b.vndName \n" +
@@ -166,7 +167,7 @@
                " declare mycurDeli cursor for\n" +
                " select a.docCode,a.hDMemo,\n" +
                "  a.docStatus,b.MatCode,b.MatName,b.rowid ,b.digit,b.SODoccode,b.SOrowid,j.dbId\n" +
                "  a.docStatus,b.MatCode,b.MatName,b.rowid ,b.digit,b.SODoccode,b.SOrowid,j.dbId,a.uploads\n" +
                " from t130301H a join t130301D b on a.DocCode  = b.DocCode\n" +
                " join gform c on  a.formid= c.formid\n" +
                " left join t110601 d on a.cccode = d.cccode\n" +
@@ -183,7 +184,7 @@
                " order by a.doccode asc,b.DocItem asc \n" +
                " open mycurDeli \n" +
                " fetch next from mycurDeli into @docCode,@hDMemo,\n" +
                "  @docStatus,@MatCode,@MatName,@RowId,@digit,@soDocCode,@soRowId,@dbId\n" +
                "  @docStatus,@MatCode,@MatName,@RowId,@digit,@soDocCode,@soRowId,@dbId,@uploads\n" +
                " while @@FETCH_STATUS = 0 \n" +
                " begin\n" +
/*
@@ -244,7 +245,7 @@
                " ItemMemo ,soDocCode,canceldigit, \n" +
                " brand,cv2 , \n" +
                " packingQuantity,[weight] ,totalWeight , \n" +
                " unsubscribeDoccode,sORowid ,errMsg,dbId) \n" +
                " unsubscribeDoccode,sORowid ,errMsg,dbId,uploads) \n" +
                "  values(@docCode , \n" +
                " @cvenCode ,@cvenName  , \n" +
                " @hDMemo, \n" +
@@ -253,10 +254,10 @@
                " @ItemMemo ,@soDocCode,@canceldigit, \n" +
                " @brand,@cv2 , \n" +
                " @packingQuantity,@weight ,@totalWeight , \n" +
                " @unsubscribeDoccode,@sORowid ,@errMsg,@dbId )\n" +
                " @unsubscribeDoccode,@sORowid ,@errMsg,@dbId,@uploads )\n" +
                // "  end \n" +
                "  fetch next from mycurDeli into @docCode, @hDMemo,\n" +
                "    @docStatus,@MatCode,@MatName,@RowId,@digit,@soDocCode,@soRowId,@dbId\n" +
                "    @docStatus,@MatCode,@MatName,@RowId,@digit,@soDocCode,@soRowId,@dbId,@uploads\n" +
                " end \n" +
                " close mycurDeli\n" +
                " deallocate mycurDeli \n" +
@@ -267,15 +268,18 @@
                "     ItemMemo ,soDocCode,canceldigit, \n" +
                "     brand,cv2 , \n" +
                "     packingQuantity,[weight] as weight ,totalWeight , \n" +
                "     unsubscribeDoccode,sORowid ,errMsg,dbId\n" +
                "     unsubscribeDoccode,sORowid ,errMsg,dbId,uploads\n" +
                " from @table ";
        T130301Entity t130301Entity = null;
        List<Map<String, Object>> list = this.jdbcTemplate.queryForList(hsql, docCode);
        if (list != null && list.size() > 0) {
            t130301Entity = new T130301Entity();
            t130301Entity.setRefCode(docCode);
            List<T130301DetailEntity> detailEntityList = new ArrayList<>();
            for (Map<String, Object> map : list) {
                t130301Entity.setHDMemo(GridUtils.prossRowSetDataType_String(map, "hDMemo"));
                t130301Entity.setUploads(GridUtils.prossRowSetDataType_String(map, "uploads"));
                detailEntityList.add(new T130301DetailEntity(
                        GridUtils.prossRowSetDataType_String(map, "matCode"),
                        GridUtils.prossRowSetDataType_String(map, "matName"),
@@ -302,22 +306,29 @@
    }
    @Override
    public T120201Entity getT120201(String docCode) {
    public List<T120201Entity> getT120201(String docCode) {
        return this.jdbcTemplate.query(
                " set nocount on \n" +
                        " select a.DistributorPoDocCode,b.docCode,b.MatCode,b.refrowid,b.Price,c.dbid as cltDbid from t120201H a \n" +
                        " join t120201D b on a.DocCode=b.DocCode\n" +
                        " join t110203 c on c.cltCode=a.CltCode\n" +
                        " where a.DocCode=?", new BeanPropertyRowMapper<>(T120201Entity.class), docCode);
    }
    @Override
    public T120201Entity getT120201ByDistributor(String docCode) {
        return this.jdbcTemplate.queryForObject(
                " set nocount on \n" +
                        " declare @cltCode varchar(50),@refCode varchar(50),@dbid int,@docCode varchar(50)=? \n" +
                        " select @cltCode=cltCode,@refCode=refCode from t120201H a join gform c on  a.formid= c.formid \n" +
                        " where a.DocCode=@docCode   and  c.postdocstatus = a.DocStatus\n" +
                        " select @dbid=dbid from t110203 where CltCode=@cltCode \n" +
                        " select @refCode as docCode,@dbid as dbid", new BeanPropertyRowMapper<>(T120201Entity.class), docCode);
                        " select a.docCode,c.dbid as vndDbid from t120201H a \n" +
                        " join t110302 c on c.vndCode=a.HeadqVndCode\n" +
                        " where isnull(c.dbid,0)<>0 and isnull(a.HeadqVndCode,'')<>'' and a.DocCode=?", new BeanPropertyRowMapper<>(T120201Entity.class), docCode);
    }
    @Override
    public T140201Entity getT140201(String docCode) {
        return this.jdbcTemplate.queryForObject(
                " set nocount on \n" +
                        " declare @cltCode varchar(50),@refCode varchar(50),@dbid int,@docCode varchar(50)=?,@logisticsCode varchar(50),@shipperCode varchar(50),@shipperName varchar(50),@logisticsCodeState varchar(50) \n" +
                        " select @cltCode=a.cltCode,@dbid=e.dbid,@refCode=d.refCode,@logisticsCode=a.logisticsCode,@shipperCode =a.shipperCode,@shipperName =a.shipperName,@logisticsCodeState=a.logisticsCodeState \n" +
                        " declare @cltCode varchar(50),@refCode varchar(50),@dbid int,@docCode varchar(50)=?,@logisticsCode varchar(50),@shipperCode varchar(50),@shipperName varchar(50),@logisticsCodeState varchar(50),@ReceipterTelephone  varchar(50) \n" +
                        " select @cltCode=a.cltCode,@dbid=e.dbid,@refCode=d.refCode,@logisticsCode=a.logisticsCode,@shipperCode =a.shipperCode,@shipperName =a.shipperName,@logisticsCodeState=a.logisticsCodeState,@ReceipterTelephone =a.ReceipterTelephone  \n" +
                        " from t140201H a " +
                        "  join gform c on  a.formid= c.formid \n" +
                        "  join t120301H b on a.refCode=b.docCode \n" +
@@ -326,24 +337,52 @@
                        " where a.DocCode=@docCode   " +
                        "  and  c.postdocstatus = a.DocStatus \n" +
                        "  and isnull(e.dbid,0)<>0\n" +
                        " select @refCode as docCode,@dbid as dbid,@logisticsCode as logisticsCode,@shipperCode as shipperCode,@shipperName as shipperName,@logisticsCodeState as logisticsCodeState", new BeanPropertyRowMapper<>(T140201Entity.class), docCode);
                        " select @refCode as docCode,@dbid as dbid,@logisticsCode as logisticsCode,@shipperCode as shipperCode,@shipperName as shipperName,@logisticsCodeState as logisticsCodeState,@ReceipterTelephone  as receipterTelephone  ", new BeanPropertyRowMapper<>(T140201Entity.class), docCode);
    }
    @Transactional
    @Override
    public Integer do130301(T120201Entity t120201Entity) {
        return this.jdbcTemplate.queryForObject(" set nocount on \n " +
                " declare @vndName varchar(50),@dbid int=?,@docCode varchar(50)=?,@refCode varchar(50)=? \n" +
    public void do130301(List<T120201Entity> list) {
        if(list==null||list.size()==0) {
            throw new ApplicationException("回传的销售数据为空");
        }
        T120201Entity t120201Entity =list.get(0);
        String sql=" set nocount on \n " +
                " declare @vndName varchar(50),@dbid int="+t120201Entity.getVndDbid()+",@docCode varchar(50)="+GridUtils.prossSqlParm(t120201Entity.getDistributorPoDocCode())+",@HeadqSoDocCode varchar(50)="+GridUtils.prossSqlParm(t120201Entity.getDocCode())+" \n" +
                " declare @matCode varchar(50),@price money,@Rowid varchar(50)" +
                " select @vndName=vndName from t110302 where dbid=@dbid \n" +
                "  update a set a.callBackMsg=@vndName+'已通过您的采购申请',a.refCode=@refCode,a.refformid=120201 from t130301H a where a.docCode=@docCode \n select @@rowcount", Integer.class, t120201Entity.getRefDbId(), t120201Entity.getDocCode(), t120201Entity.getRefDocCode());
                "  update a set a.callBackMsg=@vndName+'已通过您的采购申请',a.HeadqSoFormId=120201,a.HeadqSoDocCode=@HeadqSoDocCode from t130301H a where a.docCode=@docCode \n";
        for(T120201Entity entity:list){
            sql+="    select @matCode=null,@price=null,@Rowid=null \n" +
                    " select @matCode="+GridUtils.prossSqlParm(entity.getMatCode())+",@price="+entity.getPrice()+",@Rowid="+GridUtils.prossSqlParm(entity.getRefRowid())+" \n" +
                    " update a set a.price=@price,a.MoneyType=7 from t130301D a where a.matcode=@matCode and a.Rowid=@Rowid and a.doccode=@docCode \n";
        }
        sql += " --执行保存\n" +
                " exec p130301Save @docCode\n" +
                " declare @PostFormId int, @DocStatusValue int,@PreDocStatus int,@PostDocStatus int,@Memo varchar(50), @LinkDocInfo varchar(50),@EnterCode varchar(50)= 'SYSTEM',@EnterName varchar(50)='管理员'\n" +
                "                         select @PostFormId = FormId,@DocStatusValue = DocStatus from t130301H where docCode=@docCode\n" +
                "                    select @PreDocStatus = PreDocStatus,@PostDocStatus = a.PostDocStatus from gform a where a.formid = @PostFormId \n" +
                "                if isnull(@DocStatusValue,0) = isnull(@PreDocStatus,0)\n" +
                "                         begin \n" +
                "                            update a set DocStatus = @PostDocStatus,PostCode=@EnterCode,PostName=@EnterName,PostDate=getdate()\n" +
                "                              from t130301H a where a.DocCode = @docCode \n" +
                "                            exec p130301Post @UserCode = @EnterCode,@UserName = @EnterName, \n" +
                "                                @DocCode = @docCode,@FormId = @PostFormId,\n" +
                "                                 @DocStatusValue = @DocStatusValue,@ButtonType ='提交', \n" +
                "                                @Memo=@Memo output ,@LinkDocInfo = @LinkDocInfo output   \n" +
                "                         end" ;
         this.jdbcTemplate.execute(sql);
    }
    @Transactional
    @Override
    public Integer do140201(T140201Entity t140201Entity) {
        return this.jdbcTemplate.queryForObject(" set nocount on \n " +
                " declare @logisticsCode varchar(50)=?,@shipperCode varchar(50)=?,@shipperName varchar(50)=?,@logisticsCodeState varchar(50)=?,@docCode varchar(50)=? \n" +
                "  update a set a.logisticsCode=@logisticsCode,a.shipperCode=@shipperCode ,a.shipperName=@shipperName ,a.logisticsCodeState=@logisticsCodeState  from t130301H a where a.docCode=@docCode \n select @@rowcount", Integer.class, t140201Entity.getLogisticsCode(), t140201Entity.getShipperCode(), t140201Entity.getShipperName(), t140201Entity.getLogisticsCodeState(), t140201Entity.getDocCode());
                " declare @logisticsCode varchar(50)=?,@shipperCode varchar(50)=?,@shipperName varchar(50)=?,@logisticsCodeState varchar(50)=?,@docCode varchar(50)=?,@ReceipterTelephone  varchar(50)=? \n" +
                "  update a set a.logisticsCode=@logisticsCode,a.shipperCode=@shipperCode ,a.shipperName=@shipperName ,a.logisticsCodeState=@logisticsCodeState  from t130301H a where a.docCode=@docCode \n select @@rowcount", Integer.class, t140201Entity.getLogisticsCode(), t140201Entity.getShipperCode(), t140201Entity.getShipperName(), t140201Entity.getLogisticsCodeState(), t140201Entity.getDocCode(),t140201Entity.getReceipterTelephone());
    }
    @Transactional
@@ -361,17 +400,17 @@
    @Transactional
    @Override
    public T120201Entity do120201(T130301Entity t130301Entity) {
    public void do120201(T130301Entity t130301Entity) {
        String sql = " set nocount on\n" +
                " --表头变量\n" +
                " declare @doccode varchar(50),@dbid int=" + GridUtils.prossSqlParm(t130301Entity.getRefDbId()) + " ,@formid int=120201,@refcodeformid int=130301,@PeriodID varchar(50),@Docdate date=convert(varchar(10),getdate(),120),@doctype varchar(50)='门店单',\n" +
                " @EnterCode varchar(50)='SYSTEM',@EnterName varchar(50)='系统管理员',@EnterDate dateTime=getDate(),@ModifyName varchar(50)='系统管理员',@ModifyDate dateTime=getDate(),@DocStatus int=0,@companyID  varchar(50),@companyName varchar(150),@CltCode varchar(50),@CltName varchar(50),@PropertyAddress varchar(250),@clttype varchar(50),@hDMemo varchar(250),@ccCode varchar(50),@ccName varchar(50),@tel varchar(50),@refCode varchar(50)=" + GridUtils.prossSqlParm(t130301Entity.getRefCode()) +
                " declare @doccode varchar(50),@dbid int=" + t130301Entity.getCltDbid() + " ,@formid int=120201,@refcodeformid int=130301,@PeriodID varchar(50),@Docdate date=convert(varchar(10),getdate(),120),@doctype varchar(50)='门店单',\n" +
                " @EnterCode varchar(50)='SYSTEM',@EnterName varchar(50)='系统管理员',@EnterDate dateTime=getDate(),@ModifyName varchar(50)='系统管理员',@ModifyDate dateTime=getDate(),@DocStatus int=0,@companyID  varchar(50),@companyName varchar(150),@CltCode varchar(50),@CltName varchar(50),@PropertyAddress varchar(250),@clttype varchar(50),@hDMemo varchar(250)="+GridUtils.prossSqlParm(t130301Entity.getHDMemo())+",@ccCode varchar(50),@ccName varchar(50),@tel varchar(50),@uploads varchar(200)="+GridUtils.prossSqlParm(t130301Entity.getUploads())+",@DistributorPoDocCode varchar(50)=" + GridUtils.prossSqlParm(t130301Entity.getRefCode()) +
                " exec sp_newdoccode @formid,'SYSTEM',@doccode output\n" +
                " --取客户资料\n" +
                " select @CltCode=cltCode,@CltName=cltName,@companyID=companyid,@companyName=companyname,@ccCode=cccode,@ccName=ccname,@tel=Tel,@PropertyAddress=PropertyAddress,@clttype=clttype from t110203 where dbid=@dbid \n" +
                " select @PeriodId = dbo.GetPeriodID(@formid,@CompanyID,GETDATE())\n" +
                " insert into t120201H(doccode ,formid,PeriodID ,Docdate,doctype ,EnterCode ,EnterName ,EnterDate,ModifyName ,ModifyDate ,DocStatus,companyID,companyName,CltCode ,CltName ,PropertyAddress,clttype ,hDMemo,ccCode ,ccName ,tel,refCode,refformid )values(@doccode ,@formid,@PeriodID ,@Docdate,@doctype ,@EnterCode ,@EnterName ,@EnterDate,@ModifyName ,@ModifyDate,@DocStatus,@companyID,@companyName,@CltCode ,@CltName ,@PropertyAddress,@clttype ,@hDMemo,@ccCode ,@ccName ,@tel,@refCode,@refcodeformid )\n" +
                " insert into t120201H(doccode ,formid,PeriodID ,Docdate,doctype ,EnterCode ,EnterName ,EnterDate,ModifyName ,ModifyDate ,DocStatus,companyID,companyName,CltCode ,CltName ,PropertyAddress,clttype ,hDMemo,ccCode ,ccName ,tel,DistributorPoDocCode,DistributorPoFormId,refformid,uploads )values(@doccode ,@formid,@PeriodID ,@Docdate,@doctype ,@EnterCode ,@EnterName ,@EnterDate,@ModifyName ,@ModifyDate,@DocStatus,@companyID,@companyName,@CltCode ,@CltName ,@PropertyAddress,@clttype ,@hDMemo,@ccCode ,@ccName ,@tel,@DistributorPoDocCode,130301,@refcodeformid,@uploads )\n" +
                " ---表体变量\n" +
                " declare @docitem int,@rowid varchar(50),@matCode varchar(50),@price money,@digit money,@cv2 varchar(50),@tCcode varchar(50),@itemMemo varchar(150),@matName varchar(50),\n" +
                " @Barcode varchar(50),@Brand varchar(50),@Stcode varchar(50),@stname varchar(50),@UOM varchar(50),@baseuom varchar(50),@netprice money,@TrademarkPrice money,@special varchar(50),@weight money,@matgroup varchar(50),@matgroupname varchar(50),@TCname varchar(50) ,@TaxPrice money ,@pricetype varchar(50) ,@totalmoney2 money,@discount money,@whcode varchar(50) ,@refcodeitem varchar(50) ,@refrowid varchar(50)  ,@Pricerefcodeitem varchar(50) ,@Pricerefrowid varchar(50) ,@Pricerefcodeformid varchar(50),@MoneyType int=7,@cv1 varchar(50)\n" +
@@ -430,14 +469,14 @@
                "                if isnull(@DocStatusValue,0) = isnull(@PreDocStatus,0)\n" +
                "                         begin \n" +
                "                            update a set DocStatus = @PostDocStatus,PostCode=@EnterCode,PostName=@EnterName,PostDate=getdate()\n" +
                "                              from t120201H a where a.DocCode = @docCode \n" +
                "                             from t120201H a where a.DocCode = @docCode \n" +
                "                            exec p120201Post @UserCode = @EnterCode,@UserName = @EnterName, \n" +
                "                                @DocCode = @docCode,@FormId = @PostFormId,\n" +
                "                                 @DocStatusValue = @DocStatusValue,@ButtonType ='提交', \n" +
                "                                @Memo=@Memo output ,@LinkDocInfo = @LinkDocInfo output   \n" +
                "                         end" +
                " select @refCode as docCode,@dbid as dbid,@docCode as refDocCode";
        return this.jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(T120201Entity.class));
                "                         end" ;
        //log.info("120201sql:"+sql);
         this.jdbcTemplate.execute(sql);
    }
    @Override
@@ -458,8 +497,8 @@
    @Override
    public T120201Entity checkDocPushSuccess130301(int formid, String docCode, Integer actionType) {
        String sql = " set nocount on\n" +
                " declare  @formid int=?,@docCode varchar(50)=?,@refCode varchar(50),@dbid int\n" +
                "  select  @refCode=refCode,@dbid=b.dbid from t130301H a join gform c on  a.formid= c.formid \n" +
                " declare  @formid int=?,@docCode varchar(50)=?,@HeadqSoDocCode varchar(50),@dbid int\n" +
                "  select  @HeadqSoDocCode=HeadqSoDocCode,@dbid=b.dbid from t130301H a join gform c on  a.formid= c.formid \n" +
                "  join t110302 b on b.vndCode=a.vndCode\n" +
                "  where a.docCode=@docCode \n" +
                "  and c.postdocstatus = a.DocStatus \n";
@@ -467,13 +506,13 @@
            sql += "  and isnull(a.callBackMsg,'')<>''\n";
        }
        sql += "  and isnull(b.dbid,0)<>0\n" +
                " SELECT @refCode as docCode,@dbid as dbId";
                " SELECT @HeadqSoDocCode as docCode,@dbid as dbId";
        return this.jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(T120201Entity.class), formid, docCode);
    }
    @Override
    public Integer updateCallBackMsgBy130301(String docCode) {
        return this.jdbcTemplate.queryForObject(" set  nocount  on \n update a set a.callBackMsg=null from t130301H a where a.DocCode=? \n select @@rowcount", Integer.class, docCode);
        return this.jdbcTemplate.queryForObject(" set  nocount  on \n update a set a.callBackMsg=null,a.HeadqSoDocCode=null from t130301H a where a.DocCode=? \n select @@rowcount", Integer.class, docCode);
    }
    /**
@@ -485,11 +524,11 @@
        if (list != null && list.size() > 0) {
            String sql = "";
            for (T110562Entity t110562Entity : list) {
                sql += " \n if exists(select 1 from t110562 where   doccode='" + t110562Entity.getDocCode() + "' and rowid='" + t110562Entity.getRowId() + "')\n" +
                        " update t110562 set PushStatus=" + (t110562Entity.getPushStatus() == 0 ? 1 : 0) + ",PushDate=getdate(),PushTimes=isnull(PushTimes,0)+1 ,PushMsg='" + t110562Entity.getPushMsg() + "' where formid=" + t110562Entity.getFormId() + " and doccode='" + t110562Entity.getDocCode() + "' and rowid='" + t110562Entity.getRowId() + "' and matcode='" + t110562Entity.getMatCode() + "'" +
                sql += " \n if exists(select 1 from t110562 where  formid="+t110562Entity.getFormId()+" and doccode " +( GridUtils.prossSqlParm(t110562Entity.getDocCode())==null?"is null":"="+GridUtils.prossSqlParm(t110562Entity.getDocCode())) + " and rowid=" + GridUtils.prossSqlParm(t110562Entity.getRowId()) + ")\n" +
                        " update t110562 set PushStatus=" + (t110562Entity.getPushStatus() == 0 ? 1 : 0) + ",PushDate=getdate(),PushTimes=isnull(PushTimes,0)+1 ,PushMsg='" + t110562Entity.getPushMsg() + "' where formid=" + t110562Entity.getFormId() + " and doccode=" +GridUtils.prossSqlParm( t110562Entity.getDocCode()) + " and rowid=" + GridUtils.prossSqlParm(t110562Entity.getRowId()) + " and matcode=" +GridUtils.prossSqlParm( t110562Entity.getMatCode()) + "" +
                        " \n else \n" +
                        " insert  into t110562(FormId ,DocCode,DocItem ,RowId ,MatCode ,MatName ,Special ,Uom ,Digit ,Price,TotalMoney,StCode,StName,ItemMemo,PushStatus,PushDate,PushTimes ,PushMsg) \n" +
                        " values(" + t110562Entity.getFormId() + ",'" + t110562Entity.getDocCode() + "'," + t110562Entity.getDocItem() + ",'" + t110562Entity.getRowId() + "','" + t110562Entity.getMatCode() + "','" + t110562Entity.getMatName() + "','" + t110562Entity.getSpecial() + "','" + t110562Entity.getUom() + "'," + t110562Entity.getDigit() + "," + t110562Entity.getPrice() + "," + t110562Entity.getTotalMoney() + ",'" + t110562Entity.getStCode() + "','" + t110562Entity.getStName() + "','" + t110562Entity.getItemMemo() + "'," + (t110562Entity.getPushStatus() == 0 ? 1 : 0) + ",getdate()," + t110562Entity.getPushTimes() + ",'" + t110562Entity.getPushMsg() + "')\n";
                        " values(" + t110562Entity.getFormId() + "," + GridUtils.prossSqlParm(t110562Entity.getDocCode()) + "," + t110562Entity.getDocItem() + "," +GridUtils.prossSqlParm( t110562Entity.getRowId()) + "," + GridUtils.prossSqlParm(t110562Entity.getMatCode()) + "," + GridUtils.prossSqlParm(t110562Entity.getMatName() )+ "," +GridUtils.prossSqlParm( t110562Entity.getSpecial()) + "," + GridUtils.prossSqlParm(t110562Entity.getUom()) + "," + t110562Entity.getDigit() + "," + t110562Entity.getPrice() + "," + t110562Entity.getTotalMoney() + "," +GridUtils.prossSqlParm( t110562Entity.getStCode()) + "," + GridUtils.prossSqlParm(t110562Entity.getStName()) + "," +GridUtils.prossSqlParm( t110562Entity.getItemMemo() )+ "," + (t110562Entity.getPushStatus() == 0 ? 1 : 0) + ",getdate()," + t110562Entity.getPushTimes() + "," +GridUtils.prossSqlParm( t110562Entity.getPushMsg()) + ")\n";
            }
            final Integer result = getSimpleJdbcTemplate().queryForObject("set nocount on \n " + sql + "  \n select @@rowcount;", Integer.class);
@@ -499,7 +538,18 @@
        }
        return false;
    }
    @Transactional
    @Override
    public Integer del121501(T120201Entity t120201Entity) {
        return this.jdbcTemplate.queryForObject("set nocount  on \n" +
                " declare @dbid int =?,@HeadqCltCode varchar(20),@docCode varchar(50)=? \n" +
                " select @HeadqCltCode=cltCode from t110203 where dbid=@dbid \n" +
                "  begin \n" +
                " exec ppublicdel  @docCode,121501\n" +
                " delete from t121501D where HeadqCltCode=@HeadqCltCode and refcodeitem =@docCode\n" +
                " delete from t121501H where HeadqCltCode=@HeadqCltCode and  refcode=@docCode\n" +
                "  end \n select @@rowcount", Integer.class,t120201Entity.getCltDbid(), t120201Entity.getDocCode());
    }
    @Transactional
    @Override
    public Integer del120201(T120201Entity t120201Entity) {
@@ -510,7 +560,7 @@
                "  select -2 \n" +
                "  else\n" +
                "  begin \n" +
                "  declare @refcode varchar(20), @rowcount int,@userCode varchar(50)='SYSTEM',\n" +
                "  declare @DistributorPoDocCode varchar(20), @rowcount int,@userCode varchar(50)='SYSTEM',\n" +
                " @userName varchar(50)='系统管理员' ,@formId int=120201 ,@formName varchar(50)='销售订单',@SqlWhere varchar(150)\n" +
                " select @SqlWhere='doccode='''+@docCode+''''\n" +
                " exec pSaveRecForDeleted @UserCode=@userCode,@UserName=@userName,@OrgDocCode = @docCode,@OrgFormID = @formId,@OrgFormName=@formName,@SqlWhere =@SqlWhere\n" +
@@ -518,11 +568,13 @@
                " delete from t120201D where doccode =@docCode\n" +
                " insert into gdocmodifylog(DocFormID,EventFormID,DocCode,DocDate, PreDocStatus,PostDocStatus,UserName,Event,EventTime )   \n" +
                " select formid ,@formId,doccode,docdate,docstatus, docstatus , @userName,'删除单据',getdate()  from t120201H with (nolock)  where doccode =@docCode; \n" +
                " select @refcode = refcode from t120201H with (nolock)  where doccode =@docCode and blclosed = -1  \n" +
                " if isnull(@refcode,'') <> ''\n" +
               /*
                " select @DistributorPoDocCode = DistributorPoDocCode from t120201H with (nolock)  where doccode =@docCode and blclosed = -1  \n" +
                " if isnull(@DistributorPoDocCode,'') <> ''\n" +
                " begin\n" +
                " update t120201H set cleardoccode = null ,blclosed = 0  where doccode =@refcode and blclosed = 1 \n" +
                " end\n" +
                */
                " delete from t120201H where doccode =@docCode\n" +
                " select @rowcount =@@rowcount\n" +
                " if @rowcount = 0 begin raiserror('删除单据 %s 出错,或者不存在此单据', 16,1, @docCode)  return  end \n" +
@@ -581,17 +633,14 @@
        }
    }
    @Override
    public List<T110302> get110302ByBrand() {
        return this.jdbcTemplate.query(" select brands,dbid,pullSalesOrderToHeadqLastDateTime,pullStockToHeadqLastDateTime from t110302 where isnull(dbid,0)<>0", new BeanPropertyRowMapper<>(T110302.class));
    }
    @Transactional
    @Override
    public String do12021All(Push120201Entity entity) {
    public void do120201All(Push120201Entity entity) {
        String sql = " set nocount  on\n" +
                " ---定义变量 \n" +
                " declare @doccode varchar(50),@companyID varchar(50),@companyName varchar(50),@HeadqCltCode varchar(50),@HeadqCltName varchar(50),@ccCode varchar(50),@ccName varchar(50),@dbid int,@tel varchar(50),@PropertyAddress varchar(50),@clttype varchar(50), @PreDocStatus int,@PostDocStatus int,@DocStatusValue int,@FormId int, @Memo varchar(200),@LinkDocInfo varchar(200),@doccode1 varchar(50), @docitem int, @rowId varchar(50), @matName varchar(200)=null,@Barcode varchar(150)=null,@Brand varchar(150)=null,@UOM varchar(150)=null,@baseuom varchar(150)=null,@netprice decimal,@TrademarkPrice money=null,@special varchar(100)=null,@weight money=null,@matgroup varchar(100)=null,@matgroupname varchar(100)=null,@TCname varchar(100)=null,@TaxPrice money=null,@pricetype varchar(100)=null,@discount money=null,@whcode varchar(100)=null,@refcodeitem varchar(100)=null,@refrowid varchar(100)=null,@refcodeformid int,@Pricerefcodeitem varchar(100)=null,@Pricerefrowid varchar(100)=null,@Pricerefcodeformid int=null,@matCode varchar(50),@price money,@digit money,@itemMemo varchar(200),@stCode varchar(50),@stName varchar(50),@cv2 varchar(20),@totalmoney money,@totalmoney2 money,@MoneyType int,@CaiGouStatus int ,@CaiGouDoccode varchar(50),@CaiGouFormid int,@CaiGouFormType int ,@CaiGouAmount varchar(50) ,@CaiGouLastDate datetime,@uploads varchar(200)  \n ";
                " declare @doccode varchar(50),@companyID varchar(50),@companyName varchar(50),@HeadqCltCode varchar(50),@HeadqCltName varchar(50),@ccCode varchar(50),@ccName varchar(50),@dbid int,@tel varchar(50),@PropertyAddress varchar(50),@clttype varchar(50), @PreDocStatus int,@PostDocStatus int,@DocStatusValue int,@FormId int, @Memo varchar(200),@LinkDocInfo varchar(200),@doccode1 varchar(50), @docitem int, @rowId varchar(50), @matName varchar(200)=null,@Barcode varchar(150)=null,@Brand varchar(150)=null,@UOM varchar(150)=null,@baseuom varchar(150)=null,@netprice decimal,@TrademarkPrice money=null,@special varchar(100)=null,@weight money=null,@matgroup varchar(100)=null,@matgroupname varchar(100)=null,@TCname varchar(100)=null,@TaxPrice money=null,@pricetype varchar(100)=null,@discount money=null,@whcode varchar(100)=null,@refcodeitem varchar(100)=null,@refrowid varchar(100)=null,@refcodeformid int,@Pricerefcodeitem varchar(100)=null,@Pricerefrowid varchar(100)=null,@Pricerefcodeformid int=null,@matCode varchar(50),@price money,@digit money,@itemMemo varchar(200),@stCode varchar(50),@stName varchar(50),@cv2 varchar(20),@totalmoney money,@totalmoney2 money,@MoneyType int,@CaiGouStatus varchar(50) ,@CaiGouDoccode varchar(50),@CaiGouFormid int,@CaiGouFormType int ,@CaiGouAmount varchar(50) ,@CaiGouLastDate datetime,@uploads varchar(200)  \n ";
        for (T121501Entity t120201Entity : entity.getList()) {
            //--客户资料
@@ -599,8 +648,11 @@
            sql += get120201Head(t120201Entity);
            sql += get120201Detail(t120201Entity);
        }
        log.info("120201sql:"+sql);
        return this.jdbcTemplate.queryForObject(sql + " \n select GETDATE()", String.class);
        if(StringUtils.isNotBlank(entity.getPullSalesOrderFromDistributorLastDateTime())) {
            sql += " update  a set  a.PullSalesOrderFromDistributorLastDateTime='"+entity.getPullSalesOrderFromDistributorLastDateTime()+"' from t110203 a where a.dbid="+entity.getCustomerDbid();
        }
       // log.info("120201sql:"+sql);
         this.jdbcTemplate.execute(sql);
    }
    private String get120201Head(T121501Entity entity) {
@@ -609,12 +661,12 @@
        sb.append("  select @doccode1=doccode from t121501h a where a.HeadqCltCode=@HeadqCltCode and a.refCode=" + GridUtils.prossSqlParm(head.getDocCode()) + "  \n" +
                " if @@rowcount >0 \n" +
                "  begin \n" +
                " update a set a.Docdate=" + GridUtils.prossSqlParm(head.getDocDate()) + ",a.doctype=" + GridUtils.prossSqlParm(head.getDocType()) + ",a.DocStatus=" + head.getDocStatus() + ",a.[CltCode]=" + GridUtils.prossSqlParm(head.getCltCode()) + ",a.[CltName]=" + GridUtils.prossSqlParm(head.getCltName()) + ",a.[PropertyAddress]=" + GridUtils.prossSqlParm(head.getPropertyAddress()) + ",a.hDMemo=" + GridUtils.prossSqlParm(head.getHDMemo()) + ",a.tel=" + GridUtils.prossSqlParm(head.getTel()) + ",a.tel2=" + GridUtils.prossSqlParm(head.getTel2()) + ",a.CaiGouStatus="+head.getCaiGouStatus()+",a.CaiGouDoccode="+GridUtils.prossSqlParm(head.getCaiGouDoccode())+",a.CaiGouFormid ="+head.getCaiGouFormid()+",a.CaiGouFormType="+head.getCaiGouFormType()+" ,a.CaiGouAmount ="+head.getCaiGouAmount()+" ,a.CaiGouLastDate="+GridUtils.prossSqlParm(head.getCaiGouLastDate())+",a.uploads="+GridUtils.prossSqlParm(head.getUploads())+"  from t121501h a where a.HeadqCltCode=@HeadqCltCode and a.refCode=" + GridUtils.prossSqlParm(head.getDocCode()) + "  \n" +
                " update a set a.Docdate=" + GridUtils.prossSqlParm(head.getDocDate()) + ",a.doctype=" + GridUtils.prossSqlParm(head.getDocType()) + ",a.DocStatus=" + head.getDocStatus() + ",a.[CltCode]=" + GridUtils.prossSqlParm(head.getCltCode()) + ",a.[CltName]=" + GridUtils.prossSqlParm(head.getCltName()) + ",a.[PropertyAddress]=" + GridUtils.prossSqlParm(head.getPropertyAddress()) + ",a.hDMemo=" + GridUtils.prossSqlParm(head.getHDMemo()) + ",a.tel=" + GridUtils.prossSqlParm(head.getTel()) + ",a.tel2=" + GridUtils.prossSqlParm(head.getTel2()) + ",a.CaiGouStatus="+GridUtils.prossSqlParm(head.getCaiGouStatus())+",a.CaiGouDoccode="+GridUtils.prossSqlParm(head.getCaiGouDoccode())+",a.CaiGouFormid ="+head.getCaiGouFormid()+",a.CaiGouFormType="+head.getCaiGouFormType()+" ,a.CaiGouAmount ="+head.getCaiGouAmount()+" ,a.CaiGouLastDate="+GridUtils.prossSqlParm(head.getCaiGouLastDate())+",a.uploads="+GridUtils.prossSqlParm(head.getUploads())+"  from t121501h a where a.HeadqCltCode=@HeadqCltCode and a.refCode=" + GridUtils.prossSqlParm(head.getDocCode()) + "  \n" +
                "  end \n" +
                "  else \n")
                .append(" begin \n" +
                        " exec sp_newdoccode 121501,'SYSTEM',@doccode1 output \n" +
                        " insert into t121501h(docCode,formid,PeriodID,Docdate,doctype,EnterCode,EnterName,DocStatus,companyID,companyName,[CltCode],[CltName],[PropertyAddress],hDMemo,tel,tel2,hdcurrency,hdcurrencyrate,refCode,HeadqCltCode,HeadqCltName,CaiGouStatus  ,CaiGouDoccode ,CaiGouFormid ,CaiGouFormType  ,CaiGouAmount ,CaiGouLastDate ,uploads) values(@doccode1,121501,dbo.GetPeriodID(121501,@companyID,convert(char(10),GetDate(),120)),convert(char(10),GetDate(),120)," + GridUtils.prossSqlParm(head.getDocType()) + "," + GridUtils.prossSqlParm(head.getEnterCode()) + "," + GridUtils.prossSqlParm(head.getEnterName()) + ",0,@companyId,@companyName," + GridUtils.prossSqlParm(head.getCltCode()) + "," + GridUtils.prossSqlParm(head.getCltName()) + "," + GridUtils.prossSqlParm(head.getPropertyAddress()) + "," + GridUtils.prossSqlParm(head.getHDMemo()) + "," + GridUtils.prossSqlParm(head.getTel()) + "," + GridUtils.prossSqlParm(head.getTel2()) + ",'RMB',1," + GridUtils.prossSqlParm(head.getDocCode()) + ",@HeadqCltCode,@HeadqCltName,"+head.getCaiGouStatus()+","+GridUtils.prossSqlParm(head.getCaiGouDoccode())+","+head.getCaiGouFormid()+","+head.getCaiGouFormType()+","+head.getCaiGouAmount()+","+GridUtils.prossSqlParm(head.getCaiGouLastDate())+","+GridUtils.prossSqlParm(head.getUploads())+") \n" +
                        " insert into t121501h(docCode,formid,PeriodID,Docdate,doctype,EnterCode,EnterName,DocStatus,companyID,companyName,[CltCode],[CltName],[PropertyAddress],hDMemo,tel,tel2,hdcurrency,hdcurrencyrate,refCode,HeadqCltCode,HeadqCltName,CaiGouStatus  ,CaiGouDoccode ,CaiGouFormid ,CaiGouFormType  ,CaiGouAmount ,CaiGouLastDate ,uploads) values(@doccode1,121501,dbo.GetPeriodID(121501,@companyID,convert(char(10),GetDate(),120)),convert(char(10),GetDate(),120)," + GridUtils.prossSqlParm(head.getDocType()) + "," + GridUtils.prossSqlParm(head.getEnterCode()) + "," + GridUtils.prossSqlParm(head.getEnterName()) + ",0,@companyId,@companyName," + GridUtils.prossSqlParm(head.getCltCode()) + "," + GridUtils.prossSqlParm(head.getCltName()) + "," + GridUtils.prossSqlParm(head.getPropertyAddress()) + "," + GridUtils.prossSqlParm(head.getHDMemo()) + "," + GridUtils.prossSqlParm(head.getTel()) + "," + GridUtils.prossSqlParm(head.getTel2()) + ",'RMB',1," + GridUtils.prossSqlParm(head.getDocCode()) + ",@HeadqCltCode,@HeadqCltName,"+GridUtils.prossSqlParm(head.getCaiGouStatus())+","+GridUtils.prossSqlParm(head.getCaiGouDoccode())+","+head.getCaiGouFormid()+","+head.getCaiGouFormType()+","+head.getCaiGouAmount()+","+GridUtils.prossSqlParm(head.getCaiGouLastDate())+","+GridUtils.prossSqlParm(head.getUploads())+") \n" +
                        " end \n");
        return sb.toString();
    }
@@ -695,7 +747,7 @@
                "                @discount money, @cv2 varchar(80), @unsubscribeDoccode varchar(200), @subDocdate datetime , \n" +
                "                @cltdocdate datetime,@cltType varchar(50),@sourceInfo varchar(50),@clttel varchar(50),@clttel2 varchar(50),@cltpropertyAddress varchar(200), \n" +
                "                @cltenterName  varchar(50),@cltsellerName varchar(50),@cltHDNote  varchar(200),  \n" +
                "                @cltreferralsName varchar(50),@cltbrithday varchar(50) ,@cltdocStatus int, @cltdocStatusName varchar(50),@baseuom varchar(50),@netprice money,@special varchar(50),@weight money,@matgroup varchar(50),@matgroupname varchar(50),@TCname varchar(50) ,@TaxPrice money ,@pricetype varchar(50) ,@totalmoney2 money ,@whcode varchar(50) ,@refcodeitem varchar(50),@refrowid varchar(50) ,@refcodeformid int ,@Pricerefcodeitem varchar(50) ,@Pricerefrowid  varchar(50),@Pricerefcodeformid int,@MoneyType int,@CaiGouStatus int ,@CaiGouDoccode varchar(50),@CaiGouFormid int,@CaiGouFormType int ,@CaiGouAmount varchar(50) ,@CaiGouLastDate datetime,@uploads varchar(200) \n" +
                "                @cltreferralsName varchar(50),@cltbrithday varchar(50) ,@cltdocStatus int, @cltdocStatusName varchar(50),@baseuom varchar(50),@netprice money,@special varchar(50),@weight money,@matgroup varchar(50),@matgroupname varchar(50),@TCname varchar(50) ,@TaxPrice money ,@pricetype varchar(50) ,@totalmoney2 money ,@whcode varchar(50) ,@refcodeitem varchar(50),@refrowid varchar(50) ,@refcodeformid int ,@Pricerefcodeitem varchar(50) ,@Pricerefrowid  varchar(50),@Pricerefcodeformid int,@MoneyType int,@CaiGouStatus varchar(50) ,@CaiGouDoccode varchar(50),@CaiGouFormid int,@CaiGouFormType int ,@CaiGouAmount varchar(50) ,@CaiGouLastDate datetime,@uploads varchar(200) \n" +
                "                declare @table table (shouKuanAmount money,docCode varchar(20),preSendDate datetime,docType varchar(50),\n" +
                "                cltCode varchar(20),cltName varchar(80),linkMan varchar(50),ccCode varchar(20),ccName varchar(50),hDMemo varchar(400), tel varchar(50), \n" +
                "                tel2 varchar(50),propertyAddress varchar(200), sellerName varchar(50), shopGuideName varchar(50),serviceName varchar(50), \n" +
@@ -707,7 +759,7 @@
                "                discount money, cv2 varchar(80), unsubscribeDoccode varchar(200), subDocdate datetime , \n" +
                "                cltdocdate datetime,cltType varchar(50),sourceInfo varchar(50),clttel varchar(50),clttel2 varchar(50),cltpropertyAddress varchar(200), \n" +
                "                cltenterName  varchar(50),cltsellerName varchar(50),cltHDNote  varchar(200),  \n" +
                "                cltreferralsName varchar(50),cltbrithday varchar(50) ,cltdocStatus int, cltdocStatusName varchar(50) ,baseuom varchar(50),netprice money,special varchar(50),weight money,matgroup varchar(50),matgroupname varchar(50),TCname varchar(50) ,TaxPrice money ,pricetype varchar(50) ,totalmoney2 money ,whcode varchar(50) ,refcodeitem varchar(50),refrowid varchar(50) ,refcodeformid int ,Pricerefcodeitem varchar(50) ,Pricerefrowid  varchar(50),Pricerefcodeformid int,MoneyType int,CaiGouStatus int,CaiGouDoccode varchar(50),CaiGouFormid int,CaiGouFormType int ,CaiGouAmount varchar(50) ,CaiGouLastDate datetime,uploads varchar(200))\n" +
                "                cltreferralsName varchar(50),cltbrithday varchar(50) ,cltdocStatus int, cltdocStatusName varchar(50) ,baseuom varchar(50),netprice money,special varchar(50),weight money,matgroup varchar(50),matgroupname varchar(50),TCname varchar(50) ,TaxPrice money ,pricetype varchar(50) ,totalmoney2 money ,whcode varchar(50) ,refcodeitem varchar(50),refrowid varchar(50) ,refcodeformid int ,Pricerefcodeitem varchar(50) ,Pricerefrowid  varchar(50),Pricerefcodeformid int,MoneyType int,CaiGouStatus varchar(50),CaiGouDoccode varchar(50),CaiGouFormid int,CaiGouFormType int ,CaiGouAmount varchar(50) ,CaiGouLastDate datetime,uploads varchar(200))\n" +
                "                declare @MatCode varchar(50),@MatName varchar(120)  ,@Brands varchar(500)=?,@LastPullDate datetime=?\n" +
                "                declare mycurDeli cursor for\n" +
@@ -740,7 +792,7 @@
                "                join t110203 e on b.cltcode = e.cltcode \n" +
                "                where \n" +
                "                d.Brand in (select list from getinstr(@Brands)) \n" +
                "                and b.ModifyDate between @LastPullDate and getdate() \n" +
                "                and (b.ModifyDate is null or b.ModifyDate between @LastPullDate and getdate()) \n" +
                "                and exists(select 1 from gform c where b.formid= c.formid  and c.postdocstatus = b.DocStatus ) \n" +
                "                order by b.DocCode\n" +
                "                open mycurDeli \n" +
@@ -820,7 +872,8 @@
                "    TCname ,TaxPrice ,pricetype ,totalmoney2  ,whcode ,refcodeitem ,refrowid ,refcodeformid ,Pricerefcodeitem ,CaiGouStatus,CaiGouDoccode ,CaiGouFormid ,CaiGouFormType  ,CaiGouAmount ,CaiGouLastDate,uploads,\n" +
                "    Pricerefrowid ,Pricerefcodeformid,MoneyType \n" +
                "                  from @table";
        List<Map<String, Object>> list = this.jdbcTemplate.queryForList(sql, t110302.getBrands(), t110302.getPullSalesOrderToHeadqLastDateTime());
        //System.out.println(">>>"+sql);
        List<Map<String, Object>> list = this.jdbcTemplate.queryForList(sql, t110302.getBrands(), t110302.getPullSalesOrderFromDistributorLastDateTime());
        if (list != null && list.size() > 0) {
            results = new ArrayList<>();
            Set<Object> distinctDoccdeList = list.stream().map(x -> x.get("docCode")).collect(Collectors.toSet());//取出集合中不重复单号
@@ -862,7 +915,7 @@
                                GridUtils.prossRowSetDataType_String(map, "enterDate"),
                                GridUtils.prossRowSetDataType_String(map, "modifyName"),
                                GridUtils.prossRowSetDataType_String(map, "modifyDate"),
                                GridUtils.prossRowSetDataType_Integer(map, "CaiGouStatus"),
                                GridUtils.prossRowSetDataType_String(map, "CaiGouStatus"),
                                GridUtils.prossRowSetDataType_String(map, "CaiGouDoccode"),
                                GridUtils.prossRowSetDataType_Integer(map, "CaiGouFormid"),
                                GridUtils.prossRowSetDataType_Integer(map, "CaiGouFormType"),
@@ -986,12 +1039,6 @@
    }
    @Transactional
    @Override
    public Integer updatePullSalesOrderToHeadqLastDateTime(Push120201Entity entity) {
        return this.jdbcTemplate.queryForObject(" set nocount on \n update  a set  a.PullSalesOrderToHeadqLastDateTime=? from t110302 a where a.dbid=? \n select @@rowcount", Integer.class, entity.getPullSalesOrderToHeadqLastDateTime(), entity.getVndDbid());
    }
    @Override
    public List<T210610Entity> getT210610(String docCode) {
        String sql = " set nocount  on\n" +
@@ -1100,7 +1147,7 @@
    @Override
    public List<T110203VO> get110203ByDbid() {
        return this.jdbcTemplate.query("set nocount  on\n" +
                " select dbid,isnull(PushMatCodeToDistributorLastDateTime,'2000-01-01 00:00:00') as PushMatCodeToDistributorLastDateTime from t110203 where isnull(dbid,0)<>0",new BeanPropertyRowMapper<>(T110203VO.class));
                " select dbid,isnull(PushMatCodeToDistributorLastDateTime,'2000-01-01 00:00:00') as PushMatCodeToDistributorLastDateTime,brands,isnull(PullSalesOrderFromDistributorLastDateTime,'2000-01-01 00:00:00') as pullSalesOrderFromDistributorLastDateTime,isnull(PullStockFromDistributorLastDateTime,'2000-01-01 00:00:00') as pullStockFromDistributorLastDateTime from t110203 where isnull(dbid,0)<>0",new BeanPropertyRowMapper<>(T110203VO.class));
    }
    @Override
@@ -1113,7 +1160,7 @@
                " a.CalCostType,\n" +
                " a.MatType,\n" +
                " a.qrCode,\n" +
                " a.baseuomrate\n" +
                " a.baseuomrate,a.photoPath \n" +
                "  from t110503 a join t110501 b on a.MatGroup=b.MatGroup \n" +
                "   where \n" +
                " a.ModifyDate is null or a.ModifyDate between isnull(@PushMatCodeToDistributorLastDateTime,'2000-01-01 00:00:00') and getdate()";
@@ -1125,7 +1172,7 @@
        String sql=" declare @MatGroup varchar(50),@MatGroupName varchar(80),@ParentRowId varchar(20),@rowid varchar(20),@treecontrol varchar(600)\n" +
                " declare @MatCode varchar(50),@MatName varchar(80),@Special varchar(80),@PurchasePrice money \n" +
                " declare @doccode varchar(20),@companyID varchar(50),@companyName varchar(50),@now datetime = getdate()\n" +
                " declare @HeadqVndCode varchar(50),@HeadqVndName varchar(50),@dbid int="+entity.getVndDbid()+",@PreDocStatus int,@PostDocStatus int,@DocStatusValue int,@FormId int = 110514,@pushLatDateTime datetime,@BaseUOM varchar(50),\n" +
                " declare @HeadqVndCode varchar(50),@HeadqVndName varchar(50),@dbid int="+entity.getVndDbid()+",@PreDocStatus int,@PostDocStatus int,@DocStatusValue int,@FormId int = 110514,@pushLatDateTime datetime,@BaseUOM varchar(50),@PhotoPath varchar(200),\n" +
                " @brand varchar(50),\n" +
                " @CalCostType varchar(50),\n" +
                " @MatType varchar(50),\n" +
@@ -1137,7 +1184,7 @@
        for(T110503Data data :entity.getList()) {
            sql +=
                    " select @MatGroup ="+GridUtils.prossSqlParm(data.getMatGroup())+",@MatGroupName  ="+GridUtils.prossSqlParm(data.getMatGroupName())+",@ParentRowId= "+GridUtils.prossSqlParm(data.getParentRowId())+",@rowid  ="+GridUtils.prossSqlParm(data.getRowid())+",@treecontrol  ="+GridUtils.prossSqlParm(data.getTreecontrol())+"\n" +
                            " select @MatCode  ="+GridUtils.prossSqlParm(data.getMatCode())+",@MatName  ="+GridUtils.prossSqlParm(data.getMatName())+",@Special  ="+GridUtils.prossSqlParm(data.getSpecial())+",@PurchasePrice = "+data.getSalesPrice()+",@pushLatDateTime="+GridUtils.prossSqlParm(entity.getNowDateTime())+",@BaseUOM="+GridUtils.prossSqlParm(data.getBaseUOM())+",@brand="+GridUtils.prossSqlParm(data.getBrand())+",@CalCostType="+GridUtils.prossSqlParm(data.getCalCostType())+",@MatType="+GridUtils.prossSqlParm(data.getMatType())+",@qrCode="+GridUtils.prossSqlParm(data.getQrCode())+",@baseuomrate="+data.getBaseuomrate()+",@stCode='A'\n" +
                            " select @MatCode  ="+GridUtils.prossSqlParm(data.getMatCode())+",@MatName  ="+GridUtils.prossSqlParm(data.getMatName())+",@Special  ="+GridUtils.prossSqlParm(data.getSpecial())+",@PurchasePrice = "+data.getSalesPrice()+",@pushLatDateTime="+GridUtils.prossSqlParm(entity.getNowDateTime())+",@BaseUOM="+GridUtils.prossSqlParm(data.getBaseUOM())+",@brand="+GridUtils.prossSqlParm(data.getBrand())+",@CalCostType="+GridUtils.prossSqlParm(data.getCalCostType())+",@MatType="+GridUtils.prossSqlParm(data.getMatType())+",@qrCode="+GridUtils.prossSqlParm(data.getQrCode())+",@baseuomrate="+data.getBaseuomrate()+",@stCode='A',@PhotoPath="+GridUtils.prossSqlParm(data.getPhotoPath())+"\n" +
                            " if not exists(select 1 from t110501 a where a.MatGroup = @MatGroup) \n" +
                            " begin\n" +
                            "     if exists(select 1 \n" +
@@ -1158,7 +1205,7 @@
                            " if @@rowcount > 0 \n" +
                            " begin \n" +
                            " update a set a.MatName = @MatName ,a.Special = @Special ,a.PurchasePrice = @PurchasePrice,\n" +
                            "   a.PushMatCodeToDistributorLastDateTime=@pushLatDateTime,a.BaseUOM=@BaseUOM,a.brand=@brand,a.CalCostType=@CalCostType,a.MatType=@MatType,a.qrCode=@qrCode,a.baseuomrate=@baseuomrate \n" +
                            "   a.PushMatCodeToDistributorLastDateTime=@pushLatDateTime,a.BaseUOM=@BaseUOM,a.brand=@brand,a.CalCostType=@CalCostType,a.MatType=@MatType,a.qrCode=@qrCode,a.baseuomrate=@baseuomrate,a.PhotoPath=@PhotoPath,a.MatGroup=@MatGroup,matgroupname=@MatGroupName \n" +
                            " from t110503 a where a.matcode= @matcode \n" +
                            " end else \n" +
                            " begin\n" +
@@ -1168,15 +1215,15 @@
                            "     from sys.objects a join sys.columns b on a.object_id = b.object_id\n" +
                            "     where a.name = 't110503' and b.name = 'matcode' and b.is_computed = 1 ) \n" +
                            "  begin \n" +
                            "     select @sql = 'insert into t110503 (doccode, formid, periodid, docdate, companyid, docstatus, entercode, entername, enterdate, modifyname, modifydate,ShopMatCode,matname,special,PurchasePrice,PushMatCodeToDistributorLastDateTime,MatGroup,matgroupname,BaseUOM,brand,vndcode,vndname,CalCostType,MatType,qrCode,baseuomrate,stCode) ' + \n" +
                            "     select @sql = 'insert into t110503 (doccode, formid, periodid, docdate, companyid, docstatus, entercode, entername, enterdate, modifyname, modifydate,ShopMatCode,matname,special,PurchasePrice,PushMatCodeToDistributorLastDateTime,MatGroup,matgroupname,BaseUOM,brand,vndcode,vndname,CalCostType,MatType,qrCode,baseuomrate,stCode,PhotoPath) ' + \n" +
                            "             ' values (''' +isnull(@doccode,'')+ ''',''' +cast(isnull(@FormId,0) as varchar(20))+ ''',''' + dbo.GetPeriodID(@FormId,@companyID,convert(varchar(10),@now,120))+ ''',''' + convert(char(10),@now,120)+ ''',''' +\n" +
                            "           @companyid+ ''',0,''' +isnull(@HeadqVndCode,'')+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + convert(varchar(10),@now,120)+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + convert(varchar(10),@now,120)+ ''',''' +isnull(@matcode,'')+ ''',''' +isnull(@matname,'')+ ''',''' +isnull(@special,'')+ ''',''' +cast(isnull(@PurchasePrice,0) as varchar(20))+ ''',''' +convert(varchar(19),@pushLatDateTime,120)+ ''',''' + isnull(@MatGroup,'')+ ''',''' + isnull(@matgroupname,'')+ ''',''' + isnull(@BaseUOM,'')+ ''',''' + isnull(@brand,'')+ ''',''' + isnull(@HeadqVndCode,'')+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + isnull(@CalCostType,'')+ ''',''' + isnull(@MatType,'')+ ''',''' + isnull(@qrCode,'')+ ''',''' + cast(isnull(@baseuomrate,0) as varchar(20))+''',''A'')' \n" +
                            "           @companyid+ ''',0,''' +isnull(@HeadqVndCode,'')+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + convert(varchar(10),@now,120)+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + convert(varchar(10),@now,120)+ ''',''' +isnull(@matcode,'')+ ''',''' +isnull(@matname,'')+ ''',''' +isnull(@special,'')+ ''',''' +cast(isnull(@PurchasePrice,0) as varchar(20))+ ''',''' +convert(varchar(19),@pushLatDateTime,120)+ ''',''' + isnull(@MatGroup,'')+ ''',''' + isnull(@matgroupname,'')+ ''',''' + isnull(@BaseUOM,'')+ ''',''' + isnull(@brand,'')+ ''',''' + isnull(@HeadqVndCode,'')+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + isnull(@CalCostType,'')+ ''',''' + isnull(@MatType,'')+ ''',''' + isnull(@qrCode,'')+ ''',''' + cast(isnull(@baseuomrate,0) as varchar(20))+''',''A'','''+isnull(@PhotoPath,'')+''')' \n" +
                            "     exec(@sql)  \n" +
                            "  end else \n" +
                            "  begin \n" +
                            "     select @sql = 'insert into t110503 (doccode, formid, periodid, docdate, companyid, docstatus, entercode, entername, enterdate, modifyname, modifydate,MatCode,matname,special,PurchasePrice,PushMatCodeToDistributorLastDateTime,MatGroup,matgroupname,BaseUOM,brand,vndcode,vndname,CalCostType,MatType,qrCode,baseuomrate) ' + \n" +
                            "             ' values (''' +isnull(@doccode,'')+ ''',''' +cast(isnull(@FormId,0) as varchar(20))+ ''',''' + dbo.GetPeriodID(@FormId,@companyID,convert(varchar(10),@now,120))+ ''',''' + convert(char(10),@now,120)+ ''',''' +\n" +
                            "           @companyid+ ''',0,''' +isnull(@HeadqVndCode,'')+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + convert(varchar(10),@now,120)+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + convert(varchar(10),@now,120)+ ''',''' +isnull(@matcode,'')+ ''',''' +isnull(@matname,'')+ ''',''' +isnull(@special,'')+ ''',''' +cast(isnull(@PurchasePrice,0) as varchar(20))+ ''',''' +convert(varchar(19),@pushLatDateTime,120)+ ''',''' + isnull(@MatGroup,'')+ ''',''' + isnull(@matgroupname,'')+ ''',''' + isnull(@BaseUOM,'')+ ''',''' + isnull(@brand,'')+ ''',''' + isnull(@HeadqVndCode,'')+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + isnull(@CalCostType,'')+ ''',''' + isnull(@MatType,'')+ ''',''' + isnull(@qrCode,'')+ ''',''' + cast(isnull(@baseuomrate,0) as varchar(20))+''',''A'')' \n" +
                            "           @companyid+ ''',0,''' +isnull(@HeadqVndCode,'')+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + convert(varchar(10),@now,120)+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + convert(varchar(10),@now,120)+ ''',''' +isnull(@matcode,'')+ ''',''' +isnull(@matname,'')+ ''',''' +isnull(@special,'')+ ''',''' +cast(isnull(@PurchasePrice,0) as varchar(20))+ ''',''' +convert(varchar(19),@pushLatDateTime,120)+ ''',''' + isnull(@MatGroup,'')+ ''',''' + isnull(@matgroupname,'')+ ''',''' + isnull(@BaseUOM,'')+ ''',''' + isnull(@brand,'')+ ''',''' + isnull(@HeadqVndCode,'')+ ''',''' + isnull(@HeadqVndName,'')+ ''',''' + isnull(@CalCostType,'')+ ''',''' + isnull(@MatType,'')+ ''',''' + isnull(@qrCode,'')+ ''',''' + cast(isnull(@baseuomrate,0) as varchar(20))+''',''A'','''+isnull(@PhotoPath,'')+''')' \n" +
                            "     exec(@sql)  \n" +
                            "   end \n" +
                            " end \n" +
@@ -1193,20 +1240,49 @@
        return this.jdbcTemplate.queryForObject("set nocount  on \n" +
                "  update a set a.PushMatCodeToDistributorLastDateTime=? from t110203 a where a.dbid=? \n select @@rowcount",Integer.class,entity.getNowDateTime(),entity.getCltDbid());
    }
    @Transactional
    @Override
    public List<AttachmentEntity> getAttachmentInfo(String uuid) {
    public Integer update120201ByVndCode(CallBack120201Entity entity) {
        return this.jdbcTemplate.queryForObject("set nocount  on \n" +
                "   declare @HeadqVndCode varchar(50),@HeadqVndName varchar(50),@dbid int=?,@docCodeList varchar(500)=? \n" +
                " select @HeadqVndCode=vndCode,@HeadqVndName=vndName from t110302 where isnull(dbid,0)=@dbid \n" +
                " if @@rowcount>0 \n" +
                "  begin \n" +
                "  update a set a.HeadqVndCode=@HeadqVndCode ,a.HeadqVndName=@HeadqVndName from t120201H a where a.doccode in(@docCodeList) \n  end \n select @@rowcount ",Integer.class,entity.getVndDbid(),entity.getDocCodeList());
    }
    /**
     *
     * @param uuid
     * @param formid
     * @param fieldid
     * @param headflag
     * @return
     */
    @Override
    public List<AttachmentEntity> getAttachmentInfo(String uuid,Integer formid,String fieldid,int headflag) {
        if(StringUtils.isBlank(uuid)){
            return null;
        }
        String tableName=" _sys_Attachment9";
        String[] strings = uuid.split(";");
        if(strings.length>2){
            //表示多附件
            tableName=" _sys_Attachment";
        String sql="";
        if(headflag==0){
        sql="select case when isnull(controltype,0)=19 then  '_sys_Attachment' else '_sys_Attachment9' end as name from gField \n" +
                "where formid=? and fieldid=? and headflag=?";
        }else{
            sql="select case when isnull(gridcontroltype,0)=19 then  '_sys_Attachment' else '_sys_Attachment9' end as name from gField \n" +
                    "where formid=? and fieldid=? and headflag=?";
        }
        String tableName=this.jdbcTemplate.queryForObject(sql,String.class,formid,fieldid,headflag);
        return this.jdbcTemplate.query("set nocount on \n" +
        List<AttachmentEntity> list= this.jdbcTemplate.query("set nocount on \n" +
                "  select unid,seq,FileType,formid,fieldid,OriginalFileName,FileSize from "+tableName+" where unid=?",new BeanPropertyRowMapper<>(AttachmentEntity.class),uuid);
        if("_sys_Attachment9".equalsIgnoreCase(tableName)){
            if(list!=null&&list.size()>0){
                list.stream().forEach(x->{
                    //0表示单附件9类型
                    x.setAttachemntType("0");
                });
            }
        }
        return list;
    }
}