diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java index 0ffa227f..64ceea25 100644 --- a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java @@ -85,6 +85,14 @@ public class DefaultNumberConstants { */ public static final int ELEVEN_NUMBER = 11; + + /** + * 21 + */ + public static final int TWELVE_NUMBER = 12; + + + /** * 14 */ diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseCallDeduct.java b/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseCallDeduct.java index 18f2c579..82faab11 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseCallDeduct.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseCallDeduct.java @@ -18,6 +18,8 @@ import java.util.Date; @EntityListeners(AuditingEntityListener.class) public class BaseCallDeduct implements Serializable { + private static final long serialVersionUID = 8524392736006591529L; + @Column(name = "deduct_duration") @ApiModelProperty(value = "扣减时长") private Integer deductDuration; @@ -53,4 +55,9 @@ public class BaseCallDeduct implements Serializable { @Column(name="type") @ApiModelProperty(value = "消费类型1 话费消耗 2 套餐充值 3 余额充值") private Integer type; + + @Column(name = "combo_type") + @ApiModelProperty(value = "套餐类型") + private String comboType; + } diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/enums/ResponseCode.java b/ad-platform-pojo/src/main/java/com/baiye/model/enums/ResponseCode.java index f0d0f376..43949d18 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/enums/ResponseCode.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/enums/ResponseCode.java @@ -142,6 +142,12 @@ public enum ResponseCode { * 当前账户未登录或不在线 */ ACCOUNT_NOT_LOGGED_OR_NOT_ONLINE("1030", "当前账户未登录或不在线"), + + /** + * 修改套餐失败 + */ + UPDATE_COMBO_FRIEND("1033","修改套餐失败!"), + /** * * 非超级管理员不能修改数据 diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/settlement/service/impl/CallCostServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/settlement/service/impl/CallCostServiceImpl.java index aacd85ab..9db35439 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/settlement/service/impl/CallCostServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/settlement/service/impl/CallCostServiceImpl.java @@ -102,8 +102,8 @@ public class CallCostServiceImpl implements CallCostService { CompanyDto companyById = companyService.findCompanyById(companyId); int callMode = organizeService.getOrganizeByUserId(userId).getCallMode(); //获取呼叫单价 - PayFatherTemplate payFatherTemplate = payFatherTemplateRepository.findById(payTemplate.getFatherTemplateId()).orElseGet(PayFatherTemplate::new); - double price = callMode == 0 ? payFatherTemplate.getDoubleCallFee() : payFatherTemplate.getRollCallFee(); + // PayFatherTemplate payFatherTemplate = payFatherTemplateRepository.findById(payTemplate.getFatherTemplateId()).orElseGet(PayFatherTemplate::new); + double price = callMode == 0 ? companyById.getDoubleCallFee() : companyById.getRollCallFee(); //今日计算预扣 double estimateAmountToDay = getEstimateAmount(list, price); diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/CallDeduct.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/CallDeduct.java new file mode 100644 index 00000000..436a5271 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/CallDeduct.java @@ -0,0 +1,33 @@ +package com.baiye.modules.system.domain; + +import com.baiye.model.entity.BaseCallDeduct; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import javax.persistence.*; + +/** + * @author Enzo + * @date : 2022/11/9 + */ + +@Getter +@Setter +@Entity +@Table(name = "tb_call_deduct") +@ApiModel(value = "callDeduct") +public class CallDeduct extends BaseCallDeduct { + + private static final long serialVersionUID = 4589747995298896266L; + + @Id + @ApiModelProperty(value = "消费扣减表,主键id(自动递增)") + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Transient + private String username; +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Company.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Company.java index 4598dac5..31b259e0 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Company.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Company.java @@ -1,5 +1,6 @@ package com.baiye.modules.system.domain; +import com.baiye.constant.DefaultNumberConstants; import com.baiye.model.base.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -102,23 +103,30 @@ public class Company extends BaseEntity implements Serializable { @ApiModelProperty("授权状态") @Column(name = "authorization_state") private Boolean authorizationState = Boolean.FALSE; + @ApiModelProperty("版本号") @Column(name = "version") - private int version=0; + private Integer version = DefaultNumberConstants.ZERO_NUMBER; + @ApiModelProperty("双呼价格") @Column(name = "double_call_fee") private Double doubleCallFee; + @ApiModelProperty("去显号价格") @Column(name = "roll_call_fee") private Double rollCallFee; + @ApiModelProperty("抖音去显号价格") @Column(name = "tiktok_call_fee") private Double tiktokCallFee; + @ApiModelProperty("投流去显号价格") @Column(name = "delivery_call_fee") private Double deliveryCallFee; + @ApiModelProperty("拓客去显号价格") @Column(name = "talk_call_fee") private Double talkCallFee; + } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/PayFatherTemplate.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/PayFatherTemplate.java index c2741f37..3744f7f2 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/PayFatherTemplate.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/PayFatherTemplate.java @@ -38,27 +38,12 @@ public class PayFatherTemplate implements Serializable { @NotNull(message = "模板名称不能为空", groups = {AddGroup.class}) private String name; - @Column(name = "double_call_fee") - @NotNull(message = "双呼费用不能为空", groups = {AddGroup.class}) - @ApiModelProperty(value = "双呼费用") - private Double doubleCallFee; - - - @Column(name = "dmp_delivery_fee") - @NotNull(message = "投流费用", groups = {AddGroup.class}) - @ApiModelProperty(value = "投流费用") - private Double dmpDeliveryFee; - - - @Column(name = "roll_call_fee") - @NotNull(message = "点呼费用不能为空", groups = {AddGroup.class}) - @ApiModelProperty(value = "点呼费用") - private Double rollCallFee; @Column(name = "status") @ApiModelProperty(value = "状态: 0:可用 1:禁用") private Integer status; + @CreationTimestamp @Column(name = "create_time") @ApiModelProperty(value = "创建时间") diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/vo/CallDeductResponseVO.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/vo/CallDeductResponseVO.java new file mode 100644 index 00000000..e0aa8af5 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/vo/CallDeductResponseVO.java @@ -0,0 +1,22 @@ +package com.baiye.modules.system.domain.vo; + +import cn.hutool.core.date.DatePattern; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +/** + * @author Enzo + * @date : 2022/11/10 + */ +@Data +public class CallDeductResponseVO { + + private String callMonth; + + private Double total; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATE_PATTERN, timezone = "GMT+8") + private Date billDate; +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/vo/CallDeductVO.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/vo/CallDeductVO.java new file mode 100644 index 00000000..87bb7404 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/vo/CallDeductVO.java @@ -0,0 +1,36 @@ +package com.baiye.modules.system.domain.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author Enzo + * @date : 2022/11/9 + */ + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CallDeductVO { + + + /** + * 获取月份 + * @return + */ + private Double total; + + + /** + * 获取消费金额 + * @return + */ + private Integer year; + + + private Integer month; + + + +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/vo/CompanyComboVO.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/vo/CompanyComboVO.java new file mode 100644 index 00000000..7b7572d4 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/vo/CompanyComboVO.java @@ -0,0 +1,44 @@ +package com.baiye.modules.system.domain.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * @author Enzo + * @date : 2022/11/10 + */ +@Data +public class CompanyComboVO { + + @ApiModelProperty("公司id") + private Long companyId; + + @ApiModelProperty("模板名称") + private String templateName; + + @ApiModelProperty("公司名称") + private String companyName; + + @ApiModelProperty("双呼价格") + private Double doubleCallFee; + + @ApiModelProperty("去显号价格") + private Double rollCallFee; + + @ApiModelProperty("抖音去显号价格") + private Double tiktokCallFee; + + @ApiModelProperty("投流去显号价格") + private Double deliveryCallFee; + + @ApiModelProperty("拓客去显号价格") + private Double talkCallFee; + + @ApiModelProperty("坐席号") + private Integer seatNumber; + + @ApiModelProperty("修改时间") + private Date updateTime; +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/CallDeductRepository.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/CallDeductRepository.java new file mode 100644 index 00000000..a3469067 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/CallDeductRepository.java @@ -0,0 +1,57 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.baiye.modules.system.repository; + +import cn.hutool.core.date.DateTime; +import com.baiye.modules.system.domain.CallDeduct; +import com.baiye.modules.system.domain.vo.CallDeductVO; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; + +import java.util.Date; +import java.util.List; + +/** +* @author Enzo +* @date 2022-11-9 +*/ +public interface CallDeductRepository extends JpaRepository, JpaSpecificationExecutor { + + /** + * 时间查找 + * @param companyId + * @param beginTime + * @param endTime + * @return + */ + @Query(value = "SELECT new com.baiye.modules.system.domain.vo.CallDeductVO(sum (c.deductAmount) as total, year(c.createTime), month(c.createTime)) from CallDeduct c" + + " WHERE c.companyId = ?1 and c.createTime >= ?2 and c.createTime <=?3 group by year(c.createTime), month(c.createTime)") + List findByCompanyIdAndTime(Long companyId, Date beginTime, Date endTime); + + + + + /** + * 公司id查找记录 + * @param companyId + * @param parse + * @param endDate + * @return + */ + @Query(value = "from CallDeduct where companyId = ?1 and createTime >= ?2 and createTime <= ?3") + List queryByCompanyIdAndTime(Long companyId, DateTime parse, DateTime endDate); +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/UserRepository.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/UserRepository.java index b6e63343..25232846 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/UserRepository.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/UserRepository.java @@ -263,4 +263,13 @@ public interface UserRepository extends JpaRepository, JpaSpecificat void updateExpirationTimeById(Date expirationTime, Long id); + /** + * 根据公司 + * + * @param companyId / + * @return / + */ + int countByCompanyId(Long companyId); + + } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/CallDeductController.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/CallDeductController.java new file mode 100644 index 00000000..9fba2f6b --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/CallDeductController.java @@ -0,0 +1,57 @@ +package com.baiye.modules.system.rest; + +import com.baiye.modules.system.service.CallDeductService; +import com.baiye.modules.system.service.dto.CallDeductMonthQueryCriteria; +import com.baiye.modules.system.service.dto.CallDeductQueryCriteria; +import com.baiye.util.SecurityUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * @author Enzo + * @date : 2022/11/9 + */ +@Api(tags = "消费记录") +@Slf4j +@RestController +@AllArgsConstructor +@RequestMapping(value = "/api/call/deduct") +public class CallDeductController { + + + private final CallDeductService callDeductService; + + + @ApiOperation("消费记录/按月统计") + @GetMapping("/list") + public ResponseEntity list(CallDeductQueryCriteria criteria, Pageable pageable) { + Long companyId = SecurityUtils.getCompanyId(); + return new ResponseEntity<>(callDeductService.queryAll(criteria, pageable, companyId), HttpStatus.OK); + } + + @ApiOperation("消费记录/按月统计") + @GetMapping("/month/list") + public ResponseEntity monthList(CallDeductMonthQueryCriteria criteria, Pageable pageable) { + Long companyId = SecurityUtils.getCompanyId(); + return new ResponseEntity<>(callDeductService.queryMonthList(criteria, pageable, companyId), HttpStatus.OK); + } + + @ApiOperation("导出数据") + @GetMapping(value = "/download") + public void download(HttpServletResponse response, CallDeductMonthQueryCriteria criteria) throws IOException { + callDeductService.download(criteria, SecurityUtils.getCompanyId(), response); + } + + +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/CompanyController.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/CompanyController.java index de205c5c..ad17d9c8 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/CompanyController.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/CompanyController.java @@ -1,6 +1,7 @@ package com.baiye.modules.system.rest; import com.baiye.modules.system.service.CompanyService; +import com.baiye.modules.system.service.dto.CompanyComboDTO; import com.baiye.modules.system.service.dto.CompanyDto; import com.baiye.modules.system.service.dto.CompanyQueryCriteria; import com.baiye.util.SecurityUtils; @@ -69,4 +70,20 @@ public class CompanyController { } + @ApiOperation("套餐列表") + @GetMapping("/comboList") + public ResponseEntity comboList(CompanyQueryCriteria criteria, Pageable pageable) { + return new ResponseEntity<>(companyService.comboList(criteria, pageable), HttpStatus.OK); + } + + + + @ApiOperation("设置套餐") + @PostMapping("/update/combo") + public ResponseEntity updateCombo(@Validated @RequestBody CompanyComboDTO comboDTO) { + return new ResponseEntity<>(companyService.updateCompanyCombo(comboDTO), HttpStatus.OK); + } + + + } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/CallDeductService.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/CallDeductService.java new file mode 100644 index 00000000..52851b62 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/CallDeductService.java @@ -0,0 +1,57 @@ +package com.baiye.modules.system.service; + +import com.baiye.modules.system.service.dto.CallDeductMonthQueryCriteria; +import com.baiye.modules.system.service.dto.CallDeductQueryCriteria; +import org.springframework.data.domain.Pageable; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Map; + +/** + * @author Enzo + * @date : 2022/11/9 + */ +public interface CallDeductService { + + + /** + * 查询记录 + * + * @param criteria + * @param pageable + * @param companyId + * @return + */ + Map queryAll(CallDeductQueryCriteria criteria, Pageable pageable, Long companyId); + + /** + * 月份查找记录 + * @param criteria + * @param pageable + * @param companyId + * @return + */ + Map queryMonthList(CallDeductMonthQueryCriteria criteria, Pageable pageable, Long companyId); + + /** + * 保存记录 + * + * @param unitAmount + * @param userId + * @param companyId + * @param number + * @param combo + * @return + */ + Boolean saveUserCombo(Double unitAmount, Long userId, Long companyId, Integer number, String combo); + + /** + * 下载Excel + * @param criteria + * @param companyId + * @param response + * @throws IOException + */ + void download(CallDeductMonthQueryCriteria criteria, Long companyId, HttpServletResponse response) throws IOException; +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/CompanyService.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/CompanyService.java index 9c4c5e5c..c34f1bab 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/CompanyService.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/CompanyService.java @@ -1,6 +1,7 @@ package com.baiye.modules.system.service; import com.baiye.modules.system.domain.Company; +import com.baiye.modules.system.service.dto.CompanyComboDTO; import com.baiye.modules.system.service.dto.CompanyDto; import com.baiye.modules.system.service.dto.CompanyQueryCriteria; import org.springframework.data.domain.Pageable; @@ -141,4 +142,19 @@ public interface CompanyService { * @return */ Company findCompanyByUserId(Long userId); + + /** + * 修改公司套餐 + * @param comboDTO + * @return + */ + Boolean updateCompanyCombo(CompanyComboDTO comboDTO); + + /** + * 套餐分页 + * @param criteria + * @param pageable + * @return + */ + Map comboList(CompanyQueryCriteria criteria, Pageable pageable); } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CallDeductMonthQueryCriteria.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CallDeductMonthQueryCriteria.java new file mode 100644 index 00000000..994ac324 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CallDeductMonthQueryCriteria.java @@ -0,0 +1,31 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.baiye.modules.system.service.dto; + +import com.baiye.annotation.Query; +import lombok.Data; + +/** +* @author Zheng Jie +* @date 2019-04-10 +*/ +@Data +public class CallDeductMonthQueryCriteria { + + + @Query + private String queryTime; +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CallDeductQueryCriteria.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CallDeductQueryCriteria.java new file mode 100644 index 00000000..8e977dd0 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CallDeductQueryCriteria.java @@ -0,0 +1,37 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.baiye.modules.system.service.dto; + +import com.baiye.annotation.Query; +import lombok.Data; + +import java.sql.Timestamp; +import java.util.List; + +/** +* @author Zheng Jie +* @date 2019-04-10 +*/ +@Data +public class CallDeductQueryCriteria { + + @Query + private Long companyId; + + + @Query(type = Query.Type.BETWEEN) + private List createTime; +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CompanyComboDTO.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CompanyComboDTO.java new file mode 100644 index 00000000..f4ff47ff --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CompanyComboDTO.java @@ -0,0 +1,46 @@ +package com.baiye.modules.system.service.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.DecimalMax; +import javax.validation.constraints.DecimalMin; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * @author Enzo + * @date : 2022/11/10 + */ +@Data +public class CompanyComboDTO { + + @NotNull + @ApiModelProperty("公司id") + private Long companyId; + + @ApiModelProperty("双呼价格") + @DecimalMin(value = "0.0") + @DecimalMax(value = "999.0") + private Double doubleCallFee; + + @ApiModelProperty("去显号价格") + @DecimalMin(value = "0.0") + @DecimalMax(value = "999.0") + private Double rollCallFee; + + @ApiModelProperty("抖音去显号价格") + @DecimalMin(value = "0.0") + @DecimalMax(value = "999.0") + private Double tiktokCallFee; + + @ApiModelProperty("投流去显号价格") + @DecimalMin(value = "0.0") + @DecimalMax(value = "999.0") + private Double deliveryCallFee; + + @ApiModelProperty("拓客去显号价格") + @DecimalMin(value = "0.0") + @DecimalMax(value = "999.0") + private Double talkCallFee; +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CompanyDto.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CompanyDto.java index 7869da7e..ee5ff7d3 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CompanyDto.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CompanyDto.java @@ -91,4 +91,21 @@ public class CompanyDto extends BaseDTO implements Serializable { private Boolean authorizationState; private int version = 0; + + @ApiModelProperty("双呼价格") + private Double doubleCallFee; + + @ApiModelProperty("去显号价格") + private Double rollCallFee; + + @ApiModelProperty("抖音去显号价格") + private Double tiktokCallFee; + + @ApiModelProperty("投流去显号价格") + private Double deliveryCallFee; + + @ApiModelProperty("拓客去显号价格") + private Double talkCallFee; + + } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/CallDeductServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/CallDeductServiceImpl.java new file mode 100644 index 00000000..a2986f59 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/CallDeductServiceImpl.java @@ -0,0 +1,156 @@ +package com.baiye.modules.system.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.text.StrPool; +import cn.hutool.core.util.ObjectUtil; +import com.baiye.constant.DefaultNumberConstants; +import com.baiye.modules.system.domain.CallDeduct; +import com.baiye.modules.system.domain.User; +import com.baiye.modules.system.domain.vo.CallDeductResponseVO; +import com.baiye.modules.system.domain.vo.CallDeductVO; +import com.baiye.modules.system.repository.CallDeductRepository; +import com.baiye.modules.system.repository.UserRepository; +import com.baiye.modules.system.service.CallDeductService; +import com.baiye.modules.system.service.CompanyService; +import com.baiye.modules.system.service.dto.CallDeductMonthQueryCriteria; +import com.baiye.modules.system.service.dto.CallDeductQueryCriteria; +import com.baiye.modules.system.service.dto.CompanyDto; +import com.baiye.util.FileUtil; +import com.baiye.util.PageUtil; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Enzo + * @date : 2022/11/9 + */ +@Service +@RequiredArgsConstructor +public class CallDeductServiceImpl implements CallDeductService { + + private final UserRepository userRepository; + + private final CompanyService companyService; + + private final CallDeductRepository callDeductRepository; + + + @Override + public Map queryAll(CallDeductQueryCriteria criteria, Pageable pageable, Long companyId) { + List createTime = criteria.getCreateTime(); + List voList = Lists.newArrayList(); + if (CollUtil.isNotEmpty(criteria.getCreateTime())) { + Timestamp endTime = createTime.get(DefaultNumberConstants.ONE_NUMBER); + Timestamp beginTime = createTime.get(DefaultNumberConstants.ZERO_NUMBER); + return getStringObjectMap(pageable, voList, + callDeductRepository.findByCompanyIdAndTime(companyId, beginTime, endTime)); + } + // 往前推移12月 + DateTime endDate = DateUtil.date(); + DateTime startTime = DateUtil.offsetMonth + (endDate, -DefaultNumberConstants.TWELVE_NUMBER); + return getStringObjectMap(pageable, voList, + callDeductRepository.findByCompanyIdAndTime(companyId, startTime, endDate)); + } + + private Map getStringObjectMap(Pageable pageable, List voList, List callDeductVOList) { + callDeductVOList.forEach( + vo -> { + String year = String.valueOf(vo.getYear()); + CallDeductResponseVO deductResponseVO = new CallDeductResponseVO(); + String format = year.concat(StrPool.DASHED.concat(String.valueOf(vo.getMonth()))); + DateTime parse = DateUtil.parse(format, "yyyy-MM"); + DateTime dateTime = + DateUtil.beginOfMonth(DateUtil.offsetMonth(parse, + DefaultNumberConstants.ONE_NUMBER)); + deductResponseVO.setCallMonth(format); + deductResponseVO.setTotal(vo.getTotal()); + deductResponseVO.setBillDate(dateTime); + voList.add(deductResponseVO); + }); + return PageUtil.toPage(PageUtil.toPage + (pageable.getPageNumber(), pageable.getPageSize(), voList), voList.size()); + } + + @Override + public Map queryMonthList(CallDeductMonthQueryCriteria criteria, Pageable pageable, Long companyId) { + Map map = Maps.newHashMap(); + String queryTime = criteria.getQueryTime(); + DateTime parse = DateUtil.parse(queryTime, "yyyy-MM"); + DateTime endDate = DateUtil.offsetMonth(parse, DefaultNumberConstants.ONE_NUMBER); + List deductList = + callDeductRepository.queryByCompanyIdAndTime + (companyId, parse, endDate); + deductList.forEach(deduct -> { + User byId = userRepository.findById(deduct.getMemberId()).orElseGet(User::new); + if (ObjectUtil.isNotNull(byId)) { + deduct.setUsername(byId.getUsername()); + } + }); + + List list = PageUtil.toPage(pageable.getPageNumber(), + pageable.getPageSize(), deductList); + CompanyDto companyById = companyService.findCompanyById(companyId); + map.put("content", list); + map.put("chargeBill", queryTime); + map.put("totalElements", deductList.size()); + map.put("companyName", companyById.getCompanyName()); + map.put("billTarikh", DateUtil.format(endDate, DatePattern.NORM_DATE_PATTERN)); + return map; + } + + @Override + public Boolean saveUserCombo(Double unitAmount, Long userId, Long companyId, Integer number, String combo) { + CallDeduct deduct = new CallDeduct(); + deduct.setType(number); + deduct.setMemberId(userId); + deduct.setComboType(combo); + deduct.setCompanyId(companyId); + deduct.setStatus(Boolean.TRUE); + deduct.setDeductAmount(unitAmount); + return callDeductRepository.save(deduct).getId() != null; + } + + @Override + public void download(CallDeductMonthQueryCriteria criteria, Long companyId, HttpServletResponse response) throws IOException { + String queryTime = criteria.getQueryTime(); + DateTime parse = DateUtil.parse(queryTime, "yyyy-MM"); + DateTime endDate = DateUtil.offsetMonth(parse, DefaultNumberConstants.ONE_NUMBER); + List deductList = + callDeductRepository.queryByCompanyIdAndTime + (companyId, parse, endDate); + deductList.forEach(deduct -> { + User byId = userRepository.findById(deduct.getMemberId()).orElseGet(User::new); + if (ObjectUtil.isNotNull(byId)) { + deduct.setUsername(byId.getUsername()); + } + }); + + List> list = new ArrayList<>(); + for (CallDeduct deduct : deductList) { + Map map = new LinkedHashMap<>(); + map.put("账号名称", deduct.getUsername()); + map.put("费用类型", deduct.getType() == DefaultNumberConstants.ONE_NUMBER ? "日结话费" : "套餐充值"); + map.put("费用金额", deduct.getDeductAmount()); + map.put("扣减日期", deduct.getCreateTime()); + map.put("扣减状态", Boolean.TRUE.equals(deduct.getStatus()) ? "成功" : "失败"); + map.put("套餐类型", deduct.getComboType()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/CompanyServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/CompanyServiceImpl.java index 54141544..3c76fa66 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/CompanyServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/CompanyServiceImpl.java @@ -9,16 +9,21 @@ import com.baiye.exception.EntityExistException; import com.baiye.model.enums.ResponseCode; import com.baiye.modules.security.service.OnlineUserService; import com.baiye.modules.system.domain.Company; +import com.baiye.modules.system.domain.PayFatherTemplate; +import com.baiye.modules.system.domain.vo.CompanyComboVO; import com.baiye.modules.system.repository.CompanyRepository; import com.baiye.modules.system.repository.UserRepository; import com.baiye.modules.system.service.AgentService; import com.baiye.modules.system.service.CompanyService; +import com.baiye.modules.system.service.PayFatherTemplateService; +import com.baiye.modules.system.service.dto.CompanyComboDTO; import com.baiye.modules.system.service.dto.CompanyDto; import com.baiye.modules.system.service.dto.CompanyQueryCriteria; import com.baiye.modules.system.service.mapstruct.CompanyMapper; import com.baiye.util.PageUtil; import com.baiye.util.QueryHelp; import com.baiye.util.SecurityUtils; +import com.google.common.collect.Lists; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; @@ -27,6 +32,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -39,9 +45,9 @@ import java.util.Map; public class CompanyServiceImpl implements CompanyService { - private final CompanyRepository companyRepository; + private final PayFatherTemplateService payFatherTemplateService; - private final OnlineUserService onlineUserService; + private final CompanyRepository companyRepository; private final UserRepository userRepository; @@ -181,4 +187,38 @@ public class CompanyServiceImpl implements CompanyService { return companyRepository.findByUserId(userId); } + @Override + public Boolean updateCompanyCombo(CompanyComboDTO comboDTO) { + if (ObjectUtil.isNotNull(comboDTO.getCompanyId())) { + Company company = companyRepository.findById + (comboDTO.getCompanyId()).orElseGet(Company::new); + if (ObjectUtil.isNotNull(company)) { + BeanUtil.copyProperties(comboDTO, company); + return ObjectUtil.isNotNull(companyRepository.save(company).getId()); + } + } + throw new BadRequestException(ResponseCode.UPDATE_COMBO_FRIEND.getDesc()); + } + + @Override + public Map comboList(CompanyQueryCriteria criteria, Pageable pageable) { + + List comboVOList = Lists.newArrayList(); + Page page = companyRepository.findAll + ((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); + for (Company company : page.getContent()) { + CompanyComboVO comboVO = new CompanyComboVO(); + int num = userRepository.countByCompanyId(company.getId()); + BeanUtil.copyProperties(company, comboVO); + comboVO.setSeatNumber(num); + comboVO.setCompanyId(company.getId()); + if (ObjectUtil.isNotNull(company.getTemplateId())) { + PayFatherTemplate byId = payFatherTemplateService.findById(company.getTemplateId()); + comboVO.setTemplateName(byId.getName()); + } + comboVOList.add(comboVO); + } + return PageUtil.toPage(comboVOList, page.getTotalElements()); + } + } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/PayFatherTemplateServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/PayFatherTemplateServiceImpl.java index b69ce45c..3d8f623e 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/PayFatherTemplateServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/PayFatherTemplateServiceImpl.java @@ -1,15 +1,14 @@ package com.baiye.modules.system.service.impl; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ObjectUtil; import com.baiye.constant.DefaultNumberConstants; import com.baiye.exception.BadRequestException; import com.baiye.modules.system.domain.Company; -import com.baiye.modules.system.domain.PayFatherTemplate; import com.baiye.modules.system.domain.PayCombo; +import com.baiye.modules.system.domain.PayFatherTemplate; import com.baiye.modules.system.repository.CompanyRepository; -import com.baiye.modules.system.repository.PayFatherTemplateRepository; import com.baiye.modules.system.repository.PayComboRepository; +import com.baiye.modules.system.repository.PayFatherTemplateRepository; import com.baiye.modules.system.service.PayFatherTemplateService; import com.baiye.modules.system.service.dto.PayFatherTemplateQueryCriteria; import com.baiye.util.PageUtil; @@ -24,7 +23,6 @@ import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.text.DecimalFormat; import java.util.List; import java.util.Map; import java.util.Set; @@ -47,12 +45,6 @@ public class PayFatherTemplateServiceImpl implements PayFatherTemplateService { @Transactional(rollbackFor = Exception.class) public void add(PayFatherTemplate payFatherTemplate) { payFatherTemplate.setStatus(DefaultNumberConstants.ZERO_NUMBER); - String deliveryFee = new DecimalFormat("#.00").format(payFatherTemplate.getDmpDeliveryFee()); - String doubleCall = new DecimalFormat("#.00").format(payFatherTemplate.getDoubleCallFee()); - String rollCall = new DecimalFormat("#.00").format(payFatherTemplate.getRollCallFee()); - payFatherTemplate.setDoubleCallFee(Double.parseDouble(doubleCall)); - payFatherTemplate.setDmpDeliveryFee(Double.parseDouble(deliveryFee)); - payFatherTemplate.setRollCallFee(Double.parseDouble(rollCall)); payFatherTemplateRepository.save(payFatherTemplate); } @@ -61,9 +53,7 @@ public class PayFatherTemplateServiceImpl implements PayFatherTemplateService { public void update(PayFatherTemplate payFatherTemplate) { Integer status = payFatherTemplate.getStatus(); String name = payFatherTemplate.getName(); - Double doubleCallFee = payFatherTemplate.getDoubleCallFee(); - Double deliveryFee = payFatherTemplate.getDmpDeliveryFee(); - Double rollCallFee = payFatherTemplate.getRollCallFee(); + PayFatherTemplate updateTemplate = payFatherTemplateRepository.findById(payFatherTemplate.getId()).orElseGet(PayFatherTemplate::new); if (status != null) { updateTemplate.setStatus(status); @@ -71,15 +61,6 @@ public class PayFatherTemplateServiceImpl implements PayFatherTemplateService { if (StringUtils.isNotBlank(name)) { updateTemplate.setName(name); } - if (doubleCallFee != null) { - updateTemplate.setDoubleCallFee(doubleCallFee); - } - if (rollCallFee != null) { - updateTemplate.setRollCallFee(rollCallFee); - } - if (ObjectUtil.isNotNull(deliveryFee)) { - updateTemplate.setRollCallFee(deliveryFee); - } payFatherTemplateRepository.save(updateTemplate); } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java index b53d5e50..0f860189 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java @@ -71,6 +71,7 @@ import java.util.*; public class UserServiceImpl implements UserService { + private final UserMapper userMapper; private final RedisUtils redisUtils; private final RoleRepository repository; @@ -92,6 +93,8 @@ public class UserServiceImpl implements UserService { private final OrganizeUserRepository organizeUserRepository; private final TaskRepository taskRepository; + private final CallDeductService callDeductService; + @Override @Transactional(rollbackFor = Exception.class) public Boolean fileCreateUser(List excels, Long companyId, UserDto userDto) { @@ -647,8 +650,8 @@ public class UserServiceImpl implements UserService { companyById.getUserBalance() != null ? companyById.getUserBalance() : DefaultNumberConstants.ZERO_NUMBER; // 计算金额 - Double totalAmount = NumberUtil.add(payCombo.getAmount(), payCombo.getBaseAmount()); - totalAmount = NumberUtil.mul(totalAmount, Double.valueOf(String.valueOf(userIds.size()))); + Double unitAmount = NumberUtil.add(payCombo.getAmount(), payCombo.getBaseAmount()); + Double totalAmount = NumberUtil.mul(unitAmount, Double.valueOf(String.valueOf(userIds.size()))); double deductionBalance = NumberUtil.sub(balance, totalAmount); // 判断余额 if (deductionBalance < DefaultNumberConstants.ZERO_NUMBER) { @@ -663,6 +666,8 @@ public class UserServiceImpl implements UserService { templateUser.setPayComboId(templateId); // 插入信息 Boolean result = payTemplateUserService.add(templateUser); + // 记录套餐 + callDeductService.saveUserCombo(unitAmount, userId, companyId, DefaultNumberConstants.TWO_NUMBER, "充值套餐"); payComboLogService.addPayTemplateLog(templateId, userId, result); } } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/dao/CallDeductRepository.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/dao/CallDeductRepository.java deleted file mode 100644 index e3e99f35..00000000 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/dao/CallDeductRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baiye.modules.telemarkting.dao; - -import com.baiye.modules.telemarkting.entity.CallDeduct; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.stereotype.Repository; - -@Repository -public interface CallDeductRepository extends JpaRepository, JpaSpecificationExecutor { -} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/CallDeduct.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/CallDeduct.java deleted file mode 100644 index 9772092e..00000000 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/entity/CallDeduct.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baiye.modules.telemarkting.entity; - -import com.baiye.model.entity.BaseCallDeduct; -import io.swagger.annotations.ApiModelProperty; -import lombok.Getter; -import lombok.Setter; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.io.Serializable; - -/** - * @author jt - */ -@Entity -@Getter -@Setter -@Table(name = "tb_call_deduct") -@EntityListeners(AuditingEntityListener.class) -public class CallDeduct extends BaseCallDeduct implements Serializable { - @Id - @ApiModelProperty(value = "主键id(自动递增)") - @Column(name = "id") - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - -} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java index d7313b2b..a104c966 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java @@ -11,8 +11,10 @@ import com.baiye.exception.BadRequestException; import com.baiye.feign.SourceClueClient; import com.baiye.http.CommonResponse; import com.baiye.model.enums.CallStatusEnum; +import com.baiye.modules.system.domain.CallDeduct; import com.baiye.modules.system.domain.Clue; import com.baiye.modules.system.domain.Company; +import com.baiye.modules.system.repository.CallDeductRepository; import com.baiye.modules.system.repository.CompanyRepository; import com.baiye.modules.system.service.CompanyService; import com.baiye.modules.telemarkting.dao.*; @@ -62,6 +64,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { private CompanyService companyService; @Resource private CallDeductRepository callDeductRepository; + @Resource private CompanyRepository companyRepository; @@ -292,8 +295,8 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { AllCallInfo allCallInfo = allCallInfoRepository.findBySessionId(otherLeg); // int status = DefaultNumberConstants.ONE_NUMBER; if (ObjectUtil.isNotEmpty(allCallInfo)) { - //相同说明是分机号的回调 - if (sessionId.equals(otherLeg) && StrUtil.isNotBlank(rollCallBackDTO.getRecord_file_url())) { + // 相同说明是分机号的回调 + if (sessionId.equals(otherLeg) && CharSequenceUtil.isNotBlank(rollCallBackDTO.getRecord_file_url())) { allCallInfoRepository.updateByRecord(DefaultNumberConstants.ONE_NUMBER, rollCallBackDTO.getRecord_file_url(), allCallInfo.getId()); } else { //拨打线索号的回调 @@ -303,7 +306,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { allCallInfoRepository.updateByDurationAndStatus(DefaultNumberConstants.TWO_NUMBER, Integer.valueOf(rollCallBackDTO.getDuration()), allCallInfo.getId()); //更新资源通话状态 CompletableFuture.runAsync(() -> updateSourceCallStatus(allCallInfo.getClueId(), DefaultNumberConstants.TWO_NUMBER)); - //TODO 实时扣除话费 + // TODO 实时扣除话费 callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), Integer.valueOf(rollCallBackDTO.getDuration()), 2); } else { //更新资源通话状态 @@ -343,19 +346,25 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { //模板费用 double fee; + String typeStr; if (callType == DefaultNumberConstants.ONE_NUMBER) { //双呼 fee = company.getDoubleCallFee(); + typeStr = "双呼套餐"; } else { //点呼 if (clueType == DefaultNumberConstants.THREE_NUMBER) { fee = company.getTiktokCallFee(); + typeStr = "抖音套餐"; } else if (clueType == DefaultNumberConstants.FOUR_NUMBER) { fee = company.getDeliveryCallFee(); + typeStr = "投流套餐"; } else if (clueType == DefaultNumberConstants.FIVE_NUMBER) { fee = company.getTalkCallFee(); + typeStr = "拓客套餐"; } else { fee = company.getRollCallFee(); + typeStr = "crm套餐"; } } double minDuration = dealDuration(duration); @@ -367,6 +376,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { callDeduct.setMemberId(memberId); callDeduct.setCompanyId(companyId); callDeduct.setStatus(false); + callDeduct.setComboType(typeStr); callDeduct.setCreateTime(new Date()); callDeduct.setVersion(company.getVersion()); callDeduct.setType(DefaultNumberConstants.ONE_NUMBER); diff --git a/manage/ad-platform-management/src/main/java/com/baiye/timed/DeliveryBalanceTask.java b/manage/ad-platform-management/src/main/java/com/baiye/timed/DeliveryBalanceTask.java index 4abccb30..8c5d235c 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/timed/DeliveryBalanceTask.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/timed/DeliveryBalanceTask.java @@ -9,7 +9,6 @@ import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.StrPool; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import com.baiye.config.properties.DeliveryProperties; import com.baiye.constant.DefaultNumberConstants; import com.baiye.modules.system.domain.Company; @@ -54,7 +53,6 @@ public class DeliveryBalanceTask { private final DeliveryRecordService deliveryRecordService; - private final PayFatherTemplateService payFatherTemplateService; @Scheduled(cron = "0 0/30 8-23 * * ? ") @@ -74,11 +72,8 @@ public class DeliveryBalanceTask { Company companyByUserId = companyService.findCompanyByUserId(userId); if (ObjectUtil.isNotNull(companyByUserId) && ObjectUtil.isNotNull(companyByUserId.getTemplateId())) { - // 查找模板 - PayFatherTemplate template = - payFatherTemplateService.findById(companyByUserId.getTemplateId()); - if (ObjectUtil.isNotNull(template) && - ObjectUtil.isNotNull(template.getDmpDeliveryFee())) { + // 判断价格 + if (ObjectUtil.isNotNull(companyByUserId.getDeliveryCallFee())) { // 每次100000 数据 List> lists = Lists.partition (list, DefaultNumberConstants.ONE_HUNDRED_THOUSAND); @@ -86,7 +81,7 @@ public class DeliveryBalanceTask { for (List taskImeiList : lists) { // 大于100 进行兑换 if (taskImeiList.size() >= DefaultNumberConstants.ONE_HUNDRED) { - BigDecimal decimal = NumberUtil.mul(template.getDmpDeliveryFee(), BigDecimal.valueOf(taskImeiList.size())); + BigDecimal decimal = NumberUtil.mul(companyByUserId.getDeliveryCallFee(), BigDecimal.valueOf(taskImeiList.size())); BigDecimal sub = NumberUtil.sub(companyByUserId.getUserBalance(), decimal); // 判断余额 if (sub.compareTo(BigDecimal.valueOf diff --git a/services/ad-platform-source/src/main/java/com/baiye/task/MailSourceTask.java b/services/ad-platform-source/src/main/java/com/baiye/task/MailSourceTask.java index 03ad1483..394f504e 100644 --- a/services/ad-platform-source/src/main/java/com/baiye/task/MailSourceTask.java +++ b/services/ad-platform-source/src/main/java/com/baiye/task/MailSourceTask.java @@ -3,13 +3,14 @@ package com.baiye.task; import cn.hutool.core.codec.Base64; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.text.StrPool; import cn.hutool.core.text.csv.CsvData; import cn.hutool.core.text.csv.CsvReader; import cn.hutool.core.text.csv.CsvUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.json.JSONUtil; import com.baiye.config.properties.DeliveryProperties; import com.baiye.constant.DefaultNumberConstants; import com.baiye.exception.BadRequestException; @@ -31,10 +32,13 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import javax.mail.Flags; import javax.mail.Message; +import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; import java.io.File; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Objects; @@ -106,6 +110,7 @@ public class MailSourceTask { List> partitions = ListUtil.partition(phoneList, 200); for (List partition : partitions) { String join = Joiner.on(StrPool.COMMA).skipNulls().join(partition); + // 批量解析号码 SecretResponseBean responseBean = DecryptPnoUtil.batchDecryptPno (Base64.encode(StringUtils.substringBeforeLast(join, StrPool.COMMA))); if (Objects.nonNull(responseBean)) { @@ -117,7 +122,7 @@ public class MailSourceTask { } } if (CollUtil.isNotEmpty(decryptList)) { - log.info("=================== the decryptList as {} =====================", JSONUtil.toJsonStr(decryptList)); + log.info("=================== the decryptList size as {} =====================", decryptList.size()); // 将imei转为线索 clueService.saveClue(tagList, decryptList, byTaskName.getTaskId(), byTaskName.getUserId(), DefaultNumberConstants.FOUR_NUMBER); @@ -126,7 +131,6 @@ public class MailSourceTask { task.setId(taskId); task.setTotalNumber(taskNum); task.setIsDistribution(DefaultNumberConstants.ONE_NUMBER); - // 删除邮件 删除文件 FileUtil.del(path); FileUtil.del(unzipPath); @@ -139,10 +143,34 @@ public class MailSourceTask { } } } catch (Exception e) { - log.error("=================== the receive mail error time as {} ===========", e.getMessage()); + log.error("=================== the receive mail error message as {} ===========", e.getMessage()); throw new BadRequestException("接收邮件失败"); } } } + + /** + * 删除七天前数据 + */ + @Scheduled(cron = "0 25 23 * * ? ") + public void deleteMail() { + // 获取邮件内容 + List list = MailUtil.readMailByIMAP + (deliveryProperties.getEmailAddress(), deliveryProperties.getEmailPassword()); + try { + for (Message message : list) { + Date sentDate = message.getSentDate(); + // 时间偏移三十天 + DateTime dateTime = DateUtil.offsetDay(DateUtil.date(), -DefaultNumberConstants.SEVEN_NUMBER); + if (dateTime.after(sentDate)) { + // 删除邮件 + message.setFlag(Flags.Flag.DELETED, Boolean.TRUE); + } + } + } catch (MessagingException e) { + log.error("=================== the delete mail error message as {} ===========", e.getMessage()); + throw new BadRequestException(e.getMessage()); + } + } }