123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- package com.steerinfo.dil.service.impl;
- import com.steerinfo.dil.mapper.AmsContaactPriceMaterialMapper;
- import com.steerinfo.dil.mapper.AmsContractTruckPriceMapper;
- import com.steerinfo.dil.mapper.RmsReceivePlaceMapper;
- import com.steerinfo.dil.model.AmsContaactPriceMaterial;
- import com.steerinfo.dil.model.AmsContractTransportPrice;
- import com.steerinfo.dil.model.RmsReceivePlace;
- import com.steerinfo.dil.service.IAmsContractTruckPriceService;
- import com.steerinfo.dil.util.DataChange;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- import java.util.Stack;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- @Service(value = "amsContractTruckPriceService")
- public class AmsContractTruckPriceServiceImpl implements IAmsContractTruckPriceService {
- @Autowired
- private AmsContractTruckPriceMapper amsContractTruckPriceMapper;
- @Autowired
- RmsReceivePlaceMapper rmsReceivePlaceMapper;
- @Autowired
- AmsContaactPriceMaterialMapper amsContaactPriceMaterialMapper;
-
- @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);
-
- 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);
-
- 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) {
-
- 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();
- }
-
- @Override
- @Transactional
- public int batchUpdateTransportPriceByOilPrice(Map<String,Object> map) {
-
- int i = 0;
-
- BigDecimal oilTypeId = DataChange.dataToBigDecimal(map.get("oilTypeId"));
-
- BigDecimal newOilPrice = DataChange.dataToBigDecimal(map.get("newOilPrice"));
-
- List<Map<String, Object>> PriceValueList = amsContractTruckPriceMapper.getPriceValueList(oilTypeId);
- for (Map<String, Object> stringObjectMap : PriceValueList) {
-
- BigDecimal oilpriceBase = DataChange.dataToBigDecimal(stringObjectMap.get("oilpriceBase"));
-
- BigDecimal oilpriceChangeThreshold = DataChange.dataToBigDecimal(stringObjectMap.get("oilpriceChangeThreshold"));
-
- BigDecimal n = (newOilPrice.subtract(oilpriceBase)).divide(oilpriceBase,4,4);
-
- if(n.abs().doubleValue()>oilpriceChangeThreshold.doubleValue()){
- i+=addANewAmsContractTransportPrice(stringObjectMap,n,newOilPrice);
- }
- }
- return i;
-
- }
-
- @Transactional
- public int addANewAmsContractTransportPrice(Map<String, Object> stringObjectMap,BigDecimal n,BigDecimal newOilPrice){
-
- BigDecimal nowPriceValue;
-
- AmsContractTransportPrice oldAmsContractTransportPrice = new AmsContractTransportPrice();
-
-
- 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 Date());
-
- amsContractTransportPrice.setInsertUsername("admin");
- amsContractTransportPrice.setInsertTime(new Date());
- amsContractTransportPrice.setUpdateUsername("admin");
- amsContractTransportPrice.setUpdateTime(new Date());
- amsContractTransportPrice.setInsertUpdateRemark("无");
-
- amsContractTransportPrice.setDeleted(new BigDecimal(0));
-
- BigDecimal formulaId = DataChange.dataToBigDecimal(stringObjectMap.get("cargonameId"));
- amsContractTransportPrice.setCargonameId(formulaId);
- try {
- nowPriceValue = UpdatePureBenzenePriceValueByOilPrice(n.toString(),amsContractTransportPrice.getPriceValue(),formulaId);
-
- nowPriceValue = nowPriceValue.divide(new BigDecimal(1),2,4);
-
- amsContractTransportPrice.setPriceValue(nowPriceValue);
-
- amsContractTransportPrice.setOilpriceBase(newOilPrice);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- int insert = amsContractTruckPriceMapper.insert(amsContractTransportPrice);
- return insert;
- }
-
- 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);
- }
-
- 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;
- }
-
- @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);
-
- amsContractTransportPrice.setLineId(lineId);
- amsContractTransportPrice.setOilpriceChangeThreshold(oilpriceChangeThreshold);
- amsContractTransportPrice.setOilTypeId(oilTypeId);
- amsContractTransportPrice.setPriceValue(priceValue);
- amsContractTransportPrice.setPriceDate(priceDate);
- amsContractTransportPrice.setCapacityTypeId(capacityTypeId);
- amsContractTransportPrice.setCargonameId(formulaId);
-
- 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();
-
- amsContaactPriceMaterial.setId(amsContractTruckPriceMapper.selectPriceMaterialMaxId());
- amsContaactPriceMaterial.setMaterialId(DataChange.dataToBigDecimal(map.get("materialId")));
- amsContaactPriceMaterial.setPriceId(amsContractTransportPrice.getPriceId());
- i = amsContaactPriceMaterialMapper.insertSelective(amsContaactPriceMaterial);
- }
- return i;
- }
- @Override
- public List<Map<String, Object>> getInwardContractPrice(Map<String, Object> mapValue) {
- List<Map<String,Object>>mapList = amsContractTruckPriceMapper.getInwardContractPrice(mapValue);
- for (Map<String,Object>map:mapList
- ) {
- List<Map<String,Object>> materialList = amsContaactPriceMaterialMapper.getMaterialName(DataChange.dataToBigDecimal(map.get("priceId")));
- 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","元/趟");
- }
- }
- return mapList;
- }
- @Override
- public List<Map<String, Object>> selectInwardPrice(Map<String, Object> mapvalue) {
- return amsContractTruckPriceMapper.selectInwardPrice(mapvalue);
- }
- }
|