New file |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |