package com.malk.huagao.service.impl;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.malk.huagao.entity.*;
import com.malk.huagao.mapper.KdYdOrderDetailMapper;
import com.malk.huagao.mapper.KdYdOrderMapper;
import com.malk.huagao.mapper.KdYdOrderPaymentMapper;
import com.malk.huagao.service.IKdYdOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.malk.server.aliwork.YDConf;
import com.malk.server.aliwork.YDParam;
import com.malk.server.aliwork.YDSearch;
import com.malk.server.common.McR;
import com.malk.server.dingtalk.DDR_New;
import com.malk.service.aliwork.YDClient;
import com.malk.utils.UtilHttp;
import com.malk.utils.UtilMap;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
/**
*
* 服务实现类
*
*
* @author LQY
* @since 2025-10-15
*/
@Service
public class KdYdOrderServiceImpl extends ServiceImpl implements IKdYdOrderService {
@Autowired
private YDClient ydClient;
@Autowired
private KdYdOrderMapper kdYdOrderMapper;
@Autowired
private KdYdOrderDetailMapper kdYdOrderDetailMapper;
@Autowired
private KdYdOrderPaymentMapper kdYdOrderPaymentMapper;
@Override
public Map insertkdYdOrder(Map map) {
Map result = new HashMap<>();
try {
MDC.put("MDC_KEY_PID", "1003");
String formInstId = UtilMap.getString(map, "formInstId");
String type = UtilMap.getString(map, "type");
// 处理特殊操作类型
if ("del".equals(type)) {
String bm = UtilMap.getString(map, "bm");
Map headers = new HashMap<>();
headers.put("Content-Type", "application/x-www-form-urlencoded");
Map formParams = new HashMap<>();
Map djbh = new HashMap<>();
djbh.put("djbh", bm);
result.put("data", djbh);
String jsonStr = JSON.toJSONString(result);
formParams.put("jsons", jsonStr);
System.out.println("====" + formParams);
HttpResponse response = HttpRequest.post("http://113.45.187.194:70/xk/dyzn/WsBasedyzn.asmx/hgdjydtbdeletexsdd")
.headerMap(headers, true)
.form(formParams)
.timeout(30000) // 30秒超时
.execute();
String responseBody = response.body();
// 返回删除操作的格式
result.put("table", "KD_YD_ORDER");
result.put("action", "del");
result.put("data", new HashMap() {{
put("bm", bm); // 删除的主键或标识
put("msg", "删除成功");
}});
return result;
}
if ("cancel".equals(type)) {
String bm = UtilMap.getString(map, "bm");
Map headers = new HashMap<>();
headers.put("Content-Type", "application/x-www-form-urlencoded");
Map formParams = new HashMap<>();
Map djbh = new HashMap<>();
djbh.put("djbh", bm);
result.put("data", djbh);
String jsonStr = JSON.toJSONString(result);
System.out.println("==" + jsonStr);
formParams.put("jsons", jsonStr);
HttpResponse response = HttpRequest.post("http://113.45.187.194:70/xk/dyzn/WsBasedyzn.asmx/hgdjydtbExcuteOperationxsdd")
.headerMap(headers, true)
.form(formParams)
.timeout(30000) // 30秒超时
.execute();
String responseBody = response.body();
String msg = JSON.parseArray(responseBody)
.getJSONObject(0)
.getString("msg");
ydClient.operateData(
YDParam.builder()
.formInstanceId(formInstId)
.updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textareaField_mkxqgrvq", msg)))
.useLatestVersion(true).build(),
YDConf.FORM_OPERATION.update);
// 返回作废操作的格式
result.put("table", "KD_YD_ORDER");
result.put("action", "cancel"); // 作废通常是修改状态
result.put("data", new HashMap() {{
put("bm", bm); // 作废状态
put("msg", "作废成功");
// 其他作废需要的数据
}});
return result;
}
// 查询表单数据
DDR_New ddrNew = ydClient.queryData(YDParam.builder()
.formInstId(formInstId)
.build(), YDConf.FORM_QUERY.retrieve_id);
Map formData = ddrNew.getFormData();
// 提取主表字段
String djlx = UtilMap.getString(formData, "selectField_mejowmna");
String khmc = UtilMap.getString(formData, "textField_mejnamf2");
// String khmc = "五岳";
// String djbh = UtilMap.getString(formData, "textField_mjs6fuwo");
// 判断操作类型对应的action
String actionType;
String djbh = null;
if ("edit".equals(type)) {
djbh = UtilMap.getString(formData, "textField_mjs6fuwo");
actionType = "edit";
} else {
actionType = "add";
djbh = "";
}
// 提取其他字段...
LocalDateTime rq = parseTimestamp(UtilMap.getString(formData, "dateField_mejowmnb"));
String khxypj = UtilMap.getString(formData, "selectField_mewirdx4");
String ywlx = UtilMap.getString(formData, "textField_mfxv2vfz");
String xsy = UtilMap.getString(formData, "employeeField_mejowmng").replace("[\"", "").replace("\"]", "").trim();
String xslx = UtilMap.getString(formData, "selectField_mejowmnc");
String bzq = UtilMap.getString(formData, "selectField_mf6gyfkq");
String xsbm = UtilMap.getString(formData, "departmentSelectField_mfxv2vfu").replace("[\"", "").replace("\"]", "").trim();
String bz = UtilMap.getString(formData, "textareaField_mejnamfb");
String jsbb = UtilMap.getString(formData, "selectField_mejowmnk");
String sktj = UtilMap.getString(formData, "selectField_mgisux07");
String zdzkestr = UtilMap.getString(formData, "numberField_mejowmni");
BigDecimal zdzke = toBigDecimal(zdzkestr);
String sestr = UtilMap.getString(formData, "numberField_mfxv2vgh");
BigDecimal se = toBigDecimal(sestr);
String jestr = UtilMap.getString(formData, "numberField_mfxv2vgj");
BigDecimal je = toBigDecimal(jestr);
String jshjstr = UtilMap.getString(formData, "numberField_mewfgzkv");
BigDecimal jshj = toBigDecimal(jshjstr);
String sfhs = UtilMap.getString(formData, "radioField_mfxv2vg4");
String jws = UtilMap.getString(formData, "radioField_mfxv2vgm");
List