|
@@ -26,11 +26,10 @@ import com.szwl.model.excel.CoinOrderTarget;
|
|
|
import com.szwl.model.excel.OrderByAdminTarget;
|
|
|
import com.szwl.model.excel.OrderByClientidTarget;
|
|
|
import com.szwl.model.excel.OrderTarget;
|
|
|
-import com.szwl.model.query.Filter;
|
|
|
-import com.szwl.model.query.Pageable;
|
|
|
-import com.szwl.model.query.StatisticsParam;
|
|
|
-import com.szwl.model.query.TOrderParam;
|
|
|
+import com.szwl.model.query.*;
|
|
|
+import com.szwl.model.utils.DateUtils;
|
|
|
import com.szwl.model.utils.FgObjectUtil;
|
|
|
+import com.szwl.model.utils.JsonUtils;
|
|
|
import com.szwl.service.TAreaService;
|
|
|
import com.szwl.service.TCoinOrderService;
|
|
|
import com.szwl.service.TEquipmentService;
|
|
@@ -40,7 +39,6 @@ import com.szwl.service.es.EsTOrderService;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
-import org.apache.commons.lang.time.DateUtils;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
@@ -661,178 +659,7 @@ public class TOrderController {
|
|
|
.setData(chartColumn)
|
|
|
.setMessage("SUCCESS"));
|
|
|
}
|
|
|
- /**
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- @ApiOperation(value = "机器获取数据统计")
|
|
|
- @PostMapping("/getStatisticsByClientId")
|
|
|
- public ResponseEntity<?> getStatisticsByClientId(@RequestBody StatisticsParam param) {
|
|
|
- TEquipment equipment0 = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
|
|
|
- param.setAdminId(String.valueOf(equipment0.getAdminId()));
|
|
|
- // 判断是否为外国
|
|
|
- param.setIfForeign(isForeignUser(param.getAdminId()));
|
|
|
- log.info("param:{}", param);
|
|
|
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(param.getAdminId()));
|
|
|
- if(admin.getType()<2){
|
|
|
- param.setAdminId(null);
|
|
|
- if(param.getEquipmentId()!=null){
|
|
|
- //查机器
|
|
|
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
|
|
|
- param.setClientId(equipment.getClientId());
|
|
|
- }
|
|
|
- if(StringUtils.isNotEmpty(param.getClientId())){
|
|
|
- //补全clientId
|
|
|
- TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
|
|
|
- param.setClientId(tEquipment.getClientId());
|
|
|
- param.setClientId(tEquipment.getClientId());
|
|
|
- }
|
|
|
- }else {
|
|
|
- if(admin.getType()==2){
|
|
|
- //商家
|
|
|
- if(param.getEquipmentId()!=null&¶m.getEquipmentId()!=""){
|
|
|
- //查机器
|
|
|
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
|
|
|
- param.setClientId(equipment.getClientId());
|
|
|
-
|
|
|
- }
|
|
|
- if(StringUtils.isNotEmpty(param.getClientId())){
|
|
|
- param.setAdminId(null);
|
|
|
- //判断是否是这个商家的
|
|
|
- TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
|
|
|
- if(tEquipment.getAdminId().toString().equals(admin.getId().toString())){
|
|
|
- param.setClientId(tEquipment.getClientId());
|
|
|
- param.setEquipmentId(String.valueOf(tEquipment.getId()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(admin.getType()==3){
|
|
|
- //子账户只能查相对的机器的订单
|
|
|
- //商家子账户
|
|
|
- if(param.getEquipmentId()!=null){
|
|
|
- //查机器
|
|
|
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(param.getEquipmentId()));
|
|
|
- param.setClientId(equipment.getClientId());
|
|
|
-
|
|
|
- }else{
|
|
|
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
|
|
|
- if(adminEquipment.getType().equals("0")){
|
|
|
- TAdmin admin1 = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
|
|
|
- param.setAdminId(admin1.getId().toString());
|
|
|
- }else {
|
|
|
- List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(param.getAdminId()));
|
|
|
- param.setClientIds(list);
|
|
|
- }
|
|
|
- }
|
|
|
- if(StringUtils.isNotEmpty(param.getClientId())){
|
|
|
- param.setAdminId(null);
|
|
|
- //判断是否是这个子账号的
|
|
|
- TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(param.getClientId()));
|
|
|
-
|
|
|
- TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getId())));
|
|
|
- if(adminEquipment.getType().equals("0")){
|
|
|
- TAdmin admin1 = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
|
|
|
- if(tEquipment.getAdminId().toString().equals(admin1.getId())){
|
|
|
- param.setAdminId(null);
|
|
|
- param.setClientId(tEquipment.getClientId());
|
|
|
- param.setEquipmentId(String.valueOf(tEquipment.getId()));
|
|
|
- }
|
|
|
- }else {
|
|
|
- int i = 0;
|
|
|
- List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(param.getAdminId()));
|
|
|
- if(list.size()>0){
|
|
|
- for(String clientID:list){
|
|
|
- if(clientID.equals(tEquipment.getClientId())){
|
|
|
- i++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(i>0){
|
|
|
- param.setClientId(tEquipment.getClientId());
|
|
|
- param.setEquipmentId(String.valueOf(tEquipment.getId()));
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if(StringUtils.isNotEmpty(param.getUsername())){
|
|
|
- if(param.getUsername().equals("all")){
|
|
|
- //商家查全部
|
|
|
- //判断是不是商家账户
|
|
|
- if(admin.getType()==3){
|
|
|
- //查下级账户id集合
|
|
|
- List<Long> list = R.getDataIfSuccess(szwlFeign.getAdminIdList(param.getAdminId()));
|
|
|
- if(list.size()>0){
|
|
|
- param.setAdminIds(list);
|
|
|
- param.setAdminId(null);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- FgObjectUtil.objectNullOrEmptySel(param, "chartType$");
|
|
|
- ChartColumn chartColumn = new ChartColumn();
|
|
|
- if(StringUtils.isNotEmpty(param.getIfForeign())&¶m.getIfForeign().equals("1")){
|
|
|
- if(StringUtils.isNotEmpty(param.getPayType())&¶m.getPayType().equals("all")){
|
|
|
- param.setPayType(null);
|
|
|
- }
|
|
|
- //国外查MYSQL
|
|
|
-
|
|
|
- chartColumn = orderService.getStatistics(param);
|
|
|
- }else{
|
|
|
- //查去年的数据找数据库
|
|
|
- String endDate = param.getEndDate();
|
|
|
- String toYear = "2022-01-01 00:00:00";
|
|
|
- Date date =null;
|
|
|
- Date year = null;
|
|
|
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- try {
|
|
|
- //使用SimpleDateFormat的parse()方法生成Date
|
|
|
- date = sf.parse(endDate);
|
|
|
- year = sf.parse(toYear);
|
|
|
- } catch (ParseException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- if(date.getTime()<year.getTime()){
|
|
|
- chartColumn = orderService.getStatistics(param);
|
|
|
- }else {
|
|
|
- if (ElasticsearchRunner.ES_RUNNING) {
|
|
|
- try {
|
|
|
- // 查es
|
|
|
- chartColumn = esTOrderService.getStatistics(param);
|
|
|
- }catch (Exception e){
|
|
|
- log.error("使用es 查询发生错误:{}",e);
|
|
|
- // 查 mysql
|
|
|
-// chartColumn = tOrderService.getStatistics(param);
|
|
|
- }
|
|
|
- }else{
|
|
|
- // 查 mysql
|
|
|
-// chartColumn = tOrderService.getStatistics(param);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-// if (ElasticsearchRunner.ES_RUNNING) {
|
|
|
-// try {
|
|
|
-// // 查es
|
|
|
-// chartColumn = esTOrderService.getStatistics(param);
|
|
|
-// }catch (Exception e){
|
|
|
-// log.error("使用es 查询发生错误:{}",e);
|
|
|
-// // 查 mysql
|
|
|
-// chartColumn = tOrderService.getStatistics(param);
|
|
|
-// }
|
|
|
-// }else{
|
|
|
-// // 查 mysql
|
|
|
-// chartColumn = tOrderService.getStatistics(param);
|
|
|
-// }
|
|
|
- return ResponseEntity
|
|
|
- .status(HttpStatus.OK)
|
|
|
- .body(new ResultMessage()
|
|
|
- .setCode(true)
|
|
|
- .setData(chartColumn)
|
|
|
- .setMessage("SUCCESS"));
|
|
|
- }
|
|
|
/**
|
|
|
* 统计 机器销售排行
|
|
|
* @param param
|
|
@@ -1750,6 +1577,55 @@ public class TOrderController {
|
|
|
esTOrderService.insertData(order);
|
|
|
return R.ok("同步es成功");
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 线上通过时间分组
|
|
|
+ * @param clientId
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @param unit
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getStatisticsByClientId", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
|
|
|
+ @ResponseBody
|
|
|
+ public Object getStatisticsByClientId(String clientId, String startTime, String endTime, Integer unit) {
|
|
|
+ String date = "";
|
|
|
+ switch (unit) {
|
|
|
+ //按小时计算
|
|
|
+ case 0:
|
|
|
+ date = DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss;
|
|
|
+ break;
|
|
|
+ //按天
|
|
|
+ case 1:
|
|
|
+ date = DateUtils.PATTERN_yyyy_MM_dd;
|
|
|
+ break;
|
|
|
+ //按月
|
|
|
+ case 2:
|
|
|
+ date = DateUtils.PATTERN_yyyy_MM;
|
|
|
+ break;
|
|
|
+ //按年
|
|
|
+ case 3:
|
|
|
+ date = DateUtils.PATTERN_yyyy;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat(date);
|
|
|
+ Date date1 = null;
|
|
|
+ Date date2 = null;
|
|
|
+ try {
|
|
|
+ date1 = format.parse(startTime);
|
|
|
+ date2 = format.parse(endTime);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ List<OrderStatisticsDTO> list = orderService.findByTime(clientId, date1, date2, unit);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("code", 0);
|
|
|
+ jsonObject.put("data", JsonUtils.toJson(list));
|
|
|
+ jsonObject.put("errmsg", "");
|
|
|
+
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取每天的开始时间 00:00:00:00
|
|
|
*
|