KdYdZpServiceImpl.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package com.malk.huagao.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.malk.huagao.entity.*;
  5. import com.malk.huagao.mapper.KdYdReceivableDetailMapper;
  6. import com.malk.huagao.mapper.KdYdReceivableMapper;
  7. import com.malk.huagao.mapper.KdYdZpDetailMapper;
  8. import com.malk.huagao.mapper.KdYdZpMapper;
  9. import com.malk.huagao.service.IKdYdZpService;
  10. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  11. import com.malk.server.aliwork.YDConf;
  12. import com.malk.server.aliwork.YDParam;
  13. import com.malk.server.dingtalk.DDR_New;
  14. import com.malk.service.aliwork.YDClient;
  15. import com.malk.utils.UtilMap;
  16. import org.slf4j.MDC;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import java.math.BigDecimal;
  20. import java.math.RoundingMode;
  21. import java.time.Instant;
  22. import java.time.LocalDateTime;
  23. import java.time.ZoneId;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * <p>
  28. * 服务实现类
  29. * </p>
  30. *
  31. * @author LQY
  32. * @since 2025-10-16
  33. */
  34. @Service
  35. public class KdYdZpServiceImpl extends ServiceImpl<KdYdZpMapper, KdYdZp> implements IKdYdZpService {
  36. @Autowired
  37. private YDClient ydClient;
  38. @Autowired
  39. private KdYdZpMapper kdYdZpMapper;
  40. @Autowired
  41. private KdYdZpDetailMapper kdYdZpDetailMapper;
  42. @Override
  43. public void insertkdYdZp(Map map) {
  44. MDC.put("MDC_KEY_PID", "1003");
  45. String formInstId = UtilMap.getString(map, "formInstId");
  46. String type = UtilMap.getString(map, "type");
  47. if ("3".equals(type)) {
  48. String bm = UtilMap.getString(map, "bm");
  49. KdYdZp kdYdZp = new KdYdZp();
  50. kdYdZp.setOperationType("3");
  51. kdYdZp.setSyncStatus("0");
  52. kdYdZpMapper.update(kdYdZp, new LambdaQueryWrapper<KdYdZp>().eq(KdYdZp::getDjbh, bm));
  53. return; // 或者根据你的业务逻辑返回相应的结果
  54. }
  55. DDR_New ddrNew = ydClient.queryData(YDParam.builder()
  56. .formInstId(formInstId)
  57. .build(), YDConf.FORM_QUERY.retrieve_id);
  58. Map formData = ddrNew.getFormData();
  59. String djlx = UtilMap.getString(formData, "radioField_mg3cexkm");
  60. // long receivableId = UtilMap.getLong(formData, "textField_mgt4w4ip");
  61. String kh = UtilMap.getString(formData, "textField_mhn5h4mo");
  62. String kpfs = UtilMap.getString(formData, "selectField_mg3cexke");
  63. String fph = UtilMap.getString(formData, "textField_mejmml3a");
  64. LocalDateTime ywrq = parseTimestamp(UtilMap.getString(formData, "dateField_mejmml39"));
  65. String bb = UtilMap.getString(formData, "selectField_mg3fuqvn");
  66. String bz = UtilMap.getString(formData, "textareaField_mejmml3e");
  67. String djbh = UtilMap.getString(formData, "serialNumberField_mhn4661d");
  68. String spdzyx = UtilMap.getString(formData, "textField_mejmml3d");
  69. String dddjbh = UtilMap.getString(formData, "textField_mg3cexkf");
  70. String ysddjbh = UtilMap.getString(formData, "textField_mejmml3k");
  71. String jshjstr = UtilMap.getString(formData, "numberField_mejmml38");
  72. BigDecimal jshj = toBigDecimal(jshjstr);
  73. List<Map> tableField = (List<Map>) formData.get("tableField_mf6el3zx");
  74. KdYdZp kdYdZp = new KdYdZp();
  75. kdYdZp.setDjlx(djlx);
  76. kdYdZp.setKpfs(kpfs);
  77. kdYdZp.setDjbh(djbh);
  78. kdYdZp.setFph(fph);
  79. kdYdZp.setYwrq(ywrq);
  80. // kdYdZp.setReceivableId(receivableId);
  81. kdYdZp.setBb(bb);
  82. kdYdZp.setJshj(jshj);
  83. kdYdZp.setBz(bz);
  84. kdYdZp.setKh(kh);
  85. kdYdZp.setSyncStatus("0");
  86. kdYdZp.setOperationType("1");
  87. kdYdZp.setSpdzyx(spdzyx);
  88. kdYdZp.setCreateTime(LocalDateTime.now());
  89. // kdYdZp.setForminstid(formInstId);
  90. if ("2".equals(type)) {
  91. kdYdZp.setOperationType(type);
  92. kdYdZpMapper.update(kdYdZp, new LambdaQueryWrapper<KdYdZp>().eq(KdYdZp::getDjbh, djbh));
  93. } else {
  94. kdYdZpMapper.insert(kdYdZp);
  95. }
  96. Long id = kdYdZp.getId();
  97. int count = 1;
  98. for (Map item : tableField) {
  99. String wlbm = safeGetString(item, "textField_mf6el3zy");
  100. String wlmc = safeGetString(item, "textField_mf6el3zz");
  101. String ggxh = safeGetString(item, "textField_mejmtic5");
  102. String jjdw = safeGetString(item, "textField_mf6el400");
  103. String ssxl = safeGetString(item, "selectField_mejnamfm");
  104. BigDecimal dj = toBigDecimal(safeGetString(item, "numberField_mf6el402"));
  105. BigDecimal hsdj = toBigDecimal(safeGetString(item, "numberField_mejmticb"));
  106. BigDecimal sl = toBigDecimal(safeGetString(item, "numberField_mf6el403"));
  107. BigDecimal se = toBigDecimal(safeGetString(item, "numberField_mf6el406"));
  108. BigDecimal zjshj = toBigDecimal(safeGetString(item, "numberField_mejmtic7"));
  109. String ph = safeGetString(item, "textField_mf6el409");
  110. BigDecimal jjsl = toBigDecimal(safeGetString(item, "numberField_mejmtic6"));
  111. BigDecimal zkl = toBigDecimal(safeGetString(item, "numberField_mf6el404"));
  112. BigDecimal bhsje = toBigDecimal(safeGetString(item, "numberField_mejmticc"));
  113. BigDecimal zke = toBigDecimal(safeGetString(item, "numberField_mf6el405"));
  114. BigDecimal rjdj = toBigDecimal(safeGetString(item, "numberField_mg3cexkl"));
  115. String gg = safeGetString(item, "textField_mf6el40b");
  116. String xxddbm = safeGetString(item, "textField_mf6el408");
  117. // String ysdjbh = safeGetString(item, "textField_mhn5h4mi");
  118. KdYdZpDetail kdYdZpDetail = new KdYdZpDetail();
  119. kdYdZpDetail.setZpId(id);
  120. kdYdZpDetail.setWlbm(wlbm);
  121. kdYdZpDetail.setWlmc(wlmc);
  122. kdYdZpDetail.setGgxh(ggxh);
  123. kdYdZpDetail.setJjdw(jjdw);
  124. kdYdZpDetail.setSsxl(ssxl);
  125. kdYdZpDetail.setDj(dj);
  126. kdYdZpDetail.setHsdj(hsdj);
  127. kdYdZpDetail.setSl(sl);
  128. kdYdZpDetail.setSe(se);
  129. kdYdZpDetail.setJe(zjshj);
  130. kdYdZpDetail.setPh(ph);
  131. kdYdZpDetail.setJjsl(jjsl);
  132. kdYdZpDetail.setZkl(zkl);
  133. kdYdZpDetail.setBhsje(bhsje);
  134. kdYdZpDetail.setZke(zke);
  135. kdYdZpDetail.setRjdj(rjdj);
  136. kdYdZpDetail.setGg(gg);
  137. kdYdZpDetail.setXxddbh(xxddbm);
  138. kdYdZpDetail.setDetailId(count);
  139. kdYdZpDetail.setSyncStatus("0");
  140. kdYdZpDetail.setOperationType("1");
  141. if ("2".equals(type) || "3".equals(type)) {
  142. kdYdZpDetail.setOperationType(type);
  143. kdYdZpDetailMapper.update(kdYdZpDetail, new LambdaQueryWrapper<KdYdZpDetail>().eq(KdYdZpDetail::getDetailId, count));
  144. } else {
  145. kdYdZpDetailMapper.insert(kdYdZpDetail);
  146. }
  147. count++;
  148. }
  149. }
  150. private static LocalDateTime parseTimestamp(String timestampStr) {
  151. if (timestampStr == null || timestampStr.trim().isEmpty()) return null;
  152. try {
  153. long timestamp = Long.parseLong(timestampStr.trim());
  154. return LocalDateTime.ofInstant(
  155. Instant.ofEpochMilli(timestamp),
  156. ZoneId.systemDefault()
  157. );
  158. } catch (NumberFormatException e) {
  159. return null;
  160. }
  161. }
  162. private static int parseInt(String str, int defaultValue) {
  163. if (str == null || str.trim().isEmpty()) {
  164. return defaultValue;
  165. }
  166. try {
  167. return Integer.parseInt(str.trim());
  168. } catch (NumberFormatException e) {
  169. return defaultValue;
  170. }
  171. }
  172. private String safeGetString(Map formData, String key) {
  173. Object val = formData.get(key);
  174. return val == null ? "" : String.valueOf(val);
  175. }
  176. public static BigDecimal toBigDecimal(String str) {
  177. if (str == null || str.trim().isEmpty()) {
  178. return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
  179. }
  180. try {
  181. return new BigDecimal(str.trim())
  182. .setScale(2, RoundingMode.HALF_UP);
  183. } catch (NumberFormatException e) {
  184. // 返回默认值而不是抛出异常,避免程序中断
  185. return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
  186. }
  187. }
  188. /**
  189. * 重载方法,支持Number类型输入
  190. */
  191. public static BigDecimal toBigDecimal(Number number) {
  192. if (number == null) {
  193. return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
  194. }
  195. return new BigDecimal(number.toString())
  196. .setScale(2, RoundingMode.HALF_UP);
  197. }
  198. }