BmstruckDetailsOrderServiceImpl.java 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528
  1. package com.steerinfo.dil.service.impl;
  2. import com.steerinfo.dil.feign.AmsFeign;
  3. import com.steerinfo.dil.feign.JoinApiFeign;
  4. import com.steerinfo.dil.feign.OmsFeign;
  5. import com.steerinfo.dil.mapper.AmsContractTransportPriceMapper;
  6. import com.steerinfo.dil.mapper.BmstruckDetailsOrderMapper;
  7. import com.steerinfo.dil.mapper.OmstruckOrderMapper;
  8. import com.steerinfo.dil.model.AmsContractTransportPrice;
  9. import com.steerinfo.dil.model.BmstruckDetailsOrder;
  10. import com.steerinfo.dil.model.OmstruckOrder;
  11. import com.steerinfo.dil.service.IBmstruckDetailsOrderService;
  12. import com.steerinfo.dil.util.DataChange;
  13. import com.steerinfo.dil.util.EASUtil;
  14. import com.steerinfo.dil.util.NoUtil;
  15. import com.steerinfo.dil.util.SaleLogUtil;
  16. import io.swagger.models.auth.In;
  17. import org.apache.shiro.crypto.hash.Hash;
  18. import org.junit.Test;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import javax.annotation.Resource;
  23. import java.lang.reflect.Array;
  24. import java.math.BigDecimal;
  25. import java.math.RoundingMode;
  26. import java.text.DecimalFormat;
  27. import java.util.*;
  28. import java.util.regex.Matcher;
  29. import java.util.regex.Pattern;
  30. /**
  31. * @Description:
  32. * @Author:HuJianGuo
  33. * @GreateTime:2021/9/24 17:34
  34. * @Version:V2.0
  35. */
  36. @Service
  37. public class BmstruckDetailsOrderServiceImpl implements IBmstruckDetailsOrderService {
  38. @Autowired
  39. BmstruckDetailsOrderMapper bmstruckDetailsOrderMapper;
  40. @Autowired
  41. BmstruckFormulaServiceImpl bmstruckFormulaService;
  42. @Autowired
  43. NoUtil noUtil;
  44. @Autowired
  45. JoinApiFeign joinApiFeign;
  46. @Autowired
  47. EASUtil easUtil;
  48. @Autowired
  49. OmstruckOrderMapper omstruckOrderMapper;
  50. @Autowired
  51. OmsFeign omsFeign;
  52. @Autowired
  53. AmsFeign amsFeign;
  54. @Autowired
  55. SaleLogUtil saleLogUtil;
  56. @Autowired
  57. AmsContractTransportPriceMapper amsContractTransportPriceMapper;
  58. //以下订单类型是需要算计量实绩的
  59. final private List<Integer> inwardTypeList = Arrays.asList(10,11,15,16,23,24,20,25);
  60. //以下订单类型是需要根据线路去匹配承运起止范围以及物资
  61. final private List<Integer> toLineAndMaterial = Arrays.asList(10,20,23,24);
  62. //以下订单类型是需要去根据固定承运起止范围以及物资
  63. final private List<Integer> fixLineList = Arrays.asList(15,16);
  64. //以下订单类型是钢材
  65. final private List<Integer> steelTypeList = Arrays.asList(25);
  66. /**
  67. * 展示汽运详单列表
  68. * @param mapVal
  69. * @return
  70. */
  71. @Override
  72. public List<Map<String, Object>> getTruckDetailsOrderList(Map<String, Object> mapVal) {
  73. Integer orderType = (Integer) mapVal.get("orderType");
  74. List<Map<String, Object>> truckDetailsOrderList;
  75. if (orderType <= 3 && orderType >= 1) {
  76. truckDetailsOrderList = bmstruckDetailsOrderMapper.getSaleTruckDetailsOrderList(mapVal);
  77. }
  78. else {
  79. truckDetailsOrderList = bmstruckDetailsOrderMapper.getTruckDetailsOrderList(mapVal);
  80. }
  81. return truckDetailsOrderList;
  82. }
  83. /**
  84. * 新增详单
  85. * @param orderId
  86. * @return
  87. */
  88. @Override
  89. public synchronized int insertSelective(BigDecimal orderId) throws Exception {
  90. System.out.println(orderId + "生成计费详单");
  91. List<Map<String,Object>> weightTaskResultIdList = bmstruckDetailsOrderMapper.getSteelWeightTaskResultId(orderId);
  92. //根据该id寻找相同的订单号
  93. List<BigDecimal> orderIds = bmstruckDetailsOrderMapper.getOrderIds(orderId);
  94. for (BigDecimal orderId1 : orderIds) {
  95. weightTaskResultIdList.addAll(bmstruckDetailsOrderMapper.getSteelWeightTaskResultId(orderId1));
  96. }
  97. Map<String,Object> priceMap = getPriceId(orderId);
  98. if (priceMap == null || priceMap.size() == 0) {
  99. return 0;
  100. }
  101. BigDecimal priceId = (BigDecimal) priceMap.get("priceId");
  102. if (priceId.intValue() == 0) {
  103. return 0;
  104. }
  105. int result = 0;
  106. //优先根据计量批次新增详单
  107. List<Map<String,Object>> batchIdList = bmstruckDetailsOrderMapper.getWeightBatchIds(orderId);
  108. if(batchIdList.size()>0){
  109. for(Map<String, Object> map : batchIdList){
  110. if(map == null) {
  111. System.out.println("空Map,释放");
  112. continue;
  113. }
  114. BigDecimal weightBatchId = DataChange.dataToBigDecimal(map.get("weightBatchId"));
  115. //判断该批次有没有结算数据
  116. if(bmstruckDetailsOrderMapper.getIsHaveDetailsOrderByBatch(weightBatchId) > 0 ){
  117. continue;
  118. }
  119. try {
  120. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
  121. BigDecimal priceValue = getPriceValue(priceId);
  122. BigDecimal netWeight = DataChange.dataToBigDecimal(map.get("netWeight"));
  123. // 得到计费公式
  124. String formula_string = null;
  125. if (orderType.intValue() == 3) {
  126. // 得到采购汽运计费公式
  127. formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(8));
  128. // 替换采购汽运运计算公式
  129. formula_string = formula_string.replace("到厂计量湿吨",netWeight.toString())
  130. .replace("单价",priceValue.toString());
  131. }
  132. if (orderType.intValue() >= 1 && orderType.intValue() <= 3) {
  133. // 得到销售10km差距内的汽运计费公式
  134. formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(10));
  135. // 替换采购汽运运计算公式
  136. formula_string = formula_string.replace("运输单价",priceValue.toString())
  137. .replace("物资净重",netWeight.toString());
  138. }
  139. String s = toSufExpr(formula_string);
  140. BigDecimal detailsAmountOld = calSufExpr(s);
  141. BigDecimal detailsAmount = detailsAmountOld.setScale(2,RoundingMode.HALF_UP);
  142. BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
  143. if (orderType.intValue() == 3) {
  144. BigDecimal purchaseOrderId = getFormulaMembers(orderId);
  145. bmstruckDetailsOrder.setPurchaseOrderId(purchaseOrderId);
  146. }
  147. if (orderType.intValue() == 2 || orderType.intValue() == 1) {
  148. bmstruckDetailsOrder.setWetherToStatement(new BigDecimal(0));
  149. }
  150. // 得到最大id
  151. BigDecimal detailsId = selectMaxId();
  152. String detailsNo = noUtil.setResultNo("QYXD", detailsId);
  153. bmstruckDetailsOrder.setDetailsId(detailsId);
  154. bmstruckDetailsOrder.setWeightBatchId(weightBatchId);
  155. bmstruckDetailsOrder.setOrderId(orderId);
  156. bmstruckDetailsOrder.setDetailsNo(detailsNo);
  157. bmstruckDetailsOrder.setPriceId(priceId);
  158. bmstruckDetailsOrder.setDetailsAmount(detailsAmount);
  159. bmstruckDetailsOrder.setDetailsTime(new Date());
  160. // 设置常规字段
  161. bmstruckDetailsOrder.setInsertTime(new Date());
  162. bmstruckDetailsOrder.setUpdateTime(new Date());
  163. bmstruckDetailsOrder.setInsertUsername("admin");
  164. bmstruckDetailsOrder.setUpdateUsername("admin");
  165. bmstruckDetailsOrder.setInsertUpdateRemark("无");
  166. result += bmstruckDetailsOrderMapper.insertSelective(bmstruckDetailsOrder);
  167. }catch (Exception e){
  168. //不打印给控制台(有可能是正常情况)
  169. e.printStackTrace();
  170. }
  171. }
  172. return result;
  173. }
  174. //根据计量实绩新增详单
  175. for (Map<String, Object> map : weightTaskResultIdList) {
  176. if(map == null) {
  177. System.out.println("空Map,释放");
  178. continue;
  179. }
  180. BigDecimal weightTaskResultId = DataChange.dataToBigDecimal(map.get("weightTaskResultId"));
  181. if(weightTaskResultId == null) {
  182. System.out.println("计量实绩Id为空,释放");
  183. continue;
  184. }
  185. //判断该计量实绩有没有结算数据
  186. if(bmstruckDetailsOrderMapper.getIsHaveDetailsOrder(weightTaskResultId) > 0 ){
  187. continue;
  188. }
  189. BigDecimal netWeightIsNull = bmstruckDetailsOrderMapper.getNetWeight(weightTaskResultId);
  190. if (netWeightIsNull == null) {
  191. System.out.println("没有计量实绩,不生成结算数据:" + orderId);
  192. continue;
  193. }
  194. //BigDecimal detailsAmountOld=new BigDecimal(0);
  195. try {
  196. BigDecimal detailsAmountOld = generateTruckFees(orderId, weightTaskResultId);
  197. BigDecimal detailsAmount = detailsAmountOld.setScale(2,RoundingMode.HALF_UP);
  198. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
  199. BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
  200. if (orderType.intValue() == 3) {
  201. BigDecimal purchaseOrderId = getFormulaMembers(orderId);
  202. bmstruckDetailsOrder.setPurchaseOrderId(purchaseOrderId);
  203. }
  204. if (orderType.intValue() == 2 || orderType.intValue() == 1) {
  205. bmstruckDetailsOrder.setWetherToStatement(new BigDecimal(0));
  206. }
  207. // 得到最大id
  208. BigDecimal detailsId = selectMaxId();
  209. String detailsNo = noUtil.setResultNo("QYXD", detailsId);
  210. bmstruckDetailsOrder.setDetailsId(detailsId);
  211. bmstruckDetailsOrder.setWeightTaskResultId(weightTaskResultId);
  212. bmstruckDetailsOrder.setOrderId(orderId);
  213. bmstruckDetailsOrder.setDetailsNo(detailsNo);
  214. bmstruckDetailsOrder.setPriceId(priceId);
  215. bmstruckDetailsOrder.setDetailsAmount(detailsAmount);
  216. bmstruckDetailsOrder.setDetailsTime(new Date());
  217. // 设置常规字段
  218. bmstruckDetailsOrder.setInsertTime(new Date());
  219. bmstruckDetailsOrder.setUpdateTime(new Date());
  220. bmstruckDetailsOrder.setInsertUsername("admin");
  221. bmstruckDetailsOrder.setUpdateUsername("admin");
  222. bmstruckDetailsOrder.setInsertUpdateRemark("无");
  223. result += bmstruckDetailsOrderMapper.insertSelective(bmstruckDetailsOrder);
  224. }catch (Exception e){
  225. //不打印给控制台(有可能是正常情况)
  226. e.printStackTrace();
  227. }
  228. }
  229. return result;
  230. }
  231. /**
  232. * 新增详单(只为计费详单修改数据时才使用)
  233. * @param orderId
  234. * @return
  235. */
  236. @Override
  237. public synchronized int insertSelectiveNew(BigDecimal orderId,BigDecimal priceId) throws Exception {
  238. List<Map<String,Object>> weightTaskResultIdList = bmstruckDetailsOrderMapper.getSteelWeightTaskResultId(orderId);
  239. System.out.println("根据运单查询到的计量实绩数据为," + weightTaskResultIdList);
  240. if(priceId == null) {
  241. return 0;
  242. }
  243. if (priceId.intValue() == 0) {
  244. return 0;
  245. }
  246. int result = 0;
  247. //优先根据计量批次新增详单
  248. List<Map<String,Object>> batchIdList = bmstruckDetailsOrderMapper.getWeightBatchIds(orderId);
  249. if(batchIdList.size()>0){
  250. for(Map<String, Object> map : batchIdList){
  251. if(map == null) {
  252. System.out.println("空Map,释放");
  253. continue;
  254. }
  255. BigDecimal weightBatchId = DataChange.dataToBigDecimal(map.get("weightBatchId"));
  256. //判断该批次有没有结算数据
  257. if(bmstruckDetailsOrderMapper.getIsHaveDetailsOrderByBatch(weightBatchId) > 0 ){
  258. // bmstruckDetailsOrderMapper.updateDetailsStatusByBatchId(weightBatchId);
  259. continue;
  260. }
  261. try {
  262. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
  263. BigDecimal priceValue = getPriceValue(priceId);
  264. BigDecimal netWeight = DataChange.dataToBigDecimal(map.get("netWeight"));
  265. // 得到计费公式
  266. String formula_string = null;
  267. if (orderType.intValue() == 3) {
  268. // 得到采购汽运计费公式
  269. formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(8));
  270. // 替换采购汽运运计算公式
  271. formula_string = formula_string.replace("到厂计量湿吨",netWeight.toString())
  272. .replace("单价",priceValue.toString());
  273. }
  274. if (orderType.intValue() >= 1 && orderType.intValue() <= 3) {
  275. // 得到销售10km差距内的汽运计费公式
  276. formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(10));
  277. // 替换采购汽运运计算公式
  278. formula_string = formula_string.replace("运输单价",priceValue.toString())
  279. .replace("物资净重",netWeight.toString());
  280. }
  281. String s = toSufExpr(formula_string);
  282. BigDecimal detailsAmountOld = calSufExpr(s);
  283. Double amount = detailsAmountOld.doubleValue();
  284. BigDecimal detailsAmount = new BigDecimal(amount).setScale(2,RoundingMode.HALF_UP);
  285. BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
  286. if (orderType.intValue() == 3) {
  287. BigDecimal purchaseOrderId = getFormulaMembers(orderId);
  288. bmstruckDetailsOrder.setPurchaseOrderId(purchaseOrderId);
  289. }
  290. if (orderType.intValue() == 2 || orderType.intValue() == 1) {
  291. bmstruckDetailsOrder.setWetherToStatement(new BigDecimal(0));
  292. }
  293. // 得到最大id
  294. BigDecimal detailsId = selectMaxId();
  295. String detailsNo = noUtil.setResultNo("QYXD", detailsId);
  296. bmstruckDetailsOrder.setDetailsId(detailsId);
  297. bmstruckDetailsOrder.setWeightBatchId(weightBatchId);
  298. bmstruckDetailsOrder.setOrderId(orderId);
  299. bmstruckDetailsOrder.setDetailsNo(detailsNo);
  300. bmstruckDetailsOrder.setPriceId(priceId);
  301. bmstruckDetailsOrder.setPriceValue(priceValue);
  302. bmstruckDetailsOrder.setDetailsAmount(detailsAmount);
  303. bmstruckDetailsOrder.setDetailsTime(new Date());
  304. // 设置常规字段
  305. bmstruckDetailsOrder.setInsertTime(new Date());
  306. bmstruckDetailsOrder.setUpdateTime(new Date());
  307. bmstruckDetailsOrder.setInsertUsername("admin");
  308. bmstruckDetailsOrder.setUpdateUsername("admin");
  309. bmstruckDetailsOrder.setInsertUpdateRemark("无");
  310. result += bmstruckDetailsOrderMapper.insertSelective(bmstruckDetailsOrder);
  311. }catch (Exception e){
  312. //不打印给控制台(有可能是正常情况)
  313. e.printStackTrace();
  314. }
  315. }
  316. return result;
  317. }
  318. for (Map<String, Object> map : weightTaskResultIdList) {
  319. if(map == null) {
  320. System.out.println("map为空");
  321. continue;
  322. }
  323. BigDecimal weightTaskResultId = DataChange.dataToBigDecimal(map.get("weightTaskResultId"));
  324. if (weightTaskResultId == null) {
  325. System.out.println("计量实绩Id为空");
  326. continue;
  327. }
  328. //判断该计量实绩有没有结算数据
  329. if(bmstruckDetailsOrderMapper.getIsHaveDetailsOrder(weightTaskResultId) > 0 ){
  330. continue;
  331. }
  332. BigDecimal netWeightIsNull = bmstruckDetailsOrderMapper.getNetWeight(weightTaskResultId);
  333. if (netWeightIsNull == null) {
  334. System.out.println("没有计量实绩,不生成结算数据:" + orderId);
  335. continue;
  336. }
  337. //BigDecimal detailsAmountOld=new BigDecimal(0);
  338. try {
  339. BigDecimal detailsAmountOld = generateTruckFeesNew(orderId, weightTaskResultId);
  340. Double amount = detailsAmountOld.doubleValue();
  341. BigDecimal detailsAmount = new BigDecimal(amount).setScale(2,RoundingMode.HALF_UP);
  342. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
  343. BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
  344. if (orderType.intValue() == 3) {
  345. BigDecimal purchaseOrderId = getFormulaMembers(orderId);
  346. bmstruckDetailsOrder.setPurchaseOrderId(purchaseOrderId);
  347. }
  348. if (orderType.intValue() == 2 || orderType.intValue() == 1) {
  349. bmstruckDetailsOrder.setWetherToStatement(new BigDecimal(0));
  350. }
  351. // 得到最大id
  352. BigDecimal detailsId = selectMaxId();
  353. String detailsNo = noUtil.setResultNo("QYXD", detailsId);
  354. bmstruckDetailsOrder.setDetailsId(detailsId);
  355. bmstruckDetailsOrder.setWeightTaskResultId(weightTaskResultId);
  356. bmstruckDetailsOrder.setOrderId(orderId);
  357. bmstruckDetailsOrder.setDetailsNo(detailsNo);
  358. bmstruckDetailsOrder.setPriceId(priceId);
  359. bmstruckDetailsOrder.setPriceValue(getPriceValue(priceId));
  360. bmstruckDetailsOrder.setDetailsAmount(detailsAmount);
  361. bmstruckDetailsOrder.setDetailsTime(new Date());
  362. // 设置常规字段
  363. bmstruckDetailsOrder.setInsertTime(new Date());
  364. bmstruckDetailsOrder.setUpdateTime(new Date());
  365. bmstruckDetailsOrder.setInsertUsername("admin");
  366. bmstruckDetailsOrder.setUpdateUsername("admin");
  367. bmstruckDetailsOrder.setInsertUpdateRemark("无");
  368. result += bmstruckDetailsOrderMapper.insertSelective(bmstruckDetailsOrder);
  369. System.out.println("订单生成了结算单据" + orderId);
  370. }catch (Exception e){
  371. //不打印给控制台(有可能是正常情况)
  372. e.printStackTrace();
  373. }
  374. }
  375. return result;
  376. }
  377. /**
  378. * 查询最大id
  379. * @return
  380. */
  381. @Override
  382. public BigDecimal selectMaxId() {
  383. return bmstruckDetailsOrderMapper.selectDetailsId();
  384. }
  385. /**
  386. * 展示汽运实绩列表
  387. * @param mapVal
  388. * @return
  389. */
  390. @Override
  391. public List<Map<String, Object>> getTruckResultList(Map<String, Object> mapVal) {
  392. BigDecimal orderId = (BigDecimal) mapVal.get("orderId") ;
  393. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
  394. List<Map<String,Object>> mapList;
  395. if (orderType.intValue() <= 3 && orderType.intValue() >= 1) {
  396. mapList = bmstruckDetailsOrderMapper.getSaleTruckResultList(mapVal);
  397. }
  398. else {
  399. mapList = bmstruckDetailsOrderMapper.getTruckResultList(mapVal);
  400. }
  401. return mapList;
  402. }
  403. /**
  404. * 得到计算因子
  405. * @param orderId
  406. * @return
  407. */
  408. @Override
  409. public BigDecimal getFormulaMembers(BigDecimal orderId) {
  410. return bmstruckDetailsOrderMapper.getFormulaMembers(orderId);
  411. }
  412. /**
  413. * 得到价格id
  414. * @return
  415. */
  416. @Override
  417. public Map<String, Object> getPriceId(BigDecimal orderId) {
  418. return bmstruckDetailsOrderMapper.getPriceId(orderId);
  419. }
  420. /**
  421. * 得到单价
  422. * @param priceId
  423. * @return
  424. */
  425. @Override
  426. public BigDecimal getPriceValue(BigDecimal priceId) {
  427. return bmstruckDetailsOrderMapper.getPriceValue(priceId);
  428. }
  429. /**
  430. * 得到到厂湿重
  431. * @param weightTaskResultId
  432. * @return
  433. */
  434. @Override
  435. public BigDecimal getNetWeight(BigDecimal weightTaskResultId) {
  436. return bmstruckDetailsOrderMapper.getNetWeight(weightTaskResultId);
  437. }
  438. /**
  439. * 展示未转成销售账单的销售详单
  440. * @param mapVal
  441. * @param orderType
  442. * @return
  443. */
  444. @Override
  445. public List<Map<String, Object>> getUnFinishedTruckDetailsOrderList(Map<String, Object> mapVal, Integer orderType) {
  446. if (mapVal == null) {
  447. mapVal = new HashMap<>();
  448. }
  449. mapVal.put("orderType",new BigDecimal(orderType));
  450. return bmstruckDetailsOrderMapper.getUnFinishedTruckDetailsOrderList(mapVal);
  451. }
  452. //通过不同的值,查询未生成账单的计费详单
  453. @Override
  454. public List<Map<String, Object>> getUnFinishedConvertedTruckDetailsOrderList(Map<String, Object> mapVal, Integer orderType) {
  455. //orderType:1:计时,2:计数,3:计重,4:包月
  456. if(orderType==1){
  457. return bmstruckDetailsOrderMapper.getUnFinishedTimeTruckDetailsOrderList(mapVal);
  458. }
  459. else if(orderType==2){
  460. return bmstruckDetailsOrderMapper.getUnFinishedNumTruckDetailsOrderList(mapVal);
  461. }
  462. else if(orderType==3){
  463. return bmstruckDetailsOrderMapper.getUnFinishedWeightTruckDetailsOrderList(mapVal);
  464. }
  465. else if(orderType==4){
  466. return bmstruckDetailsOrderMapper.getUnFinishedMonthTruckDetailsOrderList(mapVal);
  467. }
  468. return null;
  469. }
  470. /**
  471. * 替换汽运费公式并进行计算
  472. * @param orderId
  473. * @return
  474. * @throws Exception
  475. */
  476. public BigDecimal generateTruckFees(BigDecimal orderId,BigDecimal weightTaskResultId) throws Exception {
  477. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
  478. Map<String, Object> priceMap = getPriceId(orderId);
  479. BigDecimal priceId = (BigDecimal) priceMap.get("priceId");
  480. BigDecimal priceValue = getPriceValue(priceId);
  481. BigDecimal netWeight = getNetWeight(weightTaskResultId);
  482. //用于给单价id为2400的生成详单
  483. // if (priceValue==null||priceValue.compareTo(BigDecimal.ZERO)==0){
  484. // //该值为任意给的值
  485. // priceValue=BigDecimal.TEN;
  486. // }
  487. // 得到计费公式
  488. String formula_string = null;
  489. if (orderType.intValue() == 3) {
  490. // 得到采购汽运计费公式
  491. formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(8));
  492. // 替换采购汽运运计算公式
  493. formula_string = formula_string.replace("到厂计量湿吨",netWeight.toString())
  494. .replace("单价",priceValue.toString());
  495. }
  496. if (orderType.intValue() >= 1 && orderType.intValue() <= 3) {
  497. // BigDecimal distance = new BigDecimal(101);
  498. // 得到销售汽运计费公式
  499. // if (distance.intValue() >= 91 || distance.intValue() <= 109) {
  500. // 得到销售10km差距内的汽运计费公式
  501. formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(10));
  502. // 替换采购汽运运计算公式
  503. formula_string = formula_string.replace("运输单价",priceValue.toString())
  504. .replace("物资净重",netWeight.toString());
  505. // }
  506. // else {
  507. // // 得到销售10km差距外的汽运计费公式
  508. // formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(11));
  509. // // 替换采购汽运运计算公式
  510. // formula_string = formula_string.replace("运输单价",priceValue.toString())
  511. // .replace("运输距离",distance.toString())
  512. // .replace("物资净重",netWeight.toString());
  513. // }
  514. }
  515. String s = toSufExpr(formula_string);
  516. return calSufExpr(s);
  517. }
  518. /**
  519. * 钢材直接修改计算运费
  520. * @param priceValue
  521. * @param weightTaskResultId
  522. * @return
  523. * @throws Exception
  524. */
  525. public BigDecimal generateTruckFeesForDirect(BigDecimal priceValue,BigDecimal weightTaskResultId) throws Exception {
  526. BigDecimal netWeight = getNetWeight(weightTaskResultId);
  527. // 得到计费公式
  528. String formula_string = null;
  529. formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(10));
  530. // 替换采购汽运运计算公式
  531. formula_string = formula_string.replace("运输单价",priceValue.toString())
  532. .replace("物资净重",netWeight.toString());
  533. String s = toSufExpr(formula_string);
  534. return calSufExpr(s);
  535. }
  536. /**
  537. * 替换汽运费公式并进行计算(专为计费详单服务)
  538. * @param orderId
  539. * @return
  540. * @throws Exception
  541. */
  542. public BigDecimal generateTruckFeesNew (BigDecimal orderId,BigDecimal weightTaskResultId) throws Exception {
  543. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
  544. Map<String, Object> priceMap = getPriceId(orderId);
  545. BigDecimal priceId = (BigDecimal) priceMap.get("priceId");
  546. BigDecimal priceValue = getPriceValue(priceId);
  547. BigDecimal netWeight = getNetWeight(weightTaskResultId);
  548. //用于给单价id为2400的生成详单
  549. if (priceValue==null||priceValue.compareTo(BigDecimal.ZERO)==0){
  550. //该值为任意给的值
  551. priceValue=BigDecimal.TEN;
  552. }
  553. // 得到计费公式
  554. String formula_string = null;
  555. if (orderType.intValue() == 3) {
  556. // 得到采购汽运计费公式
  557. formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(8));
  558. // 替换采购汽运运计算公式
  559. formula_string = formula_string.replace("到厂计量湿吨",netWeight.toString())
  560. .replace("单价",priceValue.toString());
  561. }
  562. if (orderType.intValue() >= 1 && orderType.intValue() <= 3) {
  563. // BigDecimal distance = new BigDecimal(101);
  564. // 得到销售汽运计费公式
  565. // if (distance.intValue() >= 91 || distance.intValue() <= 109) {
  566. // 得到销售10km差距内的汽运计费公式
  567. formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(10));
  568. // 替换采购汽运运计算公式
  569. formula_string = formula_string.replace("运输单价",priceValue.toString())
  570. .replace("物资净重",netWeight.toString());
  571. // }
  572. // else {
  573. // // 得到销售10km差距外的汽运计费公式
  574. // formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(11));
  575. // // 替换采购汽运运计算公式
  576. // formula_string = formula_string.replace("运输单价",priceValue.toString())
  577. // .replace("运输距离",distance.toString())
  578. // .replace("物资净重",netWeight.toString());
  579. // }
  580. }
  581. String s = toSufExpr(formula_string);
  582. return calSufExpr(s);
  583. }
  584. public BigDecimal updateSteelAmounts(Map<String,Object> map) throws Exception {
  585. BigDecimal orderId = DataChange.dataToBigDecimal(map.get("orderId"));
  586. BigDecimal weightTaskResultId = DataChange.dataToBigDecimal(map.get("weightTaskResultId"));
  587. BigDecimal weightBatchId = DataChange.dataToBigDecimal(map.get("weightBatchId"));
  588. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
  589. BigDecimal priceId = DataChange.dataToBigDecimal(map.get("priceId"));
  590. BigDecimal priceValue = getPriceValue(priceId);
  591. if(priceValue==null){
  592. //单价为Null,则返回0
  593. return new BigDecimal(0);
  594. }
  595. BigDecimal netWeight = null;
  596. if(weightBatchId != null && weightBatchId.intValue() != 0) {
  597. netWeight = getWeightBatchNetWeight(weightBatchId);
  598. }else{
  599. netWeight = getNetWeight(weightTaskResultId);
  600. }
  601. // 得到计费公式
  602. String formula_string = null;
  603. if (orderType.intValue() >= 1 && orderType.intValue() <= 3) {
  604. // BigDecimal distance = new BigDecimal(101);
  605. // 得到销售汽运计费公式
  606. // if (distance.intValue() >= 91 || distance.intValue() <= 109) {
  607. // 得到销售10km差距内的汽运计费公式
  608. formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(10));
  609. // 替换采购汽运运计算公式
  610. formula_string = formula_string.replace("运输单价",priceValue.toString())
  611. .replace("物资净重",netWeight.toString());
  612. // }
  613. // else {
  614. // // 得到销售10km差距外的汽运计费公式
  615. // formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(11));
  616. // // 替换采购汽运运计算公式
  617. // formula_string = formula_string.replace("运输单价",priceValue.toString())
  618. // .replace("运输距离",distance.toString())
  619. // .replace("物资净重",netWeight.toString());
  620. // }
  621. }
  622. String s = toSufExpr(formula_string);
  623. return calSufExpr(s);
  624. }
  625. private BigDecimal getWeightBatchNetWeight(BigDecimal weightBatchId) {
  626. return bmstruckDetailsOrderMapper.getWeightBatchNetWeight(weightBatchId);
  627. }
  628. /**
  629. * 中缀转换后缀表达式
  630. */
  631. public String toSufExpr(String s) {
  632. StringBuffer sufExpr = new StringBuffer();
  633. Stack<String> stack = new Stack<>();
  634. //压入空方便判断
  635. stack.push(null);
  636. Pattern pattern = Pattern.compile("\\(int\\)|(?<!\\d|[)])-?\\d+(\\.\\d+)?|!=|>=|<=|==|[+\\-*/%()><=|]");
  637. Matcher matcher = pattern.matcher(s);
  638. while (matcher.find()) {
  639. String group = matcher.group();
  640. if (group.matches("!=|>=|<=|==|[+\\-*/%()><=|]|\\(int\\)")) {//是运算符
  641. if (group.equals("(")) {//之间压栈
  642. stack.push(group);
  643. } else if (group.equals(")")) {//等于右括号,一直弹栈,直到遇到左括号
  644. String pop = null;
  645. while (!(pop = stack.pop()).equals("(")) {//遍历循环至左括号
  646. sufExpr.append(pop + " ");
  647. }
  648. } else {//是运算符:加减乘除强转,根据优先级压栈
  649. while (getPriority(group) <= getPriority(stack.peek())) {
  650. String pop = stack.pop();
  651. System.out.println(pop);
  652. System.out.println(sufExpr);
  653. if(pop!=null&&!pop.equals("|")){
  654. sufExpr.append(pop + " ");
  655. }
  656. }
  657. stack.push(group);
  658. }
  659. } else {//是数字
  660. sufExpr.append(group + " ");
  661. }
  662. }
  663. String pop = null;
  664. while (null != (pop = stack.pop())) {
  665. sufExpr.append(pop + " ");
  666. }
  667. return sufExpr.toString();
  668. }
  669. /**
  670. * 设置出栈优先级,(:优先级最低,表示只有遇到)才能出栈
  671. * 当栈顶遇到优先级比自己小或等于的弹栈
  672. */
  673. public Integer getPriority(String c) {
  674. if (c == null) {
  675. return 0;
  676. }
  677. switch (c) {
  678. case "(":
  679. return 1;
  680. case "+":
  681. case "-":
  682. return 2;
  683. case "*":
  684. case "/":
  685. case "%":
  686. return 3;
  687. case ">":
  688. case "<":
  689. case ">=":
  690. case "<=":
  691. case "!=":
  692. case "==":
  693. return 4;
  694. case "|":
  695. return 5;
  696. case "=":
  697. return 6;
  698. case "(int)":
  699. return 7;
  700. }
  701. return 0;
  702. }
  703. /**
  704. * 计算值
  705. */
  706. public BigDecimal cal(BigDecimal a1, BigDecimal a2, String operator) throws Exception {
  707. switch (operator){
  708. case "+":return a1.add(a2);
  709. case "-":return a1.subtract(a2);
  710. case "*":return a1.multiply(a2);
  711. case "/":return a1.divide(a2,3,BigDecimal.ROUND_CEILING);
  712. case "%":return a1.divideAndRemainder(a2)[1];
  713. default:
  714. break;
  715. }
  716. throw new Exception("非法运算符");
  717. }
  718. public Boolean calBoolean(BigDecimal a1, BigDecimal a2, String operator) throws Exception {
  719. switch (operator){
  720. case ">":return a1.compareTo(a2) == 1;
  721. case "<":return a1.compareTo(a2) == -1;
  722. case ">=":return a1.compareTo(a2) > -1;
  723. case "<=":return a1.compareTo(a2) < 1;
  724. case "!=":return a1.compareTo(a2) != 0;
  725. case "==":return a1.compareTo(a2) == 0;
  726. default:
  727. break;
  728. }
  729. throw new Exception("非法运算符");
  730. }
  731. /**
  732. * 计算后缀表达式
  733. */
  734. public BigDecimal calSufExpr(String sufExpr) throws Exception {
  735. Stack<BigDecimal> stack = new Stack<>();
  736. Pattern pattern=Pattern.compile("\\(int\\)|-?\\d+(\\.\\d+)?|!=|>=|<=|==|[+\\-*/%><=]");//提取运算符和数字
  737. Matcher matcher = pattern.matcher(sufExpr);
  738. BigDecimal result=new BigDecimal("0.0");
  739. while (matcher.find()){
  740. String group = matcher.group();
  741. if(group.matches("[+\\-*/%]")){
  742. BigDecimal a1 =stack.pop();
  743. BigDecimal a2 =stack.pop();
  744. result = cal(a2, a1, group);
  745. stack.push(result);
  746. }
  747. else if(group.equals("(int)")){
  748. BigDecimal pop = stack.pop();
  749. BigDecimal bigDecimal = pop.setScale(0, BigDecimal.ROUND_DOWN);
  750. stack.push(bigDecimal);
  751. }
  752. else if(group.matches("!=|>=|<=|==|[><]")){
  753. BigDecimal a1 =stack.pop();
  754. BigDecimal a2 =stack.pop();
  755. stack.push(calBoolean(a2,a1,group)?new BigDecimal(1):new BigDecimal(0));
  756. }
  757. else if(group.equals("=")){
  758. BigDecimal a1 =stack.pop();
  759. BigDecimal a2 =stack.pop();
  760. if (a2.compareTo(new BigDecimal(1))==0) {
  761. stack.push(a1);
  762. }
  763. }
  764. else {//为数字直接压栈
  765. stack.push(new BigDecimal(group));
  766. }
  767. }
  768. return result;
  769. }
  770. /**
  771. * 新增内转汽运详单
  772. * @param orderId
  773. * @return
  774. * @throws Exception
  775. */
  776. @Override
  777. public int addConvertedDetailsOrder(BigDecimal orderId) throws Exception {
  778. // 得到最大id
  779. BigDecimal detailsId = selectMaxId();
  780. String detailsNo = noUtil.setResultNo("QYXD", detailsId);
  781. // 新增详单实体
  782. BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
  783. // 设置常规字段
  784. bmstruckDetailsOrder.setInsertTime(new Date());
  785. bmstruckDetailsOrder.setInsertUsername("admin");
  786. bmstruckDetailsOrder.setInsertUpdateRemark("无");
  787. // 通过订单号获取物资信息以及结算方式
  788. Map<String, Object> mapVal=getSettlement(orderId);
  789. //需求类型(0:计重;1:计时;2:计次;3:包月)
  790. String requirementType=mapVal.get("requirementType").toString();
  791. Integer materialId =Integer.parseInt(mapVal.get("materialId").toString());
  792. //通过物资id以及结算方式获取单价;
  793. BigDecimal priceId=getPriceByWz(requirementType,materialId);
  794. // 将单价存入实体
  795. bmstruckDetailsOrder.setPriceId(priceId);
  796. // 获取物资数量/计时获取时长/计数为一次/包月为包月价
  797. if("0".equals(requirementType)){
  798. //通过单价ID获取单价
  799. BigDecimal price=getPriceValue(priceId);
  800. //获取物资重量
  801. BigDecimal weight=getNetWeight(priceId);
  802. bmstruckDetailsOrder.setDetailsAmount(new BigDecimal(price.doubleValue()*weight.doubleValue()));
  803. }
  804. else{
  805. //通过单价ID获取单价
  806. BigDecimal price=getPriceValue(priceId);
  807. bmstruckDetailsOrder.setDetailsAmount(price);
  808. }
  809. return bmstruckDetailsOrderMapper.insertSelective(bmstruckDetailsOrder);
  810. }
  811. //通过物资id以及结算方式获取单价;
  812. @Override
  813. public BigDecimal getPriceByWz(String requirementType, Integer materialId) {
  814. return bmstruckDetailsOrderMapper.getPriceByWz(requirementType,materialId);
  815. }
  816. @Override
  817. // 通过订单号获取物资信息以及结算方式
  818. public Map<String, Object> getSettlement(BigDecimal orderId) {
  819. return bmstruckDetailsOrderMapper.getSettlement(orderId);
  820. }
  821. /**
  822. * 修改详单
  823. * @param mapValue
  824. * @return
  825. */
  826. @Override
  827. public synchronized int updateDetailsOrder(Map<String, Object> mapValue) {
  828. System.out.println("修改单价,时间:" + new Date() + "-----------" + mapValue);
  829. BigDecimal orderId = DataChange.dataToBigDecimal(mapValue.get("orderId"));
  830. BigDecimal priceId = DataChange.dataToBigDecimal(mapValue.get("priceId"));
  831. BigDecimal priceValue = getPriceValue(priceId);
  832. System.out.println("运单Id,为" + orderId);
  833. System.out.println("随接口传输过来的单价Id,为" + priceId);
  834. try {
  835. int i = insertSelectiveNew(orderId,priceId);
  836. } catch (Exception e) {
  837. //不打印给控制台(可能是正常情况)
  838. }
  839. //根据运输订单id查询计费详单id
  840. OmstruckOrder omstruckOrder = new OmstruckOrder();
  841. omstruckOrder.setOrderId(orderId);
  842. omstruckOrder.setPriceId(priceId);
  843. try{
  844. //通过userId查询出用户名
  845. String carrierName = bmstruckDetailsOrderMapper.getCarrierNameForPriceValue((String) mapValue.get("userId"));
  846. System.out.println("正在执行该操作的人员为:" + carrierName + "时间为:" + new Date()) ;
  847. //根据运输ID查询出记录下来的用户名
  848. String recordUserName = bmstruckDetailsOrderMapper.getUserName(orderId);
  849. if (recordUserName==null){
  850. omstruckOrder.setRecordUsername(carrierName+",");
  851. }else {
  852. String[] s = recordUserName.split(",");
  853. if (s.length < 2){
  854. omstruckOrder.setRecordUsername(recordUserName+carrierName+",");
  855. }else if (s.length ==2){
  856. omstruckOrder.setRecordUsername(recordUserName+carrierName);
  857. }else if (s.length==3){
  858. s[0]=s[1];
  859. s[1]=s[2];
  860. s[2]=carrierName;
  861. omstruckOrder.setRecordUsername(s[0]+","+s[1]+","+s[2]);
  862. }
  863. }
  864. }catch (Exception e){
  865. System.out.println("e"+e.getMessage());
  866. }
  867. // List<BigDecimal> detailIds = bmstruckDetailsOrderMapper.getDetailIds(orderId);
  868. List<Map<String,Object>> batchIdList = bmstruckDetailsOrderMapper.getWeightBatchIds(orderId);
  869. //根据批次id去查询计费详单id
  870. List<BigDecimal> detailIds = new ArrayList<>();
  871. try {
  872. detailIds = bmstruckDetailsOrderMapper.getDetailIdsByWeightBatchId(batchIdList);
  873. } catch (Exception e) {}
  874. omstruckOrderMapper.updateByPrimaryKeySelective(omstruckOrder);
  875. int result = 0;
  876. for (BigDecimal detailsId : detailIds) {
  877. BmstruckDetailsOrder bmstruckDetailsOrder = bmstruckDetailsOrderMapper.selectByPrimaryKey(detailsId);
  878. bmstruckDetailsOrder.setHistoryDetailsAmount(bmstruckDetailsOrder.getDetailsAmount());
  879. // 重新设置单价
  880. BigDecimal priceId1 = bmstruckDetailsOrder.getPriceId();
  881. bmstruckDetailsOrder.setPriceids(priceId1+","+priceId);
  882. bmstruckDetailsOrder.setPriceId(priceId);
  883. bmstruckDetailsOrder.setOrderId(orderId);
  884. bmstruckDetailsOrder.setPriceValue(priceValue);
  885. BigDecimal weightTaskResultId = bmstruckDetailsOrder.getWeightTaskResultId();
  886. BigDecimal weightBatchId = bmstruckDetailsOrder.getWeightBatchId();
  887. Map<String,Object> map = new HashMap<>();
  888. if(weightBatchId != null) {
  889. map.put("orderId",orderId);
  890. map.put("weightBatchId",weightBatchId);
  891. map.put("priceId",priceId);
  892. }else{
  893. map.put("orderId",orderId);
  894. map.put("weightTaskResultId",weightTaskResultId);
  895. map.put("priceId",priceId);
  896. }
  897. try {
  898. // 计算出新的详单金额
  899. BigDecimal newAmount = updateSteelAmounts(map);
  900. bmstruckDetailsOrder.setDetailsAmount(newAmount.divide(new BigDecimal(1),2, RoundingMode.HALF_UP));
  901. //修改单价的历史时间
  902. //omstruckOrderMapper.modifyOldTime(priceId,new Date());
  903. }catch (Exception e) {
  904. System.out.println("更新历史时间失败");
  905. }
  906. System.out.println("更新详单数据成功");
  907. result = bmstruckDetailsOrderMapper.updateByPrimaryKeySelective(bmstruckDetailsOrder);
  908. }
  909. /*try {
  910. amsFeign.copySteelPrice(mapValue);
  911. } catch (Exception e) {
  912. e.printStackTrace();
  913. }*/
  914. if(DataChange.dataToBigDecimal(mapValue.get("updatePlace")).intValue() == 1) {
  915. System.out.println("更新asom里面的实际地址数据");
  916. Map<String, Object> stringObjectMap = bmstruckDetailsOrderMapper.getsaleShippingAddressId(mapValue);
  917. BigDecimal saleShippingAddressId = (BigDecimal) stringObjectMap.get("saleShippingAddressId");
  918. BigDecimal historyShippingAddressId = (BigDecimal) stringObjectMap.get("historyShippingAddressId");
  919. bmstruckDetailsOrderMapper.updateActuallyPlace(mapValue);
  920. //if (historyShippingAddressId!=null){
  921. // //修改地址(不修改历史地址)
  922. // bmstruckDetailsOrderMapper.updatePlaceNew(mapValue);
  923. //}else if (historyShippingAddressId==null ) {
  924. // mapValue.put("historyPlaceId", saleShippingAddressId);
  925. // //修改地址(不修改历史地址)
  926. // bmstruckDetailsOrderMapper.updatePlace(mapValue);
  927. //}
  928. }
  929. System.out.println("修改单价,时间:" + new Date() + "-----------" + mapValue);
  930. return result;
  931. }
  932. @Override
  933. public int updateAsomPriceId(Map<String, Object> mapValue) {
  934. System.out.println("更新ASOM表里面的数据实际地址数据" + mapValue + "----------" + new Date());
  935. //前面更新运单时更新过地址了,这里就不更新了,如果订单ID为空,才更新
  936. if(DataChange.dataToBigDecimal(mapValue.get("updatePlace")).intValue() == 1 && mapValue.get("orderId")==null) {
  937. Map<String, Object> stringObjectMap = bmstruckDetailsOrderMapper.getsaleShippingAddressId(mapValue);
  938. BigDecimal saleShippingAddressId = (BigDecimal) stringObjectMap.get("saleShippingAddressId");
  939. BigDecimal historyShippingAddressId = (BigDecimal) stringObjectMap.get("historyShippingAddressId");
  940. bmstruckDetailsOrderMapper.updateActuallyPlace(mapValue);
  941. //if (historyShippingAddressId!=null){
  942. // //修改地址(不修改历史地址)
  943. // bmstruckDetailsOrderMapper.updatePlaceNew(mapValue);
  944. //}else if (historyShippingAddressId==null ) {
  945. // mapValue.put("historyPlaceId", saleShippingAddressId);
  946. // //修改地址(不修改历史地址)
  947. // bmstruckDetailsOrderMapper.updatePlace(mapValue);
  948. //}
  949. }
  950. return bmstruckDetailsOrderMapper.updateAsomPriceId(mapValue);
  951. }
  952. @Override
  953. public BigDecimal getCarrierIdBySSO(String carrierSsoId) {
  954. return bmstruckDetailsOrderMapper.getCarrierIdBySSO(carrierSsoId);
  955. }
  956. // 根据单价id查询价格和地址
  957. @Override
  958. public Map<String,Object> findAddressAndPrice(Integer priceId) {
  959. return bmstruckDetailsOrderMapper.findAddressAndPrice(new BigDecimal(priceId));
  960. }
  961. /**
  962. * 增加焦炭途损费
  963. * @param map
  964. * @return
  965. */
  966. @Override
  967. public int addLossFeeOfCoke(Map<String,Object> map) {
  968. BigDecimal lossFees = DataChange.dataToBigDecimal(map.get("lossFees"));
  969. BigDecimal detailsId = DataChange.dataToBigDecimal(map.get("detailsId"));
  970. BmstruckDetailsOrder bmstruckDetailsOrder = bmstruckDetailsOrderMapper.selectByPrimaryKey(detailsId);
  971. BigDecimal detailsAmount = bmstruckDetailsOrder.getDetailsAmount();
  972. DecimalFormat df = new DecimalFormat("0.00");
  973. Double newAmount = detailsAmount.doubleValue() - lossFees.doubleValue();
  974. String newAmountStr = df.format(newAmount);
  975. bmstruckDetailsOrder.setDetailsAmount(new BigDecimal(newAmountStr));
  976. int result = bmstruckDetailsOrderMapper.updateByPrimaryKeySelective(bmstruckDetailsOrder);
  977. return result;
  978. }
  979. /*
  980. 内转计重计费详单
  981. */
  982. @Override
  983. public List<Map<String, Object>> getInwardWeightDetailsOrder(Map<String, Object> mapValue, Integer orderType) {
  984. List<Map<String,Object>>mapList = new ArrayList<>();
  985. switch (orderType){
  986. case 10:
  987. List<Map<String, Object>> inwardReportResult = bmstruckDetailsOrderMapper.getPurInwarWeightDetailsOrder(mapValue);
  988. return inwardReportResult;
  989. case 21:
  990. return bmstruckDetailsOrderMapper.getInwardTimeDetailsOrder(mapValue);
  991. case 11:
  992. return bmstruckDetailsOrderMapper.getAllInwardWeight(mapValue);
  993. case 26:
  994. return bmstruckDetailsOrderMapper.getInwardCountDetailsOrder(mapValue);
  995. default:
  996. break;
  997. }
  998. return mapList;
  999. }
  1000. @Override
  1001. public synchronized int inserInwardOrder(Map<String, Object> mapVal) {
  1002. //获取运输订单ID
  1003. BigDecimal orderId= DataChange.dataToBigDecimal(mapVal.get("orderId"));
  1004. //根据运输订单去查找订单类型
  1005. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
  1006. //根据运输订单id去查询计费详单id
  1007. if(bmstruckDetailsOrderMapper.selectDetailsByOrder(orderId) > 0){
  1008. return -1;
  1009. }
  1010. List<Map<String,Object>> priceAmountList = new ArrayList<>();
  1011. if(inwardTypeList.contains(orderType.intValue())){
  1012. //获取该订单的计量实绩ID以及净重,只会返回一条数据
  1013. priceAmountList = bmstruckDetailsOrderMapper.getWeightTaskResultId(orderId);
  1014. }
  1015. if(toLineAndMaterial.contains(orderType.intValue())){
  1016. //如果在以上订单类型里面则需要根据运输订单ID去找线路和物资
  1017. Map<String,Object> priceInfoPur = bmstruckDetailsOrderMapper.getPriceInfoPur(orderId);
  1018. //根据物资品类ID和承运起止范围去匹配单价
  1019. Map<String,Object> map = bmstruckDetailsOrderMapper.getPurInwardPrice(priceInfoPur);
  1020. if(map != null){
  1021. mapVal.putAll(map);
  1022. }else{
  1023. return -1;
  1024. }
  1025. }
  1026. if(fixLineList.contains(orderType.intValue())){
  1027. //拼装车皮进厂以及一焦化采购焦炭进厂
  1028. Map<String,Object> priceInfoPur = bmstruckDetailsOrderMapper.getPriceInfoPur(orderId);
  1029. priceInfoPur.put("transRangeId",1);
  1030. //根据物资品类ID和承运起止范围去匹配单价
  1031. Map<String,Object> map = bmstruckDetailsOrderMapper.getPurInwardPrice(priceInfoPur);
  1032. if(map != null){
  1033. mapVal.putAll(map);
  1034. }else{
  1035. return -1;
  1036. }
  1037. }
  1038. if(steelTypeList.contains(orderType.intValue())){
  1039. //钢材倒库
  1040. //首先获取净重
  1041. //BigDecimal netWeight = bmstruckDetailsOrderMapper.selectNetWeight(orderId);
  1042. //mapVal.put("netWeight",netWeight);
  1043. //获取单价
  1044. Map<String, Object> priceInfoPur = new HashMap<>();
  1045. priceInfoPur.put("transRangeId",1);
  1046. priceInfoPur.put("materialTypeId",5102);
  1047. Map<String,Object> map = bmstruckDetailsOrderMapper.getPurInwardPrice(priceInfoPur);
  1048. if(map != null){
  1049. mapVal.putAll(map);
  1050. }else{
  1051. return -1;
  1052. }
  1053. }
  1054. if(orderType.intValue() == 21 || orderType.intValue()==26){
  1055. //计时/计次
  1056. priceAmountList.add(mapVal);
  1057. }
  1058. //获取单价ID
  1059. BigDecimal priceId = DataChange.dataToBigDecimal(mapVal.get("priceId")) ;
  1060. //获取单价值
  1061. BigDecimal priceValue = DataChange.dataToBigDecimal(mapVal.get("priceValue"));
  1062. if(priceId == null){
  1063. System.out.println(orderId + "没有单价");
  1064. return 1;
  1065. }
  1066. int result = 0;
  1067. for (Map<String, Object> map : priceAmountList) {
  1068. BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
  1069. //查询计重且计时
  1070. String s = bmstruckDetailsOrderMapper.selectWeightAndTimeByOrderId(orderId);
  1071. int num=0;
  1072. if (s!=null && s.contains("计时且过计量")){
  1073. num=21;
  1074. }
  1075. if(inwardTypeList.contains(orderType.intValue()) && num==0){
  1076. BigDecimal weightTaskResultId = DataChange.dataToBigDecimal(map.get("weightTaskResultId"));
  1077. BigDecimal netWeight = null;
  1078. if(mapVal.get("netWeight") != null) {
  1079. //因为事务的关系,部分订单结束时可能没有净重,故需要添加净重
  1080. netWeight = DataChange.dataToBigDecimal(mapVal.get("netWeight"));
  1081. }
  1082. else{
  1083. netWeight = DataChange.dataToBigDecimal(map.get("netWeight"));
  1084. }
  1085. //计算详单金额
  1086. BigDecimal detailsAmount = new BigDecimal(priceValue.doubleValue()*netWeight.doubleValue());
  1087. //保留两位小数
  1088. DecimalFormat df = new DecimalFormat("0.00");
  1089. String format = df.format(detailsAmount);
  1090. //关联计量实绩
  1091. bmstruckDetailsOrder.setWeightTaskResultId(weightTaskResultId);
  1092. if(priceId != null && priceValue !=null && detailsAmount.intValue() > 0){
  1093. bmstruckDetailsOrder.setDetailsAmount(new BigDecimal(format));
  1094. }
  1095. }
  1096. //内转计时结算
  1097. if(orderType.intValue() == 21 || num==21){
  1098. BigDecimal resultTime = DataChange.dataToBigDecimal(mapVal.get("Time1"));
  1099. //保留两位小数
  1100. DecimalFormat df = new DecimalFormat("0.00");
  1101. BigDecimal settleTime = new BigDecimal(String.valueOf(resultTime.divide(new BigDecimal(60), 14, BigDecimal.ROUND_HALF_UP)));
  1102. if(settleTime.doubleValue()<2.00){
  1103. BigDecimal detailsAmount = new BigDecimal(priceValue.doubleValue()*2);
  1104. bmstruckDetailsOrder.setDetailsAmount(new BigDecimal(df.format(detailsAmount)));
  1105. }else{
  1106. BigDecimal detailsAmount = new BigDecimal(priceValue.doubleValue()*settleTime.doubleValue());
  1107. bmstruckDetailsOrder.setDetailsAmount(new BigDecimal(df.format(detailsAmount)));
  1108. }
  1109. }
  1110. //内转计次结算
  1111. if(orderType.intValue() == 26){
  1112. //保留两位小数
  1113. DecimalFormat df = new DecimalFormat("0.00");
  1114. BigDecimal detailsAmount = new BigDecimal(priceValue.doubleValue());
  1115. bmstruckDetailsOrder.setDetailsAmount(new BigDecimal(df.format(detailsAmount)));
  1116. }
  1117. bmstruckDetailsOrder.setPriceId(priceId);
  1118. bmstruckDetailsOrder.setInsertUpdateRemark("单价存在");
  1119. // 得到最大id
  1120. BigDecimal detailsId = selectMaxId();
  1121. bmstruckDetailsOrder.setOrderId(orderId);
  1122. String detailsNo = noUtil.setResultNo("QYXD", detailsId);
  1123. bmstruckDetailsOrder.setDetailsId(detailsId);
  1124. bmstruckDetailsOrder.setDetailsNo(detailsNo);
  1125. bmstruckDetailsOrder.setDetailsTime(new Date());
  1126. // 设置常规字段
  1127. bmstruckDetailsOrder.setInsertTime(new Date());
  1128. bmstruckDetailsOrder.setWetherToStatement(new BigDecimal(0));
  1129. bmstruckDetailsOrder.setInsertUsername("admin");
  1130. bmstruckDetailsOrder.setUpdateUsername("admin");
  1131. result += bmstruckDetailsOrderMapper.insertSelective(bmstruckDetailsOrder);
  1132. }
  1133. return result;
  1134. }
  1135. @Override
  1136. public int updateDetails() {
  1137. List<Map<String,Object>>mapList = bmstruckDetailsOrderMapper.selectDetailsNoAmount();
  1138. int i=0;
  1139. for (Map<String,Object>map:mapList
  1140. ) {
  1141. //获取详单ID、价格值,净重
  1142. BigDecimal detailsId = DataChange.dataToBigDecimal(map.get("detailsId"));
  1143. BigDecimal netWeight = DataChange.dataToBigDecimal(map.get("netWeight"));
  1144. BigDecimal priceValue = DataChange.dataToBigDecimal(map.get("priceValue"));
  1145. BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
  1146. bmstruckDetailsOrder.setDetailsId(detailsId);
  1147. BigDecimal detailsAmount = new BigDecimal(priceValue.doubleValue()*netWeight.doubleValue());
  1148. DecimalFormat df = new DecimalFormat("0.00");
  1149. String format = df.format(detailsAmount);
  1150. bmstruckDetailsOrder.setDetailsAmount(new BigDecimal(format));
  1151. i += bmstruckDetailsOrderMapper.updateByPrimaryKeySelective(bmstruckDetailsOrder);
  1152. }
  1153. return i;
  1154. }
  1155. /*
  1156. 内转计重+计时计费详单
  1157. */
  1158. @Override
  1159. public List<Map<String, Object>> getInwardWeightTimeDetailsOrder(Map<String, Object> mapValue, Integer orderType) {
  1160. List<Map<String,Object>>mapListWeight = new ArrayList<>();
  1161. List<Map<String,Object>>mapListTime = new ArrayList<>();
  1162. //计重计费详单查询结果
  1163. mapListWeight = bmstruckDetailsOrderMapper.getInwardWeightDetailsOrder(mapValue);
  1164. //for(Map<String, Object> mapListWeightOne : mapListWeight)
  1165. //{
  1166. // mapListWeightOne.put("resultTime","null");
  1167. //}
  1168. //计时计费详单查询结果
  1169. mapListTime = bmstruckDetailsOrderMapper.getInwardTimeDetailsOrder(mapValue);
  1170. //将计时查询结果加入到计重查询结果中
  1171. for(Map<String, Object> mapListTimeOne:mapListTime)
  1172. { mapListTimeOne.put("capacityNumber",mapListTimeOne.remove("capacityNum"));
  1173. mapListWeight.add(mapListTimeOne);
  1174. }
  1175. //返回计重+计时计费详单查询结果
  1176. return mapListWeight;
  1177. }
  1178. @Override
  1179. public List<Map<String, Object>> getNoInwardDetails(Map<String, Object> mapValue) {
  1180. return bmstruckDetailsOrderMapper.getNoInwardDetails(mapValue);
  1181. }
  1182. @Override
  1183. public List<Map<String, Object>> getSteelTruckDetailsOrder(Map<String, Object> mapValue) {
  1184. return bmstruckDetailsOrderMapper.getSteelTruckDetailsOrder(mapValue);
  1185. }
  1186. @Override
  1187. public int newInwardSettle(List<Map<String,Object>> orderIds) {
  1188. int count = 0;
  1189. //遍历数组
  1190. for(Map<String,Object> orderIdMap:orderIds){
  1191. Integer orderId = DataChange.dataToBigDecimal(orderIdMap.get("orderId")).intValue();
  1192. //根据运输ID获取订单类型
  1193. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(new BigDecimal(orderId));
  1194. //根据订单类型调用不同的方法
  1195. //如果订单类型是11,
  1196. if(orderType.intValue() == 11){
  1197. List<BigDecimal> detailsIds = bmstruckDetailsOrderMapper.getDetailsIdByOrderId(orderId);
  1198. if(detailsIds.size() == 0){
  1199. omsFeign.closeInwardOrder(orderId);
  1200. count++;
  1201. }else{
  1202. for(int i=0;i<detailsIds.size();i++){
  1203. bmstruckDetailsOrderMapper.deleteByPrimaryKey(detailsIds.get(i));
  1204. omsFeign.closeInwardOrder(orderId);
  1205. count++;
  1206. }
  1207. }
  1208. }
  1209. if(orderType.intValue() == 10 || orderType.intValue() == 20){
  1210. //根据运输订单ID找寻计费详单ID
  1211. List<BigDecimal> detailsIds = bmstruckDetailsOrderMapper.getDetailsIdByOrderId(orderId);
  1212. for(BigDecimal detailsId:detailsIds){
  1213. //根据详单ID物理删除详单
  1214. bmstruckDetailsOrderMapper.deleteByPrimaryKey(detailsId);
  1215. count++;
  1216. }
  1217. inserInwardOrder(orderIdMap);
  1218. }
  1219. if(orderType.intValue() == 23 || orderType.intValue() == 24){
  1220. List<BigDecimal> detailsIds = bmstruckDetailsOrderMapper.getDetailsIdByOrderId(orderId);
  1221. for(BigDecimal detailsId:detailsIds){
  1222. //根据详单ID物理删除详单
  1223. bmstruckDetailsOrderMapper.deleteByPrimaryKey(detailsId);
  1224. count++;
  1225. }
  1226. inserInwardOrder(orderIdMap);
  1227. }
  1228. if(orderType.intValue() == 16 || orderType.intValue() == 15){
  1229. List<BigDecimal> detailsIds = bmstruckDetailsOrderMapper.getDetailsIdByOrderId(orderId);
  1230. for(BigDecimal detailsId:detailsIds){
  1231. //根据详单ID物理删除详单
  1232. bmstruckDetailsOrderMapper.deleteByPrimaryKey(detailsId);
  1233. count++;
  1234. }
  1235. inserInwardOrder(orderIdMap);
  1236. }
  1237. }
  1238. return count;
  1239. }
  1240. @Override
  1241. public int updateDetailsStatus(List<Integer> detailsOrderList) {
  1242. int i = 0;
  1243. for(Integer detailsId :detailsOrderList) {
  1244. if(detailsId == null) {
  1245. continue;
  1246. }
  1247. //BigDecimal detailId = DataChange.dataToBigDecimal(map.get("detailId"));
  1248. //BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
  1249. //bmstruckDetailsOrder.setDetailsId(detailId);
  1250. //bmstruckDetailsOrder.setWetherToStatement(new BigDecimal(1));
  1251. //i += bmstruckDetailsOrderMapper.updateByPrimaryKeySelective(bmstruckDetailsOrder);
  1252. try {
  1253. i += bmstruckDetailsOrderMapper.updateDetailsStatus(detailsId);
  1254. } catch (Exception e) {
  1255. e.printStackTrace();
  1256. }
  1257. /*BigDecimal priceId = omstruckOrderMapper.getPriceId(orderId);
  1258. omstruckOrderMapper.modifyOldTime(priceId,new Date());*/
  1259. }
  1260. return i;
  1261. }
  1262. @Override
  1263. public int getSaleOrderStatus(BigDecimal orderId) {
  1264. return bmstruckDetailsOrderMapper.getSaleOrderStatus(orderId);
  1265. }
  1266. @Override
  1267. public synchronized int insertPriceValue(List<Map<String, Object>> mapList) {
  1268. for (Map<String, Object> map : mapList) {
  1269. Integer placeId =(Integer) map.get("placeId");
  1270. //根据位置ID去查询是否有单价存在,如果有就跳过
  1271. BigDecimal priceIdInt = bmstruckDetailsOrderMapper.getPriceIdInt(placeId);
  1272. if (priceIdInt!=null&&priceIdInt.compareTo(BigDecimal.ZERO)!=0){
  1273. break;
  1274. }else {
  1275. ////新增单价
  1276. //BigDecimal orderId = DataChange.dataToBigDecimal(map.get("orderId"));
  1277. //BigDecimal omsTruckOrderPriceId = bmstruckDetailsOrderMapper.getOmsTruckOrderPriceId(orderId);
  1278. //Map<String,Object> map1=new HashMap<>();
  1279. //map1.put("orderId",orderId);
  1280. //map1.put("priceId",omsTruckOrderPriceId);
  1281. //try {
  1282. // amsFeign.copySteelPrice(map1);
  1283. //} catch (Exception e) {
  1284. // e.printStackTrace();
  1285. //}
  1286. //单价的主键
  1287. //map1.put("priceId",bmstruckDetailsOrderMapper.selectMaxIdNew());
  1288. //map1.put("priceValue",map.get("priceValue"));
  1289. //map1.put("placeId",placeId);
  1290. //bmstruckDetailsOrderMapper.insertPriceValue(map1);
  1291. }
  1292. }
  1293. return 0;
  1294. }
  1295. public int cancelMakeSure(List<Integer> detailsOrderList) {
  1296. int i = 0;
  1297. for(Integer detailsId :detailsOrderList) {
  1298. if(detailsId == null) {
  1299. continue;
  1300. }
  1301. //BigDecimal detailId = DataChange.dataToBigDecimal(map.get("detailId"));
  1302. //BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
  1303. //bmstruckDetailsOrder.setDetailsId(detailId);
  1304. //bmstruckDetailsOrder.setWetherToStatement(new BigDecimal(1));
  1305. //i += bmstruckDetailsOrderMapper.updateByPrimaryKeySelective(bmstruckDetailsOrder);
  1306. i += bmstruckDetailsOrderMapper.cancelMakeSure(detailsId);
  1307. /*BigDecimal priceId = omstruckOrderMapper.getPriceId(orderId);
  1308. omstruckOrderMapper.modifyOldTime(priceId,new Date());*/
  1309. }
  1310. return i;
  1311. }
  1312. @Override
  1313. public synchronized int updateDetailsDirect(Map<String, Object> mapValue) throws Exception {
  1314. List<BigDecimal> orderIds = (List<BigDecimal>) mapValue.get("orderList");
  1315. BigDecimal priceValue = DataChange.dataToBigDecimal(mapValue.get("detailAmount"));//以java变量名为准,这里是所填写的单价值
  1316. if(priceValue.intValue() < 0){
  1317. throw new Exception("单价不能小于等于0");
  1318. }
  1319. String detailRemark = mapValue.get("detailRemark").toString();
  1320. String userId = mapValue.get("userId").toString();
  1321. String userName = bmstruckDetailsOrderMapper.getUserNameByUserId(userId);
  1322. String url = mapValue.get("url").toString();
  1323. AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
  1324. BigDecimal priceId = amsContractTransportPriceMapper.selectMaxId();
  1325. amsContractTransportPrice.setPriceId(priceId);
  1326. amsContractTransportPrice.setPriceValue(priceValue);
  1327. amsContractTransportPrice.setPriceDate(new Date());
  1328. int result = 0;
  1329. for(int i=0;i<orderIds.size();i++){
  1330. BigDecimal orderId = DataChange.dataToBigDecimal(orderIds.get(i));
  1331. //校验
  1332. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
  1333. if(orderType.intValue() != 1){
  1334. throw new Exception("订单类型错误,不允许生成汽运计费详单");
  1335. }
  1336. //更新订单表单价
  1337. bmstruckDetailsOrderMapper.updateOrderPrice(orderId,priceId);
  1338. //更新车序号表单价
  1339. bmstruckDetailsOrderMapper.updateAsomPriceIdByOrderId(orderId,priceId);
  1340. saleLogUtil.logOrder(orderId,"直接修改单价",userName,SaleLogUtil.UPDATE);
  1341. //查询订单计量详情
  1342. List<Map<String,Object>> batchIdList = bmstruckDetailsOrderMapper.getWeightBatchIds(orderId);
  1343. for (Map<String, Object> map : batchIdList) {
  1344. if(null == map){
  1345. continue;
  1346. }
  1347. BigDecimal weightBatchId = DataChange.dataToBigDecimal(map.get("weightBatchId"));
  1348. //根据计量实绩查找批次ID
  1349. BigDecimal netWeight = DataChange.dataToBigDecimal(map.get("netWeight"));
  1350. if (netWeight == null) {
  1351. System.out.println("没有计量实绩,不生成结算数据:" + orderId);
  1352. continue;
  1353. }
  1354. // 得到计费公式
  1355. String formula_string = null;
  1356. if (orderType.intValue() >= 1 && orderType.intValue() <= 3) {
  1357. // 得到销售10km差距内的汽运计费公式
  1358. formula_string = bmstruckFormulaService.getTruckFormula(new BigDecimal(10));
  1359. // 替换采购汽运运计算公式
  1360. formula_string = formula_string.replace("运输单价",priceValue.toString())
  1361. .replace("物资净重",netWeight.toString());
  1362. }
  1363. String s = toSufExpr(formula_string);
  1364. BigDecimal detailsAmountOld = calSufExpr(s);
  1365. Double amount = detailsAmountOld.doubleValue();
  1366. BigDecimal detailsAmount = new BigDecimal(amount).setScale(2,RoundingMode.HALF_UP);
  1367. if(bmstruckDetailsOrderMapper.getIsHaveDetailsOrderByBatch(weightBatchId) > 0 ){
  1368. //获取详单ID
  1369. BigDecimal detailsId = bmstruckDetailsOrderMapper.getDetailsIdByBatchId(weightBatchId);
  1370. BmstruckDetailsOrder bmstruckDetailsOrder = bmstruckDetailsOrderMapper.selectByPrimaryKey(detailsId);
  1371. bmstruckDetailsOrder.setPriceId(priceId);
  1372. bmstruckDetailsOrder.setPriceValue(priceValue);
  1373. bmstruckDetailsOrder.setOrderId(orderId);
  1374. bmstruckDetailsOrder.setDetailsId(detailsId);
  1375. bmstruckDetailsOrder.setDetailsAmount(detailsAmount);
  1376. result += bmstruckDetailsOrderMapper.updateByPrimaryKeySelective(bmstruckDetailsOrder);
  1377. continue;
  1378. }
  1379. //计算总费用
  1380. //判断该计量实绩有没有结算数据
  1381. //否则,新增详单
  1382. try {
  1383. BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
  1384. bmstruckDetailsOrder.setWetherToStatement(new BigDecimal(0));
  1385. // 得到最大id
  1386. BigDecimal detailsId = selectMaxId();
  1387. String detailsNo = noUtil.setResultNo("QYXD", detailsId);
  1388. bmstruckDetailsOrder.setDetailsId(detailsId);
  1389. bmstruckDetailsOrder.setWeightBatchId(weightBatchId);
  1390. bmstruckDetailsOrder.setOrderId(orderId);
  1391. bmstruckDetailsOrder.setDetailsNo(detailsNo);
  1392. bmstruckDetailsOrder.setDetailsAmount(detailsAmount);
  1393. bmstruckDetailsOrder.setDetailsTime(new Date());
  1394. bmstruckDetailsOrder.setPriceValue(priceValue);//填写的单价
  1395. bmstruckDetailsOrder.setPhoto(url);//上传的凭证图片路径
  1396. bmstruckDetailsOrder.setRemark(detailRemark);//凭证备注
  1397. // 设置常规字段
  1398. bmstruckDetailsOrder.setInsertTime(new Date());
  1399. bmstruckDetailsOrder.setUpdateTime(new Date());
  1400. bmstruckDetailsOrder.setInsertUsername(userId);
  1401. bmstruckDetailsOrder.setUpdateUsername("admin");
  1402. bmstruckDetailsOrder.setInsertUpdateRemark("无");
  1403. result += bmstruckDetailsOrderMapper.insertSelective(bmstruckDetailsOrder);
  1404. }catch (Exception e){
  1405. //不打印给控制台(有可能是正常情况)
  1406. e.printStackTrace();
  1407. }
  1408. }
  1409. }
  1410. amsContractTransportPriceMapper.insertSelective(amsContractTransportPrice);
  1411. return result;
  1412. }
  1413. @Override
  1414. public int addTruckDetail(Map<String, Object> mapValue) throws Exception {
  1415. List<BigDecimal> orderIds = (List<BigDecimal>) mapValue.get("orderList");
  1416. BigDecimal detailsAmount = DataChange.dataToBigDecimal(mapValue.get("detailAmount"));
  1417. String detailRemark = mapValue.get("detailRemark").toString();
  1418. String userId = mapValue.get("userId").toString();
  1419. String urls = "" + mapValue.get("urls");
  1420. int result = 0;
  1421. for(int i=0;i<orderIds.size();i++){
  1422. BigDecimal orderId = DataChange.dataToBigDecimal(orderIds.get(i));
  1423. //校验
  1424. BigDecimal orderType = bmstruckDetailsOrderMapper.getOrderType(orderId);
  1425. if(orderType.intValue() != 1){
  1426. throw new Exception("订单类型错误,不允许生成汽运计费详单");
  1427. }
  1428. List<Map<String,Object>> weightTaskResultIdList = bmstruckDetailsOrderMapper.getSteelWeightTaskResultId(orderId);
  1429. if(weightTaskResultIdList.size()<=0){
  1430. throw new Exception("没有计量实绩,无法冲红");
  1431. }
  1432. //新增详单
  1433. try {
  1434. // 得到最大id
  1435. BigDecimal detailsId = selectMaxId();
  1436. BmstruckDetailsOrder bmstruckDetailsOrder = new BmstruckDetailsOrder();
  1437. bmstruckDetailsOrder.setWetherToStatement(new BigDecimal(0));
  1438. String detailsNo = noUtil.setResultNo("QYXD", detailsId);
  1439. bmstruckDetailsOrder.setWeightTaskResultId(DataChange.dataToBigDecimal(weightTaskResultIdList.get(0).get("weightTaskResultId")));
  1440. bmstruckDetailsOrder.setDetailsId(detailsId);
  1441. bmstruckDetailsOrder.setOrderId(orderId);
  1442. bmstruckDetailsOrder.setDetailsNo(detailsNo);
  1443. bmstruckDetailsOrder.setDetailsAmount(detailsAmount);
  1444. bmstruckDetailsOrder.setDetailsTime(new Date());
  1445. bmstruckDetailsOrder.setRemark(detailRemark);//凭证备注
  1446. bmstruckDetailsOrder.setPhoto(urls);//图片
  1447. // 设置常规字段
  1448. bmstruckDetailsOrder.setInsertTime(new Date());
  1449. bmstruckDetailsOrder.setUpdateTime(new Date());
  1450. bmstruckDetailsOrder.setInsertUsername(userId);
  1451. bmstruckDetailsOrder.setUpdateUsername("admin");
  1452. bmstruckDetailsOrder.setInsertUpdateRemark("无");
  1453. result += bmstruckDetailsOrderMapper.insertSelective(bmstruckDetailsOrder);
  1454. }catch (Exception e){
  1455. e.printStackTrace();
  1456. }
  1457. }
  1458. return result;
  1459. }
  1460. @Override
  1461. public int updateConsignee(Map<String, Object> map) throws Exception {
  1462. bmstruckDetailsOrderMapper.updateConsignee(map);
  1463. //记录日志
  1464. saleLogUtil.logOrder(map,"修改计费详单的收货客户",SaleLogUtil.UPDATE);
  1465. return 0;
  1466. }
  1467. }