123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879 |
- package com.steerinfo.dil.service.impl;
- import com.steerinfo.dil.mapper.AmsContaactPriceMaterialMapper;
- import com.steerinfo.dil.mapper.AmsContractTruckPriceMapper;
- import com.steerinfo.dil.mapper.RmsLineNodePointMapper;
- import com.steerinfo.dil.mapper.RmsReceivePlaceMapper;
- import com.steerinfo.dil.model.AmsContaactPriceMaterial;
- import com.steerinfo.dil.model.AmsContractTransportPrice;
- import com.steerinfo.dil.model.RmsLineNodePoint;
- import com.steerinfo.dil.model.RmsReceivePlace;
- import com.steerinfo.dil.service.IAmsContractTruckPriceService;
- import com.steerinfo.dil.util.DataChange;
- import org.apache.commons.lang.math.NumberUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.lang.reflect.Array;
- import java.math.BigDecimal;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- /**
- * AmsContractTransportPrice服务实现:
- * @author generator
- * @version 1.0-SNAPSHORT 2021-09-06 07:10
- * 类描述
- * 修订历史:
- * 日期:2021-09-06
- * 作者:generator
- * 参考:
- * 描述:AmsContractTransportPrice服务实现
- * @see null
- * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
- */
- @Service(value = "amsContractTruckPriceService")
- public class AmsContractTruckPriceServiceImpl implements IAmsContractTruckPriceService {
- @Autowired
- private AmsContractTruckPriceMapper amsContractTruckPriceMapper;
- @Autowired
- RmsReceivePlaceMapper rmsReceivePlaceMapper;
- @Autowired
- AmsContaactPriceMaterialMapper amsContaactPriceMaterialMapper;
- //@Autowired
- //private RmsLineNodePoint rmsLineNodePoint;
- @Autowired
- private RmsLineNodePointMapper rmsLineNodePointMapper;
- /**
- * 新增汽运单价
- * @Author zzd
- * @Date 2022/1/20 11:33
- * @param mapValue
- * @return
- **/
- @Transactional
- @Override
- public int addAmsContractTransportPrice(Map<String,Object> mapValue) {
- BigDecimal shipperId = DataChange.dataToBigDecimal(mapValue.get("shipperId"));
- BigDecimal carrierId = DataChange.dataToBigDecimal(mapValue.get("carrierId"));
- BigDecimal addressId = DataChange.dataToBigDecimal(mapValue.get("addressId"));
- BigDecimal lineId = DataChange.dataToBigDecimal(mapValue.get("lineId"));
- BigDecimal capacityTypeId = DataChange.dataToBigDecimal(mapValue.get("capacityTypeId"));
- BigDecimal formulaId = DataChange.dataToBigDecimal(mapValue.get("formulaId"));
- BigDecimal priceValue = DataChange.dataToBigDecimal(mapValue.get("priceValue"));
- Date priceDate = new Date((Long)mapValue.get("priceDate"));
- BigDecimal type = DataChange.dataToBigDecimal(mapValue.get("type"));
- BigDecimal oilpriceBase = DataChange.dataToBigDecimal(mapValue.get("oilpriceBase"));
- BigDecimal oilTypeId = DataChange.dataToBigDecimal(mapValue.get("oilTypeId"));
- BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(mapValue.get("oilpriceChangeThreshold"));
- AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
- String place = (String) mapValue.get("place");
- if (place != null && place.length() != 0) {
- BigDecimal placeId = rmsReceivePlaceMapper.getPlaceId(mapValue);
- if (placeId != null) {
- amsContractTransportPrice.setPlaceId(placeId);
- }
- else {
- RmsReceivePlace rmsReceivePlace = new RmsReceivePlace();
- rmsReceivePlace.setAddressId(addressId);
- rmsReceivePlace.setAddressDeliveryAddress(place);
- rmsReceivePlace.setPlaceId(rmsReceivePlaceMapper.selectMaxId());
- }
- }
- amsContractTransportPrice.setType(type);
- amsContractTransportPrice.setOilpriceBase(oilpriceBase);
- amsContractTransportPrice.setShipperId(shipperId);
- amsContractTransportPrice.setOilpriceChangeThreshold(oilpriceChangeThreshold);
- amsContractTransportPrice.setOilTypeId(oilTypeId);
- amsContractTransportPrice.setPriceValue(priceValue);
- amsContractTransportPrice.setPriceDate(priceDate);
- amsContractTransportPrice.setCapacityTypeId(capacityTypeId);
- amsContractTransportPrice.setCargonameId(formulaId);
- amsContractTransportPrice.setCarrierId(carrierId);
- //生成主键id
- amsContractTransportPrice.setPriceId(amsContractTruckPriceMapper.selectMaxId());
- if(lineId == null){
- //计算并插入吨公里
- BigDecimal priceTonKilometer = calculationPriceTonKilometer(lineId, priceValue);
- amsContractTransportPrice.setPriceTonKilometer(priceTonKilometer);
- }
- amsContractTransportPrice.setType(new BigDecimal(1));
- amsContractTransportPrice.setInsertUsername("admin");
- amsContractTransportPrice.setInsertTime(new Date());
- amsContractTransportPrice.setUpdateUsername("admin");
- amsContractTransportPrice.setUpdateTime(new Date());
- amsContractTransportPrice.setInsertUpdateRemark("无");
- amsContractTransportPrice.setDeleted(new BigDecimal(0));
- return amsContractTruckPriceMapper.insertSelective(amsContractTransportPrice);
- }
- //计算吨公里值
- public BigDecimal calculationPriceTonKilometer(BigDecimal lineId,BigDecimal priceValue){
- //查询参考运距
- BigDecimal linePathLength = amsContractTruckPriceMapper.getLinePathLength(lineId);
- //计算吨公里 吨公里(元/吨.km) = 运价(元/吨)/ 参考运距(公里),保留4位小数
- BigDecimal priceTonKilometer = priceValue.divide(linePathLength, 4, BigDecimal.ROUND_HALF_UP);
- return priceTonKilometer;
- }
- @Override
- public List<Map<String, Object>> getAmsContractTransportPrice(Map<String, Object> map) {
- return amsContractTruckPriceMapper.getAmsContractTransportPrice(map);
- }
- @Override
- public int deleteAmsContractTransportPrice(BigDecimal priceId) {
- AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
- amsContractTransportPrice.setId(priceId);
- amsContractTransportPrice.setDeleted(new BigDecimal(1));
- return amsContractTruckPriceMapper.updateByPrimaryKeySelective(amsContractTransportPrice);
- }
- @Override
- public List<Map<String, Object>> getCarrierName() {
- return amsContractTruckPriceMapper.getCarrierName();
- }
- @Override
- public List<Map<String, Object>> getLineNo() {
- return amsContractTruckPriceMapper.getLineNo();
- }
- @Override
- public List<Map<String, Object>> getCapacityNumber() {
- return amsContractTruckPriceMapper.getCapacityNumber();
- }
- @Override
- public List<Map<String, Object>> getAddressDeliveryAddress(Map<String,Object> map) {
- return amsContractTruckPriceMapper.getAddressDeliveryAddress(map);
- }
- @Override
- public List<Map<String, Object>> selectByPriceId(BigDecimal priceId) {
- return amsContractTruckPriceMapper.selectByPriceId(priceId);
- }
- @Override
- public int updateAmsContractTransportPrice(AmsContractTransportPrice amsContractTransportPrice) {
- //获取路线Id和运价
- BigDecimal lineId = amsContractTransportPrice.getLineId();
- BigDecimal priceValue = amsContractTransportPrice.getPriceValue();
- //如果传入路线则修改运价
- if(lineId != null){
- BigDecimal priceId = amsContractTransportPrice.getPriceId();
- //获取未修改前的汽运单价信息
- AmsContractTransportPrice amsContractTransportPrice1 = amsContractTruckPriceMapper.selectByPrimaryKey(priceId);
- //若运价修改了
- if(!amsContractTransportPrice.getPriceValue().equals(amsContractTransportPrice1.getPriceValue())){
- //计算并插入吨公里
- BigDecimal priceTonKilometer = calculationPriceTonKilometer(lineId, priceValue);
- amsContractTransportPrice.setPriceTonKilometer(priceTonKilometer);
- }
- }
- amsContractTransportPrice.setUpdateTime(new Date());
- return amsContractTruckPriceMapper.updateByPrimaryKeySelective(amsContractTransportPrice);
- }
- @Override
- public List<Map<String, Object>> getOriginAndNowOilPrice() {
- return amsContractTruckPriceMapper.getOriginAndNowOilPrice();
- }
- @Override
- public List<Map<String, Object>> getCargoName() {
- return amsContractTruckPriceMapper.getCargoName();
- }
- @Override
- public List<Map<String, Object>> getOilTypeName() {
- return amsContractTruckPriceMapper.getOilTypeName();
- }
- /**
- * 批量修改运输单价
- * @return
- */
- @Override
- @Transactional
- public int batchUpdateTransportPriceByOilPrice(Map<String,Object> map){
- //正数的判断条件
- String flag= (String) map.get("flag");
- //运输单价变化的条数
- int i = 0;
- //获取油品名称ID
- BigDecimal oilTypeId = DataChange.dataToBigDecimal(map.get("oilTypeId"));
- //获取预执行油价
- BigDecimal newOilPrice = DataChange.dataToBigDecimal(map.get("newOilPrice"));
- BigDecimal type = new BigDecimal(1);
- //根据油品名称ID和非历史油价筛选出符合条件的运价合集
- List<Map<String, Object>> PriceValueList = amsContractTruckPriceMapper.getPriceValueList(oilTypeId);
- for (Map<String, Object> stringObjectMap : PriceValueList) {
- //有距离则是销售钢材
- if (stringObjectMap.get("haulDistance")!=null) {
- //中标价格或者收货地址(库存)则重新计算价格
- if (stringObjectMap.get("referenceHt")!=null || stringObjectMap.get("inventory")!=null){
- //跳过;
- continue;
- }else{
- //判断省市区(镇),拿到关联的中标数据
- Map<String, Object> zb = amsContractTruckPriceMapper.selectByPlaceId(DataChange.dataToBigDecimal(stringObjectMap.get("placeId")));
- BigDecimal zbDistance = DataChange.dataToBigDecimal(zb.get("haulDistance"));
- BigDecimal distance = DataChange.dataToBigDecimal(stringObjectMap.get("haulDistance"));
- if (zbDistance.intValue()!=0 && distance.intValue()!=0){
- BigDecimal subtract = zbDistance.subtract(distance);
- if (subtract.intValue()>10 || subtract.intValue()<-10){
- //大于正负10km重新计算价格
- //跳过
- continue;
- }else{
- //小于10km取中标价格
- Map<String,Object> updatePrice=new HashMap<>();
- updatePrice.put("priceId",DataChange.dataToBigDecimal(stringObjectMap.get("priceId")));
- updatePrice.put("priceValue",DataChange.dataToBigDecimal(zb.get("priceValue")));
- return amsContractTruckPriceMapper.updateByPriceId(updatePrice);
- }
- }
- }
- }
- stringObjectMap.put("priceDate",map.get("priceDate"));
- //获取该条单价的原油价基准
- BigDecimal oilpriceBase = DataChange.dataToBigDecimal(stringObjectMap.get("oilpriceBase"));
- //获取该条单价的油价变化率阈值
- BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(stringObjectMap.get("oilpriceChangeThreshold"));
- //计算油价变化率,公式:n=(当前油价-基数)÷基数×100% (9.06-8.26)/8.26
- BigDecimal n = (oilpriceBase.subtract(newOilPrice)).divide(newOilPrice,4,4);
- //若油价变化率超过该条单价的油价变化率阈值,修改原单价为历史数据,新增一条单价
- if(n.abs().doubleValue()>oilpriceChangeThreshold.doubleValue()){
- //加一个判断(如果数据为正数则需要二次判断,如果数据为负数则直接生效)
- try{
- if(newOilPrice.compareTo(oilpriceBase)==-1){
- //直接降低油价
- i+=addANewAmsContractTransportPrice(stringObjectMap,n,newOilPrice);
- }else if (newOilPrice.compareTo(oilpriceBase)==1 && "1".equals(flag)){
- //加上两个判断之后
- i+=addANewAmsContractTransportPrice(stringObjectMap,n,newOilPrice);
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }
- return i;
- // if(updateOilPrice>0.05||updateOilPrice<-0.05) {
- // //逐条修改吨公里数
- // for (Map<String, Object> stringObjectMap : priceValueAndPriceTonKilometer) {
- // //主键Id
- // BigDecimal priceId = (BigDecimal) stringObjectMap.get("priceId");
- // //原运价
- // BigDecimal priceValue = (BigDecimal) stringObjectMap.get("priceValue");
- // //吨公里数
- // BigDecimal priceTonKilometer = (BigDecimal) stringObjectMap.get("priceTonKilometer");
- // //参考距离,四舍五入,保留两位小数
- // BigDecimal distance;
- // if (priceTonKilometer.doubleValue() != 0) {
- // distance = priceValue.divide(priceTonKilometer, 2, BigDecimal.ROUND_HALF_UP);
- // //现运价
- // Double nowPriceValue = priceValue.doubleValue() * 0.65 + priceValue.doubleValue() * 0.35 * (1 + updateOilPrice);
- // BigDecimal nowPriceValue1 = new BigDecimal(nowPriceValue);
- // //新吨公里数
- // BigDecimal newPriceTonKilometer = nowPriceValue1.divide(distance, 4, BigDecimal.ROUND_HALF_UP);
- // //通过主键修改一条吨公里数
- // amsContractTruckPriceMapper.updatePriceTonKilometer(priceId, newPriceTonKilometer);
- // }
- // return amsContractTruckPriceMapper.batchUpdateTransportPriceByOilPrice(updateOilPrice);
- // }
- // }
- }
- /**
- * 油价变化率超过该条单价的油价变化率阈值,修改原单价为历史数据,新增一条执行单价
- * @param stringObjectMap
- * @param n
- * @param newOilPrice
- * @return
- * @throws Exception
- */
- @Transactional
- public int addANewAmsContractTransportPrice(Map<String, Object> stringObjectMap,BigDecimal n,BigDecimal newOilPrice) throws ParseException {
- //定义将要改变的执行价
- BigDecimal nowPriceValue;
- //存储原运输单价实绩对象
- AmsContractTransportPrice oldAmsContractTransportPrice = new AmsContractTransportPrice();
- //查询货物名称
- // String cargonameValue = amsContractTruckPriceMapper.getCargonameValue(new BigDecimal(stringObjectMap.get("cargonameId").toString()));
- //获取原主键Id
- BigDecimal priceId = (BigDecimal) stringObjectMap.get("priceId");
- //修改原单价为历史数据
- oldAmsContractTransportPrice.setPriceId(priceId);
- oldAmsContractTransportPrice.setDeleted(new BigDecimal(1));
- amsContractTruckPriceMapper.updateByPrimaryKeySelective(oldAmsContractTransportPrice);
- //获取原单价的所有数据
- AmsContractTransportPrice amsContractTransportPrice = amsContractTruckPriceMapper.selectByPrimaryKey(priceId);
- //生成主键
- BigDecimal i = amsContractTruckPriceMapper.selectMaxId();
- amsContractTransportPrice.setPriceId(i);
- //生成执行日期
- amsContractTransportPrice.setPriceDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) stringObjectMap.get("priceDate")));
- //常规字段
- amsContractTransportPrice.setInsertUsername("admin");
- amsContractTransportPrice.setInsertTime(new Date());
- amsContractTransportPrice.setUpdateUsername("admin");
- amsContractTransportPrice.setUpdateTime(new Date());
- amsContractTransportPrice.setInsertUpdateRemark("无");
- //修改现单价为执行数据
- amsContractTransportPrice.setDeleted(new BigDecimal(0));
- // //若货物名称为焦炭
- // if(cargonameValue.equals("焦炭")){
- // //现执行价=((63.00+63.00*0.13*n)+(66.50+66.50*0.3*n)+40.00)
- // //调用焦炭运价计算公式计算现执行价
- // try {
- // nowPriceValue = UpdateCokePriceValueByOilPrice(n.toString());
- // //保留两位小数
- // nowPriceValue = nowPriceValue.divide(new BigDecimal(1),2,4);
- // //调整焦炭运价
- // amsContractTransportPrice.setPriceValue(nowPriceValue);
- // //修改基准油价
- // amsContractTransportPrice.setOilpriceBase(newOilPrice);
- // } catch (Exception e) {
- // e.printStackTrace();
- // }
- // }
- // if(cargonameValue.equals("纯苯")){
- // //现执行价=(中标价*0.7)+(中标价*0.3)*(1+n)
- // //调用纯苯运价计算公式计算现执行价
- // try {
- // nowPriceValue = UpdatePureBenzenePriceValueByOilPrice(n.toString(),amsContractTransportPrice.getPriceValue());
- // //保留两位小数
- // nowPriceValue = nowPriceValue.divide(new BigDecimal(1),2,4);
- // //调整纯苯运价
- // amsContractTransportPrice.setPriceValue(nowPriceValue);
- // //修改基准油价
- // amsContractTransportPrice.setOilpriceBase(newOilPrice);
- // } catch (Exception e) {
- // e.printStackTrace();
- // }
- // }
- // 得到油价联动公式id
- //BigDecimal formulaId = DataChange.dataToBigDecimal(stringObjectMap.get("cargonameId"));
- //BigDecimal formulaId= (BigDecimal) stringObjectMap.get("cargonameId");
- String s= (String) stringObjectMap.get("cargonameId");
- BigDecimal formulaId = NumberUtils.createBigDecimal(s.trim());
- amsContractTransportPrice.setCargonameId(formulaId);
- try {
- nowPriceValue = UpdatePureBenzenePriceValueByOilPrice(n.toString(),amsContractTransportPrice.getPriceValue(),formulaId);
- //保留两位小数
- nowPriceValue = nowPriceValue.divide(new BigDecimal(1),3,0);
- //调整纯苯运价
- amsContractTransportPrice.setPriceValue(nowPriceValue);
- //修改基准油价
- amsContractTransportPrice.setOilpriceBase(newOilPrice);
- } catch (Exception e) {
- e.printStackTrace();
- return 0;
- }
- //新增数据
- int insert = amsContractTruckPriceMapper.insert(amsContractTransportPrice);
- return insert;
- }
- /**
- * 替换焦炭运价公式并进行计算
- * @param n
- * @return
- * @throws Exception
- */
- public BigDecimal UpdateCokePriceValueByOilPrice(String n) throws Exception {
- // 得到运算公式
- String formula_string = null;
- // 得到焦炭运价计算公式
- formula_string = amsContractTruckPriceMapper.getTruckFormula(new BigDecimal(12));
- // 替换焦炭运价计算公式
- formula_string = formula_string.replace("油价变动率",n);
- String s = toSufExpr(formula_string);
- return calSufExpr(s);
- }
- /**
- * 替换运价公式并进行计算
- * @param n
- * @return
- * @throws Exception
- */
- public BigDecimal UpdatePureBenzenePriceValueByOilPrice(String n,BigDecimal priceValue,BigDecimal formulaId) throws Exception {
- // 得到运算公式
- String formula_string;
- // 得到运价计算公式
- formula_string = amsContractTruckPriceMapper.getTruckFormula(formulaId);
- if (formula_string.contains("中标价") && formula_string.contains("油价变动率")) {
- // 替换纯苯运价计算公式
- formula_string = formula_string.replace("中标价", priceValue.toString())
- .replace("油价变动率", n);
- }
- else {
- // 替换焦炭
- formula_string = formula_string.replace("油价变动率",n);
- }
- String s = toSufExpr(formula_string);
- return calSufExpr(s);
- }
- /**
- * 中缀转换后缀表达式
- */
- public String toSufExpr(String s) {
- StringBuffer sufExpr = new StringBuffer();
- Stack<String> stack = new Stack<>();
- //压入空方便判断
- stack.push(null);
- Pattern pattern = Pattern.compile("\\(int\\)|(?<!\\d|[)])-?\\d+(\\.\\d+)?|!=|>=|<=|==|[+\\-*/%()><=|]");
- Matcher matcher = pattern.matcher(s);
- while (matcher.find()) {
- String group = matcher.group();
- if (group.matches("!=|>=|<=|==|[+\\-*/%()><=|]|\\(int\\)")) {//是运算符
- if (group.equals("(")) {//之间压栈
- stack.push(group);
- } else if (group.equals(")")) {//等于右括号,一直弹栈,直到遇到左括号
- String pop = null;
- while (!(pop = stack.pop()).equals("(")) {//遍历循环至左括号
- sufExpr.append(pop + " ");
- }
- } else {//是运算符:加减乘除强转,根据优先级压栈
- while (getPriority(group) <= getPriority(stack.peek())) {
- String pop = stack.pop();
- System.out.println(pop);
- System.out.println(sufExpr);
- if(pop!=null&&!pop.equals("|")){
- sufExpr.append(pop + " ");
- }
- }
- stack.push(group);
- }
- } else {//是数字
- sufExpr.append(group + " ");
- }
- }
- String pop = null;
- while (null != (pop = stack.pop())) {
- sufExpr.append(pop + " ");
- }
- return sufExpr.toString();
- }
- /**
- * 设置出栈优先级,(:优先级最低,表示只有遇到)才能出栈
- * 当栈顶遇到优先级比自己小或等于的弹栈
- */
- public Integer getPriority(String c) {
- if (c == null) {
- return 0;
- }
- switch (c) {
- case "(":
- return 1;
- case "+":
- case "-":
- return 2;
- case "*":
- case "/":
- case "%":
- return 3;
- case ">":
- case "<":
- case ">=":
- case "<=":
- case "!=":
- case "==":
- return 4;
- case "|":
- return 5;
- case "=":
- return 6;
- case "(int)":
- return 7;
- }
- return 0;
- }
- /**
- * 计算值
- */
- public BigDecimal cal(BigDecimal a1, BigDecimal a2, String operator) throws Exception {
- switch (operator){
- case "+":return a1.add(a2);
- case "-":return a1.subtract(a2);
- case "*":return a1.multiply(a2);
- case "/":return a1.divide(a2,3,BigDecimal.ROUND_CEILING);
- case "%":return a1.divideAndRemainder(a2)[1];
- default:
- break;
- }
- throw new Exception("非法运算符");
- }
- public Boolean calBoolean(BigDecimal a1, BigDecimal a2, String operator) throws Exception {
- switch (operator){
- case ">":return a1.compareTo(a2) == 1;
- case "<":return a1.compareTo(a2) == -1;
- case ">=":return a1.compareTo(a2) > -1;
- case "<=":return a1.compareTo(a2) < 1;
- case "!=":return a1.compareTo(a2) != 0;
- case "==":return a1.compareTo(a2) == 0;
- default:
- break;
- }
- throw new Exception("非法运算符");
- }
- /**
- * 计算后缀表达式
- */
- public BigDecimal calSufExpr(String sufExpr) throws Exception {
- Stack<BigDecimal> stack = new Stack<>();
- Pattern pattern=Pattern.compile("\\(int\\)|-?\\d+(\\.\\d+)?|!=|>=|<=|==|[+\\-*/%><=]");//提取运算符和数字
- Matcher matcher = pattern.matcher(sufExpr);
- BigDecimal result=new BigDecimal("0.0");
- while (matcher.find()){
- String group = matcher.group();
- if(group.matches("[+\\-*/%]")){
- BigDecimal a1 =stack.pop();
- BigDecimal a2 =stack.pop();
- result = cal(a2, a1, group);
- stack.push(result);
- }
- else if(group.equals("(int)")){
- BigDecimal pop = stack.pop();
- BigDecimal bigDecimal = pop.setScale(0, BigDecimal.ROUND_DOWN);
- stack.push(bigDecimal);
- }
- else if(group.matches("!=|>=|<=|==|[><]")){
- BigDecimal a1 =stack.pop();
- BigDecimal a2 =stack.pop();
- stack.push(calBoolean(a2,a1,group)?new BigDecimal(1):new BigDecimal(0));
- }
- else if(group.equals("=")){
- BigDecimal a1 =stack.pop();
- BigDecimal a2 =stack.pop();
- if (a2.compareTo(new BigDecimal(1))==0) {
- stack.push(a1);
- }
- }
- else {//为数字直接压栈
- stack.push(new BigDecimal(group));
- }
- }
- return result;
- }
- /**
- * 边输边查具体地址
- * @param map
- * @return
- */
- @Override
- public List<Map<String, Object>> getRealAddressByLike(Map<String, Object> map) {
- return amsContractTruckPriceMapper.getRealAddressByLike(map);
- }
- @Override
- public int insertInwardPrice(Map<String, Object> mapValue) {
- int i = 0;
- BigDecimal capacityTypeId = DataChange.dataToBigDecimal(mapValue.get("capacityTypeId"));
- BigDecimal lineId = DataChange.dataToBigDecimal(mapValue.get("rangeId"));
- BigDecimal formulaId = DataChange.dataToBigDecimal(mapValue.get("formulaId"));
- BigDecimal priceValue = DataChange.dataToBigDecimal(mapValue.get("priceValue"));
- Date priceDate = new Date((Long)mapValue.get("priceDate"));
- BigDecimal type = DataChange.dataToBigDecimal(mapValue.get("type"));
- BigDecimal oilpriceBase = DataChange.dataToBigDecimal(mapValue.get("oilpriceBase"));
- BigDecimal oilTypeId = DataChange.dataToBigDecimal(mapValue.get("oilTypeId"));
- BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(mapValue.get("oilpriceChangeThreshold"));
- List<Map<String,Object>>mapList = (List<Map<String, Object>>) mapValue.get("mapList");
- AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
- amsContractTransportPrice.setType(type);
- amsContractTransportPrice.setOilpriceBase(oilpriceBase);
- //承运起止点ID
- amsContractTransportPrice.setLineId(lineId);
- amsContractTransportPrice.setOilpriceChangeThreshold(oilpriceChangeThreshold);
- amsContractTransportPrice.setOilTypeId(oilTypeId);
- amsContractTransportPrice.setPriceValue(priceValue);
- amsContractTransportPrice.setPriceDate(priceDate);
- amsContractTransportPrice.setCapacityTypeId(capacityTypeId);
- amsContractTransportPrice.setCargonameId(formulaId);
- //生成主键id
- amsContractTransportPrice.setPriceId(amsContractTruckPriceMapper.selectMaxId());
- amsContractTransportPrice.setInsertUsername("admin");
- amsContractTransportPrice.setInsertTime(new Date());
- amsContractTransportPrice.setUpdateUsername("admin");
- amsContractTransportPrice.setUpdateTime(new Date());
- amsContractTransportPrice.setInsertUpdateRemark("无");
- amsContractTransportPrice.setDeleted(new BigDecimal(0));
- i = amsContractTruckPriceMapper.insertSelective(amsContractTransportPrice);
- for (Map<String,Object>map:mapList
- ) {
- map.get("materialId");
- AmsContaactPriceMaterial amsContaactPriceMaterial = new AmsContaactPriceMaterial();
- //设置最大主键ID
- amsContaactPriceMaterial.setId(amsContractTruckPriceMapper.selectPriceMaterialMaxId());
- amsContaactPriceMaterial.setMaterialId(DataChange.dataToBigDecimal(map.get("materialId")));
- amsContaactPriceMaterial.setPriceId(amsContractTransportPrice.getPriceId());
- amsContaactPriceMaterial.setDeleted(new BigDecimal(0));
- i = amsContaactPriceMaterialMapper.insertSelective(amsContaactPriceMaterial);
- }
- return i;
- }
- @Override
- public List<Map<String, Object>> getInwardContractPrice(Map<String, Object> mapValue) {
- String material="";
- // if (mapValue.get("materialNames")!=null && mapValue.get("materialNames").toString().contains("、")) {
- // material= mapValue.get("materialNames").toString();
- // mapValue.put("materialNames",null);
- // }
- List<Map<String,Object>>mapList = amsContractTruckPriceMapper.getInwardContractPrice(mapValue);
- for (Map<String,Object>map:mapList
- ) {
- List<Map<String,Object>> materialList = amsContaactPriceMaterialMapper.getMaterialName(map);
- String materialNames = "";
- int i = 1;
- for (Map<String,Object>materialMap:materialList
- ) {
- if(i==materialList.size()){
- materialNames = materialNames + materialMap.get("materialName") ;
- }
- else{
- materialNames = materialNames + materialMap.get("materialName") + "、";
- }
- i++;
- }
- map.put("materialNames",materialNames);
- if(((BigDecimal)map.get("type")).intValue() == 2){
- map.put("type","元/吨");
- }else if(((BigDecimal)map.get("type")).intValue() == 5){
- map.put("type","元/小时");
- }else if(((BigDecimal)map.get("type")).intValue() == 6){
- map.put("type","元/趟");
- }
- // if (material!=null &&
- // material.contains("、") &&
- // material.equals(materialNames)) {
- // List<Map<String, Object>> newMapList=new ArrayList<>();
- // newMapList.add(map);
- // return newMapList;
- // }
- }
- return mapList;
- }
- @Override
- public List<Map<String, Object>> selectInwardPrice(Map<String, Object> mapvalue) {
- return amsContractTruckPriceMapper.selectInwardPrice(mapvalue);
- }
- @Override
- public List<Map<String, Object>> getRangePoint(Map<String, Object> mapValue) {
- return amsContractTruckPriceMapper.getRangePoint(mapValue);
- }
- @Override
- public int insertLineNodePoint(Map<String, Object> map) {
- RmsLineNodePoint rmsLineNodePoint = new RmsLineNodePoint();
- BigDecimal rangeId = DataChange.dataToBigDecimal(map.get("rangeId"));
- String loadName = (String)map.get("loadPointName");
- String unloadName = (String)map.get("unloadPointName");
- rmsLineNodePoint.setId(rmsLineNodePointMapper.lineMaxId());
- rmsLineNodePoint.setTransRangeId(rangeId);
- rmsLineNodePoint.setLoadPointName(loadName);
- rmsLineNodePoint.setUnloadPointName(unloadName);
- rmsLineNodePoint.setDeleted(new BigDecimal(0));
- int i = rmsLineNodePointMapper.insertSelective(rmsLineNodePoint);
- return i;
- }
- @Override
- public int updatePriceById(Map<String, Object> map) {
- int count = 0;
- //获取单价ID
- BigDecimal priceId = DataChange.dataToBigDecimal(map.get("priceId"));
- //获取物资详ID
- List<Map<String, Object>> materialTypeList = (List<Map<String,Object>>)map.get("materialTypeList");
- for (Map<String,Object> materialTypeMap:materialTypeList){
- }
- return count;
- }
- @Override
- public int updatePriceByPriceId(Map<String, Object> mapValue){
- int i = 0;
- BigDecimal capacityTypeId = DataChange.dataToBigDecimal(mapValue.get("capacityTypeId"));
- BigDecimal lineId = DataChange.dataToBigDecimal(mapValue.get("rangeId"));
- BigDecimal formulaId = DataChange.dataToBigDecimal(mapValue.get("cargonameId"));
- BigDecimal priceValue = DataChange.dataToBigDecimal(mapValue.get("priceValue"));
- Date priceDate = new Date((Long)mapValue.get("priceDate"));
- BigDecimal type = DataChange.dataToBigDecimal(mapValue.get("type"));
- BigDecimal oilpriceBase = DataChange.dataToBigDecimal(mapValue.get("oilpriceBase"));
- // BigDecimal oilTypeId = DataChange.dataToBigDecimal(mapValue.get("oilTypeId"));
- BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(mapValue.get("oilpriceChangeThreshold"));
- List<Map<String,Object>>mapList = (List<Map<String, Object>>) mapValue.get("mapList");
- BigDecimal priceId=DataChange.dataToBigDecimal(mapValue.get("priceId"));
- AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
- amsContractTransportPrice.setOilpriceBase(oilpriceBase);
- // amsContractTransportPrice.setOilTypeId(oilTypeId); 油品名称
- amsContractTransportPrice.setPriceValue(priceValue);
- amsContractTransportPrice.setPriceDate(priceDate);
- amsContractTransportPrice.setCargonameId(formulaId);
- amsContractTransportPrice.setPriceId(priceId);
- amsContractTransportPrice.setUpdateTime(new Date());
- i = amsContractTruckPriceMapper.updateByPrimaryKeySelective(amsContractTransportPrice);
- // 根据priceId先查询之前是否有物资
- // 如果有,但是接受的没有就删除
- List<Map<String, Object>> selectwz = amsContractTruckPriceMapper.selectwz(mapValue);
- if (!selectwz.isEmpty() && mapList.isEmpty()){
- i = amsContaactPriceMaterialMapper.deletePriceByPriceId(mapValue.get("priceId").toString());
- }
- //把之前的全删了,然后新增
- if (mapList!=null && mapList.size()>0) {
- i = amsContaactPriceMaterialMapper.deletePriceByPriceId(mapValue.get("priceId").toString());
- }
- for (Map<String,Object>map:mapList
- ) {
- //新增
- AmsContaactPriceMaterial amsContaactPriceMaterial = new AmsContaactPriceMaterial();
- //设置最大主键ID
- amsContaactPriceMaterial.setId(amsContractTruckPriceMapper.selectPriceMaterialMaxId());
- amsContaactPriceMaterial.setMaterialId(DataChange.dataToBigDecimal(map.get("materialId")));
- amsContaactPriceMaterial.setPriceId(amsContractTransportPrice.getPriceId());
- amsContaactPriceMaterial.setDeleted(new BigDecimal(0));
- i = amsContaactPriceMaterialMapper.insertSelective(amsContaactPriceMaterial);
- }
- return i;
- }
- @Override
- public List<Map<String, Object>> getwz(Map<String, Object> map){
- List<Map<String, Object>> selectwz = amsContractTruckPriceMapper.selectwz(map);
- return selectwz;
- }
- @Override
- public Map<String, Object> getcargonameId(Map<String, Object> map) {
- Map<String, Object> value = amsContractTruckPriceMapper.getcargonameId(map);
- return value;
- }
- @Override
- public int updateDCodd() {
- return amsContractTruckPriceMapper.updateDCodd();
- }
- @Override
- public int updateDCnew() {
- return amsContractTruckPriceMapper.updateDCnew();
- }
- @Transactional
- @Override
- public int insertInwardPriceExcel(Map<String,Object> mapValue){
- int i=0;
- try{
- Object rowsList = mapValue.get("rowsList");
- ArrayList arrayList = (ArrayList) rowsList;
- //先查询在单价表之前是否有记录,有则禁用
- for (Object map : arrayList) {
- //查询收货地址
- Map entity = (Map)map;
- if (entity.get("addressDistrict")!=null){
- if (entity.get("addressDistrict").toString().contains("区") || entity.get("addressDistrict").toString().contains("县")){
- entity.put("addressDistrict","重庆");
- }
- }
- //查询收货地址
- List<String> selectshdz = amsContractTruckPriceMapper.selectshdz(entity);
- //录入收货地址
- if (selectshdz==null) {
- entity.put("addressId",amsContractTruckPriceMapper.selectMaxIdrra()+1);
- amsContractTruckPriceMapper.insertshdz(entity);
- }
- Map<String, Object> selectxxdz=new HashMap<>();
- //查询详细地址
- if (selectshdz!=null && selectshdz.size()>0) {
- entity.put("addressId",selectshdz);
- selectxxdz = amsContractTruckPriceMapper.selectxxdz(entity);
- }
- if (selectxxdz!=null && selectxxdz.get("placeId")!=null) {
- i = amsContractTruckPriceMapper.updateDelectByPlaceId(selectxxdz);
- }
- //录入详细地址
- if (selectxxdz==null){
- entity.put("placeId",amsContractTruckPriceMapper.selectMaxIdrrp()+1);
- entity.put("addressId",DataChange.dataToBigDecimal(entity.get("addressId").toString().replace("[","").replace("]","")));
- amsContractTruckPriceMapper.insertxxdz(entity);
- }
- //生成主键id
- AmsContractTransportPrice amsContractTransportPrice = new AmsContractTransportPrice();
- amsContractTransportPrice.setPriceId(amsContractTruckPriceMapper.selectMaxId());
- amsContractTransportPrice.setInsertUsername("admin");
- amsContractTransportPrice.setInsertTime(new Date());
- amsContractTransportPrice.setUpdateUsername("admin");
- amsContractTransportPrice.setUpdateTime(new Date());
- amsContractTransportPrice.setInsertUpdateRemark("无");
- amsContractTransportPrice.setDeleted(new BigDecimal(0));
- SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
- Date priceDate = dateformat.parse("2022-9-26");
- amsContractTransportPrice.setPriceDate(priceDate);
- if(selectxxdz!=null && selectxxdz.get("placeId")!=null){
- amsContractTransportPrice.setPlaceId(DataChange.dataToBigDecimal(selectxxdz.get("placeId")));
- }else if(entity!=null && entity.get("placeId")!=null){
- amsContractTransportPrice.setPlaceId(DataChange.dataToBigDecimal(entity.get("placeId")));
- }
- amsContractTransportPrice.setHaulDistance(DataChange.dataToBigDecimal(entity.get("haulDistance")));
- amsContractTransportPrice.setPriceValue(DataChange.dataToBigDecimal(entity.get("priceValue")));
- amsContractTransportPrice.setPriceTonKilometer(DataChange.dataToBigDecimal(entity.get("priceTonKilometer")));
- if (entity!=null && entity.get("carrierAbbreviation")!=null){
- String cys= entity.get("carrierAbbreviation").toString();
- if (cys!=null) {
- Map<String, Object> selectcys=new HashMap<>();
- if(cys.contains("/")){
- String[] cyss = cys.split("/");
- for (int j = 0; j < cyss.length; j++) {
- selectcys = amsContractTruckPriceMapper.selectcys(cyss[j]);
- if (selectcys!=null && selectcys.get("carrierId")!=null) {
- amsContractTransportPrice.setCarrierId(DataChange.dataToBigDecimal(selectcys.get("carrierId")));//承运商id
- }
- }
- }else{
- selectcys = amsContractTruckPriceMapper.selectcys(cys);
- amsContractTransportPrice.setCarrierId(DataChange.dataToBigDecimal(selectcys.get("carrierId")));//承运商id
- }
- }
- }
- if (entity!=null && entity.get("yes")!=null) {
- if (entity.get("yes").toString().equals("1")){
- //中标合同
- amsContractTransportPrice.setReferenceHt(DataChange.dataToBigDecimal(1));
- }else{
- //库存
- amsContractTransportPrice.setInventory(DataChange.dataToBigDecimal(1));
- }
- }
- i = amsContractTruckPriceMapper.insertSelective(amsContractTransportPrice);
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- return i;
- }
- }
|