AmsContractTruckPriceServiceImpl.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. package com.steerinfo.dil.service.impl;
  2. import com.steerinfo.dil.mapper.AmsContaactPriceMaterialMapper;
  3. import com.steerinfo.dil.mapper.AmsContractTruckPriceMapper;
  4. import com.steerinfo.dil.mapper.RmsReceivePlaceMapper;
  5. import com.steerinfo.dil.model.AmsContaactPriceMaterial;
  6. import com.steerinfo.dil.model.AmsContractTransportPrice;
  7. import com.steerinfo.dil.model.RmsReceivePlace;
  8. import com.steerinfo.dil.service.IAmsContractTruckPriceService;
  9. import com.steerinfo.dil.util.DataChange;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import java.math.BigDecimal;
  14. import java.util.Date;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.Stack;
  18. import java.util.regex.Matcher;
  19. import java.util.regex.Pattern;
  20. /**
  21. * AmsContractTransportPrice服务实现:
  22. * @author generator
  23. * @version 1.0-SNAPSHORT 2021-09-06 07:10
  24. * 类描述
  25. * 修订历史:
  26. * 日期:2021-09-06
  27. * 作者:generator
  28. * 参考:
  29. * 描述:AmsContractTransportPrice服务实现
  30. * @see null
  31. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  32. */
  33. @Service(value = "amsContractTruckPriceService")
  34. public class AmsContractTruckPriceServiceImpl implements IAmsContractTruckPriceService {
  35. @Autowired
  36. private AmsContractTruckPriceMapper amsContractTruckPriceMapper;
  37. @Autowired
  38. RmsReceivePlaceMapper rmsReceivePlaceMapper;
  39. @Autowired
  40. AmsContaactPriceMaterialMapper amsContaactPriceMaterialMapper;
  41. /**
  42. * 新增汽运单价
  43. * @Author zzd
  44. * @Date 2022/1/20 11:33
  45. * @param mapValue
  46. * @return
  47. **/
  48. @Transactional
  49. @Override
  50. public int addAmsContractTransportPrice(Map<String,Object> mapValue) {
  51. BigDecimal shipperId = DataChange.dataToBigDecimal(mapValue.get("shipperId"));
  52. BigDecimal carrierId = DataChange.dataToBigDecimal(mapValue.get("carrierId"));
  53. BigDecimal addressId = DataChange.dataToBigDecimal(mapValue.get("addressId"));
  54. BigDecimal lineId = DataChange.dataToBigDecimal(mapValue.get("lineId"));
  55. BigDecimal capacityTypeId = DataChange.dataToBigDecimal(mapValue.get("capacityTypeId"));
  56. BigDecimal formulaId = DataChange.dataToBigDecimal(mapValue.get("formulaId"));
  57. BigDecimal priceValue = DataChange.dataToBigDecimal(mapValue.get("priceValue"));
  58. Date priceDate = new Date((Long)mapValue.get("priceDate"));
  59. BigDecimal type = DataChange.dataToBigDecimal(mapValue.get("type"));
  60. BigDecimal oilpriceBase = DataChange.dataToBigDecimal(mapValue.get("oilpriceBase"));
  61. BigDecimal oilTypeId = DataChange.dataToBigDecimal(mapValue.get("oilTypeId"));
  62. BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(mapValue.get("oilpriceChangeThreshold"));
  63. AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
  64. String place = (String) mapValue.get("place");
  65. if (place != null && place.length() != 0) {
  66. BigDecimal placeId = rmsReceivePlaceMapper.getPlaceId(mapValue);
  67. if (placeId != null) {
  68. amsContractTransportPrice.setPlaceId(placeId);
  69. }
  70. else {
  71. RmsReceivePlace rmsReceivePlace = new RmsReceivePlace();
  72. rmsReceivePlace.setAddressId(addressId);
  73. rmsReceivePlace.setAddressDeliveryAddress(place);
  74. rmsReceivePlace.setPlaceId(rmsReceivePlaceMapper.selectMaxId());
  75. }
  76. }
  77. amsContractTransportPrice.setType(type);
  78. amsContractTransportPrice.setOilpriceBase(oilpriceBase);
  79. amsContractTransportPrice.setShipperId(shipperId);
  80. amsContractTransportPrice.setOilpriceChangeThreshold(oilpriceChangeThreshold);
  81. amsContractTransportPrice.setOilTypeId(oilTypeId);
  82. amsContractTransportPrice.setPriceValue(priceValue);
  83. amsContractTransportPrice.setPriceDate(priceDate);
  84. amsContractTransportPrice.setCapacityTypeId(capacityTypeId);
  85. amsContractTransportPrice.setCargonameId(formulaId);
  86. amsContractTransportPrice.setCarrierId(carrierId);
  87. //生成主键id
  88. amsContractTransportPrice.setPriceId(amsContractTruckPriceMapper.selectMaxId());
  89. if(lineId == null){
  90. //计算并插入吨公里
  91. BigDecimal priceTonKilometer = calculationPriceTonKilometer(lineId, priceValue);
  92. amsContractTransportPrice.setPriceTonKilometer(priceTonKilometer);
  93. }
  94. amsContractTransportPrice.setType(new BigDecimal(1));
  95. amsContractTransportPrice.setInsertUsername("admin");
  96. amsContractTransportPrice.setInsertTime(new Date());
  97. amsContractTransportPrice.setUpdateUsername("admin");
  98. amsContractTransportPrice.setUpdateTime(new Date());
  99. amsContractTransportPrice.setInsertUpdateRemark("无");
  100. amsContractTransportPrice.setDeleted(new BigDecimal(0));
  101. return amsContractTruckPriceMapper.insertSelective(amsContractTransportPrice);
  102. }
  103. //计算吨公里值
  104. public BigDecimal calculationPriceTonKilometer(BigDecimal lineId,BigDecimal priceValue){
  105. //查询参考运距
  106. BigDecimal linePathLength = amsContractTruckPriceMapper.getLinePathLength(lineId);
  107. //计算吨公里 吨公里(元/吨.km) = 运价(元/吨)/ 参考运距(公里),保留4位小数
  108. BigDecimal priceTonKilometer = priceValue.divide(linePathLength, 4, BigDecimal.ROUND_HALF_UP);
  109. return priceTonKilometer;
  110. }
  111. @Override
  112. public List<Map<String, Object>> getAmsContractTransportPrice(Map<String, Object> map) {
  113. return amsContractTruckPriceMapper.getAmsContractTransportPrice(map);
  114. }
  115. @Override
  116. public int deleteAmsContractTransportPrice(BigDecimal priceId) {
  117. AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
  118. amsContractTransportPrice.setId(priceId);
  119. amsContractTransportPrice.setDeleted(new BigDecimal(1));
  120. return amsContractTruckPriceMapper.updateByPrimaryKeySelective(amsContractTransportPrice);
  121. }
  122. @Override
  123. public List<Map<String, Object>> getCarrierName() {
  124. return amsContractTruckPriceMapper.getCarrierName();
  125. }
  126. @Override
  127. public List<Map<String, Object>> getLineNo() {
  128. return amsContractTruckPriceMapper.getLineNo();
  129. }
  130. @Override
  131. public List<Map<String, Object>> getCapacityNumber() {
  132. return amsContractTruckPriceMapper.getCapacityNumber();
  133. }
  134. @Override
  135. public List<Map<String, Object>> getAddressDeliveryAddress(Map<String,Object> map) {
  136. return amsContractTruckPriceMapper.getAddressDeliveryAddress(map);
  137. }
  138. @Override
  139. public List<Map<String, Object>> selectByPriceId(BigDecimal priceId) {
  140. return amsContractTruckPriceMapper.selectByPriceId(priceId);
  141. }
  142. @Override
  143. public int updateAmsContractTransportPrice(AmsContractTransportPrice amsContractTransportPrice) {
  144. //获取路线Id和运价
  145. BigDecimal lineId = amsContractTransportPrice.getLineId();
  146. BigDecimal priceValue = amsContractTransportPrice.getPriceValue();
  147. //如果传入路线则修改运价
  148. if(lineId != null){
  149. BigDecimal priceId = amsContractTransportPrice.getPriceId();
  150. //获取未修改前的汽运单价信息
  151. AmsContractTransportPrice amsContractTransportPrice1 = amsContractTruckPriceMapper.selectByPrimaryKey(priceId);
  152. //若运价修改了
  153. if(!amsContractTransportPrice.getPriceValue().equals(amsContractTransportPrice1.getPriceValue())){
  154. //计算并插入吨公里
  155. BigDecimal priceTonKilometer = calculationPriceTonKilometer(lineId, priceValue);
  156. amsContractTransportPrice.setPriceTonKilometer(priceTonKilometer);
  157. }
  158. }
  159. amsContractTransportPrice.setUpdateTime(new Date());
  160. return amsContractTruckPriceMapper.updateByPrimaryKeySelective(amsContractTransportPrice);
  161. }
  162. @Override
  163. public List<Map<String, Object>> getOriginAndNowOilPrice() {
  164. return amsContractTruckPriceMapper.getOriginAndNowOilPrice();
  165. }
  166. @Override
  167. public List<Map<String, Object>> getCargoName() {
  168. return amsContractTruckPriceMapper.getCargoName();
  169. }
  170. @Override
  171. public List<Map<String, Object>> getOilTypeName() {
  172. return amsContractTruckPriceMapper.getOilTypeName();
  173. }
  174. /**
  175. * 批量修改运输单价
  176. * @return
  177. */
  178. @Override
  179. @Transactional
  180. public int batchUpdateTransportPriceByOilPrice(Map<String,Object> map) {
  181. //运输单价变化的条数
  182. int i = 0;
  183. //获取油品名称ID
  184. BigDecimal oilTypeId = DataChange.dataToBigDecimal(map.get("oilTypeId"));
  185. //获取预执行油价
  186. BigDecimal newOilPrice = DataChange.dataToBigDecimal(map.get("newOilPrice"));
  187. //根据油品名称ID和非历史油价筛选出符合条件的运价合集
  188. List<Map<String, Object>> PriceValueList = amsContractTruckPriceMapper.getPriceValueList(oilTypeId);
  189. for (Map<String, Object> stringObjectMap : PriceValueList) {
  190. //获取该条单价的原油价基准
  191. BigDecimal oilpriceBase = DataChange.dataToBigDecimal(stringObjectMap.get("oilpriceBase"));
  192. //获取该条单价的油价变化率阈值
  193. BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(stringObjectMap.get("oilpriceChangeThreshold"));
  194. //计算油价变化率,公式:n=(当前油价-基数)÷基数×100%
  195. BigDecimal n = (newOilPrice.subtract(oilpriceBase)).divide(oilpriceBase,4,4);
  196. //若油价变化率超过该条单价的油价变化率阈值,修改原单价为历史数据,新增一条单价
  197. if(n.abs().doubleValue()>oilpriceChangeThreshold.doubleValue()){
  198. i+=addANewAmsContractTransportPrice(stringObjectMap,n,newOilPrice);
  199. }
  200. }
  201. return i;
  202. // if(updateOilPrice>0.05||updateOilPrice<-0.05) {
  203. // //逐条修改吨公里数
  204. // for (Map<String, Object> stringObjectMap : priceValueAndPriceTonKilometer) {
  205. // //主键Id
  206. // BigDecimal priceId = (BigDecimal) stringObjectMap.get("priceId");
  207. // //原运价
  208. // BigDecimal priceValue = (BigDecimal) stringObjectMap.get("priceValue");
  209. // //吨公里数
  210. // BigDecimal priceTonKilometer = (BigDecimal) stringObjectMap.get("priceTonKilometer");
  211. // //参考距离,四舍五入,保留两位小数
  212. // BigDecimal distance;
  213. // if (priceTonKilometer.doubleValue() != 0) {
  214. // distance = priceValue.divide(priceTonKilometer, 2, BigDecimal.ROUND_HALF_UP);
  215. // //现运价
  216. // Double nowPriceValue = priceValue.doubleValue() * 0.65 + priceValue.doubleValue() * 0.35 * (1 + updateOilPrice);
  217. // BigDecimal nowPriceValue1 = new BigDecimal(nowPriceValue);
  218. // //新吨公里数
  219. // BigDecimal newPriceTonKilometer = nowPriceValue1.divide(distance, 4, BigDecimal.ROUND_HALF_UP);
  220. // //通过主键修改一条吨公里数
  221. // amsContractTruckPriceMapper.updatePriceTonKilometer(priceId, newPriceTonKilometer);
  222. // }
  223. // return amsContractTruckPriceMapper.batchUpdateTransportPriceByOilPrice(updateOilPrice);
  224. // }
  225. // }
  226. }
  227. /**
  228. * 油价变化率超过该条单价的油价变化率阈值,修改原单价为历史数据,新增一条执行单价
  229. * @param stringObjectMap
  230. * @param n
  231. * @param newOilPrice
  232. * @return
  233. * @throws Exception
  234. */
  235. @Transactional
  236. public int addANewAmsContractTransportPrice(Map<String, Object> stringObjectMap,BigDecimal n,BigDecimal newOilPrice){
  237. //定义将要改变的执行价
  238. BigDecimal nowPriceValue;
  239. //存储原运输单价实绩对象
  240. AmsContractTransportPrice oldAmsContractTransportPrice = new AmsContractTransportPrice();
  241. //查询货物名称
  242. // String cargonameValue = amsContractTruckPriceMapper.getCargonameValue(new BigDecimal(stringObjectMap.get("cargonameId").toString()));
  243. //获取原主键Id
  244. BigDecimal priceId = (BigDecimal) stringObjectMap.get("priceId");
  245. //修改原单价为历史数据
  246. oldAmsContractTransportPrice.setPriceId(priceId);
  247. oldAmsContractTransportPrice.setDeleted(new BigDecimal(1));
  248. amsContractTruckPriceMapper.updateByPrimaryKeySelective(oldAmsContractTransportPrice);
  249. //获取原单价的所有数据
  250. AmsContractTransportPrice amsContractTransportPrice = amsContractTruckPriceMapper.selectByPrimaryKey(priceId);
  251. //生成主键
  252. BigDecimal i = amsContractTruckPriceMapper.selectMaxId();
  253. amsContractTransportPrice.setPriceId(i);
  254. //生成执行日期
  255. amsContractTransportPrice.setPriceDate(new Date());
  256. //常规字段
  257. amsContractTransportPrice.setInsertUsername("admin");
  258. amsContractTransportPrice.setInsertTime(new Date());
  259. amsContractTransportPrice.setUpdateUsername("admin");
  260. amsContractTransportPrice.setUpdateTime(new Date());
  261. amsContractTransportPrice.setInsertUpdateRemark("无");
  262. //修改现单价为执行数据
  263. amsContractTransportPrice.setDeleted(new BigDecimal(0));
  264. // //若货物名称为焦炭
  265. // if(cargonameValue.equals("焦炭")){
  266. // //现执行价=((63.00+63.00*0.13*n)+(66.50+66.50*0.3*n)+40.00)
  267. // //调用焦炭运价计算公式计算现执行价
  268. // try {
  269. // nowPriceValue = UpdateCokePriceValueByOilPrice(n.toString());
  270. // //保留两位小数
  271. // nowPriceValue = nowPriceValue.divide(new BigDecimal(1),2,4);
  272. // //调整焦炭运价
  273. // amsContractTransportPrice.setPriceValue(nowPriceValue);
  274. // //修改基准油价
  275. // amsContractTransportPrice.setOilpriceBase(newOilPrice);
  276. // } catch (Exception e) {
  277. // e.printStackTrace();
  278. // }
  279. // }
  280. // if(cargonameValue.equals("纯苯")){
  281. // //现执行价=(中标价*0.7)+(中标价*0.3)*(1+n)
  282. // //调用纯苯运价计算公式计算现执行价
  283. // try {
  284. // nowPriceValue = UpdatePureBenzenePriceValueByOilPrice(n.toString(),amsContractTransportPrice.getPriceValue());
  285. // //保留两位小数
  286. // nowPriceValue = nowPriceValue.divide(new BigDecimal(1),2,4);
  287. // //调整纯苯运价
  288. // amsContractTransportPrice.setPriceValue(nowPriceValue);
  289. // //修改基准油价
  290. // amsContractTransportPrice.setOilpriceBase(newOilPrice);
  291. // } catch (Exception e) {
  292. // e.printStackTrace();
  293. // }
  294. // }
  295. // 得到油价联动公式id
  296. BigDecimal formulaId = DataChange.dataToBigDecimal(stringObjectMap.get("cargonameId"));
  297. amsContractTransportPrice.setCargonameId(formulaId);
  298. try {
  299. nowPriceValue = UpdatePureBenzenePriceValueByOilPrice(n.toString(),amsContractTransportPrice.getPriceValue(),formulaId);
  300. //保留两位小数
  301. nowPriceValue = nowPriceValue.divide(new BigDecimal(1),2,4);
  302. //调整纯苯运价
  303. amsContractTransportPrice.setPriceValue(nowPriceValue);
  304. //修改基准油价
  305. amsContractTransportPrice.setOilpriceBase(newOilPrice);
  306. } catch (Exception e) {
  307. e.printStackTrace();
  308. }
  309. //新增数据
  310. int insert = amsContractTruckPriceMapper.insert(amsContractTransportPrice);
  311. return insert;
  312. }
  313. /**
  314. * 替换焦炭运价公式并进行计算
  315. * @param n
  316. * @return
  317. * @throws Exception
  318. */
  319. public BigDecimal UpdateCokePriceValueByOilPrice(String n) throws Exception {
  320. // 得到运算公式
  321. String formula_string = null;
  322. // 得到焦炭运价计算公式
  323. formula_string = amsContractTruckPriceMapper.getTruckFormula(new BigDecimal(12));
  324. // 替换焦炭运价计算公式
  325. formula_string = formula_string.replace("油价变动率",n);
  326. String s = toSufExpr(formula_string);
  327. return calSufExpr(s);
  328. }
  329. /**
  330. * 替换运价公式并进行计算
  331. * @param n
  332. * @return
  333. * @throws Exception
  334. */
  335. public BigDecimal UpdatePureBenzenePriceValueByOilPrice(String n,BigDecimal priceValue,BigDecimal formulaId) throws Exception {
  336. // 得到运算公式
  337. String formula_string;
  338. // 得到运价计算公式
  339. formula_string = amsContractTruckPriceMapper.getTruckFormula(formulaId);
  340. if (formula_string.contains("中标价") && formula_string.contains("油价变动率")) {
  341. // 替换纯苯运价计算公式
  342. formula_string = formula_string.replace("中标价", priceValue.toString())
  343. .replace("油价变动率", n);
  344. }
  345. else {
  346. // 替换焦炭
  347. formula_string = formula_string.replace("油价变动率",n);
  348. }
  349. String s = toSufExpr(formula_string);
  350. return calSufExpr(s);
  351. }
  352. /**
  353. * 中缀转换后缀表达式
  354. */
  355. public String toSufExpr(String s) {
  356. StringBuffer sufExpr = new StringBuffer();
  357. Stack<String> stack = new Stack<>();
  358. //压入空方便判断
  359. stack.push(null);
  360. Pattern pattern = Pattern.compile("\\(int\\)|(?<!\\d|[)])-?\\d+(\\.\\d+)?|!=|>=|<=|==|[+\\-*/%()><=|]");
  361. Matcher matcher = pattern.matcher(s);
  362. while (matcher.find()) {
  363. String group = matcher.group();
  364. if (group.matches("!=|>=|<=|==|[+\\-*/%()><=|]|\\(int\\)")) {//是运算符
  365. if (group.equals("(")) {//之间压栈
  366. stack.push(group);
  367. } else if (group.equals(")")) {//等于右括号,一直弹栈,直到遇到左括号
  368. String pop = null;
  369. while (!(pop = stack.pop()).equals("(")) {//遍历循环至左括号
  370. sufExpr.append(pop + " ");
  371. }
  372. } else {//是运算符:加减乘除强转,根据优先级压栈
  373. while (getPriority(group) <= getPriority(stack.peek())) {
  374. String pop = stack.pop();
  375. System.out.println(pop);
  376. System.out.println(sufExpr);
  377. if(pop!=null&&!pop.equals("|")){
  378. sufExpr.append(pop + " ");
  379. }
  380. }
  381. stack.push(group);
  382. }
  383. } else {//是数字
  384. sufExpr.append(group + " ");
  385. }
  386. }
  387. String pop = null;
  388. while (null != (pop = stack.pop())) {
  389. sufExpr.append(pop + " ");
  390. }
  391. return sufExpr.toString();
  392. }
  393. /**
  394. * 设置出栈优先级,(:优先级最低,表示只有遇到)才能出栈
  395. * 当栈顶遇到优先级比自己小或等于的弹栈
  396. */
  397. public Integer getPriority(String c) {
  398. if (c == null) {
  399. return 0;
  400. }
  401. switch (c) {
  402. case "(":
  403. return 1;
  404. case "+":
  405. case "-":
  406. return 2;
  407. case "*":
  408. case "/":
  409. case "%":
  410. return 3;
  411. case ">":
  412. case "<":
  413. case ">=":
  414. case "<=":
  415. case "!=":
  416. case "==":
  417. return 4;
  418. case "|":
  419. return 5;
  420. case "=":
  421. return 6;
  422. case "(int)":
  423. return 7;
  424. }
  425. return 0;
  426. }
  427. /**
  428. * 计算值
  429. */
  430. public BigDecimal cal(BigDecimal a1, BigDecimal a2, String operator) throws Exception {
  431. switch (operator){
  432. case "+":return a1.add(a2);
  433. case "-":return a1.subtract(a2);
  434. case "*":return a1.multiply(a2);
  435. case "/":return a1.divide(a2,3,BigDecimal.ROUND_CEILING);
  436. case "%":return a1.divideAndRemainder(a2)[1];
  437. default:
  438. break;
  439. }
  440. throw new Exception("非法运算符");
  441. }
  442. public Boolean calBoolean(BigDecimal a1, BigDecimal a2, String operator) throws Exception {
  443. switch (operator){
  444. case ">":return a1.compareTo(a2) == 1;
  445. case "<":return a1.compareTo(a2) == -1;
  446. case ">=":return a1.compareTo(a2) > -1;
  447. case "<=":return a1.compareTo(a2) < 1;
  448. case "!=":return a1.compareTo(a2) != 0;
  449. case "==":return a1.compareTo(a2) == 0;
  450. default:
  451. break;
  452. }
  453. throw new Exception("非法运算符");
  454. }
  455. /**
  456. * 计算后缀表达式
  457. */
  458. public BigDecimal calSufExpr(String sufExpr) throws Exception {
  459. Stack<BigDecimal> stack = new Stack<>();
  460. Pattern pattern=Pattern.compile("\\(int\\)|-?\\d+(\\.\\d+)?|!=|>=|<=|==|[+\\-*/%><=]");//提取运算符和数字
  461. Matcher matcher = pattern.matcher(sufExpr);
  462. BigDecimal result=new BigDecimal("0.0");
  463. while (matcher.find()){
  464. String group = matcher.group();
  465. if(group.matches("[+\\-*/%]")){
  466. BigDecimal a1 =stack.pop();
  467. BigDecimal a2 =stack.pop();
  468. result = cal(a2, a1, group);
  469. stack.push(result);
  470. }
  471. else if(group.equals("(int)")){
  472. BigDecimal pop = stack.pop();
  473. BigDecimal bigDecimal = pop.setScale(0, BigDecimal.ROUND_DOWN);
  474. stack.push(bigDecimal);
  475. }
  476. else if(group.matches("!=|>=|<=|==|[><]")){
  477. BigDecimal a1 =stack.pop();
  478. BigDecimal a2 =stack.pop();
  479. stack.push(calBoolean(a2,a1,group)?new BigDecimal(1):new BigDecimal(0));
  480. }
  481. else if(group.equals("=")){
  482. BigDecimal a1 =stack.pop();
  483. BigDecimal a2 =stack.pop();
  484. if (a2.compareTo(new BigDecimal(1))==0) {
  485. stack.push(a1);
  486. }
  487. }
  488. else {//为数字直接压栈
  489. stack.push(new BigDecimal(group));
  490. }
  491. }
  492. return result;
  493. }
  494. /**
  495. * 边输边查具体地址
  496. * @param map
  497. * @return
  498. */
  499. @Override
  500. public List<Map<String, Object>> getRealAddressByLike(Map<String, Object> map) {
  501. return amsContractTruckPriceMapper.getRealAddressByLike(map);
  502. }
  503. @Override
  504. public int insertInwardPrice(Map<String, Object> mapValue) {
  505. int i = 0;
  506. BigDecimal capacityTypeId = DataChange.dataToBigDecimal(mapValue.get("capacityTypeId"));
  507. BigDecimal lineId = DataChange.dataToBigDecimal(mapValue.get("rangeId"));
  508. BigDecimal formulaId = DataChange.dataToBigDecimal(mapValue.get("formulaId"));
  509. BigDecimal priceValue = DataChange.dataToBigDecimal(mapValue.get("priceValue"));
  510. Date priceDate = new Date((Long)mapValue.get("priceDate"));
  511. BigDecimal type = DataChange.dataToBigDecimal(mapValue.get("type"));
  512. BigDecimal oilpriceBase = DataChange.dataToBigDecimal(mapValue.get("oilpriceBase"));
  513. BigDecimal oilTypeId = DataChange.dataToBigDecimal(mapValue.get("oilTypeId"));
  514. BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(mapValue.get("oilpriceChangeThreshold"));
  515. List<Map<String,Object>>mapList = (List<Map<String, Object>>) mapValue.get("mapList");
  516. AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
  517. amsContractTransportPrice.setType(type);
  518. amsContractTransportPrice.setOilpriceBase(oilpriceBase);
  519. //承运起止点ID
  520. amsContractTransportPrice.setLineId(lineId);
  521. amsContractTransportPrice.setOilpriceChangeThreshold(oilpriceChangeThreshold);
  522. amsContractTransportPrice.setOilTypeId(oilTypeId);
  523. amsContractTransportPrice.setPriceValue(priceValue);
  524. amsContractTransportPrice.setPriceDate(priceDate);
  525. amsContractTransportPrice.setCapacityTypeId(capacityTypeId);
  526. amsContractTransportPrice.setCargonameId(formulaId);
  527. //生成主键id
  528. amsContractTransportPrice.setPriceId(amsContractTruckPriceMapper.selectMaxId());
  529. amsContractTransportPrice.setInsertUsername("admin");
  530. amsContractTransportPrice.setInsertTime(new Date());
  531. amsContractTransportPrice.setUpdateUsername("admin");
  532. amsContractTransportPrice.setUpdateTime(new Date());
  533. amsContractTransportPrice.setInsertUpdateRemark("无");
  534. amsContractTransportPrice.setDeleted(new BigDecimal(0));
  535. i = amsContractTruckPriceMapper.insertSelective(amsContractTransportPrice);
  536. for (Map<String,Object>map:mapList
  537. ) {
  538. map.get("materialId");
  539. AmsContaactPriceMaterial amsContaactPriceMaterial = new AmsContaactPriceMaterial();
  540. //设置最大主键ID
  541. amsContaactPriceMaterial.setId(amsContractTruckPriceMapper.selectPriceMaterialMaxId());
  542. amsContaactPriceMaterial.setMaterialId(DataChange.dataToBigDecimal(map.get("materialId")));
  543. amsContaactPriceMaterial.setPriceId(amsContractTransportPrice.getPriceId());
  544. i = amsContaactPriceMaterialMapper.insertSelective(amsContaactPriceMaterial);
  545. }
  546. return i;
  547. }
  548. @Override
  549. public List<Map<String, Object>> getInwardContractPrice(Map<String, Object> mapValue) {
  550. List<Map<String,Object>>mapList = amsContractTruckPriceMapper.getInwardContractPrice(mapValue);
  551. for (Map<String,Object>map:mapList
  552. ) {
  553. List<Map<String,Object>> materialList = amsContaactPriceMaterialMapper.getMaterialName(DataChange.dataToBigDecimal(map.get("priceId")));
  554. String materialNames = "";
  555. int i = 1;
  556. for (Map<String,Object>materialMap:materialList
  557. ) {
  558. if(i==materialList.size()){
  559. materialNames = materialNames + materialMap.get("materialName") ;
  560. }
  561. else{
  562. materialNames = materialNames + materialMap.get("materialName") + "、";
  563. }
  564. i++;
  565. }
  566. map.put("materialNames",materialNames);
  567. if(((BigDecimal)map.get("type")).intValue() == 2){
  568. map.put("type","元/吨");
  569. }else if(((BigDecimal)map.get("type")).intValue() == 5){
  570. map.put("type","元/小时");
  571. }else if(((BigDecimal)map.get("type")).intValue() == 6){
  572. map.put("type","元/趟");
  573. }
  574. }
  575. return mapList;
  576. }
  577. @Override
  578. public List<Map<String, Object>> selectInwardPrice(Map<String, Object> mapvalue) {
  579. return amsContractTruckPriceMapper.selectInwardPrice(mapvalue);
  580. }
  581. }