增加机构人员统计

This commit is contained in:
yuyang 2022-04-24 14:28:39 +08:00
parent 2f2b2092fd
commit 29ecefa321
10 changed files with 332 additions and 13 deletions

View File

@ -103,6 +103,7 @@ public class SysUserController extends BaseController {
String[] split = username.split("&");
SysUser sysUser = userService.selectUserByUserName(split[0],split[1]);
System.out.println();
if (StringUtils.isNull(sysUser)) {
return R.fail("用户名或密码错误");
}

View File

@ -611,7 +611,7 @@
DATE_FORMAT(ho.end_time,'%H:%i:%s') as timeTwo,
co.status as status,
co.type as type,
ho.StopReasonEvcs as typeName
ho.stop_reason_evcs as typeName
FROM xhpc_history_order as ho
LEFT JOIN xhpc_charging_station as cs on cs.charging_station_id = ho.charging_station_id
LEFT JOIN xhpc_terminal as te on te.terminal_id = ho.terminal_id
@ -879,7 +879,7 @@
(SELECT account from xhpc_customers_personnel where customers_personnel_id = co.user_id and ho.source=3) as customersAccount,
co.Plate_num as plateNum,
(SELECT name from xhpc_internet_user where internet_user_id = co.user_id and co.source =1) as internetName,
ho.StopReasonEvcs as stopReasonRvcsName
ho.stop_reason_evcs as stopReasonRvcsName
from xhpc_history_order ho
left join xhpc_charging_station as ct on ct.charging_station_id = ho.charging_station_id
left join xhpc_operator as op on op.operator_id = ct.operator_id

View File

@ -3,15 +3,21 @@ package com.xhpc.user.controller;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.util.UserTypeUtil;
import com.xhpc.user.service.IXhpcCommonService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* 公共的内
@ -84,6 +90,23 @@ public class XhpcCommonController extends BaseController {
return xhpcCommonService.getMechanismDiscount(userId,userType,tenantId,chargingStationId);
}
/**
* 机构人员统计
*/
@GetMapping(value = "/getPersonnelStatistics")
public TableDataInfo getPersonnelStatistics(Long operatorId, Long chargingStationId, Long chargingPileId, Integer type, String name , String phone, String account) {
List<Map<String, Object>> list = xhpcCommonService.getPersonnelStatistics(operatorId,chargingStationId,chargingPileId,type,name,phone,account);
return getDataTable(list);
}
/**
* 机构人员统计
*/
@PostMapping(value = "/getPersonnelStatisticsExport")
public void getPersonnelStatisticsExport(HttpServletResponse response, Long operatorId, Long chargingStationId, Long chargingPileId, Integer type, String name , String phone, String account)throws IOException {
xhpcCommonService.getPersonnelStatisticsExport(response,operatorId,chargingStationId,chargingPileId,type,name,phone,account);
}

View File

@ -2,6 +2,7 @@ package com.xhpc.user.mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
@ -25,4 +26,7 @@ public interface XhpcCommonMapper {
* B端用户信息
*/
Map<String, Object> getCustomersUser(@Param("phone") String phone,@Param("userId")Long userId,@Param("serialNumber")String serialNumber,@Param("tenantId") String tenantId);
List<Map<String, Object>> getPersonnelStatistics(@Param("operatorId")Long operatorId,@Param("chargingStationId") Long chargingStationId, @Param("chargingPileId")Long chargingPileId, @Param("type")Integer type, @Param("name")String name , @Param("phone")String phone, @Param("account")String account,@Param("number") Integer number,@Param("userId") Long userId,@Param("tenantId")String tenantId);
}

View File

@ -2,7 +2,10 @@ package com.xhpc.user.service;
import com.xhpc.common.core.web.domain.AjaxResult;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
@ -39,4 +42,12 @@ public interface IXhpcCommonService {
*/
AjaxResult getMechanismDiscount(Long userId, Integer userType, String tenantId, Long chargingStationId);
/**
* 根据用户手机号获取用户信息
*/
List<Map<String, Object>> getPersonnelStatistics(Long operatorId, Long chargingStationId, Long chargingPileId, Integer type, String name , String phone, String account);
void getPersonnelStatisticsExport(HttpServletResponse response, Long operatorId, Long chargingStationId, Long chargingPileId, Integer type, String name , String phone, String account)throws IOException;
}

View File

@ -1,7 +1,14 @@
package com.xhpc.user.service.impl;
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.BigExcelWriter;
import cn.hutool.poi.excel.ExcelUtil;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.service.BaseService;
import com.xhpc.common.security.service.TokenService;
import com.xhpc.common.util.UserTypeUtil;
import com.xhpc.system.api.domain.SysUser;
import com.xhpc.system.api.model.LoginUser;
import com.xhpc.user.domain.XhpcCommunityPersonnel;
import com.xhpc.user.domain.XhpcCustomersPersonnel;
import com.xhpc.user.mapper.XhpcCommonMapper;
@ -12,8 +19,14 @@ import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -21,7 +34,7 @@ import java.util.Map;
* @date 2021/12/29 11:11
*/
@Service
public class XhpcCommonServiceImpl implements IXhpcCommonService {
public class XhpcCommonServiceImpl extends BaseService implements IXhpcCommonService {
@Autowired
private XhpcCommonMapper xhpcCommonMapper;
@ -29,7 +42,8 @@ public class XhpcCommonServiceImpl implements IXhpcCommonService {
private IXhpcCommunityService xhpcCommunityService;
@Autowired
private IXhpcCustomersService xhpcCustomersService;
@Autowired
TokenService tokenService;
@Override
public Map<String, Object> getLandUser(String phone,Long userId, Integer type,String serialNumber,String tenantId) {
@ -98,4 +112,90 @@ public class XhpcCommonServiceImpl implements IXhpcCommonService {
return AjaxResult.error();
}
}
/**
* 根据用户手机号获取用户信息
*
* @param operatorId
* @param chargingStationId
* @param chargingPileId
* @param type
* @param name
* @param phone
* @param account
*/
@Override
public List<Map<String, Object>> getPersonnelStatistics(Long operatorId, Long chargingStationId, Long chargingPileId, Integer type, String name, String phone, String account) {
//获取登陆用户
LoginUser loginUser = tokenService.getLoginUser();
SysUser sysUser = loginUser.getSysUser();
String tenantId = loginUser.getTenantId();
Long sysUserId = sysUser.getUserId();
//获取登陆用户
List<Map<String, Object>> list =new ArrayList<>();
if(!UserTypeUtil.SYS_USER_TYPE_ADMIN.equals(sysUser.getUserId())){
startPage();
if(UserTypeUtil.SYS_USER_TYPE_ONE.equals(sysUser.getUserType())){
Long logOperatorId = sysUser.getOperatorId();
//运营商看自己的场站
list = xhpcCommonMapper.getPersonnelStatistics(operatorId, chargingStationId, chargingPileId, type, name,phone,account, 1,logOperatorId,tenantId);
}else{
//查询赋值的场站
list = xhpcCommonMapper.getPersonnelStatistics(operatorId, chargingStationId, chargingPileId, type, name,phone,account, 2,sysUserId,tenantId);
}
}else{
startPage();
list =xhpcCommonMapper.getPersonnelStatistics(operatorId, chargingStationId, chargingPileId, type, name,phone,account, 0,sysUserId,tenantId);
}
return list;
}
@Override
public void getPersonnelStatisticsExport(HttpServletResponse response, Long operatorId, Long chargingStationId, Long chargingPileId, Integer type, String name, String phone, String account) throws IOException {
LoginUser loginUser = tokenService.getLoginUser();
SysUser sysUser = loginUser.getSysUser();
String tenantId = loginUser.getTenantId();
Long sysUserId = sysUser.getUserId();
//获取登陆用户
List<Map<String, Object>> list =new ArrayList<>();
if(!UserTypeUtil.SYS_USER_TYPE_ADMIN.equals(sysUser.getUserId())){
if(UserTypeUtil.SYS_USER_TYPE_ONE.equals(sysUser.getUserType())){
Long logOperatorId = sysUser.getOperatorId();
//运营商看自己的场站
list = xhpcCommonMapper.getPersonnelStatistics(operatorId, chargingStationId, chargingPileId, type, name,phone,account, 1,logOperatorId,tenantId);
}else{
//查询赋值的场站
list = xhpcCommonMapper.getPersonnelStatistics(operatorId, chargingStationId, chargingPileId, type, name,phone,account, 2,sysUserId,tenantId);
}
}else{
list =xhpcCommonMapper.getPersonnelStatistics(operatorId, chargingStationId, chargingPileId, type, name,phone,account, 0,sysUserId,tenantId);
}
// 通过工具类创建writer默认创建xls格式
BigExcelWriter writer = ExcelUtil.getBigWriter("机构人员统计.xlsx");
writer.addHeaderAlias("mechanismName", "机构类型");
writer.addHeaderAlias("account", "机构账号");
writer.addHeaderAlias("name", "用户名称");
writer.addHeaderAlias("phone", "手机号");
writer.addHeaderAlias("number", "充电次数");
writer.addHeaderAlias("totalPower", "充电度数");
writer.addHeaderAlias("totalPrice", "充电金额");
writer.addHeaderAlias("promotionDiscount", "优惠金额");
writer.setOnlyAlias(true);
// 一次性写出内容使用默认样式强制输出标题
writer.write(list, true);
//out为OutputStream需要写出到的目标流
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
ServletOutputStream out = response.getOutputStream();
writer.flush(out, true);
// 关闭writer释放内存
writer.close();
//此处记得关闭输出Servlet流
IoUtil.close(out);
}
}

View File

@ -458,7 +458,7 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
*/
private String generateRedisKey(XhpcInvoice xhpcInvoice) {
String tenantId = tokenService.getLoginUser().getSysUser().getTenantId();
String tenantId = xhpcInvoice.getTenantId();
String redisKey = "global:invoice:" + tenantId + ":";
switch (xhpcInvoice.getCreatorType()) {
case 0:

View File

@ -118,4 +118,169 @@
and xcp.tenant_id =#{tenantId}
</if>
</select>
<select id="getPersonnelStatistics" resultType="map">
<if test="type !=null and type==1">
select
concat("社区用户") as mechanismName,
xcp.account as account,
xcp.name as name,
xcp.phone as phone,
count(xho.history_order_id) number,
IFNULL(sum(xho.total_power),0) totalPower,
IFNULL(sum(xho.total_price),0) totalPrice,
IFNULL(sum(xho.promotion_discount),0) promotionDiscount
from xhpc_community_personnel as xcp
join xhpc_community xc on xc.community_id = xcp.community_id and xc.del_flag =0
left join xhpc_history_order xho on xho.source =2 and xho.user_id =xcp.community_personnel_id
where xcp.tenant_id=#{tenantId} and xcp.del_flag=0
<if test="number==1 or number==2">
and xcp.create_type=2 and xcp.create_id=#{userId}
</if>
<if test="type==1">
and xcp.create_type=2 and xcp.create_id=#{userId}
</if>
<if test="chargingStationId !=null">
and xcp.create_id=(select operator_id from xhpc_charging_station where charging_station_id=#{chargingStationId})
</if>
<if test="operatorId !=null">
and xcp.create_id=#{operatorId}
</if>
<if test="chargingPileId !=null">
and xcp.create_id=(select operator_id from xhpc_charging_station where charging_station_id=(select terminal_id from xhpc_charging_pile where charging_pile_id=#{chargingPileId}))
</if>
<if test="name !=null and name !=''">
and xcp.name like concat('%',#{name},'%')
</if>
<if test="account !=null and account !=''">
and xcp.account like concat('%',#{account},'%')
</if>
<if test="phone !=null and phone !=''">
and xcp.phone like concat('%',#{phone},'%')
</if>
GROUP BY xcp.account
</if>
<if test="type !=null and type==2">
select
concat("B端用户") as mechanismName,
xcup.account as account,
xcup.name as name,
xcup.phone as phone,
count(xho.history_order_id) number,
IFNULL(sum(xho.total_power),0) totalPower,
IFNULL(sum(xho.total_price),0) totalPrice,
IFNULL(sum(xho.promotion_discount),0) promotionDiscount
from xhpc_customers_personnel as xcup
join xhpc_customers xuc on xuc.customers_id = xcup.customers_personnel_id and xuc.del_flag =0
left join xhpc_history_order xho on xho.source =3 and xho.user_id =xcup.customers_personnel_id
where xcup.tenant_id=#{tenantId} and xcup.del_flag=0
<if test="number==1 or number==2">
and xcup.create_type=2 and xcup.create_id=#{userId}
</if>
<if test="type==1">
and xcup.create_type=2 and xcup.create_id=#{userId}
</if>
<if test="chargingStationId !=null">
and xcup.create_id=(select operator_id from xhpc_charging_station where charging_station_id=#{chargingStationId})
</if>
<if test="operatorId !=null">
and xcup.create_id=#{operatorId}
</if>
<if test="chargingPileId !=null">
and xcup.create_id=(select operator_id from xhpc_charging_station where charging_station_id=(select terminal_id from xhpc_charging_pile where charging_pile_id=#{chargingPileId}))
</if>
<if test="name !=null and name !=''">
and xcup.name like concat('%',#{name},'%')
</if>
<if test="account !=null and account !=''">
and xcup.account like concat('%',#{account},'%')
</if>
<if test="phone !=null and phone !=''">
and xcup.phone like concat('%',#{phone},'%')
</if>
GROUP BY xcup.account
</if>
<if test="type !=1 and type !=2">
select
concat("社区用户") as mechanismName,
xcp.account as account,
xcp.name as name,
xcp.phone as phone,
count(xho.history_order_id) number,
IFNULL(sum(xho.total_power),0) totalPower,
IFNULL(sum(xho.total_price),0) totalPrice,
IFNULL(sum(xho.promotion_discount),0) promotionDiscount
from xhpc_community_personnel as xcp
join xhpc_community xc on xc.community_id = xcp.community_id and xc.del_flag =0
left join xhpc_history_order xho on xho.source =2 and xho.user_id =xcp.community_personnel_id
where xcp.tenant_id=#{tenantId} and xcp.del_flag=0
<if test="number==1 or number==2">
and xcp.create_type=2 and xcp.create_id=#{userId}
</if>
<if test="type==1">
and xcp.create_type=2 and xcp.create_id=#{userId}
</if>
<if test="chargingStationId !=null">
and xcp.create_id=(select operator_id from xhpc_charging_station where charging_station_id=#{chargingStationId})
</if>
<if test="operatorId !=null">
and xcp.create_id=#{operatorId}
</if>
<if test="chargingPileId !=null">
and xcp.create_id=(select operator_id from xhpc_charging_station where charging_station_id=(select terminal_id from xhpc_charging_pile where charging_pile_id=#{chargingPileId}))
</if>
<if test="name !=null and name !=''">
and xcp.name like concat('%',#{name},'%')
</if>
<if test="account !=null and account !=''">
and xcp.account like concat('%',#{account},'%')
</if>
<if test="phone !=null and phone !=''">
and xcp.phone like concat('%',#{phone},'%')
</if>
GROUP BY xcp.account
union
select
concat("B端用户") as mechanismName,
xcup.account as account,
xcup.name as name,
xcup.phone as phone,
count(xho.history_order_id) number,
IFNULL(sum(xho.total_power),0) totalPower,
IFNULL(sum(xho.total_price),0) totalPrice,
IFNULL(sum(xho.promotion_discount),0) promotionDiscount
from xhpc_customers_personnel as xcup
join xhpc_customers xuc on xuc.customers_id = xcup.customers_personnel_id and xuc.del_flag =0
left join xhpc_history_order xho on xho.source =3 and xho.user_id =xcup.customers_personnel_id
where xcup.tenant_id=#{tenantId} and xcup.del_flag=0
<if test="number==1 or number==2">
and xcup.create_type=2 and xcup.create_id=#{userId}
</if>
<if test="type==1">
and xcup.create_type=2 and xcup.create_id=#{userId}
</if>
<if test="chargingStationId !=null">
and xcup.create_id=(select operator_id from xhpc_charging_station where charging_station_id=#{chargingStationId})
</if>
<if test="operatorId !=null">
and xcup.create_id=#{operatorId}
</if>
<if test="chargingPileId !=null">
and xcup.create_id=(select operator_id from xhpc_charging_station where charging_station_id=(select terminal_id from xhpc_charging_pile where charging_pile_id=#{chargingPileId}))
</if>
<if test="name !=null and name !=''">
and xcup.name like concat('%',#{name},'%')
</if>
<if test="account !=null and account !=''">
and xcup.account like concat('%',#{account},'%')
</if>
<if test="phone !=null and phone !=''">
and xcup.phone like concat('%',#{phone},'%')
</if>
GROUP BY xcup.account
</if>
</select>
</mapper>

View File

@ -287,11 +287,10 @@
<include refid="Base_Column_List"/>
xo.operator_id_evcs operatorIdEvcs,
xdb.dict_value attributenName,`xa`.merger_name mergerName,
GROUP_CONCAT(DISTINCT xi.`url` ORDER BY xi.create_time DESC separator ',') businessLicenseUrl
xo.business_license_id businessLicenseUrl
from xhpc_operator `xo`
LEFT JOIN xhpc_dict_biz xdb on xdb.`code` = 'operator_attribute' and xdb.dict_key = xo.attribute
LEFT JOIN xhpc_area `xa` on `xa`.`code` = xo.area_code
LEFT JOIN xhpc_img xi on FIND_IN_SET(xi.img_id,xo.business_license_id )
where xo.del_flag = 0 and xo.operator_id = #{operatorId}
</select>

View File

@ -325,15 +325,21 @@
</select>
<select id="getUserDimension" resultType="map">
SELECT
us.number number,
us.totalPrice totalPrice,
us.appUserId appUserId,
us.phone phone
from xhpc_app_user AS xaus
JOIN (
SELECT
count(xho.history_order_id) number,
IFNULL(SUM(xho.total_price),0) totalPrice,
xaus.app_user_id appUserId,
xaus.phone phone
from xhpc_app_user AS xaus
LEFT JOIN xhpc_history_order xho on xaus.app_user_id = xho.user_id and xho.source = 0 and xho.tenant_id =#{tenantId}
WHERE
xaus.del_flag = 0 and YEAR(xho.end_time)=YEAR(NOW())
xau.app_user_id appUserId,
xau.phone phone
from xhpc_app_user as xau
LEFT JOIN xhpc_history_order xho on xau.app_user_id = xho.user_id and xho.source = 0 and xho.tenant_id =#{tenantId}
where xau.del_flag =0 and YEAR(xho.end_time)=YEAR(NOW())
<if test="startTime !=null and startTime !=''">
and xho.end_time &gt;=#{startTime}
</if>
@ -343,6 +349,12 @@
<if test="phone !=null and phone !=''">
and xau.phone like concat('%', #{phone}, '%')
</if>
GROUP BY xau.app_user_id
order by totalPrice desc) us on xaus.app_user_id = us.appUserId
where xaus.del_flag = 0
<if test="activity !=null">
and us.activity &gt;= #{activity}
</if>
<if test="frequency !=null">
and us.number &gt;= #{frequency}
</if>
@ -357,6 +369,10 @@
</if>
GROUP BY xaus.app_user_id
order by totalPrice desc,number desc
</select>