Merge branch 'order' of http://139.159.177.244:3000/hurui/hai-server into order
commit
0d5392af05
File diff suppressed because one or more lines are too long
@ -0,0 +1,94 @@ |
||||
package com.bweb.controller.OrderStatistics; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.bweb.controller.ApiProductController; |
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.common.security.SessionObject; |
||||
import com.hai.common.security.UserCenter; |
||||
import com.hai.common.utils.ResponseMsgUtil; |
||||
import com.hai.model.ResponseData; |
||||
import com.hai.model.UserInfoModel; |
||||
import com.hai.service.OrderStatisticsService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/homeOrderStatistics") |
||||
@Api(value = "首页订单统计") |
||||
public class HomeOrderStatisticsController { |
||||
|
||||
Logger log = LoggerFactory.getLogger(ApiProductController.class); |
||||
|
||||
@Resource |
||||
private OrderStatisticsService orderStatisticsService; |
||||
|
||||
@Autowired |
||||
private UserCenter userCenter; |
||||
|
||||
@RequestMapping(value = "/orderStatisticsByYMD", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "根据年月日统计订单") |
||||
public ResponseData orderStatisticsByYMD( |
||||
@RequestParam(name = "dateType", required = false) Integer dateType, |
||||
@RequestParam(name = "num", required = false) Integer num, |
||||
HttpServletRequest request) { |
||||
try { |
||||
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
if (userInfoModel.getSecRole().getRoleType() != 1) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂无权限"); |
||||
} |
||||
|
||||
JSONObject object = new JSONObject(); |
||||
object.put("dateType" , dateType); |
||||
object.put("num" , num); |
||||
|
||||
return ResponseMsgUtil.success(orderStatisticsService.orderStatisticsByYMD(object)); |
||||
} catch (Exception e) { |
||||
log.error("HighOrderController --> getBackendToken() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/orderStatisticsByProductType", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "获取订单统计根据年月周日 产品类型相关数据") |
||||
public ResponseData orderStatisticsByProductType( |
||||
@RequestParam(name = "dateType", required = false) Integer dateType, |
||||
HttpServletRequest request) { |
||||
try { |
||||
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
if (userInfoModel.getSecRole().getRoleType() != 1) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂无权限"); |
||||
} |
||||
|
||||
JSONObject object = new JSONObject(); |
||||
object.put("dateType" , dateType); |
||||
|
||||
return ResponseMsgUtil.success(orderStatisticsService.orderStatisticsByProductType(object)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighOrderController --> getBackendToken() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,64 @@ |
||||
package com.hai.dao.order; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import org.apache.ibatis.annotations.Param; |
||||
import org.apache.ibatis.annotations.Select; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @serviceName OrderStatisticsMapperExt.java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description // 订单统计
|
||||
* @createTime 16:11 2022/11/2 |
||||
**/ |
||||
public interface OrderStatisticsMapperExt { |
||||
|
||||
@Select(value = { |
||||
"<script>", |
||||
"SELECT sum(pay_real_price) as sum," + |
||||
"<choose>" + |
||||
"<when test='dateType == 1'>" + |
||||
" DATE_FORMAT(create_time, '%Y-%m-%d') as time FROM high_order where order_status in (2,3) and DATE(create_time) >= DATE_SUB(CURDATE(), INTERVAL #{num} DAY )" + |
||||
"</when>" + |
||||
"<when test='dateType == 3'>" + |
||||
" DATE_FORMAT(create_time, '%Y-%m') as time FROM high_order where order_status in (2,3) and DATE(create_time) >= DATE_SUB(CURDATE(), INTERVAL #{num} MONTH )" + |
||||
"</when>" + |
||||
"<when test='dateType == 4'>" + |
||||
" DATE_FORMAT(create_time, '%Y') as time FROM high_order where order_status in (2,3) and DATE(create_time) >= DATE_SUB(CURDATE() , INTERVAL #{num} YEAR )" + |
||||
"</when>" + |
||||
"<otherwise>" + |
||||
"</otherwise>" + |
||||
"</choose>" + |
||||
" GROUP BY time" + |
||||
"</script>" |
||||
}) |
||||
List<Map<String , Object>> orderStatisticsByYMD(@Param("dateType") Integer dateType, @Param("num") Integer num); |
||||
|
||||
@Select(value = { |
||||
"<script>", |
||||
"SELECT sum(pay_real_price) as value, product_type as name FROM high_order WHERE " + |
||||
"<choose>" + |
||||
"<when test='dateType == 1'>" + |
||||
" TO_DAYS(create_time) = TO_DAYS(NOW()) " + |
||||
"</when>" + |
||||
"<when test='dateType == 2'>" + |
||||
" YEARWEEK(DATE_FORMAT(create_time,'%Y-%m-%d')) = YEARWEEK(NOW())" + |
||||
"</when>" + |
||||
"<when test='dateType == 3'>" + |
||||
" DATE_FORMAT(create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')" + |
||||
"</when>" + |
||||
"<when test='dateType == 4'>" + |
||||
" YEAR(create_time)=YEAR(NOW())" + |
||||
"</when>" + |
||||
"<otherwise>" + |
||||
"</otherwise>" + |
||||
"</choose>" + |
||||
" and order_status in (2,3) GROUP BY product_type; " + |
||||
"</script>" |
||||
}) |
||||
List<Map<String , Object>> orderStatisticsByProductType(@Param("dateType") Integer dateType); |
||||
|
||||
} |
@ -0,0 +1,37 @@ |
||||
package com.hai.service; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @serviceName OrderStatisticsService.java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description // 订单统计接口哦
|
||||
* @createTime 10:00 2022/11/3 |
||||
**/ |
||||
public interface OrderStatisticsService { |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @Name orderStatisticsByYMD |
||||
* @Description // 获取订单统计年月日相关订单数据
|
||||
* @Date 16:28 2022/11/2 |
||||
* @Param [object] |
||||
* @Return com.alibaba.fastjson.JSONObject |
||||
*/ |
||||
List<Map<String , Object>> orderStatisticsByYMD(JSONObject object); |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @Name orderStatisticsByProductType |
||||
* @Description // 获取订单统计根据年月周日 产品类型相关数据
|
||||
* @Date 14:14 2022/11/3 |
||||
* @Param [object] |
||||
* @Return java.util.List<java.util.Map < java.lang.String, java.lang.Object>> |
||||
*/ |
||||
List<Map<String , Object>> orderStatisticsByProductType(JSONObject object); |
||||
|
||||
} |
@ -0,0 +1,27 @@ |
||||
package com.hai.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hai.dao.order.OrderStatisticsMapperExt; |
||||
import com.hai.service.OrderStatisticsService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Service("orderStatisticsService") |
||||
public class OrderStatisticsServiceImpl implements OrderStatisticsService { |
||||
|
||||
@Resource |
||||
private OrderStatisticsMapperExt orderStatisticsMapperExt; |
||||
|
||||
@Override |
||||
public List<Map<String, Object>> orderStatisticsByYMD(JSONObject object) { |
||||
return orderStatisticsMapperExt.orderStatisticsByYMD(object.getInteger("dateType"), object.getInteger("num")); |
||||
} |
||||
|
||||
@Override |
||||
public List<Map<String, Object>> orderStatisticsByProductType(JSONObject object) { |
||||
return orderStatisticsMapperExt.orderStatisticsByProductType(object.getInteger("dateType")); |
||||
} |
||||
} |
Loading…
Reference in new issue