Commit be3163e1 by 高晓磊

价格趋势图调整

parent 947c41bc
......@@ -18,6 +18,18 @@ public class PriceAdjustmentEchartSearchEntity {
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date adjustmentEndDate;
/**
* 0 日 1月 2年
*/
private Integer dateType;
public Integer getDateType() {
return dateType;
}
public void setDateType(Integer dateType) {
this.dateType = dateType;
}
public List<UUID> getStationIds() {
return stationIds;
......
......@@ -31,4 +31,13 @@ public class TimeValue {
public void setValue(Double value) {
this.value = value;
}
public TimeValue(UUID id, Date time, Double value) {
this.id = id;
this.time = time;
this.value = value;
}
public TimeValue() {
}
}
......@@ -14,14 +14,25 @@ import com.xyst.dinas.price.constant.PriceAdjustmentConstant;
import com.xyst.dinas.price.dao.PriceAdjustmentDao;
import com.xyst.dinas.price.entity.*;
import com.xyst.dinas.price.enumeration.PriceAdjustmentAdjustmentStatusEnum;
import org.hibernate.criterion.*;
import org.apache.commons.lang3.time.DateUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.query.Query;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author scol
......@@ -106,7 +117,7 @@ public class PriceAdjustmentDaoImpl extends AbstractBaseDao implements PriceAdju
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
detachedCriteria.add(Restrictions.eq(BaseConstants.DEL, false));
detachedCriteria.add(Restrictions.in("station.id", id));
detachedCriteria.add(Restrictions.in("applyStatus", BizProcessState.IN_PROCESS.getValue()));
detachedCriteria.add(Restrictions.in("applyStatus", BizProcessState.IN_PROCESS.getValue(),BizProcessState.DONE_WITH_REJECT.getValue()));
detachedCriteria.addOrder(Order.desc("adjustmentDate"));
List<KObject> byCriteria = (List<KObject>) template.findByCriteria(detachedCriteria, 0, 1);
return byCriteria;
......@@ -160,6 +171,22 @@ public class PriceAdjustmentDaoImpl extends AbstractBaseDao implements PriceAdju
@Override
public List<PriceAdjustmentEchartReturnEntity> getDetailsByFilter(PriceAdjustmentEchartSearchEntity priceAdjustmentEchartSearchEntity) {
Date adjustmentEndDate = priceAdjustmentEchartSearchEntity.getAdjustmentEndDate();
Date adjustmentStartDate = priceAdjustmentEchartSearchEntity.getAdjustmentStartDate();
if(priceAdjustmentEchartSearchEntity.getDateType()==null||priceAdjustmentEchartSearchEntity.getDateType()==0){
adjustmentEndDate = priceAdjustmentEchartSearchEntity.getAdjustmentEndDate();
adjustmentStartDate = priceAdjustmentEchartSearchEntity.getAdjustmentStartDate();
}else if(priceAdjustmentEchartSearchEntity.getDateType()==1){
adjustmentEndDate = DateTimeUtils.getEndDateTimeOfMonth(adjustmentEndDate);
adjustmentStartDate = DateTimeUtils.getStartDateTimeOfDay(adjustmentStartDate);
}else if(priceAdjustmentEchartSearchEntity.getDateType()==2){
adjustmentEndDate = DateTimeUtils.getYearEnd(adjustmentEndDate);
adjustmentStartDate = DateTimeUtils.getYearStart(adjustmentStartDate);
}
if(adjustmentEndDate!=null&&adjustmentEndDate.after(new Date())){
adjustmentEndDate=new Date();
}
KClass bean = Amino.getStaticMetadataContext().getBean(PriceAdjustmentConstant.DETAIL_ENTITY, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
......@@ -183,13 +210,13 @@ public class PriceAdjustmentDaoImpl extends AbstractBaseDao implements PriceAdju
.add(Projections.alias(Projections.property("id"), "adjustmentId"))
.add(Projections.alias(Projections.property("dinasPrice"), "value")));
if (null != priceAdjustmentEchartSearchEntity.getAdjustmentEndDate()) {
detachedCriteria.add(Restrictions.le("adjustmentDate", priceAdjustmentEchartSearchEntity.getAdjustmentEndDate()));
if (null != adjustmentEndDate) {
detachedCriteria.add(Restrictions.le("adjustmentDate", adjustmentEndDate));
}
if (null != priceAdjustmentEchartSearchEntity.getAdjustmentStartDate()) {
if (null != adjustmentStartDate) {
detachedCriteria.add(
Restrictions.or(
Restrictions.ge("adjustmentEndDate", priceAdjustmentEchartSearchEntity.getAdjustmentStartDate()), Restrictions.isNull("adjustmentEndDate")));
Restrictions.ge("adjustmentEndDate", adjustmentStartDate), Restrictions.isNull("adjustmentEndDate")));
}
if (!CollectionUtils.isEmpty(priceAdjustmentEchartSearchEntity.getRegionalCompanyIds())) {
detachedCriteria.add(Restrictions.in("regionalCompany.id", priceAdjustmentEchartSearchEntity.getRegionalCompanyIds()));
......@@ -201,7 +228,7 @@ public class PriceAdjustmentDaoImpl extends AbstractBaseDao implements PriceAdju
detachedCriteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
List<HashMap<String, Object>> byCriteria = (List<HashMap<String, Object>>) template.findByCriteria(detachedCriteria);
return getPriceAdjustmentEchartReturnEntities(byCriteria, priceAdjustmentEchartSearchEntity.getAdjustmentStartDate(), priceAdjustmentEchartSearchEntity.getAdjustmentEndDate());
return getPriceAdjustmentEchartReturnEntities(byCriteria, adjustmentStartDate, adjustmentEndDate);
}
@Override
......@@ -229,14 +256,14 @@ public class PriceAdjustmentDaoImpl extends AbstractBaseDao implements PriceAdju
template.execute(session -> {
Query query = session.createQuery("update " + DETAIL_ENTITY + " as a SET a.adjustmentEndDate =:adjustmentEndDate WHERE a.id IN (:ids)");
query.setParameter("adjustmentEndDate", date);
query.setParameter("adjustmentEndDate", DateUtils.addDays(date ,-1));
query.setParameter("ids", noOverPriceDetail);
return query.executeUpdate();
});
template.execute(session -> {
Query query = session.createQuery("update " + ENTITY + " as a SET a.adjustmentEndDate =:adjustmentEndDate,a.adjustmentStatus=:adjustmentStatus WHERE a.id IN (:ids) ");
query.setParameter("adjustmentEndDate", date);
query.setParameter("adjustmentEndDate", DateUtils.addDays(date ,-1));
query.setParameter("adjustmentStatus", PriceAdjustmentAdjustmentStatusEnum.OVER.getValue());
query.setParameter("ids", masterId);
return query.executeUpdate();
......@@ -323,8 +350,7 @@ public class PriceAdjustmentDaoImpl extends AbstractBaseDao implements PriceAdju
.add(Restrictions.ne("master.adjustmentStatus", PriceAdjustmentAdjustmentStatusEnum.ABOLITION.getValue()))
.add(Restrictions.isNull("adjustmentEndDate"))
.add(Restrictions.lt("adjustmentDate", DateTimeUtils.getStartDateTimeOfDay(date)))
.add(Restrictions.in("station.id",toStartStation ))
;
.add(Restrictions.in("station.id",toStartStation ));
detachedCriteria.setProjection(Projections.projectionList().add(Projections.property("id")));
return (List<UUID>) template.findByCriteria(detachedCriteria);
}
......@@ -363,6 +389,9 @@ public class PriceAdjustmentDaoImpl extends AbstractBaseDao implements PriceAdju
List<TimeValue> priceAdjustmentList;
TimeValue priceAdjustment;
HashMap<String, LocalDate> forDate = new HashMap<>(12);
HashMap<String, Double> forValue = new HashMap<>(12);
byCriteria = byCriteria.stream().sorted(Comparator.comparing(a -> (Date) a.get("date"))).collect(Collectors.toList());
for (HashMap<String, Object> byCriterion : byCriteria) {
Object dinasTypeId = byCriterion.get("dinasTypeId");
Object stationId = byCriterion.get("stationId");
......@@ -385,21 +414,98 @@ public class PriceAdjustmentDaoImpl extends AbstractBaseDao implements PriceAdju
priceAdjustmentList = stationDetailEntity.getTimeValues();
Object o = byCriterion.get("date");
Object value = byCriterion.get("value");
priceAdjustment.setId(UUID.fromString(adjustmentId.toString()));
Date o1 = (Date) o;
if (null != adjustmentStartDate && !o1.before(adjustmentStartDate)) {
if (null != adjustmentStartDate && !o1.after(adjustmentStartDate)) {
o1 = adjustmentStartDate;
}
if (null != adjustmentStartDate && o1.after(adjustmentEndDate)) {
if (null != adjustmentStartDate && !o1.before(adjustmentEndDate)) {
o1 = adjustmentEndDate;
}
priceAdjustment.setTime(o1);
priceAdjustment.setValue(Double.valueOf(value.toString()));
priceAdjustmentList.add(priceAdjustment);
ArrayList<TimeValue> newTimeValue = setEveryDayValue(adjustmentStartDate, forDate, forValue, dinasTypeId, stationId, adjustmentId, (Date) o, (BigDecimal) value);
if (newTimeValue != null) {
priceAdjustmentList.addAll(priceAdjustmentList.size()-1,newTimeValue);
}
}
if(adjustmentEndDate!=null){
//填充至最后一天的值
setLastDayValue(priceAdjustmentEchartReturnEntities,adjustmentEndDate);
}
return priceAdjustmentEchartReturnEntities;
}
private void setLastDayValue(List<PriceAdjustmentEchartReturnEntity> priceAdjustmentEchartReturnEntities,Date lastDate) {
TimeValue timeValue;
LocalDate lastLocalDate = lastDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
for (PriceAdjustmentEchartReturnEntity priceAdjustmentEchartReturnEntity : priceAdjustmentEchartReturnEntities) {
List<StationDetailEntity> stationDetails = priceAdjustmentEchartReturnEntity.getStationDetails();
for (StationDetailEntity stationDetail : stationDetails) {
List<TimeValue> timeValues = stationDetail.getTimeValues();
int size = timeValues.size();
if(size<1){
continue;
}
timeValue= timeValues.get(size - 1);
Date time = timeValue.getTime();
LocalDate nowDate=time.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
long distance = ChronoUnit.DAYS.between(nowDate, lastLocalDate);
if (distance < 1) {
continue;
}
TimeValue finalTimeValue = timeValue;
nowDate=nowDate.plusDays(1);
Stream.iterate(nowDate, a->a.plusDays(1)).limit(distance).forEach(f-> timeValues.add(new TimeValue(finalTimeValue.getId(),Date.from(f.atStartOfDay(ZoneId.systemDefault()).toInstant()),finalTimeValue.getValue())));
}
}
}
private ArrayList<TimeValue> setEveryDayValue(Date adjustmentStartDate, HashMap<String, LocalDate> forDate, HashMap<String, Double> forValue, Object dinasTypeId, Object stationId, Object adjustmentId, Date o, BigDecimal value) {
Double startValue;
LocalDate startDate;
//值填充到每一天
LocalDate nowDate = o.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
if(forDate.containsKey(dinasTypeId.toString() + stationId)){
startDate= forDate.get(dinasTypeId + stationId.toString());
startValue= forValue.get(dinasTypeId + stationId.toString());
}else{
if(null != adjustmentStartDate){
startDate = adjustmentStartDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}else{
startDate = nowDate;
}
startValue= value.doubleValue();
}
forDate.put(dinasTypeId + stationId.toString(),nowDate);
forValue.put(dinasTypeId + stationId.toString(),value.doubleValue() );
long distance = ChronoUnit.DAYS.between(startDate, nowDate);
ArrayList<TimeValue> newTimeValue = new ArrayList<>();
Double finalStartValue = startValue;
if (distance < 1) {
return null;
}
startDate=startDate.plusDays(1);
Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance-1).forEach(f -> {
TimeValue timeValue = new TimeValue();
timeValue.setId(UUID.fromString(adjustmentId.toString()));
timeValue.setTime(Date.from(f.atStartOfDay(ZoneId.systemDefault()).toInstant()));
timeValue.setValue(finalStartValue);
newTimeValue.add(timeValue);
});
return newTimeValue;
}
private StationDetailEntity getStationDetailEntity(PriceAdjustmentEchartReturnEntity priceAdjustmentEchartReturnEntity, HashMap<String, StationDetailEntity> stationDetail, HashMap<String, Object> byCriterion, Object stationId) {
StationDetailEntity stationDetailEntity;
if (!stationDetail.containsKey(stationId + priceAdjustmentEchartReturnEntity.getDinasTypeId().toString())) {
......
......@@ -4,11 +4,10 @@ import com.beecode.bap.attachment.common.Page;
import com.beecode.bcp.core.context.AminoContextHolder;
import com.beecode.bcp.type.KObject;
import com.beecode.inz.common.BaseConstants;
import com.beecode.inz.common.util.DateTimeUtils;
import com.beecode.util.DateUtil;
import com.xyst.dinas.price.dao.PriceAdjustmentDao;
import com.xyst.dinas.price.entity.PriceAdjustmentEchartReturnEntity;
import com.xyst.dinas.price.entity.PriceAdjustmentEchartSearchEntity;
import com.xyst.dinas.price.entity.PriceAdjustmentSearchEntity;
import com.xyst.dinas.price.entity.StationDinasTypePriceDetail;
import com.xyst.dinas.price.entity.*;
import com.xyst.dinas.price.enumeration.PriceAdjustmentAdjustmentStatusEnum;
import com.xyst.dinas.price.service.PriceAdjustmentService;
import com.xyst.dinas.price.service.RegionalCompanyPriceAuthorityService;
......@@ -16,10 +15,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Transactional(rollbackFor = Exception.class)
public class PriceAdjustmentServiceImpl implements PriceAdjustmentService {
......@@ -72,7 +72,32 @@ public class PriceAdjustmentServiceImpl implements PriceAdjustmentService {
@Override
public List<PriceAdjustmentEchartReturnEntity> getChartLine(PriceAdjustmentEchartSearchEntity priceAdjustmentEchartSearchEntity) {
return priceAdjustmentDao.getDetailsByFilter(priceAdjustmentEchartSearchEntity);
List<PriceAdjustmentEchartReturnEntity> detailsByFilter = priceAdjustmentDao.getDetailsByFilter(priceAdjustmentEchartSearchEntity);
if(null==priceAdjustmentEchartSearchEntity.getDateType() || priceAdjustmentEchartSearchEntity.getDateType()==0){
return detailsByFilter;
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM");
if(priceAdjustmentEchartSearchEntity.getDateType()==2){
dateFormat= new SimpleDateFormat("yyyy");
}
SimpleDateFormat finalDateFormat = dateFormat;
for (PriceAdjustmentEchartReturnEntity priceAdjustmentEchartReturnEntity : detailsByFilter) {
List<StationDetailEntity> stationDetails = priceAdjustmentEchartReturnEntity.getStationDetails();
for (StationDetailEntity stationDetail : stationDetails) {
List<TimeValue> timeValues = stationDetail.getTimeValues();
ArrayList<TimeValue> timeValues2 = new ArrayList<>();
Map<String, List<TimeValue>> collect = timeValues.stream().collect(Collectors.groupingBy(timeValue -> finalDateFormat.format(timeValue.getTime())));
collect.forEach((s, timeValues1) -> {
try {
timeValues2.add(new TimeValue(UUID.randomUUID(),finalDateFormat.parse(s),timeValues1.stream().mapToDouble(TimeValue::getValue).summaryStatistics().getAverage()));
} catch (ParseException e) {
e.printStackTrace();
}
});
stationDetail.setTimeValues(timeValues2);
}
}
return detailsByFilter;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment