|
@@ -0,0 +1,156 @@
|
|
|
+package com.comtika.ctkcloud.server.service.userWhite.impl;
|
|
|
+
|
|
|
+import com.comtika.ctkcloud.common.result.RespWrapper;
|
|
|
+import com.comtika.ctkcloud.server.dao.UserWhiteDao;
|
|
|
+import com.comtika.ctkcloud.server.dao.WhiteCustomerDao;
|
|
|
+import com.comtika.ctkcloud.server.entity.userWhite.CtkWhiteCustomer;
|
|
|
+import com.comtika.ctkcloud.server.entity.white.CtkUserWhite;
|
|
|
+import com.comtika.ctkcloud.server.redis.RedisApi;
|
|
|
+import com.comtika.ctkcloud.server.service.userWhite.IUserWhiteService;
|
|
|
+import lombok.Data;
|
|
|
+import org.beetl.sql.core.engine.PageQuery;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class UserWhiteServiceImpl implements IUserWhiteService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserWhiteDao userWhiteDao;
|
|
|
+ @Autowired
|
|
|
+ private WhiteCustomerDao whiteCustomerDao;
|
|
|
+ @Autowired
|
|
|
+ private RedisApi redisApi;
|
|
|
+ // 查询站点设置白名单
|
|
|
+ @Override
|
|
|
+ public RespWrapper<PageQuery<Map<String, Object>>> findUserWhitePageList(Integer siteId, Integer pageNum, Integer pageSize) {
|
|
|
+ PageQuery<Map<String,Object>> pageQuery = new PageQuery<>();
|
|
|
+ pageQuery.setPara("siteId",siteId);
|
|
|
+ pageQuery.setPageNumber(pageNum);
|
|
|
+ pageQuery.setPageSize(pageSize);
|
|
|
+ pageQuery = userWhiteDao.findUserWhitePageList(pageQuery);
|
|
|
+ Map<Integer, String> smallMap = findSmallMap();
|
|
|
+ pageQuery.getList().forEach(s->{
|
|
|
+ handleAppId(smallMap,s);
|
|
|
+ });
|
|
|
+ CtkUserWhite userWhiteOrInint = findUserWhiteOrInint(siteId);
|
|
|
+ pageQuery.setPara("whiteStatus",userWhiteOrInint.getIsOpen());
|
|
|
+ pageQuery.setPara("whiteRule",userWhiteOrInint.getRule());
|
|
|
+ return RespWrapper.makeSuccessResp(pageQuery);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<List<Map<String, Object>>> findUserByNickName(String nickName) {
|
|
|
+ List<Map<String, Object>> list = userWhiteDao.findUserByNickName(nickName);
|
|
|
+ Map<Integer, String> smallMap = findSmallMap();
|
|
|
+ list.forEach(s->{
|
|
|
+ handleAppId(smallMap,s);
|
|
|
+ });
|
|
|
+ return RespWrapper.makeSuccessResp(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Boolean> addUserToWhite(Integer siteId, Integer userId) {
|
|
|
+ CtkWhiteCustomer customer = new CtkWhiteCustomer();
|
|
|
+ customer.setSiteId(siteId);
|
|
|
+ customer.setCustomerId(userId);
|
|
|
+ if(whiteCustomerDao.templateCount(customer) == 0){
|
|
|
+ whiteCustomerDao.insert(customer);
|
|
|
+ }
|
|
|
+ return RespWrapper.makeSuccessResp(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Boolean> removeUserWhite(Integer siteId, Integer userId) {
|
|
|
+ whiteCustomerDao.deleteUserWhite(siteId,userId);
|
|
|
+ return RespWrapper.makeSuccessResp(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Boolean> configWhiteRule(Integer siteId, Integer rule) {
|
|
|
+ CtkUserWhite init = findUserWhiteOrInint(siteId);
|
|
|
+ init.setRule(rule);
|
|
|
+ userWhiteDao.updateTemplateById(init);
|
|
|
+ return RespWrapper.makeSuccessResp(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Boolean> updateWhiteStatus(Integer siteId, Integer status) {
|
|
|
+ CtkUserWhite init = findUserWhiteOrInint(siteId);
|
|
|
+ if(status == 0){
|
|
|
+ init.setIsOpen(false);
|
|
|
+ }else init.setIsOpen(true);
|
|
|
+ userWhiteDao.updateTemplateById(init);
|
|
|
+ return RespWrapper.makeSuccessResp(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Boolean> checkCustomerWhite(Long customerId, String serialNo) {
|
|
|
+ Integer siteId = userWhiteDao.findDeviceSiteId(serialNo);
|
|
|
+ if(siteId == null) return RespWrapper.makeFailResp("设备对应站点错误");
|
|
|
+ CtkUserWhite init = findUserWhiteOrInint(siteId);
|
|
|
+ if(init.getIsOpen() && init.getRule() != null && init.getRule() == 0){
|
|
|
+ // 下面需要查询用户是否在设置白名单中
|
|
|
+ CtkWhiteCustomer customer = new CtkWhiteCustomer();
|
|
|
+ customer.setSiteId(siteId);
|
|
|
+ customer.setCustomerId(customerId.intValue());
|
|
|
+ if(whiteCustomerDao.templateCount(customer) == 0){
|
|
|
+ return RespWrapper.makeFailResp("你没有权限在该设备上充电,请联系管理员配置");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return RespWrapper.makeSuccessResp(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleAppId(Map<Integer, String> appMap,Map<String,Object> s){
|
|
|
+ Object appId = s.get("appId");
|
|
|
+ if(appId != null){
|
|
|
+ String s1 = appMap.get(Integer.valueOf(appId.toString()));
|
|
|
+ if(s1 != null){
|
|
|
+ s.put("appName",s1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ s.put("appName","康体佳");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final String CKT_ALL_SMALL_MAP = "comtika_all_small_key";
|
|
|
+ public Map<Integer,String> findSmallMap(){
|
|
|
+ Object o = redisApi.get(CKT_ALL_SMALL_MAP);
|
|
|
+ if(o != null) return (Map<Integer, String>) o;
|
|
|
+ List<SmallApp> list = userWhiteDao.findAllSmall();
|
|
|
+ Map<Integer,String> MAP = new HashMap<>(list.size());
|
|
|
+ list.forEach(s->{
|
|
|
+ MAP.put(s.getId(),s.getName());
|
|
|
+ });
|
|
|
+ list.clear();
|
|
|
+ redisApi.set(CKT_ALL_SMALL_MAP,MAP,5L, TimeUnit.MINUTES);
|
|
|
+ return MAP;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 小程序帮助类
|
|
|
+ @Data
|
|
|
+ public static class SmallApp{
|
|
|
+ private Integer id;
|
|
|
+ private String name;
|
|
|
+ }
|
|
|
+
|
|
|
+ private CtkUserWhite findUserWhiteOrInint(Integer siteId){
|
|
|
+ CtkUserWhite white = new CtkUserWhite();
|
|
|
+ white.setSiteId(siteId);
|
|
|
+ white = userWhiteDao.templateOne(white);
|
|
|
+ if(white == null){
|
|
|
+ white = new CtkUserWhite();
|
|
|
+ white.setSiteId(siteId);
|
|
|
+ white.setIsOpen(false);
|
|
|
+ userWhiteDao.insert(white);
|
|
|
+ }
|
|
|
+ return white;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|