AmsContractTruckPriceServiceImpl.java 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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.RmsLineNodePointMapper;
  5. import com.steerinfo.dil.mapper.RmsReceivePlaceMapper;
  6. import com.steerinfo.dil.model.AmsContaactPriceMaterial;
  7. import com.steerinfo.dil.model.AmsContractTransportPrice;
  8. import com.steerinfo.dil.model.RmsLineNodePoint;
  9. import com.steerinfo.dil.model.RmsReceivePlace;
  10. import com.steerinfo.dil.service.IAmsContractTruckPriceService;
  11. import com.steerinfo.dil.util.DataChange;
  12. import org.apache.commons.lang.math.NumberUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import java.lang.reflect.Array;
  17. import java.math.BigDecimal;
  18. import java.text.ParseException;
  19. import java.text.SimpleDateFormat;
  20. import java.util.*;
  21. import java.util.regex.Matcher;
  22. import java.util.regex.Pattern;
  23. /**
  24. * AmsContractTransportPrice服务实现:
  25. * @author generator
  26. * @version 1.0-SNAPSHORT 2021-09-06 07:10
  27. * 类描述
  28. * 修订历史:
  29. * 日期:2021-09-06
  30. * 作者:generator
  31. * 参考:
  32. * 描述:AmsContractTransportPrice服务实现
  33. * @see null
  34. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  35. */
  36. @Service(value = "amsContractTruckPriceService")
  37. public class AmsContractTruckPriceServiceImpl implements IAmsContractTruckPriceService {
  38. @Autowired
  39. private AmsContractTruckPriceMapper amsContractTruckPriceMapper;
  40. @Autowired
  41. RmsReceivePlaceMapper rmsReceivePlaceMapper;
  42. @Autowired
  43. AmsContaactPriceMaterialMapper amsContaactPriceMaterialMapper;
  44. //@Autowired
  45. //private RmsLineNodePoint rmsLineNodePoint;
  46. @Autowired
  47. private RmsLineNodePointMapper rmsLineNodePointMapper;
  48. /**
  49. * 新增汽运单价
  50. * @Author zzd
  51. * @Date 2022/1/20 11:33
  52. * @param mapValue
  53. * @return
  54. **/
  55. @Transactional
  56. @Override
  57. public int addAmsContractTransportPrice(Map<String,Object> mapValue) {
  58. BigDecimal shipperId = DataChange.dataToBigDecimal(mapValue.get("shipperId"));
  59. BigDecimal carrierId = DataChange.dataToBigDecimal(mapValue.get("carrierId"));
  60. BigDecimal addressId = DataChange.dataToBigDecimal(mapValue.get("addressId"));
  61. BigDecimal lineId = DataChange.dataToBigDecimal(mapValue.get("lineId"));
  62. BigDecimal capacityTypeId = DataChange.dataToBigDecimal(mapValue.get("capacityTypeId"));
  63. BigDecimal formulaId = DataChange.dataToBigDecimal(mapValue.get("formulaId"));
  64. BigDecimal priceValue = DataChange.dataToBigDecimal(mapValue.get("priceValue"));
  65. Date priceDate = new Date((Long)mapValue.get("priceDate"));
  66. BigDecimal type = DataChange.dataToBigDecimal(mapValue.get("type"));
  67. BigDecimal oilpriceBase = DataChange.dataToBigDecimal(mapValue.get("oilpriceBase"));
  68. BigDecimal oilTypeId = DataChange.dataToBigDecimal(mapValue.get("oilTypeId"));
  69. BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(mapValue.get("oilpriceChangeThreshold"));
  70. AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
  71. String place = (String) mapValue.get("place");
  72. if (place != null && place.length() != 0) {
  73. BigDecimal placeId = rmsReceivePlaceMapper.getPlaceId(mapValue);
  74. if (placeId != null) {
  75. amsContractTransportPrice.setPlaceId(placeId);
  76. }
  77. else {
  78. RmsReceivePlace rmsReceivePlace = new RmsReceivePlace();
  79. rmsReceivePlace.setAddressId(addressId);
  80. rmsReceivePlace.setAddressDeliveryAddress(place);
  81. rmsReceivePlace.setPlaceId(rmsReceivePlaceMapper.selectMaxId());
  82. }
  83. }
  84. amsContractTransportPrice.setType(type);
  85. amsContractTransportPrice.setOilpriceBase(oilpriceBase);
  86. amsContractTransportPrice.setShipperId(shipperId);
  87. amsContractTransportPrice.setOilpriceChangeThreshold(oilpriceChangeThreshold);
  88. amsContractTransportPrice.setOilTypeId(oilTypeId);
  89. amsContractTransportPrice.setPriceValue(priceValue);
  90. amsContractTransportPrice.setPriceDate(priceDate);
  91. amsContractTransportPrice.setCapacityTypeId(capacityTypeId);
  92. amsContractTransportPrice.setCargonameId(formulaId);
  93. amsContractTransportPrice.setCarrierId(carrierId);
  94. //生成主键id
  95. amsContractTransportPrice.setPriceId(amsContractTruckPriceMapper.selectMaxId());
  96. if(lineId == null){
  97. //计算并插入吨公里
  98. BigDecimal priceTonKilometer = calculationPriceTonKilometer(lineId, priceValue);
  99. amsContractTransportPrice.setPriceTonKilometer(priceTonKilometer);
  100. }
  101. amsContractTransportPrice.setType(new BigDecimal(1));
  102. amsContractTransportPrice.setInsertUsername("admin");
  103. amsContractTransportPrice.setInsertTime(new Date());
  104. amsContractTransportPrice.setUpdateUsername("admin");
  105. amsContractTransportPrice.setUpdateTime(new Date());
  106. amsContractTransportPrice.setInsertUpdateRemark("无");
  107. amsContractTransportPrice.setDeleted(new BigDecimal(0));
  108. return amsContractTruckPriceMapper.insertSelective(amsContractTransportPrice);
  109. }
  110. //计算吨公里值
  111. public BigDecimal calculationPriceTonKilometer(BigDecimal lineId,BigDecimal priceValue){
  112. //查询参考运距
  113. BigDecimal linePathLength = amsContractTruckPriceMapper.getLinePathLength(lineId);
  114. //计算吨公里 吨公里(元/吨.km) = 运价(元/吨)/ 参考运距(公里),保留4位小数
  115. BigDecimal priceTonKilometer = priceValue.divide(linePathLength, 4, BigDecimal.ROUND_HALF_UP);
  116. return priceTonKilometer;
  117. }
  118. @Override
  119. public List<Map<String, Object>> getAmsContractTransportPrice(Map<String, Object> map) {
  120. return amsContractTruckPriceMapper.getAmsContractTransportPrice(map);
  121. }
  122. @Override
  123. public int deleteAmsContractTransportPrice(BigDecimal priceId) {
  124. AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
  125. amsContractTransportPrice.setId(priceId);
  126. amsContractTransportPrice.setDeleted(new BigDecimal(1));
  127. return amsContractTruckPriceMapper.updateByPrimaryKeySelective(amsContractTransportPrice);
  128. }
  129. @Override
  130. public List<Map<String, Object>> getCarrierName() {
  131. return amsContractTruckPriceMapper.getCarrierName();
  132. }
  133. @Override
  134. public List<Map<String, Object>> getLineNo() {
  135. return amsContractTruckPriceMapper.getLineNo();
  136. }
  137. @Override
  138. public List<Map<String, Object>> getCapacityNumber() {
  139. return amsContractTruckPriceMapper.getCapacityNumber();
  140. }
  141. @Override
  142. public List<Map<String, Object>> getAddressDeliveryAddress(Map<String,Object> map) {
  143. return amsContractTruckPriceMapper.getAddressDeliveryAddress(map);
  144. }
  145. @Override
  146. public List<Map<String, Object>> selectByPriceId(BigDecimal priceId) {
  147. return amsContractTruckPriceMapper.selectByPriceId(priceId);
  148. }
  149. @Override
  150. public int updateAmsContractTransportPrice(AmsContractTransportPrice amsContractTransportPrice) {
  151. //获取路线Id和运价
  152. BigDecimal lineId = amsContractTransportPrice.getLineId();
  153. BigDecimal priceValue = amsContractTransportPrice.getPriceValue();
  154. //如果传入路线则修改运价
  155. if(lineId != null){
  156. BigDecimal priceId = amsContractTransportPrice.getPriceId();
  157. //获取未修改前的汽运单价信息
  158. AmsContractTransportPrice amsContractTransportPrice1 = amsContractTruckPriceMapper.selectByPrimaryKey(priceId);
  159. //若运价修改了
  160. if(!amsContractTransportPrice.getPriceValue().equals(amsContractTransportPrice1.getPriceValue())){
  161. //计算并插入吨公里
  162. BigDecimal priceTonKilometer = calculationPriceTonKilometer(lineId, priceValue);
  163. amsContractTransportPrice.setPriceTonKilometer(priceTonKilometer);
  164. }
  165. }
  166. amsContractTransportPrice.setUpdateTime(new Date());
  167. return amsContractTruckPriceMapper.updateByPrimaryKeySelective(amsContractTransportPrice);
  168. }
  169. @Override
  170. public List<Map<String, Object>> getOriginAndNowOilPrice() {
  171. return amsContractTruckPriceMapper.getOriginAndNowOilPrice();
  172. }
  173. @Override
  174. public List<Map<String, Object>> getCargoName() {
  175. return amsContractTruckPriceMapper.getCargoName();
  176. }
  177. @Override
  178. public List<Map<String, Object>> getOilTypeName() {
  179. return amsContractTruckPriceMapper.getOilTypeName();
  180. }
  181. /**
  182. * 批量修改运输单价
  183. * @return
  184. */
  185. @Override
  186. @Transactional
  187. public int batchUpdateTransportPriceByOilPrice(Map<String,Object> map){
  188. //正数的判断条件
  189. String flag= (String) map.get("flag");
  190. //运输单价变化的条数
  191. int i = 0;
  192. //获取油品名称ID
  193. BigDecimal oilTypeId = DataChange.dataToBigDecimal(map.get("oilTypeId"));
  194. //获取预执行油价
  195. BigDecimal newOilPrice = DataChange.dataToBigDecimal(map.get("newOilPrice"));
  196. BigDecimal type = new BigDecimal(1);
  197. //根据油品名称ID和非历史油价筛选出符合条件的运价合集
  198. List<Map<String, Object>> PriceValueList = amsContractTruckPriceMapper.getPriceValueList(oilTypeId);
  199. for (Map<String, Object> stringObjectMap : PriceValueList) {
  200. //有距离则是销售钢材
  201. if (stringObjectMap.get("haulDistance")!=null) {
  202. //中标价格或者收货地址(库存)则重新计算价格
  203. if (stringObjectMap.get("referenceHt")!=null || stringObjectMap.get("inventory")!=null){
  204. //跳过;
  205. continue;
  206. }else{
  207. //判断省市区(镇),拿到关联的中标数据
  208. Map<String, Object> zb = amsContractTruckPriceMapper.selectByPlaceId(DataChange.dataToBigDecimal(stringObjectMap.get("placeId")));
  209. BigDecimal zbDistance = DataChange.dataToBigDecimal(zb.get("haulDistance"));
  210. BigDecimal distance = DataChange.dataToBigDecimal(stringObjectMap.get("haulDistance"));
  211. if (zbDistance.intValue()!=0 && distance.intValue()!=0){
  212. BigDecimal subtract = zbDistance.subtract(distance);
  213. if (subtract.intValue()>10 || subtract.intValue()<-10){
  214. //大于正负10km重新计算价格
  215. //跳过
  216. continue;
  217. }else{
  218. //小于10km取中标价格
  219. Map<String,Object> updatePrice=new HashMap<>();
  220. updatePrice.put("priceId",DataChange.dataToBigDecimal(stringObjectMap.get("priceId")));
  221. updatePrice.put("priceValue",DataChange.dataToBigDecimal(zb.get("priceValue")));
  222. return amsContractTruckPriceMapper.updateByPriceId(updatePrice);
  223. }
  224. }
  225. }
  226. }
  227. stringObjectMap.put("priceDate",map.get("priceDate"));
  228. //获取该条单价的原油价基准
  229. BigDecimal oilpriceBase = DataChange.dataToBigDecimal(stringObjectMap.get("oilpriceBase"));
  230. //获取该条单价的油价变化率阈值
  231. BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(stringObjectMap.get("oilpriceChangeThreshold"));
  232. //计算油价变化率,公式:n=(当前油价-基数)÷基数×100% (9.06-8.26)/8.26
  233. BigDecimal n = (oilpriceBase.subtract(newOilPrice)).divide(newOilPrice,4,4);
  234. //若油价变化率超过该条单价的油价变化率阈值,修改原单价为历史数据,新增一条单价
  235. if(n.abs().doubleValue()>oilpriceChangeThreshold.doubleValue()){
  236. //加一个判断(如果数据为正数则需要二次判断,如果数据为负数则直接生效)
  237. try{
  238. if(newOilPrice.compareTo(oilpriceBase)==-1){
  239. //直接降低油价
  240. i+=addANewAmsContractTransportPrice(stringObjectMap,n,newOilPrice);
  241. }else if (newOilPrice.compareTo(oilpriceBase)==1 && "1".equals(flag)){
  242. //加上两个判断之后
  243. i+=addANewAmsContractTransportPrice(stringObjectMap,n,newOilPrice);
  244. }
  245. }catch (Exception e){
  246. e.printStackTrace();
  247. }
  248. }
  249. }
  250. return i;
  251. // if(updateOilPrice>0.05||updateOilPrice<-0.05) {
  252. // //逐条修改吨公里数
  253. // for (Map<String, Object> stringObjectMap : priceValueAndPriceTonKilometer) {
  254. // //主键Id
  255. // BigDecimal priceId = (BigDecimal) stringObjectMap.get("priceId");
  256. // //原运价
  257. // BigDecimal priceValue = (BigDecimal) stringObjectMap.get("priceValue");
  258. // //吨公里数
  259. // BigDecimal priceTonKilometer = (BigDecimal) stringObjectMap.get("priceTonKilometer");
  260. // //参考距离,四舍五入,保留两位小数
  261. // BigDecimal distance;
  262. // if (priceTonKilometer.doubleValue() != 0) {
  263. // distance = priceValue.divide(priceTonKilometer, 2, BigDecimal.ROUND_HALF_UP);
  264. // //现运价
  265. // Double nowPriceValue = priceValue.doubleValue() * 0.65 + priceValue.doubleValue() * 0.35 * (1 + updateOilPrice);
  266. // BigDecimal nowPriceValue1 = new BigDecimal(nowPriceValue);
  267. // //新吨公里数
  268. // BigDecimal newPriceTonKilometer = nowPriceValue1.divide(distance, 4, BigDecimal.ROUND_HALF_UP);
  269. // //通过主键修改一条吨公里数
  270. // amsContractTruckPriceMapper.updatePriceTonKilometer(priceId, newPriceTonKilometer);
  271. // }
  272. // return amsContractTruckPriceMapper.batchUpdateTransportPriceByOilPrice(updateOilPrice);
  273. // }
  274. // }
  275. }
  276. /**
  277. * 油价变化率超过该条单价的油价变化率阈值,修改原单价为历史数据,新增一条执行单价
  278. * @param stringObjectMap
  279. * @param n
  280. * @param newOilPrice
  281. * @return
  282. * @throws Exception
  283. */
  284. @Transactional
  285. public int addANewAmsContractTransportPrice(Map<String, Object> stringObjectMap,BigDecimal n,BigDecimal newOilPrice) throws ParseException {
  286. //定义将要改变的执行价
  287. BigDecimal nowPriceValue;
  288. //存储原运输单价实绩对象
  289. AmsContractTransportPrice oldAmsContractTransportPrice = new AmsContractTransportPrice();
  290. //查询货物名称
  291. // String cargonameValue = amsContractTruckPriceMapper.getCargonameValue(new BigDecimal(stringObjectMap.get("cargonameId").toString()));
  292. //获取原主键Id
  293. BigDecimal priceId = (BigDecimal) stringObjectMap.get("priceId");
  294. //修改原单价为历史数据
  295. oldAmsContractTransportPrice.setPriceId(priceId);
  296. oldAmsContractTransportPrice.setDeleted(new BigDecimal(1));
  297. amsContractTruckPriceMapper.updateByPrimaryKeySelective(oldAmsContractTransportPrice);
  298. //获取原单价的所有数据
  299. AmsContractTransportPrice amsContractTransportPrice = amsContractTruckPriceMapper.selectByPrimaryKey(priceId);
  300. //生成主键
  301. BigDecimal i = amsContractTruckPriceMapper.selectMaxId();
  302. amsContractTransportPrice.setPriceId(i);
  303. //生成执行日期
  304. amsContractTransportPrice.setPriceDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) stringObjectMap.get("priceDate")));
  305. //常规字段
  306. amsContractTransportPrice.setInsertUsername("admin");
  307. amsContractTransportPrice.setInsertTime(new Date());
  308. amsContractTransportPrice.setUpdateUsername("admin");
  309. amsContractTransportPrice.setUpdateTime(new Date());
  310. amsContractTransportPrice.setInsertUpdateRemark("无");
  311. //修改现单价为执行数据
  312. amsContractTransportPrice.setDeleted(new BigDecimal(0));
  313. // //若货物名称为焦炭
  314. // if(cargonameValue.equals("焦炭")){
  315. // //现执行价=((63.00+63.00*0.13*n)+(66.50+66.50*0.3*n)+40.00)
  316. // //调用焦炭运价计算公式计算现执行价
  317. // try {
  318. // nowPriceValue = UpdateCokePriceValueByOilPrice(n.toString());
  319. // //保留两位小数
  320. // nowPriceValue = nowPriceValue.divide(new BigDecimal(1),2,4);
  321. // //调整焦炭运价
  322. // amsContractTransportPrice.setPriceValue(nowPriceValue);
  323. // //修改基准油价
  324. // amsContractTransportPrice.setOilpriceBase(newOilPrice);
  325. // } catch (Exception e) {
  326. // e.printStackTrace();
  327. // }
  328. // }
  329. // if(cargonameValue.equals("纯苯")){
  330. // //现执行价=(中标价*0.7)+(中标价*0.3)*(1+n)
  331. // //调用纯苯运价计算公式计算现执行价
  332. // try {
  333. // nowPriceValue = UpdatePureBenzenePriceValueByOilPrice(n.toString(),amsContractTransportPrice.getPriceValue());
  334. // //保留两位小数
  335. // nowPriceValue = nowPriceValue.divide(new BigDecimal(1),2,4);
  336. // //调整纯苯运价
  337. // amsContractTransportPrice.setPriceValue(nowPriceValue);
  338. // //修改基准油价
  339. // amsContractTransportPrice.setOilpriceBase(newOilPrice);
  340. // } catch (Exception e) {
  341. // e.printStackTrace();
  342. // }
  343. // }
  344. // 得到油价联动公式id
  345. //BigDecimal formulaId = DataChange.dataToBigDecimal(stringObjectMap.get("cargonameId"));
  346. //BigDecimal formulaId= (BigDecimal) stringObjectMap.get("cargonameId");
  347. String s= (String) stringObjectMap.get("cargonameId");
  348. BigDecimal formulaId = NumberUtils.createBigDecimal(s.trim());
  349. amsContractTransportPrice.setCargonameId(formulaId);
  350. try {
  351. nowPriceValue = UpdatePureBenzenePriceValueByOilPrice(n.toString(),amsContractTransportPrice.getPriceValue(),formulaId);
  352. //保留两位小数
  353. nowPriceValue = nowPriceValue.divide(new BigDecimal(1),3,0);
  354. //调整纯苯运价
  355. amsContractTransportPrice.setPriceValue(nowPriceValue);
  356. //修改基准油价
  357. amsContractTransportPrice.setOilpriceBase(newOilPrice);
  358. } catch (Exception e) {
  359. e.printStackTrace();
  360. return 0;
  361. }
  362. //新增数据
  363. int insert = amsContractTruckPriceMapper.insert(amsContractTransportPrice);
  364. return insert;
  365. }
  366. /**
  367. * 替换焦炭运价公式并进行计算
  368. * @param n
  369. * @return
  370. * @throws Exception
  371. */
  372. public BigDecimal UpdateCokePriceValueByOilPrice(String n) throws Exception {
  373. // 得到运算公式
  374. String formula_string = null;
  375. // 得到焦炭运价计算公式
  376. formula_string = amsContractTruckPriceMapper.getTruckFormula(new BigDecimal(12));
  377. // 替换焦炭运价计算公式
  378. formula_string = formula_string.replace("油价变动率",n);
  379. String s = toSufExpr(formula_string);
  380. return calSufExpr(s);
  381. }
  382. /**
  383. * 替换运价公式并进行计算
  384. * @param n
  385. * @return
  386. * @throws Exception
  387. */
  388. public BigDecimal UpdatePureBenzenePriceValueByOilPrice(String n,BigDecimal priceValue,BigDecimal formulaId) throws Exception {
  389. // 得到运算公式
  390. String formula_string;
  391. // 得到运价计算公式
  392. formula_string = amsContractTruckPriceMapper.getTruckFormula(formulaId);
  393. if (formula_string.contains("中标价") && formula_string.contains("油价变动率")) {
  394. // 替换纯苯运价计算公式
  395. formula_string = formula_string.replace("中标价", priceValue.toString())
  396. .replace("油价变动率", n);
  397. }
  398. else {
  399. // 替换焦炭
  400. formula_string = formula_string.replace("油价变动率",n);
  401. }
  402. String s = toSufExpr(formula_string);
  403. return calSufExpr(s);
  404. }
  405. /**
  406. * 中缀转换后缀表达式
  407. */
  408. public String toSufExpr(String s) {
  409. StringBuffer sufExpr = new StringBuffer();
  410. Stack<String> stack = new Stack<>();
  411. //压入空方便判断
  412. stack.push(null);
  413. Pattern pattern = Pattern.compile("\\(int\\)|(?<!\\d|[)])-?\\d+(\\.\\d+)?|!=|>=|<=|==|[+\\-*/%()><=|]");
  414. Matcher matcher = pattern.matcher(s);
  415. while (matcher.find()) {
  416. String group = matcher.group();
  417. if (group.matches("!=|>=|<=|==|[+\\-*/%()><=|]|\\(int\\)")) {//是运算符
  418. if (group.equals("(")) {//之间压栈
  419. stack.push(group);
  420. } else if (group.equals(")")) {//等于右括号,一直弹栈,直到遇到左括号
  421. String pop = null;
  422. while (!(pop = stack.pop()).equals("(")) {//遍历循环至左括号
  423. sufExpr.append(pop + " ");
  424. }
  425. } else {//是运算符:加减乘除强转,根据优先级压栈
  426. while (getPriority(group) <= getPriority(stack.peek())) {
  427. String pop = stack.pop();
  428. System.out.println(pop);
  429. System.out.println(sufExpr);
  430. if(pop!=null&&!pop.equals("|")){
  431. sufExpr.append(pop + " ");
  432. }
  433. }
  434. stack.push(group);
  435. }
  436. } else {//是数字
  437. sufExpr.append(group + " ");
  438. }
  439. }
  440. String pop = null;
  441. while (null != (pop = stack.pop())) {
  442. sufExpr.append(pop + " ");
  443. }
  444. return sufExpr.toString();
  445. }
  446. /**
  447. * 设置出栈优先级,(:优先级最低,表示只有遇到)才能出栈
  448. * 当栈顶遇到优先级比自己小或等于的弹栈
  449. */
  450. public Integer getPriority(String c) {
  451. if (c == null) {
  452. return 0;
  453. }
  454. switch (c) {
  455. case "(":
  456. return 1;
  457. case "+":
  458. case "-":
  459. return 2;
  460. case "*":
  461. case "/":
  462. case "%":
  463. return 3;
  464. case ">":
  465. case "<":
  466. case ">=":
  467. case "<=":
  468. case "!=":
  469. case "==":
  470. return 4;
  471. case "|":
  472. return 5;
  473. case "=":
  474. return 6;
  475. case "(int)":
  476. return 7;
  477. }
  478. return 0;
  479. }
  480. /**
  481. * 计算值
  482. */
  483. public BigDecimal cal(BigDecimal a1, BigDecimal a2, String operator) throws Exception {
  484. switch (operator){
  485. case "+":return a1.add(a2);
  486. case "-":return a1.subtract(a2);
  487. case "*":return a1.multiply(a2);
  488. case "/":return a1.divide(a2,3,BigDecimal.ROUND_CEILING);
  489. case "%":return a1.divideAndRemainder(a2)[1];
  490. default:
  491. break;
  492. }
  493. throw new Exception("非法运算符");
  494. }
  495. public Boolean calBoolean(BigDecimal a1, BigDecimal a2, String operator) throws Exception {
  496. switch (operator){
  497. case ">":return a1.compareTo(a2) == 1;
  498. case "<":return a1.compareTo(a2) == -1;
  499. case ">=":return a1.compareTo(a2) > -1;
  500. case "<=":return a1.compareTo(a2) < 1;
  501. case "!=":return a1.compareTo(a2) != 0;
  502. case "==":return a1.compareTo(a2) == 0;
  503. default:
  504. break;
  505. }
  506. throw new Exception("非法运算符");
  507. }
  508. /**
  509. * 计算后缀表达式
  510. */
  511. public BigDecimal calSufExpr(String sufExpr) throws Exception {
  512. Stack<BigDecimal> stack = new Stack<>();
  513. Pattern pattern=Pattern.compile("\\(int\\)|-?\\d+(\\.\\d+)?|!=|>=|<=|==|[+\\-*/%><=]");//提取运算符和数字
  514. Matcher matcher = pattern.matcher(sufExpr);
  515. BigDecimal result=new BigDecimal("0.0");
  516. while (matcher.find()){
  517. String group = matcher.group();
  518. if(group.matches("[+\\-*/%]")){
  519. BigDecimal a1 =stack.pop();
  520. BigDecimal a2 =stack.pop();
  521. result = cal(a2, a1, group);
  522. stack.push(result);
  523. }
  524. else if(group.equals("(int)")){
  525. BigDecimal pop = stack.pop();
  526. BigDecimal bigDecimal = pop.setScale(0, BigDecimal.ROUND_DOWN);
  527. stack.push(bigDecimal);
  528. }
  529. else if(group.matches("!=|>=|<=|==|[><]")){
  530. BigDecimal a1 =stack.pop();
  531. BigDecimal a2 =stack.pop();
  532. stack.push(calBoolean(a2,a1,group)?new BigDecimal(1):new BigDecimal(0));
  533. }
  534. else if(group.equals("=")){
  535. BigDecimal a1 =stack.pop();
  536. BigDecimal a2 =stack.pop();
  537. if (a2.compareTo(new BigDecimal(1))==0) {
  538. stack.push(a1);
  539. }
  540. }
  541. else {//为数字直接压栈
  542. stack.push(new BigDecimal(group));
  543. }
  544. }
  545. return result;
  546. }
  547. /**
  548. * 边输边查具体地址
  549. * @param map
  550. * @return
  551. */
  552. @Override
  553. public List<Map<String, Object>> getRealAddressByLike(Map<String, Object> map) {
  554. return amsContractTruckPriceMapper.getRealAddressByLike(map);
  555. }
  556. @Override
  557. public int insertInwardPrice(Map<String, Object> mapValue) {
  558. int i = 0;
  559. BigDecimal capacityTypeId = DataChange.dataToBigDecimal(mapValue.get("capacityTypeId"));
  560. BigDecimal lineId = DataChange.dataToBigDecimal(mapValue.get("rangeId"));
  561. BigDecimal formulaId = DataChange.dataToBigDecimal(mapValue.get("formulaId"));
  562. BigDecimal priceValue = DataChange.dataToBigDecimal(mapValue.get("priceValue"));
  563. Date priceDate = new Date((Long)mapValue.get("priceDate"));
  564. BigDecimal type = DataChange.dataToBigDecimal(mapValue.get("type"));
  565. BigDecimal oilpriceBase = DataChange.dataToBigDecimal(mapValue.get("oilpriceBase"));
  566. BigDecimal oilTypeId = DataChange.dataToBigDecimal(mapValue.get("oilTypeId"));
  567. BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(mapValue.get("oilpriceChangeThreshold"));
  568. List<Map<String,Object>>mapList = (List<Map<String, Object>>) mapValue.get("mapList");
  569. AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
  570. amsContractTransportPrice.setType(type);
  571. amsContractTransportPrice.setOilpriceBase(oilpriceBase);
  572. //承运起止点ID
  573. amsContractTransportPrice.setLineId(lineId);
  574. amsContractTransportPrice.setOilpriceChangeThreshold(oilpriceChangeThreshold);
  575. amsContractTransportPrice.setOilTypeId(oilTypeId);
  576. amsContractTransportPrice.setPriceValue(priceValue);
  577. amsContractTransportPrice.setPriceDate(priceDate);
  578. amsContractTransportPrice.setCapacityTypeId(capacityTypeId);
  579. amsContractTransportPrice.setCargonameId(formulaId);
  580. //生成主键id
  581. amsContractTransportPrice.setPriceId(amsContractTruckPriceMapper.selectMaxId());
  582. amsContractTransportPrice.setInsertUsername("admin");
  583. amsContractTransportPrice.setInsertTime(new Date());
  584. amsContractTransportPrice.setUpdateUsername("admin");
  585. amsContractTransportPrice.setUpdateTime(new Date());
  586. amsContractTransportPrice.setInsertUpdateRemark("无");
  587. amsContractTransportPrice.setDeleted(new BigDecimal(0));
  588. i = amsContractTruckPriceMapper.insertSelective(amsContractTransportPrice);
  589. for (Map<String,Object>map:mapList
  590. ) {
  591. map.get("materialId");
  592. AmsContaactPriceMaterial amsContaactPriceMaterial = new AmsContaactPriceMaterial();
  593. //设置最大主键ID
  594. amsContaactPriceMaterial.setId(amsContractTruckPriceMapper.selectPriceMaterialMaxId());
  595. amsContaactPriceMaterial.setMaterialId(DataChange.dataToBigDecimal(map.get("materialId")));
  596. amsContaactPriceMaterial.setPriceId(amsContractTransportPrice.getPriceId());
  597. amsContaactPriceMaterial.setDeleted(new BigDecimal(0));
  598. i = amsContaactPriceMaterialMapper.insertSelective(amsContaactPriceMaterial);
  599. }
  600. return i;
  601. }
  602. @Override
  603. public List<Map<String, Object>> getInwardContractPrice(Map<String, Object> mapValue) {
  604. String material="";
  605. // if (mapValue.get("materialNames")!=null && mapValue.get("materialNames").toString().contains("、")) {
  606. // material= mapValue.get("materialNames").toString();
  607. // mapValue.put("materialNames",null);
  608. // }
  609. List<Map<String,Object>>mapList = amsContractTruckPriceMapper.getInwardContractPrice(mapValue);
  610. for (Map<String,Object>map:mapList
  611. ) {
  612. List<Map<String,Object>> materialList = amsContaactPriceMaterialMapper.getMaterialName(map);
  613. String materialNames = "";
  614. int i = 1;
  615. for (Map<String,Object>materialMap:materialList
  616. ) {
  617. if(i==materialList.size()){
  618. materialNames = materialNames + materialMap.get("materialName") ;
  619. }
  620. else{
  621. materialNames = materialNames + materialMap.get("materialName") + "、";
  622. }
  623. i++;
  624. }
  625. map.put("materialNames",materialNames);
  626. if(((BigDecimal)map.get("type")).intValue() == 2){
  627. map.put("type","元/吨");
  628. }else if(((BigDecimal)map.get("type")).intValue() == 5){
  629. map.put("type","元/小时");
  630. }else if(((BigDecimal)map.get("type")).intValue() == 6){
  631. map.put("type","元/趟");
  632. }
  633. // if (material!=null &&
  634. // material.contains("、") &&
  635. // material.equals(materialNames)) {
  636. // List<Map<String, Object>> newMapList=new ArrayList<>();
  637. // newMapList.add(map);
  638. // return newMapList;
  639. // }
  640. }
  641. return mapList;
  642. }
  643. @Override
  644. public List<Map<String, Object>> selectInwardPrice(Map<String, Object> mapvalue) {
  645. return amsContractTruckPriceMapper.selectInwardPrice(mapvalue);
  646. }
  647. @Override
  648. public List<Map<String, Object>> getRangePoint(Map<String, Object> mapValue) {
  649. return amsContractTruckPriceMapper.getRangePoint(mapValue);
  650. }
  651. @Override
  652. public int insertLineNodePoint(Map<String, Object> map) {
  653. RmsLineNodePoint rmsLineNodePoint = new RmsLineNodePoint();
  654. BigDecimal rangeId = DataChange.dataToBigDecimal(map.get("rangeId"));
  655. String loadName = (String)map.get("loadPointName");
  656. String unloadName = (String)map.get("unloadPointName");
  657. rmsLineNodePoint.setId(rmsLineNodePointMapper.lineMaxId());
  658. rmsLineNodePoint.setTransRangeId(rangeId);
  659. rmsLineNodePoint.setLoadPointName(loadName);
  660. rmsLineNodePoint.setUnloadPointName(unloadName);
  661. rmsLineNodePoint.setDeleted(new BigDecimal(0));
  662. int i = rmsLineNodePointMapper.insertSelective(rmsLineNodePoint);
  663. return i;
  664. }
  665. @Override
  666. public int updatePriceById(Map<String, Object> map) {
  667. int count = 0;
  668. //获取单价ID
  669. BigDecimal priceId = DataChange.dataToBigDecimal(map.get("priceId"));
  670. //获取物资详ID
  671. List<Map<String, Object>> materialTypeList = (List<Map<String,Object>>)map.get("materialTypeList");
  672. for (Map<String,Object> materialTypeMap:materialTypeList){
  673. }
  674. return count;
  675. }
  676. @Override
  677. public int updatePriceByPriceId(Map<String, Object> mapValue){
  678. int i = 0;
  679. BigDecimal capacityTypeId = DataChange.dataToBigDecimal(mapValue.get("capacityTypeId"));
  680. BigDecimal lineId = DataChange.dataToBigDecimal(mapValue.get("rangeId"));
  681. BigDecimal formulaId = DataChange.dataToBigDecimal(mapValue.get("cargonameId"));
  682. BigDecimal priceValue = DataChange.dataToBigDecimal(mapValue.get("priceValue"));
  683. Date priceDate = new Date((Long)mapValue.get("priceDate"));
  684. BigDecimal type = DataChange.dataToBigDecimal(mapValue.get("type"));
  685. BigDecimal oilpriceBase = DataChange.dataToBigDecimal(mapValue.get("oilpriceBase"));
  686. // BigDecimal oilTypeId = DataChange.dataToBigDecimal(mapValue.get("oilTypeId"));
  687. BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(mapValue.get("oilpriceChangeThreshold"));
  688. List<Map<String,Object>>mapList = (List<Map<String, Object>>) mapValue.get("mapList");
  689. BigDecimal priceId=DataChange.dataToBigDecimal(mapValue.get("priceId"));
  690. AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
  691. amsContractTransportPrice.setOilpriceBase(oilpriceBase);
  692. // amsContractTransportPrice.setOilTypeId(oilTypeId); 油品名称
  693. amsContractTransportPrice.setPriceValue(priceValue);
  694. amsContractTransportPrice.setPriceDate(priceDate);
  695. amsContractTransportPrice.setCargonameId(formulaId);
  696. amsContractTransportPrice.setPriceId(priceId);
  697. amsContractTransportPrice.setUpdateTime(new Date());
  698. i = amsContractTruckPriceMapper.updateByPrimaryKeySelective(amsContractTransportPrice);
  699. // 根据priceId先查询之前是否有物资
  700. // 如果有,但是接受的没有就删除
  701. List<Map<String, Object>> selectwz = amsContractTruckPriceMapper.selectwz(mapValue);
  702. if (!selectwz.isEmpty() && mapList.isEmpty()){
  703. i = amsContaactPriceMaterialMapper.deletePriceByPriceId(mapValue.get("priceId").toString());
  704. }
  705. //把之前的全删了,然后新增
  706. if (mapList!=null && mapList.size()>0) {
  707. i = amsContaactPriceMaterialMapper.deletePriceByPriceId(mapValue.get("priceId").toString());
  708. }
  709. for (Map<String,Object>map:mapList
  710. ) {
  711. //新增
  712. AmsContaactPriceMaterial amsContaactPriceMaterial = new AmsContaactPriceMaterial();
  713. //设置最大主键ID
  714. amsContaactPriceMaterial.setId(amsContractTruckPriceMapper.selectPriceMaterialMaxId());
  715. amsContaactPriceMaterial.setMaterialId(DataChange.dataToBigDecimal(map.get("materialId")));
  716. amsContaactPriceMaterial.setPriceId(amsContractTransportPrice.getPriceId());
  717. amsContaactPriceMaterial.setDeleted(new BigDecimal(0));
  718. i = amsContaactPriceMaterialMapper.insertSelective(amsContaactPriceMaterial);
  719. }
  720. return i;
  721. }
  722. @Override
  723. public List<Map<String, Object>> getwz(Map<String, Object> map){
  724. List<Map<String, Object>> selectwz = amsContractTruckPriceMapper.selectwz(map);
  725. return selectwz;
  726. }
  727. @Override
  728. public Map<String, Object> getcargonameId(Map<String, Object> map) {
  729. Map<String, Object> value = amsContractTruckPriceMapper.getcargonameId(map);
  730. return value;
  731. }
  732. @Override
  733. public int updateDCodd() {
  734. return amsContractTruckPriceMapper.updateDCodd();
  735. }
  736. @Override
  737. public int updateDCnew() {
  738. return amsContractTruckPriceMapper.updateDCnew();
  739. }
  740. @Transactional
  741. @Override
  742. public int insertInwardPriceExcel(Map<String,Object> mapValue){
  743. int i=0;
  744. try{
  745. Object rowsList = mapValue.get("rowsList");
  746. ArrayList arrayList = (ArrayList) rowsList;
  747. //先查询在单价表之前是否有记录,有则禁用
  748. for (Object map : arrayList) {
  749. //查询收货地址
  750. Map entity = (Map)map;
  751. if (entity.get("addressDistrict")!=null){
  752. if (entity.get("addressDistrict").toString().contains("区") || entity.get("addressDistrict").toString().contains("县")){
  753. entity.put("addressDistrict","重庆");
  754. }
  755. }
  756. //查询收货地址
  757. List<String> selectshdz = amsContractTruckPriceMapper.selectshdz(entity);
  758. //录入收货地址
  759. if (selectshdz==null) {
  760. entity.put("addressId",amsContractTruckPriceMapper.selectMaxIdrra()+1);
  761. amsContractTruckPriceMapper.insertshdz(entity);
  762. }
  763. Map<String, Object> selectxxdz=new HashMap<>();
  764. //查询详细地址
  765. if (selectshdz!=null && selectshdz.size()>0) {
  766. entity.put("addressId",selectshdz);
  767. selectxxdz = amsContractTruckPriceMapper.selectxxdz(entity);
  768. }
  769. if (selectxxdz!=null && selectxxdz.get("placeId")!=null) {
  770. i = amsContractTruckPriceMapper.updateDelectByPlaceId(selectxxdz);
  771. }
  772. //录入详细地址
  773. if (selectxxdz==null){
  774. entity.put("placeId",amsContractTruckPriceMapper.selectMaxIdrrp()+1);
  775. entity.put("addressId",DataChange.dataToBigDecimal(entity.get("addressId").toString().replace("[","").replace("]","")));
  776. amsContractTruckPriceMapper.insertxxdz(entity);
  777. }
  778. //生成主键id
  779. AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
  780. amsContractTransportPrice.setPriceId(amsContractTruckPriceMapper.selectMaxId());
  781. amsContractTransportPrice.setInsertUsername("admin");
  782. amsContractTransportPrice.setInsertTime(new Date());
  783. amsContractTransportPrice.setUpdateUsername("admin");
  784. amsContractTransportPrice.setUpdateTime(new Date());
  785. amsContractTransportPrice.setInsertUpdateRemark("无");
  786. amsContractTransportPrice.setDeleted(new BigDecimal(0));
  787. SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
  788. Date priceDate = dateformat.parse("2022-9-26");
  789. amsContractTransportPrice.setPriceDate(priceDate);
  790. if(selectxxdz!=null && selectxxdz.get("placeId")!=null){
  791. amsContractTransportPrice.setPlaceId(DataChange.dataToBigDecimal(selectxxdz.get("placeId")));
  792. }else if(entity!=null && entity.get("placeId")!=null){
  793. amsContractTransportPrice.setPlaceId(DataChange.dataToBigDecimal(entity.get("placeId")));
  794. }
  795. amsContractTransportPrice.setHaulDistance(DataChange.dataToBigDecimal(entity.get("haulDistance")));
  796. amsContractTransportPrice.setPriceValue(DataChange.dataToBigDecimal(entity.get("priceValue")));
  797. amsContractTransportPrice.setPriceTonKilometer(DataChange.dataToBigDecimal(entity.get("priceTonKilometer")));
  798. if (entity!=null && entity.get("carrierAbbreviation")!=null){
  799. String cys= entity.get("carrierAbbreviation").toString();
  800. if (cys!=null) {
  801. Map<String, Object> selectcys=new HashMap<>();
  802. if(cys.contains("/")){
  803. String[] cyss = cys.split("/");
  804. for (int j = 0; j < cyss.length; j++) {
  805. selectcys = amsContractTruckPriceMapper.selectcys(cyss[j]);
  806. if (selectcys!=null && selectcys.get("carrierId")!=null) {
  807. amsContractTransportPrice.setCarrierId(DataChange.dataToBigDecimal(selectcys.get("carrierId")));//承运商id
  808. }
  809. }
  810. }else{
  811. selectcys = amsContractTruckPriceMapper.selectcys(cys);
  812. amsContractTransportPrice.setCarrierId(DataChange.dataToBigDecimal(selectcys.get("carrierId")));//承运商id
  813. }
  814. }
  815. }
  816. if (entity!=null && entity.get("yes")!=null) {
  817. if (entity.get("yes").toString().equals("1")){
  818. //中标合同
  819. amsContractTransportPrice.setReferenceHt(DataChange.dataToBigDecimal(1));
  820. }else{
  821. //库存
  822. amsContractTransportPrice.setInventory(DataChange.dataToBigDecimal(1));
  823. }
  824. }
  825. i = amsContractTruckPriceMapper.insertSelective(amsContractTransportPrice);
  826. }
  827. }catch (Exception e){
  828. e.printStackTrace();
  829. }
  830. return i;
  831. }
  832. }