24 changed files with 907 additions and 0 deletions
@ -0,0 +1,15 @@ |
|||||
|
package com.epmet.dto.heart.result; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @Description 描述 |
||||
|
* @Author wangxianzhang |
||||
|
* @Date 2021/12/8 4:39 下午 |
||||
|
* @Version 1.0 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class DemandServiceCountResultDTO { |
||||
|
private String serverId; |
||||
|
private String serviceType; |
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
package com.epmet.controller; |
||||
|
|
||||
|
import com.epmet.commons.tools.utils.Result; |
||||
|
import com.epmet.service.DemandService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
/** |
||||
|
* @Description 描述 |
||||
|
* @Author wangxianzhang |
||||
|
* @Date 2021/12/8 10:44 上午 |
||||
|
* @Version 1.0 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("demand") |
||||
|
public class DemandController { |
||||
|
|
||||
|
@Autowired |
||||
|
private DemandService demandStatsService; |
||||
|
|
||||
|
/** |
||||
|
* wangxianzhang |
||||
|
* |
||||
|
* 计算客户下志愿者服务相关数据 |
||||
|
* |
||||
|
* @param customerId 客户ID,可以为空,为空则计算所有客户 |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("volunteer/daily") |
||||
|
public Result statsVolunteerDemandServicesDaily(@RequestParam(value = "customer-id", required = false) String customerId) { |
||||
|
|
||||
|
demandStatsService.statsVolunteerDemandServicesDaily(customerId); |
||||
|
|
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* <p> |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.dao.heart; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.dao.BaseDao; |
||||
|
import com.epmet.dto.heart.result.DemandServiceCountResultDTO; |
||||
|
import com.epmet.entity.heart.IcUserDemandServiceEntity; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 居民需求服务记录表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2021-11-19 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface IcUserDemandServiceDao extends BaseDao<IcUserDemandServiceEntity> { |
||||
|
|
||||
|
/** |
||||
|
* 需求服务次数查询 |
||||
|
* @param customerId 客户id |
||||
|
* @param serviceType 服务者类型 |
||||
|
*/ |
||||
|
List<DemandServiceCountResultDTO> listDemandServiceCountPage(@Param("customerId") String customerId, @Param("endTime") Date endTime, @Param("serviceType") String serviceType); |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* <p> |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.dao.heart; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.dao.BaseDao; |
||||
|
import com.epmet.entity.heart.VolunteerInfoEntity; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
/** |
||||
|
* 志愿者信息 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2021-12-08 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface VolunteerInfoDao extends BaseDao<VolunteerInfoEntity> { |
||||
|
|
||||
|
} |
@ -0,0 +1,42 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* <p> |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.dao.stats; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.dao.BaseDao; |
||||
|
import com.epmet.entity.stats.FactVolunteerServiceDailyEntity; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 志愿者服务情况统计 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2021-12-08 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface FactVolunteerServiceDailyDao extends BaseDao<FactVolunteerServiceDailyEntity> { |
||||
|
|
||||
|
/** |
||||
|
* 删除指定客户,指定dateId的志愿者服务统计记录 |
||||
|
* @param customerIds |
||||
|
* @param dateDimId |
||||
|
*/ |
||||
|
void clearVolunteerDemandServiceDailyStats(@Param("customerIds") List<String> customerIds, @Param("dateDimId") String dateDimId); |
||||
|
} |
@ -0,0 +1,75 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* <p> |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.entity.heart; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import com.epmet.commons.mybatis.entity.BaseEpmetEntity; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 居民需求服务记录表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2021-11-19 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper=false) |
||||
|
@TableName("ic_user_demand_service") |
||||
|
public class IcUserDemandServiceEntity extends BaseEpmetEntity { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 客户id |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* 需求id |
||||
|
*/ |
||||
|
private String demandRecId; |
||||
|
|
||||
|
/** |
||||
|
* 服务方类型:志愿者:volunteer;社会组织:social_org;社区自组织:community_org;区域党建单位:party_unit; |
||||
|
*/ |
||||
|
private String serviceType; |
||||
|
|
||||
|
/** |
||||
|
* 志愿者:居民端爱心互助的志愿者userId; |
||||
|
*/ |
||||
|
private String serverId; |
||||
|
|
||||
|
/** |
||||
|
* 实际服务开始时间 |
||||
|
*/ |
||||
|
private Date serviceStartTime; |
||||
|
|
||||
|
/** |
||||
|
* 实际服务结束时间 |
||||
|
*/ |
||||
|
private Date serviceEndTime; |
||||
|
|
||||
|
/** |
||||
|
* 完成情况 |
||||
|
*/ |
||||
|
private String finishDesc; |
||||
|
|
||||
|
} |
@ -0,0 +1,71 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* <p> |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.entity.heart; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.entity.BaseEpmetEntity; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 志愿者信息 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2021-12-08 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper=false) |
||||
|
@TableName("volunteer_info") |
||||
|
public class VolunteerInfoEntity extends BaseEpmetEntity { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 用户id |
||||
|
*/ |
||||
|
private String userId; |
||||
|
|
||||
|
/** |
||||
|
* 客户id |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* 志愿者自我介绍 |
||||
|
*/ |
||||
|
private String volunteerIntroduce; |
||||
|
|
||||
|
/** |
||||
|
* 志愿者签名 |
||||
|
*/ |
||||
|
private String volunteerSignature; |
||||
|
|
||||
|
/** |
||||
|
* 网格id |
||||
|
*/ |
||||
|
private String gridId; |
||||
|
|
||||
|
/** |
||||
|
* 网格名称 |
||||
|
*/ |
||||
|
private String gridName; |
||||
|
|
||||
|
} |
@ -0,0 +1,86 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* <p> |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.entity.stats; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.entity.BaseEpmetEntity; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 志愿者服务情况统计 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2021-12-08 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper=false) |
||||
|
@TableName("fact_volunteer_service_daily") |
||||
|
public class FactVolunteerServiceDailyEntity extends BaseEpmetEntity { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 客户id |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* yyyyMMdd |
||||
|
*/ |
||||
|
private String dateId; |
||||
|
|
||||
|
/** |
||||
|
* yyyyMM |
||||
|
*/ |
||||
|
private String monthId; |
||||
|
|
||||
|
/** |
||||
|
* 截止到当前dateId,当前客户下,共有多少个爱心互助的志愿者 |
||||
|
*/ |
||||
|
private Integer volunteerTotal; |
||||
|
|
||||
|
/** |
||||
|
* 截止到当前dateId,当前客户下,XX个爱心互助志愿者中,党员有多少个 |
||||
|
*/ |
||||
|
private Integer partyTotal; |
||||
|
|
||||
|
/** |
||||
|
* 截止到当前dateId,当前客户下,XX个爱心互助志愿者中,居民有多少个 |
||||
|
*/ |
||||
|
private Integer resiTotal; |
||||
|
|
||||
|
/** |
||||
|
* 服务总次数 |
||||
|
*/ |
||||
|
private Integer serviceTotal; |
||||
|
|
||||
|
/** |
||||
|
* 党员服务总次数 |
||||
|
*/ |
||||
|
private Integer partyServiceTotal; |
||||
|
|
||||
|
/** |
||||
|
* 居民服务总次数 |
||||
|
*/ |
||||
|
private Integer resiServiceTotal; |
||||
|
|
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
package com.epmet.service; |
||||
|
|
||||
|
/** |
||||
|
* @Description 需求service |
||||
|
* @Author wangxianzhang |
||||
|
* @Date 2021/12/8 12:14 下午 |
||||
|
* @Version 1.0 |
||||
|
*/ |
||||
|
public interface DemandService { |
||||
|
|
||||
|
/** |
||||
|
* wangxianzhang |
||||
|
* |
||||
|
* 按日统计 |
||||
|
* |
||||
|
* @param customerId 客户ID,可为空,为空计算所有 |
||||
|
*/ |
||||
|
void statsVolunteerDemandServicesDaily(String customerId); |
||||
|
|
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
package com.epmet.service.heart; |
||||
|
|
||||
|
import com.epmet.dto.heart.result.DemandServiceCountResultDTO; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
*@Description 爱心互助,需求service |
||||
|
*@Author wangxianzhang |
||||
|
*@Date 2021/12/8 |
||||
|
*/ |
||||
|
public interface HeartDemandService { |
||||
|
List<DemandServiceCountResultDTO> listDemandServiceCountPage(String customerId, Date endTime, int serviceCountPageNo, int serviceCountPageSize); |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
package com.epmet.service.heart; |
||||
|
|
||||
|
import com.epmet.entity.heart.VolunteerInfoEntity; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
*@Description heart 志愿者service |
||||
|
*@Author wangxianzhang |
||||
|
*@Date 2021/12/8 |
||||
|
*/ |
||||
|
public interface HeartVolunteerService { |
||||
|
List<VolunteerInfoEntity> listVolunteersPage(String customerId, Date endCreateTime, Integer pageNum, Integer pageSize); |
||||
|
} |
@ -0,0 +1,40 @@ |
|||||
|
package com.epmet.service.heart.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.epmet.commons.dynamic.datasource.annotation.DataSource; |
||||
|
import com.epmet.constant.DataSourceConstant; |
||||
|
import com.epmet.dao.heart.IcUserDemandServiceDao; |
||||
|
import com.epmet.dto.heart.result.DemandServiceCountResultDTO; |
||||
|
import com.epmet.service.heart.HeartDemandService; |
||||
|
import com.github.pagehelper.ISelect; |
||||
|
import com.github.pagehelper.Page; |
||||
|
import com.github.pagehelper.PageHelper; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @Description 爱心互助,需求service |
||||
|
* @Author wangxianzhang |
||||
|
* @Date 2021/12/8 12:33 下午 |
||||
|
* @Version 1.0 |
||||
|
*/ |
||||
|
@Service |
||||
|
@DataSource(DataSourceConstant.EPMET_HEART) |
||||
|
public class HeartDemandServiceImpl implements HeartDemandService { |
||||
|
|
||||
|
@Autowired |
||||
|
private IcUserDemandServiceDao demandServiceDao; |
||||
|
|
||||
|
@Override |
||||
|
public List<DemandServiceCountResultDTO> listDemandServiceCountPage(String customerId, Date endTime, int serviceCountPageNo, int serviceCountPageSize) { |
||||
|
return PageHelper.startPage(serviceCountPageNo, serviceCountPageSize).doSelectPage(new ISelect() { |
||||
|
@Override |
||||
|
public void doSelect() { |
||||
|
demandServiceDao.listDemandServiceCountPage(customerId, endTime, "volunteer"); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
@ -0,0 +1,40 @@ |
|||||
|
package com.epmet.service.heart.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.epmet.commons.dynamic.datasource.annotation.DataSource; |
||||
|
import com.epmet.constant.DataSourceConstant; |
||||
|
import com.epmet.dao.heart.VolunteerInfoDao; |
||||
|
import com.epmet.entity.heart.VolunteerInfoEntity; |
||||
|
import com.epmet.service.heart.HeartVolunteerService; |
||||
|
import com.github.pagehelper.ISelect; |
||||
|
import com.github.pagehelper.Page; |
||||
|
import com.github.pagehelper.PageHelper; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @Description 描述 |
||||
|
* @Author wangxianzhang |
||||
|
* @Date 2021/12/8 1:35 下午 |
||||
|
* @Version 1.0 |
||||
|
*/ |
||||
|
@Service |
||||
|
@DataSource(DataSourceConstant.EPMET_HEART) |
||||
|
public class HeartVolunteerServiceImpl implements HeartVolunteerService { |
||||
|
|
||||
|
@Autowired |
||||
|
private VolunteerInfoDao volunteerInfoDao; |
||||
|
|
||||
|
@Override |
||||
|
public List<VolunteerInfoEntity> listVolunteersPage(String customerId, Date endCreateTime, Integer pageNum, Integer pageSize) { |
||||
|
return PageHelper.startPage(pageNum, pageSize).doSelectPage(() -> { |
||||
|
LambdaQueryWrapper<VolunteerInfoEntity> query = new LambdaQueryWrapper<>(); |
||||
|
query.eq(VolunteerInfoEntity::getCustomerId, customerId); |
||||
|
query.lt(VolunteerInfoEntity::getCreatedTime, endCreateTime); |
||||
|
volunteerInfoDao.selectList(query); |
||||
|
}); |
||||
|
} |
||||
|
} |
@ -0,0 +1,184 @@ |
|||||
|
package com.epmet.service.impl; |
||||
|
|
||||
|
import com.epmet.commons.tools.constant.EpmetRoleKeyConstant; |
||||
|
import com.epmet.commons.tools.utils.DateUtils; |
||||
|
import com.epmet.dto.heart.result.DemandServiceCountResultDTO; |
||||
|
import com.epmet.entity.crm.CustomerEntity; |
||||
|
import com.epmet.entity.heart.VolunteerInfoEntity; |
||||
|
import com.epmet.entity.stats.FactVolunteerServiceDailyEntity; |
||||
|
import com.epmet.service.DemandService; |
||||
|
import com.epmet.service.crm.CustomerService; |
||||
|
import com.epmet.service.heart.HeartDemandService; |
||||
|
import com.epmet.service.heart.HeartVolunteerService; |
||||
|
import com.epmet.service.stats.DemandStatsService; |
||||
|
import com.epmet.service.user.UserService; |
||||
|
import com.epmet.util.DimIdGenerator; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.*; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* @Description 需求service |
||||
|
* @Author wangxianzhang |
||||
|
* @Date 2021/12/8 12:14 下午 |
||||
|
* @Version 1.0 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class DemandServiceImpl implements DemandService { |
||||
|
|
||||
|
@Autowired |
||||
|
private HeartDemandService heartDemandService; |
||||
|
|
||||
|
@Autowired |
||||
|
private HeartVolunteerService heartVolunteerService; |
||||
|
|
||||
|
@Autowired |
||||
|
private UserService userService; |
||||
|
|
||||
|
@Autowired |
||||
|
private DemandStatsService demandStatsService; |
||||
|
|
||||
|
@Autowired |
||||
|
private CustomerService customerService; |
||||
|
|
||||
|
@Override |
||||
|
public void statsVolunteerDemandServicesDaily(String customerId) { |
||||
|
|
||||
|
Date now = new Date(); |
||||
|
Date today = DateUtils.integrate(now, "yyyy-MM-dd"); |
||||
|
Date yestoday = DateUtils.addDateDays(today, -1); |
||||
|
|
||||
|
if (StringUtils.isNotBlank(customerId)) { |
||||
|
// 只计算单个客户
|
||||
|
clearOldDatas(Arrays.asList(customerId), yestoday); |
||||
|
statsVolunteerDemandServicesDaily4Customer(customerId, today, yestoday); |
||||
|
} else { |
||||
|
// 查询所有客户ID
|
||||
|
List<String> customerIds = customerService.listValidCustomersByCreateTime(null, null).stream().map(c -> c.getId()).collect(Collectors.toList()); |
||||
|
clearOldDatas(customerIds, yestoday); |
||||
|
customerIds.stream().forEach(cId -> { |
||||
|
statsVolunteerDemandServicesDaily4Customer(cId, today, yestoday); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 清理旧数据 |
||||
|
* @param yestoday |
||||
|
*/ |
||||
|
private void clearOldDatas(List<String> customerIds, Date yestoday) { |
||||
|
|
||||
|
String dateDimId = DimIdGenerator.getDateDimId(yestoday); |
||||
|
|
||||
|
demandStatsService.clearVolunteerDemandServiceDailyStats(customerIds, dateDimId); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 统计单个客户的志愿者服务情况 |
||||
|
* @param customerId 客户ID |
||||
|
* @param endTime 统计截止时间(<endTime) |
||||
|
*/ |
||||
|
private void statsVolunteerDemandServicesDaily4Customer(String customerId, Date endTime, Date belongTime) { |
||||
|
// 1.志愿者分流为党员志愿者&普通居民志愿者
|
||||
|
Integer volunteerTotalCount = 0; |
||||
|
// 党员志愿者数量
|
||||
|
Integer partymemberVolunteerCount = 0; |
||||
|
// 居民志愿者数量
|
||||
|
Integer resiVolunteerCount = 0; |
||||
|
|
||||
|
List<String> partymemberVolunteerUserIds = new ArrayList<>(16); |
||||
|
|
||||
|
int pageNum = 1; |
||||
|
int volunteerPageSize = 5; |
||||
|
|
||||
|
while (true) { |
||||
|
|
||||
|
int shardingStartIndex = 0; |
||||
|
int shardingSize = 2; |
||||
|
|
||||
|
List<VolunteerInfoEntity> volunteersPage = heartVolunteerService.listVolunteersPage(customerId, endTime, pageNum, volunteerPageSize); |
||||
|
|
||||
|
// 如果查询结果为0,说明没有更多的志愿者了
|
||||
|
if (volunteersPage.size() == 0) { |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
volunteerTotalCount += volunteersPage.size(); |
||||
|
|
||||
|
// 分片去确定党员身份
|
||||
|
while (true) { |
||||
|
int realShardingSize = Math.min(shardingSize, volunteersPage.size() - shardingStartIndex); |
||||
|
|
||||
|
if (realShardingSize == 0) { |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
int shardingEndIndex = shardingStartIndex + realShardingSize; |
||||
|
List<String> volunteerUserIds = volunteersPage.subList(shardingStartIndex, shardingEndIndex) |
||||
|
.stream() |
||||
|
.map((volunteerInfoEntity) -> volunteerInfoEntity.getUserId()) |
||||
|
.collect(Collectors.toList()); |
||||
|
|
||||
|
List<String> tempPartymemberUserIds = userService.filterUserIds(volunteerUserIds, EpmetRoleKeyConstant.PARTYMEMBER); |
||||
|
|
||||
|
partymemberVolunteerUserIds.addAll(tempPartymemberUserIds); |
||||
|
|
||||
|
shardingStartIndex = shardingEndIndex; |
||||
|
} |
||||
|
|
||||
|
pageNum++; |
||||
|
} |
||||
|
|
||||
|
partymemberVolunteerCount += partymemberVolunteerUserIds.size(); |
||||
|
resiVolunteerCount = volunteerTotalCount - partymemberVolunteerCount; |
||||
|
|
||||
|
//2. 查询志愿者服务次数
|
||||
|
|
||||
|
// 总服务次数
|
||||
|
int totalDemandServiceCount = 0; |
||||
|
// 党员服务次数
|
||||
|
int partymemberDemandServiceCount = 0; |
||||
|
// 居民服务次数
|
||||
|
int resiDemandServiceCount = 0; |
||||
|
|
||||
|
int serviceCountPageNo = 0; |
||||
|
int serviceCountPageSize = 1000; |
||||
|
while (true) { |
||||
|
|
||||
|
List<DemandServiceCountResultDTO> damendServiceCounts = heartDemandService.listDemandServiceCountPage(customerId, endTime, serviceCountPageNo, serviceCountPageSize); |
||||
|
|
||||
|
for (DemandServiceCountResultDTO damendServiceCount : damendServiceCounts) { |
||||
|
String serverId = damendServiceCount.getServerId(); |
||||
|
if (partymemberVolunteerUserIds.contains(serverId)) { |
||||
|
partymemberDemandServiceCount++; |
||||
|
} else { |
||||
|
resiDemandServiceCount++; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
totalDemandServiceCount += damendServiceCounts.size(); |
||||
|
|
||||
|
if (damendServiceCounts.size() <= serviceCountPageSize) { |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 3.持久化
|
||||
|
FactVolunteerServiceDailyEntity insert = new FactVolunteerServiceDailyEntity(); |
||||
|
insert.setDateId(DimIdGenerator.getDateDimId(belongTime)); |
||||
|
insert.setCustomerId(customerId); |
||||
|
insert.setMonthId(DimIdGenerator.getMonthDimId(belongTime)); |
||||
|
insert.setPartyServiceTotal(partymemberDemandServiceCount); |
||||
|
insert.setServiceTotal(totalDemandServiceCount); |
||||
|
insert.setPartyTotal(partymemberVolunteerCount); |
||||
|
insert.setResiServiceTotal(resiDemandServiceCount); |
||||
|
insert.setResiTotal(resiVolunteerCount); |
||||
|
insert.setVolunteerTotal(volunteerTotalCount); |
||||
|
|
||||
|
demandStatsService.addVolunteerServiceDaily(insert); |
||||
|
} |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
package com.epmet.service.stats; |
||||
|
|
||||
|
import com.epmet.entity.stats.FactVolunteerServiceDailyEntity; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
*@Description 统计客户下的志愿者需求服务数据 |
||||
|
*@Author wangxianzhang |
||||
|
*@Date 2021/12/8 |
||||
|
*/ |
||||
|
public interface DemandStatsService { |
||||
|
|
||||
|
|
||||
|
void addVolunteerServiceDaily(FactVolunteerServiceDailyEntity entity); |
||||
|
|
||||
|
void clearVolunteerDemandServiceDailyStats(List<String> customerIds, String dateDimId); |
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
package com.epmet.service.stats.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.epmet.commons.dynamic.datasource.annotation.DataSource; |
||||
|
import com.epmet.constant.DataSourceConstant; |
||||
|
import com.epmet.dao.stats.FactVolunteerServiceDailyDao; |
||||
|
import com.epmet.entity.stats.FactVolunteerServiceDailyEntity; |
||||
|
import com.epmet.service.stats.DemandStatsService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @Description 描述 |
||||
|
* @Author wangxianzhang |
||||
|
* @Date 2021/12/8 10:54 上午 |
||||
|
* @Version 1.0 |
||||
|
*/ |
||||
|
@Service |
||||
|
@DataSource(DataSourceConstant.STATS) |
||||
|
public class DemandStatsServiceImpl implements DemandStatsService { |
||||
|
|
||||
|
@Autowired |
||||
|
private FactVolunteerServiceDailyDao factVolunteerServiceDailyDao; |
||||
|
|
||||
|
@Override |
||||
|
public void addVolunteerServiceDaily(FactVolunteerServiceDailyEntity entity) { |
||||
|
factVolunteerServiceDailyDao.insert(entity); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void clearVolunteerDemandServiceDailyStats(List<String> customerIds, String dateDimId) { |
||||
|
factVolunteerServiceDailyDao.clearVolunteerDemandServiceDailyStats(customerIds, dateDimId); |
||||
|
} |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
CREATE TABLE epmet_data_statistical.`fact_volunteer_service_daily` |
||||
|
( |
||||
|
`ID` varchar(64) NOT NULL COMMENT '主键', |
||||
|
`CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户id', |
||||
|
`DATE_ID` varchar(8) NOT NULL COMMENT 'yyyyMMdd', |
||||
|
`MONTH_ID` varchar(6) NOT NULL COMMENT 'yyyyMM', |
||||
|
`VOLUNTEER_TOTAL` int(11) NOT NULL COMMENT '截止到当前dateId,当前客户下,共有多少个爱心互助的志愿者', |
||||
|
`PARTY_TOTAL` int(11) NOT NULL COMMENT '截止到当前dateId,当前客户下,XX个爱心互助志愿者中,党员有多少个', |
||||
|
`RESI_TOTAL` int(11) NOT NULL COMMENT '截止到当前dateId,当前客户下,XX个爱心互助志愿者中,居民有多少个', |
||||
|
`SERVICE_TOTAL` int(11) NOT NULL COMMENT '服务总次数', |
||||
|
`PARTY_SERVICE_TOTAL` int(11) NOT NULL COMMENT '党员服务总次数', |
||||
|
`RESI_SERVICE_TOTAL` int(11) NOT NULL COMMENT '居民服务总次数', |
||||
|
`DEL_FLAG` int(11) NOT NULL COMMENT '删除标识:0.未删除 1.已删除', |
||||
|
`REVISION` int(11) NOT NULL COMMENT '乐观锁', |
||||
|
`CREATED_BY` varchar(32) NOT NULL COMMENT '创建人', |
||||
|
`CREATED_TIME` datetime NOT NULL COMMENT '创建时间', |
||||
|
`UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', |
||||
|
`UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', |
||||
|
PRIMARY KEY (`ID`), |
||||
|
UNIQUE KEY `uni_vsd` (`CUSTOMER_ID`,`DATE_ID`,`DEL_FLAG`) |
||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='志愿者服务情况统计' |
@ -0,0 +1,33 @@ |
|||||
|
<?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="com.epmet.dao.heart.IcUserDemandServiceDao"> |
||||
|
|
||||
|
<resultMap type="com.epmet.entity.heart.IcUserDemandServiceEntity" id="icUserDemandServiceMap"> |
||||
|
<result property="id" column="ID"/> |
||||
|
<result property="customerId" column="CUSTOMER_ID"/> |
||||
|
<result property="demandRecId" column="DEMAND_REC_ID"/> |
||||
|
<result property="serviceType" column="SERVICE_TYPE"/> |
||||
|
<result property="serverId" column="SERVER_ID"/> |
||||
|
<result property="serviceStartTime" column="SERVICE_START_TIME"/> |
||||
|
<result property="serviceEndTime" column="SERVICE_END_TIME"/> |
||||
|
<result property="finishDesc" column="FINISH_DESC"/> |
||||
|
<result property="delFlag" column="DEL_FLAG"/> |
||||
|
<result property="revision" column="REVISION"/> |
||||
|
<result property="createdBy" column="CREATED_BY"/> |
||||
|
<result property="createdTime" column="CREATED_TIME"/> |
||||
|
<result property="updatedBy" column="UPDATED_BY"/> |
||||
|
<result property="updatedTime" column="UPDATED_TIME"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
<select id="listDemandServiceCountPage" resultType="com.epmet.dto.heart.result.DemandServiceCountResultDTO"> |
||||
|
select service.SERVER_ID, SERVICE_TYPE |
||||
|
from ic_user_demand_rec damend |
||||
|
inner join ic_user_demand_service service on (damend.ID = service.DEMAND_REC_ID and service.DEL_FLAG = 0) |
||||
|
where damend.DEL_FLAG = 0 |
||||
|
and damend.STATUS = 'finished' |
||||
|
and damend.REPORT_TIME <![CDATA[<]]> #{endTime} |
||||
|
and damend.CUSTOMER_ID = #{customerId} |
||||
|
and service.SERVICE_TYPE = #{serviceType} |
||||
|
</select> |
||||
|
</mapper> |
@ -0,0 +1,23 @@ |
|||||
|
<?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="com.epmet.dao.VolunteerInfoDao"> |
||||
|
|
||||
|
<resultMap type="com.epmet.entity.heart.VolunteerInfoEntity" id="volunteerInfoMap"> |
||||
|
<result property="id" column="ID"/> |
||||
|
<result property="userId" column="USER_ID"/> |
||||
|
<result property="customerId" column="CUSTOMER_ID"/> |
||||
|
<result property="volunteerIntroduce" column="VOLUNTEER_INTRODUCE"/> |
||||
|
<result property="volunteerSignature" column="VOLUNTEER_SIGNATURE"/> |
||||
|
<result property="delFlag" column="DEL_FLAG"/> |
||||
|
<result property="revision" column="REVISION"/> |
||||
|
<result property="createdBy" column="CREATED_BY"/> |
||||
|
<result property="createdTime" column="CREATED_TIME"/> |
||||
|
<result property="updatedBy" column="UPDATED_BY"/> |
||||
|
<result property="updatedTime" column="UPDATED_TIME"/> |
||||
|
<result property="gridId" column="GRID_ID"/> |
||||
|
<result property="gridName" column="GRID_NAME"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
|
||||
|
</mapper> |
@ -0,0 +1,37 @@ |
|||||
|
<?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="com.epmet.dao.stats.FactVolunteerServiceDailyDao"> |
||||
|
|
||||
|
<resultMap type="com.epmet.entity.stats.FactVolunteerServiceDailyEntity" id="factVolunteerServiceDailyMap"> |
||||
|
<result property="id" column="ID"/> |
||||
|
<result property="customerId" column="CUSTOMER_ID"/> |
||||
|
<result property="dateId" column="DATE_ID"/> |
||||
|
<result property="monthId" column="MONTH_ID"/> |
||||
|
<result property="volunteerTotal" column="VOLUNTEER_TOTAL"/> |
||||
|
<result property="partyTotal" column="PARTY_TOTAL"/> |
||||
|
<result property="resiTotal" column="RESI_TOTAL"/> |
||||
|
<result property="serviceTotal" column="SERVICE_TOTAL"/> |
||||
|
<result property="partyServiceTotal" column="PARTY_SERVICE_TOTAL"/> |
||||
|
<result property="resiServiceTotal" column="RESI_SERVICE_TOTAL"/> |
||||
|
<result property="delFlag" column="DEL_FLAG"/> |
||||
|
<result property="revision" column="REVISION"/> |
||||
|
<result property="createdBy" column="CREATED_BY"/> |
||||
|
<result property="createdTime" column="CREATED_TIME"/> |
||||
|
<result property="updatedBy" column="UPDATED_BY"/> |
||||
|
<result property="updatedTime" column="UPDATED_TIME"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
<delete id="clearVolunteerDemandServiceDailyStats"> |
||||
|
delete |
||||
|
from fact_volunteer_service_daily |
||||
|
where DATE_ID=#{dateDimId} |
||||
|
and CUSTOMER_ID in |
||||
|
<foreach collection="customerIds" open="(" separator="," close=")" item="customerId"> |
||||
|
#{customerId} |
||||
|
</foreach> |
||||
|
|
||||
|
</delete> |
||||
|
|
||||
|
|
||||
|
</mapper> |
Loading…
Reference in new issue