mirror of https://github.com/jeecgboot/jeecg-boot
(WIP) Dashboard package status
parent
84a2043b3e
commit
601a346634
|
@ -5,6 +5,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.modules.system.service.ISysDepartService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
@ -14,10 +17,14 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RequestMapping("/security")
|
||||
@Slf4j
|
||||
public class SecurityController {
|
||||
|
||||
@Autowired
|
||||
private ISysDepartService sysDepartService;
|
||||
@Autowired
|
||||
private Environment env;
|
||||
@GetMapping(value = "/isEmployee")
|
||||
public Result<?> checkIsEmployee () {
|
||||
String companyOrgCode = sysDepartService.queryCodeByDepartName(env.getProperty("company.orgName"));
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
return Result.ok(!sysUser.getOrgCode().contains("A04"));
|
||||
return Result.ok(sysUser.getOrgCode().equals(companyOrgCode));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,10 @@ import org.apache.shiro.SecurityUtils;
|
|||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.modules.business.service.DashboardService;
|
||||
import org.jeecg.modules.system.service.ISysDepartService;
|
||||
import org.jeecg.modules.system.service.impl.SysBaseApiImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
@ -24,9 +26,13 @@ import java.util.Map;
|
|||
@RequestMapping("/admin")
|
||||
@Slf4j
|
||||
public class AdminController {
|
||||
|
||||
@Autowired private DashboardService dashboardService;
|
||||
@Autowired private SysBaseApiImpl sysBaseApi;
|
||||
@Autowired private ISysDepartService sysDepartService;
|
||||
@Autowired private Environment env;
|
||||
|
||||
private final Integer PERIOD = 5;
|
||||
|
||||
@GetMapping(value = "/kpis")
|
||||
public Result<?> kpis(@RequestParam(value = "period", required = false) String period) {
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
|
@ -40,7 +46,21 @@ public class AdminController {
|
|||
start = LocalDateTime.now(ZoneId.of(ZoneId.SHORT_IDS.get("CTT"))).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||
}
|
||||
Map<String, ?> kpiMap = dashboardService.getKpis(start, end, roles, sysUser.getUsername());
|
||||
|
||||
System.gc();
|
||||
return Result.ok(kpiMap);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/packageStatuses")
|
||||
public Result<?> packageStatuses() {
|
||||
String companyOrgCode = sysDepartService.queryCodeByDepartName(env.getProperty("company.orgName"));
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
String orgCode = sysUser.getOrgCode();
|
||||
if(!companyOrgCode.equals(orgCode)){
|
||||
log.info("User {}, tried to access /admin/packageStatuses but is not authorized.", sysUser.getUsername());
|
||||
return Result.error(403,"Not authorized to view this page.");
|
||||
}
|
||||
Map<String, ?> packageStatuses = dashboardService.getPackageStatuses(PERIOD);
|
||||
|
||||
return Result.ok(packageStatuses);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package org.jeecg.modules.business.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @Description: parce status
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-04-18
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("parcel_status")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="parcel_status对象", description="parce status")
|
||||
public class ParcelStatus implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**主键*/
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
@ApiModelProperty(value = "主键")
|
||||
private java.lang.String id;
|
||||
/**创建人*/
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private java.lang.String createBy;
|
||||
/**创建日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "创建日期")
|
||||
private java.util.Date createTime;
|
||||
/**更新人*/
|
||||
@ApiModelProperty(value = "更新人")
|
||||
private java.lang.String updateBy;
|
||||
/**更新日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "更新日期")
|
||||
private java.util.Date updateTime;
|
||||
/**name*/
|
||||
@Excel(name = "name", width = 15)
|
||||
@ApiModelProperty(value = "name")
|
||||
private java.lang.String name;
|
||||
/**value*/
|
||||
@Excel(name = "value", width = 15)
|
||||
@ApiModelProperty(value = "value")
|
||||
private java.lang.String status;
|
||||
/**transporter api*/
|
||||
@Excel(name = "transporter api", width = 15)
|
||||
@ApiModelProperty(value = "transporter api")
|
||||
private java.lang.String api;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package org.jeecg.modules.business.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.modules.business.entity.ParcelStatus;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @Description: parce status
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-04-18
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Repository
|
||||
public interface ParcelStatusMapper extends BaseMapper<ParcelStatus> {
|
||||
}
|
|
@ -4,12 +4,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.modules.business.entity.*;
|
||||
import org.jeecg.modules.business.vo.InvoiceKpi;
|
||||
import org.jeecg.modules.business.vo.ParcelInfos;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 物流发票
|
||||
|
@ -28,4 +26,6 @@ public interface ShippingInvoiceMapper extends BaseMapper<ShippingInvoice> {
|
|||
InvoiceKpi countShippingInvoices(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end, @Param("showAllData") boolean showAllData, @Param("username") String username);
|
||||
void setPaid(@Param("invoiceNumbers") List<String> invoiceNumbers);
|
||||
Client getClientByInvoiceNumber(@Param("invoiceNumber") String invoiceNumber);
|
||||
|
||||
List<ParcelInfos> getPackageStatusInPeriod(@Param("period") int period);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.business.mapper.ParcelStatusMapper">
|
||||
</mapper>
|
|
@ -71,4 +71,35 @@
|
|||
JOIN shipping_invoice s ON s.client_id = c.id
|
||||
WHERE s.invoice_number = #{invoiceNumber}
|
||||
</select>
|
||||
<select id="getPackageStatusInPeriod" resultType="org.jeecg.modules.business.vo.ParcelInfos">
|
||||
WITH latest_parcel_trace_time AS (
|
||||
SELECT parcel_id, MAX(parcel_trace.create_time) AS create_time
|
||||
FROM parcel_trace
|
||||
JOIN parcel ON parcel.id = parcel_trace.parcel_id
|
||||
WHERE parcel_trace.create_time BETWEEN DATE_SUB(CURDATE(), INTERVAL #{period} DAY) AND CURDATE()
|
||||
GROUP BY parcel_id
|
||||
ORDER BY create_time DESC
|
||||
), latest_parcel_trace_id AS (
|
||||
SELECT parcel_trace.id
|
||||
FROM parcel_trace
|
||||
JOIN latest_parcel_trace_time
|
||||
WHERE parcel_trace.create_time = latest_parcel_trace_time.create_time
|
||||
AND parcel_trace.parcel_id = latest_parcel_trace_time.parcel_id
|
||||
)
|
||||
SELECT
|
||||
IFNULL(parcel_status.status, 'IN TRANSIT') as status,
|
||||
tracking_number as tracking_number,
|
||||
platform_order_id as platform_order_id
|
||||
FROM platform_order
|
||||
JOIN parcel ON parcel.third_bill_code = platform_order.tracking_number
|
||||
JOIN parcel_trace ON parcel_trace.parcel_id = parcel.id
|
||||
LEFT JOIN
|
||||
parcel_status ON parcel_status.name = parcel_trace.trace_status
|
||||
WHERE shipping_time BETWEEN DATE_SUB(CURDATE(), INTERVAL #{period} DAY) AND CURDATE()
|
||||
AND tracking_number IS NOT NULL
|
||||
AND erp_status IN (3,4)
|
||||
AND parcel_trace.id IN (SELECT id FROM latest_parcel_trace_id)
|
||||
</select>
|
||||
<select id="gpt">
|
||||
</select>
|
||||
</mapper>
|
|
@ -6,4 +6,6 @@ import java.util.Map;
|
|||
|
||||
public interface DashboardService {
|
||||
Map<String,?> getKpis(LocalDateTime start, LocalDateTime end, List<String> roles, String username);
|
||||
|
||||
Map<String,?> getPackageStatuses(int period);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.jeecg.modules.business.service;
|
||||
|
||||
import org.jeecg.modules.business.entity.ParcelStatus;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: parce status
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-04-18
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface IParcelStatusService extends IService<ParcelStatus> {
|
||||
|
||||
}
|
|
@ -5,9 +5,8 @@ import org.jeecg.modules.business.mapper.PlatformOrderMapper;
|
|||
import org.jeecg.modules.business.mapper.PurchaseOrderMapper;
|
||||
import org.jeecg.modules.business.mapper.ShippingInvoiceMapper;
|
||||
import org.jeecg.modules.business.service.DashboardService;
|
||||
import org.jeecg.modules.business.vo.InvoiceKpi;
|
||||
import org.jeecg.modules.business.vo.Kpi;
|
||||
import org.jeecg.modules.business.vo.OrderKpi;
|
||||
import org.jeecg.modules.business.service.IParcelStatusService;
|
||||
import org.jeecg.modules.business.vo.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -17,7 +16,9 @@ import java.time.LocalDateTime;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static java.util.stream.Collectors.*;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
|
@ -75,4 +76,19 @@ public class DashboardServiceImpl implements DashboardService {
|
|||
kpis.put("platformOrders", platformOrders);
|
||||
return kpis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ParcelQtyAndInfos> getPackageStatuses(int period) {
|
||||
List<ParcelInfos> packageStatusesAndTracking = shippingInvoiceMapper.getPackageStatusInPeriod(period);
|
||||
System.out.println("got package statuses");
|
||||
System.out.println(packageStatusesAndTracking);
|
||||
return packageStatusesAndTracking.stream().collect(
|
||||
groupingBy(ParcelInfos::getStatus, mapping(Function.identity(), toList()))).entrySet().stream().collect(
|
||||
toMap(Map.Entry::getKey, e -> {
|
||||
ParcelQtyAndInfos parcelQtyAndInfos = new ParcelQtyAndInfos();
|
||||
parcelQtyAndInfos.setQuantity(e.getValue().size());
|
||||
parcelQtyAndInfos.setParcelInfos(e.getValue());
|
||||
return parcelQtyAndInfos;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package org.jeecg.modules.business.service.impl;
|
||||
|
||||
import org.jeecg.modules.business.entity.ParcelStatus;
|
||||
import org.jeecg.modules.business.mapper.ParcelStatusMapper;
|
||||
import org.jeecg.modules.business.service.IParcelStatusService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: parce status
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-04-18
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class ParcelStatusServiceImpl extends ServiceImpl<ParcelStatusMapper, ParcelStatus> implements IParcelStatusService {
|
||||
@Autowired
|
||||
ParcelStatusMapper parcelStatusMapper;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.jeecg.modules.business.vo;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ParcelInfos {
|
||||
@JSONField(name = "tracking_number")
|
||||
private String trackingNumbers;
|
||||
@JSONField(name = "platform_order_id")
|
||||
private String platformOrderIds;
|
||||
@JSONField(name = "status")
|
||||
private String status;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.jeecg.modules.business.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ParcelQtyAndInfos {
|
||||
private Integer quantity;
|
||||
private List<ParcelInfos> parcelInfos;
|
||||
}
|
|
@ -160,7 +160,7 @@ spring:
|
|||
slow-sql-millis: 5000
|
||||
datasource:
|
||||
master:
|
||||
url: jdbc:mysql://192.168.31.16:3306/wia_app?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&connectTimeout=5000&socketTimeout=60000
|
||||
url: jdbc:mysql://192.168.31.16:3306/wia_app?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&connectTimeout=5000&socketTimeout=60000&autoReconnect=true&failOverReadOnly=false&maxReconnects=10
|
||||
username: admin
|
||||
password: WIASourcing2023+
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
@ -189,7 +189,7 @@ mybatis-plus:
|
|||
table-underline: true
|
||||
configuration:
|
||||
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
|
||||
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
# 返回类型为Map,显示null对应的字段
|
||||
call-setters-on-nulls: true
|
||||
#jeecg专用配置
|
||||
|
|
Loading…
Reference in New Issue