package com.zy.kingdee.controller; import cn.hutool.core.date.DatePattern; import cn.hutool.http.HttpRequest; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.core.annotations.AppAuth; import com.core.annotations.ManagerAuth; import com.core.common.Cools; import com.core.common.R; import com.core.exception.CoolException; import com.zy.asrs.entity.ICMO; import com.zy.common.constant.ApiInterfaceConstant; import com.zy.common.utils.HttpHandler; import com.zy.kingdee.entity.PoInStockDTO; import com.zy.kingdee.entity.ResDto; import com.zy.kingdee.utils.ERPDateUtil; import com.zy.kingdee.utils.K3ApiUtil; import com.zy.kingdee.utils.KingDeeUtils; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import okhttp3.internal.http.HttpMethod; import org.springframework.web.bind.annotation.*; import java.text.ParseException; import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.util.*; @RestController @RequestMapping("kingdee") @Slf4j public class KingdeeContorller { @RequestMapping("/get/manufacturingorder/list") @ManagerAuth() public R getManufacturingorderList(@RequestParam(defaultValue = "1")Integer curr, @RequestParam(defaultValue = "10")Integer limit, @RequestParam(required = false)String orderByField, @RequestParam(required = false)String orderByType, @RequestParam(required = false)String condition, @RequestParam Map param) { if (null == K3ApiUtil.TokenRes){ K3ApiUtil.init(); } Map map = new LinkedHashMap<>(); map.put("access_token", K3ApiUtil.TokenRes.getAccessToken()); Map jsonMap = new HashMap<>(); jsonMap.put("CurrentPage",curr); jsonMap.put("ItemsOfPage",limit); jsonMap.put("AccountDB","002"); OffsetDateTime time = OffsetDateTime.parse(param.get("time").toString()); HashMap map1 = new HashMap<>(); String s = String.valueOf(time.toLocalDate()); map1.put("Property","FPlanCommitDate"); map1.put("Type","Desc"); jsonMap.put("OrderBy",map1); // map.put("CurrentPage",1); // map.put("ItemsOfPage",10); String resStr = HttpRequest.post("api.kingdee.com" + "/koas/app007107/api/manufacturingorder/list" + K3ApiUtil.getMapStr(map)) .header("KIS-Timestamp", Long.toString(System.currentTimeMillis() / 1000L)) .header("KIS-State", "TEST" + K3ApiUtil.getNonce(12)) .header("KIS-TraceID", "TEST") .header("KIS-Ver", "1.0") .header("KIS-AuthData", K3ApiUtil.gatewayDto.getData().getAuthData()) .header("X-Api-SignHeaders", "X-Api-TimeStamp,X-Api-Nonce") .header("X-GW-Router-Addr", K3ApiUtil.gatewayDto.getData().getGwRouterAddr()) .contentType("application/json") .body(JSON.toJSONString(jsonMap)) .execute() .body(); JSONObject parseObject = JSON.parseObject(resStr); if (parseObject.get("errcode").hashCode() != 0) { throw new CoolException(parseObject.get("description").toString()); } // Map headers = new HashMap<>(); // // headers.put("KIS-Timestamp",Long.toString(System.currentTimeMillis() / 1000L)); // headers.put("KIS-State","TEST" + K3ApiUtil.getNonce(12)); // headers.put("KIS-TraceID","TEST"); // headers.put("KIS-Ver","1.0"); // headers.put("KIS-AuthData",K3ApiUtil.kingDeeRes.getAppToken()); // // headers.put("X-GW-Router-Addr",K3ApiUtil.kingDeeRes.getDomain()); // headers.put("Content-Type", "application/json;charset=utf-8"); // // // try { // String response = new HttpHandler.Builder() // .setUri("api.kingdee.com") // .setPath("/koas/app007107/api/manufacturingorder/list") // .setHeaders(headers) // .setParams(map) // .setJson(JSON.toJSONString(jsonMap)) // .build() // .doPost(); // }catch (Exception e){ // // } return R.ok(parseObject.get("data")); } // @PostMapping("/other/synchronizeTheReceiptOrder/v1") // @ManagerAuth() // @AppAuth(memo = "金蝶新增收料通知单") // public R synchronizeTheReceiptOrder(@RequestBody List icmos) { // if (null == K3ApiUtil.TokenRes){ // K3ApiUtil.init(); // } // Map map = new LinkedHashMap<>(); // map.put("access_token", K3ApiUtil.TokenRes.getAccessToken()); // Map jsonMap = new HashMap<>(); // jsonMap.put("AccountDB","004"); // jsonMap.put("Object",getPoInStockDto(icmos)); // // // String resStr = HttpRequest.post("api.kingdee.com" + "/koas/app007140/api/materialreceiptnotice/create" + K3ApiUtil.getMapStr(map)) // .header("KIS-Timestamp", Long.toString(System.currentTimeMillis() / 1000L)) // .header("KIS-State", "TEST" + K3ApiUtil.getNonce(12)) // .header("KIS-TraceID", "TEST") // .header("KIS-Ver", "1.0") // .header("KIS-AuthData", K3ApiUtil.gatewayDto.getData().getAuthData()) // .header("X-Api-SignHeaders", "X-Api-TimeStamp,X-Api-Nonce") // .header("X-GW-Router-Addr", K3ApiUtil.gatewayDto.getData().getGwRouterAddr()) // .contentType("application/json") // .body(JSON.toJSONString(jsonMap)) // .execute() // .body(); // // JSONObject parseObject = JSON.parseObject(resStr); // if (parseObject.get("errcode").hashCode() != 0) { // throw new CoolException(parseObject.get("description").toString()); // } // return R.ok(parseObject.get("data")); // } // @SneakyThrows // public PoInStockDTO getPoInStockDto(List icmos) { // PoInStockDTO.HeadDTO headDTO = new PoInStockDTO.HeadDTO(); // headDTO.setFBillNo("test001"); // headDTO.setFSupplyID(icmos.get(0).getFSupplyID()); // headDTO.setFCurrencyID(1); // headDTO.setFdate(ERPDateUtil.getDateStr(new Date(), "yyyy-MM-dd")); // headDTO.setFExchangeRate(1D); // headDTO.setFDeptID(11376); // headDTO.setFEmpID(11375); // headDTO.setFPOStyle(252); // headDTO.setFBizType(12510); // headDTO.setFWWType(0); // headDTO.setFAreaPS(20302); // // List entryDTOS = new ArrayList<>(); // for (ICMO icmo: icmos){ // PoInStockDTO.EntryDTO entryDTO = new PoInStockDTO.EntryDTO(); // entryDTO.setFAuxPropID(icmo.getFAuxPropID()); // entryDTO.setFBatchNo(icmo.getFGMPBatchNo()); // entryDTO.setFCheckMethod(352); // entryDTO.setFMTONo(icmo.getFMTONo()); // entryDTO.setFPlanMode(icmo.getFPlanMode()); // entryDTO.setFSecCoefficient(1D); // entryDTO.setFSecQty(icmo.getFQty()); // entryDTO.setFUnitID(icmo.getFUnitID().toString()); // entryDTOS.add(entryDTO); // // } // PoInStockDTO poInStockDTO = new PoInStockDTO(); // poInStockDTO.setHead(headDTO); // poInStockDTO.setEntry(entryDTOS); // // // return poInStockDTO; // } }