AmsContractTruckPriceServiceImpl.java 42 KB

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