fs-danaus
2022-01-07 1d696d90ae2e0ff011f2cff353a5bf1ab949866a
卤江南,金碟推送订单功能
8个文件已添加
304 ■■■■■ 已修改文件
src/com/yc/open/lujn/controller/KingDeeController.java 173 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/lujn/entity/DetailEntity.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/lujn/entity/ItemEntity.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/lujn/entity/OrderEntity.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/lujn/entity/PostDataEntity.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/lujn/entity/ResultEntity.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/lujn/service/KingDeeServiceIfc.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/lujn/service/KingDeeServiceImpl.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/lujn/controller/KingDeeController.java
New file
@@ -0,0 +1,173 @@
package com.yc.open.lujn.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.yc.entity.DataSourceEntity;
import com.yc.exception.ApplicationException;
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.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;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@RestController
public class KingDeeController extends BaseController {
    @Autowired
    T_22_Ifc t22ifc;
    @Autowired
    SqlDBHelperIfc mSqlDBHelperIfc;
    @Autowired
    KingDeeServiceIfc kingDeeServiceIfc;
    @Autowired
    BaseController baseController;
    @RequestMapping(value = "/lujn/post120201.do")
    public void post120201(HttpServletRequest request, HttpServletResponse response) {
        Map<String, String> map = null;
        try {
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());
            map = this.t22ifc.getParamMap(request);
        } catch (Exception e) {
            e.printStackTrace();
            this.log.error((e.getCause() != null) ? e.getCause().getMessage() : e.getMessage());
            print(response, getErrorMsg(e));
            return;
        } finally {
            SpObserver.setDBtoInstance();
        }
        String beginTime = null;
        String endTime = null;
        String mymatgroup = null;
        if (map != null) {
            beginTime = map.get("beginday");
            endTime = map.get("endday");
            mymatgroup = map.get("mymatgroup");
        }
        if (StringUtils.isBlank(beginTime)) {
            print(response, "开始日期不能为空");
            return;
        }
        if (StringUtils.isBlank(endTime)) {
            print(response, "结束日期不能为空");
            return;
        }
        if (!beginTime.equals(endTime)) {
            print(response, "开始与结束只能是在同一天");
            return;
        }
        if (StringUtils.isBlank(mymatgroup) || mymatgroup.equals("''")) {
            print(response, "物料组不能为空");
            return;
        }
        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<>();
    //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<>();
                        storeList.parallelStream().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());
                                items.add(item);
                            }
                        });
                        detail.setFentityList(items);
                        details.add(detail);
                    }
                    postDataEntity.setFbillList(details);
                    postDataEntityList.add(postDataEntity);
                });
                Map<String, List<PostDataEntity>> postMap = new ConcurrentHashMap<>();
                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)));
                log.info("金碟ERP返回结果:"+result);
                ResultEntity resultEntity = JSON.parseObject(result, ResultEntity.class);
                if(resultEntity.getResultCode().intValue() <0) {
                    if (resultEntity.getResultCode().intValue() == -2) {
                        this.kingDeeServiceIfc.update120260Log(beginTime, endTime, mymatgroup);
                        print(response, resultEntity.getResultMessage());
                    } else {
                        throw new ApplicationException(resultEntity.getResultMessage());
                    }
                }else {
                    print(response, "上传订单成功");
                }
            } else {
                print(response, "没有订单数据需要上传");
            }
        } catch (Exception e) {
            print(response, (e.getCause() != null) ? e.getCause().getMessage().trim() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
}
src/com/yc/open/lujn/entity/DetailEntity.java
New file
@@ -0,0 +1,20 @@
package com.yc.open.lujn.entity;
import lombok.Data;
import java.util.List;
@Data
public class DetailEntity {
    String FBillNo;
    String FApplicationOrgId;
    String FApplicationOrgId_Name;
    String FApplicantId = "";
    String FApplicantId_Name = "";
    String FNote = "";
    String FReceiveAddress = "";
    String FLinkMan = "";
    String FPhone = "";
    List<ItemEntity> FentityList;
}
src/com/yc/open/lujn/entity/ItemEntity.java
New file
@@ -0,0 +1,11 @@
 package com.yc.open.lujn.entity;
 import lombok.Data;
 @Data
 public class ItemEntity {
     String FEntityID;
     String FMaterialId;
     String FMaterialId_Name;
     Double FReqQty;
 }
src/com/yc/open/lujn/entity/OrderEntity.java
New file
@@ -0,0 +1,30 @@
package com.yc.open.lujn.entity;
import lombok.Data;
@Data
public class OrderEntity {
    String stcode;
    String stname;
    String docdate;
    String cltcode;
    String cltname;
    String matcode;
    String matname;
    Double digit;
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        OrderEntity order = (OrderEntity) o;
        return stcode.equals(order.stcode);
    }
    @Override
    public int hashCode() {
        return stcode.hashCode();
    }
}
src/com/yc/open/lujn/entity/PostDataEntity.java
New file
@@ -0,0 +1,15 @@
package com.yc.open.lujn.entity;
import lombok.Data;
import java.util.List;
@Data
public class PostDataEntity {
    String FSListID;
    String FStoreLocID;
    String FStoreLoc_Name;
    String FAppDate;
    String Fbill_Type;
    List<DetailEntity> FbillList;
}
src/com/yc/open/lujn/entity/ResultEntity.java
New file
@@ -0,0 +1,10 @@
package com.yc.open.lujn.entity;
import lombok.Data;
@Data
public class ResultEntity {
    Integer ResultCode;
    Integer ResultCount;
    String ResultMessage;
}
src/com/yc/open/lujn/service/KingDeeServiceIfc.java
New file
@@ -0,0 +1,10 @@
package com.yc.open.lujn.service;
import com.yc.open.lujn.entity.OrderEntity;
import java.util.List;
public interface KingDeeServiceIfc {
  List<OrderEntity> getOrderList(String beginDay, String endDay, String matGroup);
  void update120260Log(String beginDay, String endDay, String matGroup);
}
src/com/yc/open/lujn/service/KingDeeServiceImpl.java
New file
@@ -0,0 +1,35 @@
package com.yc.open.lujn.service;
import com.yc.open.lujn.entity.OrderEntity;
import com.yc.service.BaseService;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class KingDeeServiceImpl extends BaseService implements KingDeeServiceIfc {
    @Override
    public List<OrderEntity> getOrderList(String beginTime, String endTime, String mymatgroup) {
        String sql = "set nocount on\n " +
                " declare @beginDay date=?,@endDay date=?,@matGroup varchar(10)=?,@myCount int\n " +
                " select @myCount=count(1) from t120260Log where isnull(isLocked,0)=1 and beginDay=@beginDay and endDay=@endDay and matGroup=@matGroup \n " +
                " if @myCount=1 begin \n" +
                "    raiserror('"+beginTime+"期间订单分类为%s的订单数据,金碟ERP已关闭上传通道',16,1,@matGroup) return; " +
                "   end \n " +
                "   select  stcode,stname, docdate,cltcode,cltname,matcode,matname,digit from f120260(@beginDay,@endDay,@matGroup) where isnull(parentrowid,'')<>''";
        return this.jdbcTemplate.query(sql, new BeanPropertyRowMapper(OrderEntity.class), new Object[]{beginTime, endTime, mymatgroup});
    }
    @Override
    public void update120260Log(String beginTime, String endTime, String mymatgroup) {
        String sql = "set nocount on\n " +
                "  declare @beginDay date=?,@endDay date=?,@matGroup varchar(10)=?\n" +
                "   insert into t120260Log(beginday,endday,matGroup,isLocked) values (@beginDay,@endDay,@matGroup,1)";
        this.jdbcTemplate.update(sql, new Object[]{beginTime, endTime, mymatgroup});
    }
}