BmstruckDetailsOrderServiceImpl.java 70 KB

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