diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/config/ThreadConfig.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/config/ThreadConfig.java index 8b7385f..26cc40b 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/config/ThreadConfig.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/config/ThreadConfig.java @@ -22,7 +22,7 @@ public class ThreadConfig { @Autowired private ThreadPoolConfigProperties threadPoolConfigProperties; - // @Bean + @Bean public ThreadPoolExecutor threadPoolExecutor() { return new ThreadPoolExecutor(threadPoolConfigProperties.getCorePoolSize(), threadPoolConfigProperties.getMaxSize(), diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/IStandardTicketInfoService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/IStandardTicketInfoService.java index b4aaa2e..f17194c 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/IStandardTicketInfoService.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/IStandardTicketInfoService.java @@ -117,4 +117,12 @@ public interface IStandardTicketInfoService extends BaseService selectStandardTicketByDeptIdWithTicketType(List createDept, String ticketType); } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java index 1a97a48..e3dc3f2 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/StandardTicketInfoServiceImpl.java @@ -700,4 +700,20 @@ public class StandardTicketInfoServiceImpl extends BaseServiceImpl selectStandardTicketByDeptIdWithTicketType(List createDept, String ticketType) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(StandardTicketInfoEntity::getTicketType,ticketType); + queryWrapper.in(StandardTicketInfoEntity::getCreateDept,createDept); + return baseMapper.selectList(queryWrapper); + } } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketCountController.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketCountController.java new file mode 100644 index 0000000..913e112 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/controller/TicketCountController.java @@ -0,0 +1,45 @@ +package com.hnac.hzims.ticket.twoTicket.controller; + +import com.hnac.hzims.ticket.twoTicket.service.TicketCountService; +import lombok.RequiredArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.YearMonth; + +/** + * 两票统计分析模块 + * + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/7/3 13:41 + */ +@RestController +@RequiredArgsConstructor +@RequestMapping("/ticket-count") +public class TicketCountController { + + private final TicketCountService ticketCountService; + + + /** + * 两票生成月报统计 + * @param dateTime 月份 + * @return + */ + @PostMapping("/loadMonthReport/{dateTime}") + public R loadMonthReport(@PathVariable String dateTime) { + ticketCountService.loadMonthReport(dateTime); + return R.success("生成两票月报成功"); + } + + + + + + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/entity/TicketCount.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/entity/TicketCount.java new file mode 100644 index 0000000..1e5cbd0 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/entity/TicketCount.java @@ -0,0 +1,112 @@ +package com.hnac.hzims.ticket.twoTicket.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.time.YearMonth; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/7/3 11:45 + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode +@TableName("hzims_ticket_count") +public class TicketCount implements Serializable { + + + /** + * 编号 + */ + private Long id; + + + /** + * 站点id + */ + private Long deptId; + + + /** + * 日期 + */ + private String dateTime; + + + /** + * 站点名称 + */ + private String deptName; + + + /** + * 票据类型 + */ + private String ticketType; + + + /** + * 开票数量 + */ + private Integer ticketNumber; + + + /** + * 完成数量 + */ + private Integer ticketCompleteNum; + + + /** + * 延期数量 + */ + private Integer ticketDelayNum; + + + /** + * 合格数量 + */ + private Integer ticketProportionNum; + + + /** + * 创建时间 + */ + private LocalDateTime createTime; + + /** + * 更新时间 + */ + private LocalDateTime updateTime; + + + /** + * 逻辑删除 + */ + @TableField(value = "is_deleted") + @TableLogic(value = "0", delval = "1") + private Boolean deleted; + + + /** + * 创建部门 + */ + private String createDept; + + + /** + * 租户Id + */ + private String tenantId; + + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/mapper/TicketCountMapper.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/mapper/TicketCountMapper.java new file mode 100644 index 0000000..7c2b085 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/mapper/TicketCountMapper.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.ticket.twoTicket.mapper; + +import com.hnac.hzims.ticket.twoTicket.entity.TicketCount; +import com.hnac.hzims.ticket.workTicket.entity.SecondTicketInfoEntity; +import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/7/3 13:36 + */ +public interface TicketCountMapper extends UserDataScopeBaseMapper { +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/mapper/TicketCountMapper.xml b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/mapper/TicketCountMapper.xml new file mode 100644 index 0000000..6ff3619 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/mapper/TicketCountMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketCountService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketCountService.java new file mode 100644 index 0000000..baafdb9 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/TicketCountService.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.ticket.twoTicket.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.ticket.twoTicket.entity.TicketCount; +import com.hnac.hzims.ticket.twoTicket.entity.TicketInfoDanger; + +import java.time.YearMonth; +import java.util.List; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/7/3 13:37 + */ +public interface TicketCountService extends IService { + + /** + * 两票生成月报统计 + */ + void loadMonthReport(String dateTime); + +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketCountServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketCountServiceImpl.java new file mode 100644 index 0000000..9101b20 --- /dev/null +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketCountServiceImpl.java @@ -0,0 +1,254 @@ +package com.hnac.hzims.ticket.twoTicket.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.ticket.allTicket.entity.TicketInfoEvaluateEntity; +import com.hnac.hzims.ticket.allTicket.service.TicketInfoEvaluateService; +import com.hnac.hzims.ticket.standardTicket.entity.StandardTicketInfoEntity; +import com.hnac.hzims.ticket.standardTicket.service.IStandardTicketInfoService; +import com.hnac.hzims.ticket.twoTicket.entity.TicketCount; +import com.hnac.hzims.ticket.twoTicket.mapper.TicketCountMapper; +import com.hnac.hzims.ticket.twoTicket.service.TicketCountService; +import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity; +import com.hnac.hzims.ticket.workTicket.service.IWorkTicketInfoService; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springblade.core.mp.base.BaseEntity; +import org.springblade.core.secure.BladeUser; +import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tool.api.R; +import org.springblade.system.feign.ISysClient; +import org.springblade.system.user.feign.IUserClient; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.stream.Collectors; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/7/3 13:38 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class TicketCountServiceImpl extends ServiceImpl implements TicketCountService { + + + private final ThreadPoolExecutor executor; + + + private final IWorkTicketInfoService workTicketInfoService; + + + private final IUserClient userClient; + + + private final ISysClient systemClient; + + + private final TicketInfoEvaluateService ticketInfoEvaluateService; + + + private final IStandardTicketInfoService standardTicketInfoService; + + /** + * 两票生成月报统计 + * + * @param dateTime + */ + @SneakyThrows + @Override + public void loadMonthReport(String dateTime) { + //根据登录人查询所属机构及下属机构 + BladeUser user = AuthUtil.getUser(); + List createDept = userClient.getDataScope(user.getUserId()); + System.out.println("createDept = " + createDept); + //根据月份查询统计的数据 + CompletableFuture> ticketCountsCompletableFuture = CompletableFuture.supplyAsync(() -> { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(TicketCount::getDateTime, dateTime); + List ticketCounts = baseMapper.selectList(queryWrapper); + return ticketCounts; + }, executor); + //第一种工作票 + CompletableFuture oneTicketCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> { + //查询第一种工作票 + List ticketCountList = getTicketCountList(createDept, items, "6", dateTime,user); + if (CollectionUtils.isNotEmpty(ticketCountList)) { + this.saveBatch(ticketCountList); + } + }, executor); + //第二种工作票 + CompletableFuture twoTicketCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> { + //查询第一种工作票 + List ticketCountList = getTicketCountList(createDept, items, "7", dateTime,user); + if (CollectionUtils.isNotEmpty(ticketCountList)) { + this.saveBatch(ticketCountList); + } + }, executor); + //水力机械工作票 + CompletableFuture threeTicketCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> { + //查询第一种工作票 + List ticketCountList = getTicketCountList(createDept, items, "8", dateTime,user); + if (CollectionUtils.isNotEmpty(ticketCountList)) { + this.saveBatch(ticketCountList); + } + }, executor); + //操作票 + CompletableFuture standardCompletableFuture = ticketCountsCompletableFuture.thenAcceptAsync((items) -> { + //操作票 + List ticketCountList = getStandardTicketCountList(createDept, items, "3", dateTime,user); + if (CollectionUtils.isNotEmpty(ticketCountList)) { + this.saveBatch(ticketCountList); + } + + }, executor); + //执行线程操作 + CompletableFuture.allOf(ticketCountsCompletableFuture, + oneTicketCompletableFuture, + twoTicketCompletableFuture, + threeTicketCompletableFuture, + standardCompletableFuture) + .get(); + } + + /** + * 统计操作票功能 + * + * @param createDept 所属机构及下属机构 + * @param items 两票统计对象 + * @param ticketType 两票状态 + * @param dateTime + * @param user + * @return + */ + private List getStandardTicketCountList(List createDept, List items, String ticketType, String dateTime, BladeUser user) { + List ticketInfoEntities = + standardTicketInfoService.selectStandardTicketByDeptIdWithTicketType(createDept, ticketType); + if (CollectionUtils.isEmpty(ticketInfoEntities)) { + return null; + } + //根据站点分组 + Map> createDeptTickets = + ticketInfoEntities.stream().collect(Collectors.groupingBy(StandardTicketInfoEntity::getCreateDept)); + //获取 操作票的id,删除 + if (CollectionUtils.isNotEmpty(items)) { + List collect = items.stream().filter(item -> ticketType.equals(item.getTicketType())).map(TicketCount::getId).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + baseMapper.deleteBatchIds(collect); + } + } + Set>> entries = createDeptTickets.entrySet(); + List ticketCountList = new ArrayList<>(); + for (Map.Entry> entry : entries) { + TicketCount ticketCount = new TicketCount(); + ticketCount.setDateTime(dateTime); + ticketCount.setDeptId(entry.getKey()); + ticketCount.setTenantId(user.getTenantId()); + ticketCount.setCreateDept(user.getDeptId()); + //根据id获取部门名称 + R deptName = systemClient.getDeptName(entry.getKey()); + if (deptName.isSuccess()) { + ticketCount.setDeptName(deptName.getData()); + } + List values = entry.getValue(); + ticketCount.setTicketType(CollectionUtils.isNotEmpty(values) ? values.get(0).getTicketType() : ticketType); + //1. 开票数量 + List ticketNumbers = + values.stream().filter(item -> item.getFlowTaskName() != null).collect(Collectors.toList()); + ticketCount.setTicketNumber(ticketNumbers.size()); + //2. 完成数量 + List ticketCompleteNums = + values.stream().filter(item -> "结束".equals(item.getFlowTaskName())).collect(Collectors.toList()); + ticketCount.setTicketCompleteNum(ticketCompleteNums.size()); + //3. 延期数据量 + ticketCount.setTicketDelayNum(0); + //4. 合格数量 + List ticketIdList = values.stream().map(item -> item.getId()).collect(Collectors.toList()); + LambdaQueryWrapper evaluateEntityLambdaQueryWrapper = + new LambdaQueryWrapper<>(); + evaluateEntityLambdaQueryWrapper.in(TicketInfoEvaluateEntity::getTicketId, ticketIdList); + evaluateEntityLambdaQueryWrapper.eq(BaseEntity::getStatus, 1); + List evaluateEntities = ticketInfoEvaluateService.list(evaluateEntityLambdaQueryWrapper); + ticketCount.setTicketProportionNum(evaluateEntities.size()); + ticketCountList.add(ticketCount); + } + return ticketCountList; + } + + + /** + * 统计第一种工作票,第二种工作功能,机械工作票功能 + * + * @param createDept 所属机构及下属机构 + * @param items 两票统计对象 + * @param ticketType 两票状态 + * @param dateTime + * @param user + * @return + */ + private List getTicketCountList(List createDept, List items, String ticketType, String dateTime, BladeUser user) { + List ticketInfoEntities = + workTicketInfoService.selectTicketByDeptIdWithTicketType(createDept, ticketType); + if (CollectionUtils.isEmpty(ticketInfoEntities)) { + return null; + } + //根据站点分组 + Map> createDeptTickets = ticketInfoEntities.stream().collect(Collectors.groupingBy(BaseEntity::getCreateDept)); + if (CollectionUtils.isNotEmpty(items)) { + //获取工作票的id,删除 + List collect = items.stream().filter(item -> ticketType.equals(item.getTicketType())).map(TicketCount::getId).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + baseMapper.deleteBatchIds(collect); + } + } + Set>> entries = createDeptTickets.entrySet(); + + List ticketCountList = new ArrayList<>(); + for (Map.Entry> entry : entries) { + TicketCount ticketCount = new TicketCount(); + ticketCount.setDeptId(entry.getKey()); + ticketCount.setDateTime(dateTime); + //根据id获取部门名称 + R deptName = systemClient.getDeptName(entry.getKey()); + if (deptName.isSuccess()) { + ticketCount.setDeptName(deptName.getData()); + } + List values = entry.getValue(); + ticketCount.setTicketType(CollectionUtils.isNotEmpty(values) ? values.get(0).getType() : ticketType); + //1. 开票数量 + List ticketNumbers = + values.stream().filter(item -> item.getFlowTaskName() != null).collect(Collectors.toList()); + ticketCount.setTicketNumber(ticketNumbers.size()); + //2. 完成数量 + List ticketCompleteNums = + values.stream().filter(item -> "结束".equals(item.getFlowTaskName())).collect(Collectors.toList()); + ticketCount.setTicketCompleteNum(ticketCompleteNums.size()); + ticketCount.setTenantId(user.getTenantId()); + ticketCount.setCreateDept(user.getDeptId()); + //3. 延期数据量 + List ticketDelayNums = + values.stream().filter(item -> "延期".equals(item.getInput())).collect(Collectors.toList()); + ticketCount.setTicketDelayNum(ticketDelayNums.size()); + //4. 合格数量 + List ticketIdList = values.stream().map(item -> item.getId()).collect(Collectors.toList()); + LambdaQueryWrapper evaluateEntityLambdaQueryWrapper = + new LambdaQueryWrapper<>(); + evaluateEntityLambdaQueryWrapper.in(TicketInfoEvaluateEntity::getTicketId, ticketIdList); + evaluateEntityLambdaQueryWrapper.eq(BaseEntity::getStatus, 1); + List evaluateEntities = ticketInfoEvaluateService.list(evaluateEntityLambdaQueryWrapper); + ticketCount.setTicketProportionNum(evaluateEntities.size()); + ticketCountList.add(ticketCount); + } + return ticketCountList; + } +} diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/IWorkTicketInfoService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/IWorkTicketInfoService.java index f5c48bf..1ecc3f5 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/IWorkTicketInfoService.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/IWorkTicketInfoService.java @@ -155,4 +155,12 @@ public interface IWorkTicketInfoService extends BaseService selectTicketByDeptIdWithTicketType(List createDept, String ticketType); } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java index 0105a3d..f474bf5 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java @@ -48,6 +48,7 @@ import lombok.var; import org.apache.commons.collections.map.HashedMap; import org.apache.poi.ss.usermodel.Workbook; import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.mp.base.BaseEntity; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.BladePage; import org.springblade.core.mp.support.Condition; @@ -1093,4 +1094,19 @@ public class WorkTicketInfoServiceImpl extends BaseServiceImpl selectTicketByDeptIdWithTicketType(List createDept, String ticketType) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(WorkTicketInfoEntity::getType,ticketType); + queryWrapper.in(BaseEntity::getCreateDept,createDept); + return baseMapper.selectList(queryWrapper); + } } diff --git a/hzims-service/ticket/src/main/resources/db/2.0.0.sql b/hzims-service/ticket/src/main/resources/db/2.0.0.sql new file mode 100644 index 0000000..9d3c495 --- /dev/null +++ b/hzims-service/ticket/src/main/resources/db/2.0.0.sql @@ -0,0 +1,21 @@ +-- auto-generated definition +create table hzims_ticket_count +( + id bigint auto_increment comment '主键ID' + primary key, + date_time varchar(20) null comment '日期', + dept_id bigint null comment '站点Id', + dept_name varchar(100) null comment '站点名称', + ticket_type varchar(255) null comment '票据类型', + ticket_number int null comment '开票数量', + ticket_complete_num int null comment '完成数量', + ticket_delay_num int null comment '延期数量', + ticket_proportion_num int null comment '合格数量', + create_time datetime default CURRENT_TIMESTAMP null comment '创建时间', + update_time datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间', + is_deleted tinyint(1) default 0 null comment '0', + tenant_id varchar(12) null comment '租户ID', + create_dept varchar(30) null comment '创建部门' +) + comment '两票统计分析' row_format = DYNAMIC; +