diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/dto/TreeUserDTO.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/TreeUserDTO.java index 8c0792b8..c41b34a9 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/dto/TreeUserDTO.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/TreeUserDTO.java @@ -13,5 +13,7 @@ public class TreeUserDTO extends UserDto { private static final long serialVersionUID = -6936022647922476487L; + private Long templateId; + private List children; } 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 e997f0f0..575b1038 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 @@ -109,6 +109,12 @@ public enum ResponseCode { */ INSUFFICIENT_ACCOUNT_BALANCE("1019", "账户余额不足"), + /** + * + * 账户余额不足 + */ + CONNECTION_SUCCEEDED("1027", "连接成功"), + /** * * 非超级管理员不能修改数据 diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/enums/WebSocketEnums.java b/ad-platform-pojo/src/main/java/com/baiye/model/enums/WebSocketEnums.java index f199a15b..d24914a7 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/enums/WebSocketEnums.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/enums/WebSocketEnums.java @@ -11,6 +11,7 @@ import lombok.Getter; @Getter @AllArgsConstructor public enum WebSocketEnums { + /** * 置顶 */ @@ -34,7 +35,13 @@ public enum WebSocketEnums { /** * 新建 */ - CREATE(5,"create"); + CREATE(5,"create"), + + + /** + * 心跳 + */ + HEART_BEAT(6,"heart_beat"); private final Integer value; private final String type; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/CompanyRepository.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/CompanyRepository.java index 5494d9d4..86834d34 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/CompanyRepository.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/CompanyRepository.java @@ -87,4 +87,9 @@ public interface CompanyRepository extends JpaRepository, JpaSpec @Modifying @Query("UPDATE Company set templateId = ?1 where id = ?2") void updateCompanyTemplateIdById(Long templateId, Long companyId); + + /** + * 用户id查询 + */ + Company findByUserId(Long userId); } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/PayFatherTemplateRepository.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/PayFatherTemplateRepository.java index af646889..48cdc468 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/PayFatherTemplateRepository.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/repository/PayFatherTemplateRepository.java @@ -10,4 +10,6 @@ import java.util.Set; @Repository public interface PayFatherTemplateRepository extends JpaRepository, JpaSpecificationExecutor { void deleteByIdIn(Set ids); + + Set findByStatus(Integer status); } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/PayComboController.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/PayComboController.java index eb27ac55..aacd7ad8 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/PayComboController.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/rest/PayComboController.java @@ -3,6 +3,7 @@ package com.baiye.modules.system.rest; import com.baiye.http.CommonResponse; import com.baiye.modules.system.domain.PayCombo; import com.baiye.modules.system.service.PayComboService; +import com.baiye.modules.system.service.dto.PayComboQueryCriteria; import com.baiye.valid.AddGroup; import com.baiye.valid.UpdateGroup; import io.swagger.annotations.Api; @@ -37,7 +38,13 @@ public class PayComboController { @ApiOperation("查询模板列表") @GetMapping("/list") - public ResponseEntity query(){ - return new ResponseEntity<>(payComboService.query(), HttpStatus.OK); + public ResponseEntity list(){ + return new ResponseEntity<>(payComboService.list(), HttpStatus.OK); + } + + @ApiOperation("查询模板列表") + @GetMapping("/query") + public ResponseEntity query(PayComboQueryCriteria payComboQueryCriteria){ + return new ResponseEntity<>(payComboService.query(payComboQueryCriteria), HttpStatus.OK); } } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/PayComboService.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/PayComboService.java index d80a4a64..86f6d0d0 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/PayComboService.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/PayComboService.java @@ -1,6 +1,7 @@ package com.baiye.modules.system.service; import com.baiye.modules.system.domain.PayCombo; +import com.baiye.modules.system.service.dto.PayComboQueryCriteria; public interface PayComboService { @@ -20,7 +21,7 @@ public interface PayComboService { * 查询套餐模板列表 * @return */ - Object query(); + Object list(); /** * id查找模板 @@ -28,4 +29,6 @@ public interface PayComboService { * @return */ PayCombo findTemplateById(Long templateId); + + Object query(PayComboQueryCriteria payComboQueryCriteria); } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/PayComboDto.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/PayComboDto.java new file mode 100644 index 00000000..e597807b --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/PayComboDto.java @@ -0,0 +1,45 @@ +package com.baiye.modules.system.service.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.io.Serializable; +import java.util.Date; + +@Data +public class PayComboDto implements Serializable { + + private static final long serialVersionUID = 7917504710223840272L; + + @ApiModelProperty(value = "id") + private Long id; + + @ApiModelProperty(value = "套餐名称") + private String packageName; + + @ApiModelProperty(value = "套餐等级") + private Integer levelNumber; + + @ApiModelProperty(value = "父ID") + private Long fatherTemplateId; + + @ApiModelProperty(value = "金额") + private Double amount; + + @ApiModelProperty(value = "基础金额") + private Double baseAmount; + + @ApiModelProperty(value = "通话时长") + private Integer callDuration; + + @ApiModelProperty(value = "套餐天数") + private Integer packageDay; + + @ApiModelProperty(value = "状态: 0:可用 1:禁用") + private Integer status; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @ApiModelProperty(value = "修改时间") + private Date updateTime; +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/PayComboQueryCriteria.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/PayComboQueryCriteria.java new file mode 100644 index 00000000..876db1d5 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/PayComboQueryCriteria.java @@ -0,0 +1,23 @@ +package com.baiye.modules.system.service.dto; + +import com.baiye.annotation.Query; +import lombok.Data; + +/** + * 支付模板公共查询类 + */ +@Data +public class PayComboQueryCriteria { + + @Query + private Long id; + + @Query + private Integer status; + + @Query + private Long fatherTemplateId; + +// @Query(blurry = "name") +// private String name; +} 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 98a7d34e..90f565b8 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 @@ -147,6 +147,7 @@ public class CompanyServiceImpl implements CompanyService { } @Override + @CacheEvict(cacheNames = "companyCache", key = "#companyId") public void updateCompanyTemplateId(Long templateId, Long companyId) { companyRepository.updateCompanyTemplateIdById(templateId,companyId); } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/PayComboServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/PayComboServiceImpl.java index 001f8c54..ca697934 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/PayComboServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/PayComboServiceImpl.java @@ -1,12 +1,22 @@ 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.model.dto.UserDto; +import com.baiye.modules.system.domain.Company; import com.baiye.modules.system.domain.PayCombo; +import com.baiye.modules.system.domain.User; +import com.baiye.modules.system.repository.CompanyRepository; import com.baiye.modules.system.repository.PayComboRepository; +import com.baiye.modules.system.repository.UserRepository; import com.baiye.modules.system.service.CompanyService; import com.baiye.modules.system.service.PayComboService; +import com.baiye.modules.system.service.UserService; import com.baiye.modules.system.service.dto.CompanyDto; +import com.baiye.modules.system.service.dto.PayComboQueryCriteria; +import com.baiye.modules.system.service.mapstruct.PayComboMapper; +import com.baiye.util.QueryHelp; import com.baiye.util.SecurityUtils; import com.baiye.util.StringUtils; import lombok.RequiredArgsConstructor; @@ -31,7 +41,9 @@ import java.util.Set; public class PayComboServiceImpl implements PayComboService { private final PayComboRepository payComboRepository; - private final CompanyService companyService; + private final CompanyRepository companyRepository; + private final UserRepository userRepository; + private final PayComboMapper payComboMapper; @Value("${payTemplate.base_fee}") private Double baseFee; @Value("${payTemplate.beyond_fee}") @@ -77,17 +89,20 @@ public class PayComboServiceImpl implements PayComboService { } @Override - public Object query() { + public Object list() { //1、查询公司的模板 - CompanyDto company = companyService.findCompanyById(SecurityUtils.getCurrentUserId()); - Long fatherTemplateId = company.getTemplateId(); - //2、查询 - Set payCombos = payComboRepository.findByFatherTemplateIdAndStatus(fatherTemplateId, DefaultNumberConstants.ZERO_NUMBER); + User user = userRepository.findById(SecurityUtils.getCurrentUserId()).orElseGet(User::new); + Company company = companyRepository.findById(user.getCompanyId()).orElseGet(Company::new); HashMap map = new HashMap<>(); - if (CollUtil.isNotEmpty(payCombos)){ - map.put("list", payCombos); - map.put("baseFee",baseFee); - map.put("beyondFee",beyondFee); + if (ObjectUtil.isNotEmpty(company)){ + Long fatherTemplateId = company.getTemplateId(); + //2、查询 + Set payCombos = payComboRepository.findByFatherTemplateIdAndStatus(fatherTemplateId, DefaultNumberConstants.ZERO_NUMBER); + if (CollUtil.isNotEmpty(payCombos)){ + map.put("list", payCombos); + map.put("baseFee",baseFee); + map.put("beyondFee",beyondFee); + } } return map; } @@ -97,4 +112,11 @@ public class PayComboServiceImpl implements PayComboService { public PayCombo findTemplateById(Long templateId) { return payComboRepository.findById(templateId).orElseGet(PayCombo::new); } + + @Override + public Object query(PayComboQueryCriteria payComboQueryCriteria) { + payComboQueryCriteria.setStatus(DefaultNumberConstants.ZERO_NUMBER); + return payComboMapper.toDto(payComboRepository.findAll((root, criteriaQuery, criteriaBuilder) -> + QueryHelp.getPredicate(root, payComboQueryCriteria, criteriaBuilder))); + } } 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 7b993adc..d9348f19 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 @@ -83,7 +83,16 @@ public class PayFatherTemplateServiceImpl implements PayFatherTemplateService { if (CollUtil.isNotEmpty(companies)){ throw new BadRequestException("模板已绑定用户,请操作替换后然后删除"); } - payFatherTemplateRepository.deleteByIdIn(ids); + List payFatherTemplateList = payFatherTemplateRepository.findAllById(ids); + if (CollUtil.isNotEmpty(payFatherTemplateList)){ + payFatherTemplateList.forEach(pt -> pt.setStatus(DefaultNumberConstants.ONE_NUMBER)); + payFatherTemplateRepository.saveAll(payFatherTemplateList); + } + Set payComboSet = payComboRepository.findByFatherTemplateIdInAndStatus(ids, DefaultNumberConstants.ZERO_NUMBER); + if (CollUtil.isNotEmpty(payComboSet)){ + payComboSet.forEach(pt -> pt.setStatus(DefaultNumberConstants.ONE_NUMBER)); + payComboRepository.saveAll(payComboSet); + } } @Override @@ -107,7 +116,7 @@ public class PayFatherTemplateServiceImpl implements PayFatherTemplateService { @Override public Object list() { - return payFatherTemplateRepository.findAll(); + return payFatherTemplateRepository.findByStatus(DefaultNumberConstants.ZERO_NUMBER); } @Override 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 148022f6..52b4c978 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 @@ -135,6 +135,8 @@ public class UserServiceImpl implements UserService { for (RoleSmallDto role : roles) { if (role.getId() == DefaultNumberConstants.EIGHT_NUMBER) { user.setIsManager(Boolean.TRUE); + CompanyDto companyById = companyService.findCompanyById(user.getCompanyId()); + user.setTemplateId(companyById.getTemplateId()); } if (role.getId() == DefaultNumberConstants.ONE_NUMBER) { user.setIsAdmin(Boolean.TRUE); diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/PayComboMapper.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/PayComboMapper.java new file mode 100644 index 00000000..70b8f225 --- /dev/null +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/mapstruct/PayComboMapper.java @@ -0,0 +1,16 @@ +package com.baiye.modules.system.service.mapstruct; + +import com.baiye.model.base.BaseMapper; +import com.baiye.modules.system.domain.LabelOrganize; +import com.baiye.modules.system.domain.PayCombo; +import com.baiye.modules.system.service.dto.PayComboDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @author Zheng Jie +* @date 2019-03-25 +*/ +@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface PayComboMapper extends BaseMapper { +} diff --git a/manage/ad-platform-management/src/main/java/com/baiye/socket/WebSocketServer.java b/manage/ad-platform-management/src/main/java/com/baiye/socket/WebSocketServer.java index 134192b2..48984e4c 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/socket/WebSocketServer.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/socket/WebSocketServer.java @@ -6,6 +6,7 @@ import com.baiye.constant.DefaultNumberConstants; import com.baiye.http.WebSocketResponse; import com.baiye.manager.UserTokenManager; import com.baiye.model.dto.SendWebSocketDTO; +import com.baiye.model.enums.ResponseCode; import com.baiye.model.enums.WebSocketEnums; import com.baiye.modules.system.service.MessageNotificationService; import com.baiye.modules.system.service.UserMessageService; @@ -40,6 +41,7 @@ public class WebSocketServer { } private static final AtomicInteger ONLINE_COUNT = new AtomicInteger(0); + /** * concurrent包的线程安全Set,用来存放每个客户端对应的Session对象。 */ @@ -69,10 +71,16 @@ public class WebSocketServer { */ @OnClose public void onClose(Session session) { - if (onlineId != null) { - SESSIONS.remove(onlineId); - int cnt = ONLINE_COUNT.decrementAndGet(); - log.info("有连接关闭,当前连接数为:{}", cnt); + Long userId = getUserId(session); + try { + if (userId != null) { + SESSIONS.remove(userId); + int cnt = ONLINE_COUNT.decrementAndGet(); + session.close(); + log.info("有连接关闭,关闭id为{},当前连接数为:{}", userId, cnt); + } + } catch (IOException e) { + throw new RuntimeException("关闭失败"); } } @@ -83,7 +91,6 @@ public class WebSocketServer { */ @OnMessage public void onMessage(String message, Session session) { - log.info("来自客户端的消息:{}", message); JSONObject jsonObject = JSONUtil.parseObj(message); String type = "type"; UserMessageService userMessageService = @@ -144,6 +151,15 @@ public class WebSocketServer { (jsonObject.getStr(type)))); } break; + case DefaultNumberConstants.SIX_NUMBER: + userId = getUserId(session); + if (userId != null) { + sendMessage(session, JSONUtil.toJsonStr + (WebSocketResponse.createBySuccess + (jsonObject.getStr(type), + ResponseCode.CONNECTION_SUCCEEDED))); + } + break; default: break; } @@ -203,8 +219,9 @@ public class WebSocketServer { } if (session != null) { sendMessage(session, message); + log.info("=============== 发送消息成功 ==============="); } else { - log.warn("没有找到你指定ID的会话:{}", sessionId); + log.error("发送消息失败:{}", sessionId); } } @@ -225,7 +242,7 @@ public class WebSocketServer { data.setCode(DefaultNumberConstants.TWO_HUNDRED); session.getBasicRemote().sendText(JSONUtil.toJsonStr(data)); } else { - log.warn("没有找到你指定ID的会话:{}", id); + log.error("没有找到你指定ID的会话:{}", id); } } } @@ -238,7 +255,7 @@ public class WebSocketServer { session.getBasicRemote().sendText(JSONUtil.toJsonStr (WebSocketResponse.createBySuccess("userMessage", hashMap.get(id)))); } else { - log.warn("没有找到你指定ID的会话:{}", id); + log.error("没有找到你指定ID的会话:{}", id); } } } catch (IOException e) {