fs-danaus
2022-04-18 d1ae8d07e37f6157c1a84d5e012273b2f9b3d327
src/com/yc/open/lujn/controller/KingDeeController.java
@@ -4,17 +4,19 @@
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.yc.entity.DataSourceEntity;
import com.yc.exception.ApplicationException;
import com.yc.exception.CallBackMessage;
import com.yc.multiData.MultiDataSource;
import com.yc.multiData.SpObserver;
import com.yc.open.controller.BaseController;
import com.yc.open.init.InitSystemTaks;
import com.yc.open.init.Task;
import com.yc.open.lujn.entity.*;
import com.yc.open.lujn.entity.PostDataEntity;
import com.yc.open.lujn.entity.ResultEntity;
import com.yc.open.lujn.entity.T12060Entity;
import com.yc.open.lujn.service.KingDeeServiceIfc;
import com.yc.service.build.type.T_22_Ifc;
import com.yc.service.panel.SqlDBHelperIfc;
import com.yc.utils.SessionKey;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -22,9 +24,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.List;
import java.util.Map;
@RestController
@@ -85,85 +86,27 @@
        try {
            String dbId = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
            SpObserver.setDBtoInstance("_" + dbId);
            List<OrderEntity> list = this.kingDeeServiceIfc.getOrderList(beginTime, endTime, mymatgroup);
            if (list != null && list.size() > 0) {
                List<PostDataEntity> postDataEntityList = new ArrayList<>();
              final   String matGroup = mymatgroup;
              final   String dayTime = beginTime;
               //1------去重,取仓库列表
                List<OrderEntity> collect = list.stream().unordered().distinct().collect(Collectors.toList());
                collect.forEach(x -> {
                    PostDataEntity postDataEntity = new PostDataEntity();
                    postDataEntity.setFbill_Type(matGroup);
                    postDataEntity.setFSListID(RandomStringUtils.randomAlphanumeric(8));
                    postDataEntity.setFStoreLocID(x.getStcode());
                    postDataEntity.setFStoreLoc_Name(x.getStname());
                    postDataEntity.setFAppDate(dayTime);
                    //-----门店列表
                    List<DetailEntity> details = new ArrayList<>();
                    //--增加去重处理,这里保存之前已增加的门店号cltCode
                    Set<String> setList = new HashSet<>();
                    //2----取属于具体的仓库所有数据
                    List<OrderEntity> storeList = list.stream().unordered().filter(y -> y.getStcode().equals(x.getStcode())).collect(Collectors.toList());
                    String cltCode = null;
                    //3---取门店数据
                    for (OrderEntity order : storeList) {
                        if (order.getCltcode().equals(cltCode)) {
                            continue;
                        }
                        if (cltCode == null || !order.getCltcode().equals(cltCode)) {
                            cltCode = order.getCltcode();
                        }
                        //---门店信息
                        DetailEntity detail = new DetailEntity();
                        detail.setFBillNo(RandomStringUtils.randomAlphanumeric(8));
                        detail.setFApplicationOrgId(order.getCltcode());
                        detail.setFApplicationOrgId_Name(order.getCltname());
                        //---商品数据
                        List<ItemEntity> items = new ArrayList<>();
                        Set<String> itemSet = new HashSet<>();
                        storeList.stream().forEach(z -> {
                            //取同一个门店的商品明细
                            if (z.getCltcode().equals(order.getCltcode())) {
                                ItemEntity item = new ItemEntity();
                                item.setFEntityID(RandomStringUtils.randomAlphanumeric(5));
                                item.setFMaterialId(z.getMatcode());
                                item.setFMaterialId_Name(z.getMatname());
                                item.setFReqQty(z.getDigit());
                                //---去重商品
                                if (itemSet.add(item.getFMaterialId())) {
                                    items.add(item);
                                }
                            }
                        });
                        items.removeIf(Objects::isNull);//去除空对象
                        detail.setFentityList(items);
                        //---能set进去表示可以加到list里面
                        if (setList.add(detail.getFApplicationOrgId())) {
                            details.add(detail);
                        }
                    }
                    details.removeIf(Objects::isNull);
                    //---对应仓库
                    postDataEntity.setFbillList(details);
                    postDataEntityList.add(postDataEntity);
                });
                Map<String, List<PostDataEntity>> postMap = new ConcurrentHashMap<>();
                postDataEntityList.removeIf(Objects::isNull);
                postMap.put("app", postDataEntityList);
                final Task openAPI = InitSystemTaks.getTaskByIsOpenURL(dbId,"OP0036",120260);
                if(openAPI==null){
                    throw  new ApplicationException("检查9675功能号apiCode:OP0036是否已启用");
                }
                String result = this.baseController.doPostByParameterNotName(openAPI.getApiUrl(), JSON.toJSONString(postMap, new SerializeConfig(true)));
            T12060Entity entity=new T12060Entity();
            entity.setBeginTime(beginTime);
            entity.setEndTime(endTime);
            entity.setMymatgroup(mymatgroup);
            entity.setPageSize(55000);
            entity.setPageNum(1);
            final Task openAPI = InitSystemTaks.getTaskByIsOpenURL(dbId,"OP0036",120260);
            if(openAPI==null){
                throw  new ApplicationException("检查9675功能号apiCode:OP0036是否已启用");
            }
            Map<String, List<PostDataEntity>> listMap = this.kingDeeServiceIfc.getOrderList(entity);
            if (listMap != null) {
                String result = this.baseController.doPostByParameterNotName(openAPI.getApiUrl(), JSON.toJSONString(listMap, new SerializeConfig(true)));
                log.info("金碟ERP返回结果:"+result);
                ResultEntity resultEntity = JSON.parseObject(result, ResultEntity.class);
                if(resultEntity.getResultCode()==null&&resultEntity.getResultMessage()==null){
                    CallBackMessage callBackMessage = JSON.parseObject(result, CallBackMessage.class);
                    if(callBackMessage.getState()==-1){
                        throw new ApplicationException(callBackMessage.getMsg());
                    }
                }
                if(resultEntity.getResultCode().intValue() <0) {
                    if (resultEntity.getResultCode().intValue() == -2) {
                        this.kingDeeServiceIfc.update120260Log(beginTime, endTime, mymatgroup);