Merge branch 'hotfix' into develop

master
eason 6 years ago
commit 69a40a53c6

@ -10,6 +10,9 @@ import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds; import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList; import com.github.miemiedev.mybatis.paginator.domain.PageList;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -26,7 +29,7 @@ import java.util.List;
*/ */
@Service @Service
public class ActChairtyServiceImp implements ActChairtyService { public class ActChairtyServiceImp implements ActChairtyService {
Logger logger = LoggerFactory.getLogger(getClass());
@Resource @Resource
private ClientManager clientManager; private ClientManager clientManager;
@Resource @Resource
@ -64,54 +67,49 @@ public class ActChairtyServiceImp implements ActChairtyService {
public List<JSONObject> getWeekendAnalysis(JSONObject params) { public List<JSONObject> getWeekendAnalysis(JSONObject params) {
List<JSONObject> result = new ArrayList<>(); List<JSONObject> result = new ArrayList<>();
List<JSONObject> getAnalysis = actChairtyMapper.getChairtyWeekAnalysis(params.getDate("begin"), params.getDate("end")); List<JSONObject> getAnalysis = actChairtyMapper.getChairtyWeekAnalysis(params.getDate("begin"), params.getDate("end"));
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd"); DateFormatUtils df = new DateFormatUtils();
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(params.getDate("begin")); cal.setTime(params.getDate("begin"));
cal.add(cal.DAY_OF_MONTH, -1); cal.add(cal.DAY_OF_MONTH, -1);
long beginTime = params.getDate("begin").getTime(); long beginTime = params.getDate("begin").getTime();
long endTime = params.getDate("end").getTime(); long endTime = params.getDate("end").getTime();
long betweenDays = (long)((endTime - beginTime) / (1000 * 60 * 60 *24)); long betweenDays = (long)((endTime - beginTime) / (1000 * 60 * 60 *24));
List<String> weekStart = new ArrayList<String>(); List<String> weekStart = new ArrayList<>();
for(int i=0;i<=betweenDays;i++){ for(int i=0;i<=betweenDays;i++){
cal.add(cal.DAY_OF_MONTH, 1);//DATE=日 cal.add(cal.DAY_OF_MONTH, 1);//DATE=日
if ((cal.get(Calendar.DAY_OF_WEEK)) == 2) { if ((cal.get(Calendar.DAY_OF_WEEK)) == 2) {
weekStart.add(df.format(cal.getTime())); weekStart.add(df.format(cal.getTime(),"yyyy-MM-dd"));
}
} }
for(int i=0;i<weekStart.size();i++){ }
JSONObject weekDay = new JSONObject(); for(int i=0;i<weekStart.size();i++){
BigDecimal count_ordernum = new BigDecimal(0); JSONObject weekDay = new JSONObject();
BigDecimal sum_ordernum = new BigDecimal(0); BigDecimal count_ordernum = new BigDecimal(0);
String weekS = weekStart.get(i); BigDecimal sum_ordernum = new BigDecimal(0);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String weekS = weekStart.get(i);
try { try {
Date dateStar = dateFormat.parse(weekS); Date dateStar = DateUtils.parseDate(weekS,"yyyy-MM-dd");
Calendar d1 = Calendar.getInstance(); Date dateEnd = DateUtils.addDays(dateStar, 7);
d1.setTime(dateStar); for (int b = 0; b < getAnalysis.size(); b++) {
d1.add(Calendar.DAY_OF_YEAR,7); long orderDate = getAnalysis.get(b).getDate("orderdate").getTime();
Date dateEnd = d1.getTime(); if (orderDate >= dateStar.getTime() && orderDate < dateEnd.getTime()) {
for (int b = 0; b < getAnalysis.size(); b++) { count_ordernum = count_ordernum.add(getAnalysis.get(b).getBigDecimal("count_ordernum"));
long orderDate = getAnalysis.get(b).getDate("orderdate").getTime(); sum_ordernum = sum_ordernum.add(getAnalysis.get(b).getBigDecimal("sum_ordernum"));
if (orderDate >= dateStar.getTime() && orderDate < dateEnd.getTime()) {
count_ordernum = count_ordernum.add(getAnalysis.get(b).getBigDecimal("count_ordernum"));
sum_ordernum = sum_ordernum.add(getAnalysis.get(b).getBigDecimal("sum_ordernum"));
}
} }
BigDecimal chairty = new BigDecimal(0.01);
BigDecimal chairty_amount = count_ordernum.multiply(chairty);
double f1 = sum_ordernum.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
double f2 = chairty_amount.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
weekDay.put("weekstart", weekStart.get(i));
weekDay.put("count_ordernum", count_ordernum);
weekDay.put("sum_ordernum", f1);
weekDay.put("chairty_amount",f2 );
result.add(weekDay);
} catch (Exception e) {
e.printStackTrace();
} }
BigDecimal chairty = new BigDecimal(0.01);
BigDecimal chairty_amount = count_ordernum.multiply(chairty);
BigDecimal f1 = sum_ordernum.setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal f2 = chairty_amount.setScale(2, BigDecimal.ROUND_HALF_UP);
weekDay.put("weekstart", weekStart.get(i));
weekDay.put("count_ordernum", count_ordernum);
weekDay.put("sum_ordernum", f1);
weekDay.put("chairty_amount",f2 );
result.add(weekDay);
} catch (Exception e) {
logger.info("Act_Chairty Error:",e);
} }
}
return result; return result;
} }

Loading…
Cancel
Save