Bladeren bron

解决冲突

comtikaweb 4 jaren geleden
bovenliggende
commit
3c047b1587
14 gewijzigde bestanden met toevoegingen van 403 en 45 verwijderingen
  1. 16 0
      ctkcloud-common/src/main/java/com/comtika/ctkcloud/server/entity/white/CtkUserWhite.java
  2. 9 25
      ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/controller/EquipSocketController.java
  3. 66 0
      ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/controller/UserWhiteController.java
  4. 25 0
      ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/dao/UserWhiteDao.java
  5. 11 0
      ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/dao/WhiteCustomerDao.java
  6. 12 0
      ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/entity/userWhite/CtkWhiteCustomer.java
  7. 23 0
      ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/service/userWhite/IUserWhiteService.java
  8. 156 0
      ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/service/userWhite/impl/UserWhiteServiceImpl.java
  9. 24 0
      ctkcloud-equip-service/src/main/resources/sql/userWhite.md
  10. 2 1
      ctkcloud-server-service/src/main/java/com/comtika/ctkcloud/server/controller/ChargeServerController.java
  11. 13 0
      ctkcloud-server-service/src/main/java/com/comtika/ctkcloud/server/dao/white/CtkWhiteDao.java
  12. 3 3
      ctkcloud-server-service/src/main/java/com/comtika/ctkcloud/server/service/ChargeServerService.java
  13. 42 15
      ctkcloud-server-service/src/main/java/com/comtika/ctkcloud/server/service/impl/ChargeServerServiceImpl.java
  14. 1 1
      ctkcloud-server-service/src/main/resources/bootstrap.yml

+ 16 - 0
ctkcloud-common/src/main/java/com/comtika/ctkcloud/server/entity/white/CtkUserWhite.java

@@ -0,0 +1,16 @@
+package com.comtika.ctkcloud.server.entity.white;
+
+import lombok.Data;
+import org.beetl.sql.core.annotatoin.AutoID;
+
+/**
+ * 用户白名单控制
+ */
+@Data
+public class CtkUserWhite {
+    @AutoID
+    private Integer id;
+    private Integer siteId;//控制颗粒度 站点设置
+    private Boolean isOpen;//是否开启黑名单
+    private Integer rule;//白名单规则  null 没有设置规则  0 为白名单外不能使用  1 白名单内免费使用
+}

+ 9 - 25
ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/controller/EquipSocketController.java

@@ -28,6 +28,7 @@ import com.comtika.ctkcloud.server.service.equip.EquipSocketService;
 //import com.comtika.ctkcloud.server.service.equip.EquipSocketService;
 import com.comtika.ctkcloud.server.service.instructions.InstructionsService;
 
+import com.comtika.ctkcloud.server.service.userWhite.IUserWhiteService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -72,6 +73,8 @@ public class EquipSocketController extends BaseController {
 
 	@Autowired
 	InstructionsService instructionsService;
+	@Autowired
+	private IUserWhiteService iUserWhiteService;
 
 	@ApiOperation(value = "查插座列表", notes = "分页查插座设备信息")
 	@ApiImplicitParams({
@@ -217,32 +220,13 @@ public class EquipSocketController extends BaseController {
 				return RespWrapper.makeFailResp("流水号不能为空");
 			}
 			Long customerId = super.getCurrentIdByHead();
-			if (customerId == null) {
+			if (customerId == null)
 				return RespWrapper.makeUnLoginResp("token无效,您可以尝试重新登录后再试!");
-			}
-			/*if (cus != null) {
-				customerId = cus.getId();
-			} else {
-				RespWrapper<Customer> cusRes = null;
-				try {
-					cusRes = customerService.getCustomerByKey(rdSession);
-				} catch (Exception e) {
-				    log.error(LogsFactory.build(loginUser, SystemLogsType.QUERY_LOG,
-	                    "【querySocketStatus】登录态解析出错,伪造的登录或登录已过期!rdSession:"+rdSession, serialNo));
-					return RespWrapper.makeUnLoginResp(e.getMessage());
-				}
-				if (cusRes.isSuccess()) {
-					customerId = cusRes.getData().getId();
-					//如果过期 将该值存在缓存中
-				} else {
-				    log.error(LogsFactory.build(loginUser, SystemLogsType.QUERY_LOG,
-                        "【querySocketStatus】根据rdSession获取登录客户信息出错:"+rdSession, serialNo));
-					RespWrapper<NodeStatus> resp = new RespWrapper<NodeStatus>();
-					resp.setCode(cusRes.getCode());
-					resp.setMsg(cusRes.getMsg());
-					return resp;
-				}
-			}*/
+			// todo 这里增加通过设备编号查询商户是否设置白名单,如果设置白名单该这么做
+			// 根据设备流水号,查询对应站点,判断该站点是否设置
+			RespWrapper<Boolean> bk = iUserWhiteService.checkCustomerWhite(customerId,serialNo);
+			if(!bk.isSuccess()) return RespWrapper.makeFailResp(bk.getMsg());
+
 			// 先判断设备是否扫码占用,排除占用人本人
 			if (socketOccupyCache.checkCooupy(customerId, serialNo)) {
 				return RespWrapper.makeFailResp("设备已占用,请选择其他设备或稍后再试");

+ 66 - 0
ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/controller/UserWhiteController.java

@@ -0,0 +1,66 @@
+package com.comtika.ctkcloud.server.controller;
+
+import com.comtika.ctkcloud.common.base.action.BaseController;
+import com.comtika.ctkcloud.common.result.RespWrapper;
+import com.comtika.ctkcloud.common.util.StringUtil;
+import com.comtika.ctkcloud.server.service.userWhite.IUserWhiteService;
+import io.swagger.annotations.ApiOperation;
+import org.beetl.sql.core.engine.PageQuery;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 用户白名单操作
+ */
+@RestController
+@RequestMapping("userWhite")
+public class UserWhiteController extends BaseController {
+    @Autowired
+    private IUserWhiteService iUserWhiteService;
+
+    @ApiOperation(value = "根据站点id 查询用户白名单列表")
+    @GetMapping("findUserWhitePageList")
+    public RespWrapper<PageQuery<Map<String,Object>>> findUserWhitePageList(Integer siteId,Integer pageNum,Integer pageSize){
+        if(siteId == null) return RespWrapper.makeFailResp("站点id 不能为空");
+        if(pageNum == null) pageNum = 1;
+        if(pageSize == null) pageSize = 10;
+        return iUserWhiteService.findUserWhitePageList(siteId,pageNum,pageSize);
+    }
+    @ApiOperation(value = "根据用户名查询存量用户")
+    @GetMapping("findUserByNickName")
+    public RespWrapper<List<Map<String,Object>>> findUserByNickName(String nickName){
+        if(StringUtil.isEmpty(nickName))
+            return RespWrapper.makeSuccessResp(new ArrayList<>(0));
+        return iUserWhiteService.findUserByNickName(nickName);
+    }
+    @ApiOperation(value = "将用户添加白名单")
+    @PostMapping("addUserToWhite/{siteId}/{userId}")
+    public RespWrapper<Boolean> addUserToWhite(@PathVariable("siteId")Integer siteId,@PathVariable("userId")Integer userId){
+        return iUserWhiteService.addUserToWhite(siteId,userId);
+    }
+    @ApiOperation(value = "将用户移除白名单")
+    @PostMapping("removeUserWhite/{siteId}/{userId}")
+    public RespWrapper<Boolean> removeUserWhite(@PathVariable("siteId")Integer siteId,@PathVariable("userId")Integer userId){
+        return iUserWhiteService.removeUserWhite(siteId,userId);
+    }
+    @ApiOperation(value = "设置白名单规则 rule = 0 白名单外不能重蹈 rule = 1 白名单内免费充电")
+    @PostMapping("configWhiteRule/{siteId}/{rule}")
+    public RespWrapper<Boolean> configWhiteRule(@PathVariable("siteId")Integer siteId,@PathVariable("rule")Integer rule){
+       /* if(rule !=0 && rule != 1)
+            return RespWrapper.makeFailResp("暂不支持该白名单规则");*/
+        return iUserWhiteService.configWhiteRule(siteId,rule);
+    }
+    @ApiOperation(value = "白名单启动与停用 status = 0 停用 ;status = 1 白名单启用")
+    @PostMapping("updateWhiteStatus/{siteId}/{status}")
+    public RespWrapper<Boolean> updateWhiteStatus(@PathVariable("siteId")Integer siteId,@PathVariable("status")Integer status){
+        if(status != 0 && status != 1)
+            return RespWrapper.makeFailResp("状态错误");
+        return iUserWhiteService.updateWhiteStatus(siteId,status);
+    }
+
+
+}

+ 25 - 0
ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/dao/UserWhiteDao.java

@@ -0,0 +1,25 @@
+package com.comtika.ctkcloud.server.dao;
+
+import com.comtika.ctkcloud.server.entity.white.CtkUserWhite;
+import com.comtika.ctkcloud.server.service.userWhite.impl.UserWhiteServiceImpl;
+import org.beetl.sql.core.annotatoin.Param;
+import org.beetl.sql.core.annotatoin.Sql;
+import org.beetl.sql.core.annotatoin.SqlResource;
+import org.beetl.sql.core.engine.PageQuery;
+import org.beetl.sql.core.mapper.BaseMapper;
+
+import java.util.List;
+import java.util.Map;
+
+@SqlResource("userWhite")
+public interface UserWhiteDao extends BaseMapper<CtkUserWhite> {
+    PageQuery<Map<String, Object>> findUserWhitePageList(PageQuery<Map<String, Object>> pageQuery);
+
+    List<Map<String, Object>> findUserByNickName(@Param("nickName") String nickName);
+
+    @Sql(value = "select p.id,p.description name from pub_app_config p")
+    List<UserWhiteServiceImpl.SmallApp> findAllSmall();
+
+    @Sql(value = "select t.site_id from ctk_equip_terminal t LEFT JOIN ctk_equip_node n on t.id = n.equip_terminal_id LEFT JOIN ctk_equip_socket s on n.id = s.equip_node_id where s.serial_no = ? limit 1")
+    Integer findDeviceSiteId(String serialNo);
+}

+ 11 - 0
ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/dao/WhiteCustomerDao.java

@@ -0,0 +1,11 @@
+package com.comtika.ctkcloud.server.dao;
+
+import com.comtika.ctkcloud.server.entity.userWhite.CtkWhiteCustomer;
+import org.beetl.sql.core.annotatoin.Sql;
+import org.beetl.sql.core.mapper.BaseMapper;
+
+public interface WhiteCustomerDao extends BaseMapper<CtkWhiteCustomer> {
+
+    @Sql(value = "delete from ctk_white_customer where site_id = ? and customer_id = ?")
+    void deleteUserWhite(Integer siteId, Integer userId);
+}

+ 12 - 0
ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/entity/userWhite/CtkWhiteCustomer.java

@@ -0,0 +1,12 @@
+package com.comtika.ctkcloud.server.entity.userWhite;
+
+import lombok.Data;
+import org.beetl.sql.core.annotatoin.AutoID;
+
+@Data
+public class CtkWhiteCustomer {
+    @AutoID
+    private Integer id;
+    private Integer siteId;
+    private Integer customerId;
+}

+ 23 - 0
ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/service/userWhite/IUserWhiteService.java

@@ -0,0 +1,23 @@
+package com.comtika.ctkcloud.server.service.userWhite;
+
+import com.comtika.ctkcloud.common.result.RespWrapper;
+import org.beetl.sql.core.engine.PageQuery;
+
+import java.util.List;
+import java.util.Map;
+
+public interface IUserWhiteService {
+    RespWrapper<PageQuery<Map<String, Object>>> findUserWhitePageList(Integer siteId, Integer pageNum, Integer pageSize);
+
+    RespWrapper<List<Map<String, Object>>> findUserByNickName(String nickName);
+
+    RespWrapper<Boolean> addUserToWhite(Integer siteId, Integer userId);
+
+    RespWrapper<Boolean> removeUserWhite(Integer siteId, Integer userId);
+
+    RespWrapper<Boolean> configWhiteRule(Integer siteId, Integer rule);
+
+    RespWrapper<Boolean> updateWhiteStatus(Integer siteId, Integer status);
+
+    RespWrapper<Boolean> checkCustomerWhite(Long customerId, String serialNo);
+}

+ 156 - 0
ctkcloud-equip-service/src/main/java/com/comtika/ctkcloud/server/service/userWhite/impl/UserWhiteServiceImpl.java

@@ -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;
+    }
+
+}

+ 24 - 0
ctkcloud-equip-service/src/main/resources/sql/userWhite.md

@@ -0,0 +1,24 @@
+findUserWhitePageList
+===
+* 查询白名单
+SELECT
+	#page("c.app_id,c.nick_name,c.avatar_url")#
+FROM
+	ctk_white_customer w
+LEFT JOIN ctk_customer c ON w.customer_id = c.id
+where 1=1
+@if(!isEmpty(siteId)){
+    and w.site_id = #siteId#
+@}
+
+findUserByNickName
+===
+* 根据用户名查询用户存量
+SELECT
+	c.id,c.app_id,c.avatar_url,c.nick_name
+FROM
+	ctk_customer c
+where 1=1
+@if(!isEmpty(nickName)){
+    and c.nick_name like #'%'+nickName+'%'#
+@}

+ 2 - 1
ctkcloud-server-service/src/main/java/com/comtika/ctkcloud/server/controller/ChargeServerController.java

@@ -127,7 +127,8 @@ public class ChargeServerController extends BaseController{
 		if(serialNum.length() != 10)return RespWrapper.makeFailResp("流水号不合规则!请输入正确的流水号!");
 		if(chargeTime <= 0)return RespWrapper.makeFailResp("请检查充电时长是否正确!");
 		if(chagerMode == null)chagerMode = ChargeMode.TIME.getId();
-		return chargeServerService.getServerPayInfo(serialNum,chargeTime,chagerMode);
+		Long userId = super.getCurrentLoginUser().getUserId();
+		return chargeServerService.getServerPayInfo(serialNum,chargeTime,chagerMode,userId);
 	}
 
 	@ApiOperation(value = "小程序  查询订单列表", notes = "查询订单列表 必要的数, orderStatus = 充电状态  0=充电中  1=充电完成,2=已关闭 ,3=全部")

+ 13 - 0
ctkcloud-server-service/src/main/java/com/comtika/ctkcloud/server/dao/white/CtkWhiteDao.java

@@ -0,0 +1,13 @@
+package com.comtika.ctkcloud.server.dao.white;
+
+import com.comtika.ctkcloud.server.entity.white.CtkUserWhite;
+import org.beetl.sql.core.annotatoin.Sql;
+import org.beetl.sql.core.mapper.BaseMapper;
+
+public interface CtkWhiteDao extends BaseMapper<CtkUserWhite> {
+    @Sql(value = "select *from ctk_user_white where site_id = ?")
+    CtkUserWhite findSiteWhite(Integer siteId);
+
+    @Sql(value = "select count(1) from ctk_white_customer c where c.site_id = ? and c.customer_id = ?")
+    Integer checkWhiteList(Integer siteId, Long userId);
+}

+ 3 - 3
ctkcloud-server-service/src/main/java/com/comtika/ctkcloud/server/service/ChargeServerService.java

@@ -27,7 +27,7 @@ public interface ChargeServerService {
 	RespWrapper<String> serverStartCharger(ChargeReqData chargeReqData,
 			Long userId);
 	/**
-	 * 
+	 *
 	 * @Title: serverEndCharger
 	 * @Description: TODO(结束订单)
 	 * @param orderNo
@@ -70,14 +70,14 @@ public interface ChargeServerService {
 	 * 简单查询订单情况
 	 */
 	RespWrapper<Map<String, Object>> queryOrderInfo(String orderNo);
-	
+
 	/**根据集中器编号查订单号与流水号*/
 	RespWrapper<List<CtkServiceOrder>> queryOrderNoList(String addrNo);
 	/**
 	 * 计算预计金额
 	 */
 	RespWrapper<SiteSimpleCacheDataEntity> getServerPayInfo(String serialNum,
-                                                            Integer chargerValue, Integer chargeMade);
+                                                            Integer chargerValue, Integer chargeMade,Long userId);
 	/**清空站点的缓存值*/
 	RespWrapper<Boolean> clearRedisVauleInChargerServer(Long id);
 	/**智能卡充电*/

+ 42 - 15
ctkcloud-server-service/src/main/java/com/comtika/ctkcloud/server/service/impl/ChargeServerServiceImpl.java

@@ -32,13 +32,17 @@ import com.comtika.ctkcloud.server.core.cache.ServerCache;
 import com.comtika.ctkcloud.server.core.eunms.RefundStrategy;
 import com.comtika.ctkcloud.server.dao.*;
 import com.comtika.ctkcloud.server.dao.order.CtkServiceOrderDao;
+import com.comtika.ctkcloud.server.dao.white.CtkWhiteDao;
 import com.comtika.ctkcloud.server.entity.*;
 import com.comtika.ctkcloud.server.entity.chargeserver.CtkServiceOrder;
 import com.comtika.ctkcloud.server.entity.equip.CtkEquipNode;
 import com.comtika.ctkcloud.server.entity.equip.CtkEquipSocket;
+import com.comtika.ctkcloud.server.entity.white.CtkUserWhite;
 import com.comtika.ctkcloud.server.feign.EquipService;
 import com.comtika.ctkcloud.server.feign.Instructions;
+import com.comtika.ctkcloud.server.feign.MyBankFeign;
 import com.comtika.ctkcloud.server.service.ChargeServerService;
+
 import org.beetl.sql.core.engine.PageQuery;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -88,8 +92,10 @@ public class ChargeServerServiceImpl implements ChargeServerService{
 	@Autowired
 	private CtkOnlineRefundWayDao ctkOnlineRefundWayDao;
 
-	/*@Autowired
-	private MyBankFeign myBankFeign;*/
+	@Autowired
+	private MyBankFeign myBankFeign;
+	@Autowired
+	private CtkWhiteDao ctkWhiteDao;
 
 	/**
 	 * 判断用户 是否还在充电
@@ -108,7 +114,7 @@ public class ChargeServerServiceImpl implements ChargeServerService{
 	 * @throws //解析数据异常
 	 * @变更记录  2018年9月3日 上午11:01:14 actor_miss create
 	 */
-	private RespWrapper<SiteSimpleCacheDataEntity> checkCharger(ChargeReqData chargeReqData) throws Exception{
+	private RespWrapper<SiteSimpleCacheDataEntity> checkCharger(ChargeReqData chargeReqData,Long userId) throws Exception{
 		boolean bl = false;//是否按电量充电
 		int num = chargeReqData.getChargerValue();
 		RespWrapper<SiteSimpleCacheDataEntity> siteServerInfo = serverDataHandleUtil.findSiteServerInfo(chargeReqData.getStreamNo());
@@ -120,14 +126,17 @@ public class ChargeServerServiceImpl implements ChargeServerService{
 			bl = true;
 		}
 		SiteSimpleCacheDataEntity data2 = siteServerInfo.getData();
-		int culFee = 0;
-		if(bl){//下面是按电量校验是否正确
-			culFee = serverDataHandleUtil.changeTotalFeeByNum(data2, num) ;
-		}else{
-			culFee = serverDataHandleUtil.getTotalFeeByTime(data2,num);
+		// 不是白名单需呀校验金额
+		if(!checkUserWhite(userId, data2.getSiteId())) {
+			int culFee = 0;
+			if(bl){//下面是按电量校验是否正确
+				culFee = serverDataHandleUtil.changeTotalFeeByNum(data2, num) ;
+			}else{
+				culFee = serverDataHandleUtil.getTotalFeeByTime(data2,num);
+			}
+			if(culFee != chargeReqData.getTotalFee())
+				return RespWrapper.makeFailResp("充电服务层,校验金额有误");
 		}
-		if(culFee != chargeReqData.getTotalFee())
-			return RespWrapper.makeFailResp("充电服务层,校验金额有误");
 		return siteServerInfo;
 	}
 	public static void main(String[] args){
@@ -386,7 +395,7 @@ public class ChargeServerServiceImpl implements ChargeServerService{
 			if(loginType == CustomerTypeEnum.ALIPAY.getId()) entity.setPayModel(ChargerPayModle.ALI_YE.getId());//支付模式
 
 			/***检验充电金额*/
-			SiteSimpleCacheDataEntity data2 = checkChargerAfter(chargeReqData);//优化充电金额校验  2019/7/31 23:27
+			SiteSimpleCacheDataEntity data2 = checkChargerAfter(chargeReqData,userId);//优化充电金额校验  2019/7/31 23:27
 			// System.out.println("站点缓存数据为:"+data2.toString());
 			siteName = data2.getSiteName();
 			boolean isKWH = (chargeReqData.getChargerMode() == ChargeMode.C_NUM.getId());
@@ -467,8 +476,8 @@ public class ChargeServerServiceImpl implements ChargeServerService{
 		return chargerTime;
 	}
 	/**校验金额*/
-	private SiteSimpleCacheDataEntity checkChargerAfter(ChargeReqData chargeReqData)throws Exception{
-		return RespResult.resDataChange(checkCharger(chargeReqData));
+	private SiteSimpleCacheDataEntity checkChargerAfter(ChargeReqData chargeReqData,Long userId)throws Exception{
+		return RespResult.resDataChange(checkCharger(chargeReqData,userId));
 	}
 	/**在线支付充电
 	 *在线充电去的网商模块
@@ -679,7 +688,7 @@ public class ChargeServerServiceImpl implements ChargeServerService{
 		try {
 			if(chargeReqData.getRechargeNo() == null) return RespWrapper.makeFailResp("在线支付时必须传充值订单唯一标识");
 			/**检验充电金额*/
-			SiteSimpleCacheDataEntity data2 = checkChargerAfter(chargeReqData);
+			SiteSimpleCacheDataEntity data2 = checkChargerAfter(chargeReqData,userId);
 			siteName = data2.getSiteName();
 			boolean isKWH = (chargeReqData.getChargerMode() == ChargeMode.C_NUM.getId());
 			/** 根据流水号查询插座信息*/
@@ -1231,10 +1240,18 @@ public class ChargeServerServiceImpl implements ChargeServerService{
 	 * 小程序   根据流水号查询对应的 站点费用
 	 */
 	@Override
-	public RespWrapper<SiteSimpleCacheDataEntity> getServerPayInfo(String serialNum,Integer chargeTime, Integer chargerMode) {
+	public RespWrapper<SiteSimpleCacheDataEntity> getServerPayInfo(String serialNum,Integer chargeTime, Integer chargerMode,Long userId) {
 		 RespWrapper<SiteSimpleCacheDataEntity> findSiteServerInfo = serverDataHandleUtil.findSiteServerInfo(serialNum);
 		 if(findSiteServerInfo.isSuccess()){
 		 	SiteSimpleCacheDataEntity data = findSiteServerInfo.getData();
+		 	// TODO 2020 05 10 这里增加白名单处理
+			 boolean isWhite = checkUserWhite(userId,data.getSiteId());
+			 if(isWhite){
+				 data.setChangeFee(0);
+				 data.setServiceCharge(0);
+				 return findSiteServerInfo;
+			 }
+		 	// 这里判断是否是在
 		 	if(chargerMode != ChargeMode.C_NUM.getId()){//不是按电量查询
 				data.setChangeFee(serverDataHandleUtil.getTotalFeeByTime(data, chargeTime));
 		 	}else{//下面是按电量查询
@@ -1245,6 +1262,16 @@ public class ChargeServerServiceImpl implements ChargeServerService{
 		 return findSiteServerInfo;
 	}
 
+	private boolean checkUserWhite(Long userId, Integer siteId) {
+		CtkUserWhite white = ctkWhiteDao.findSiteWhite(siteId);
+		if(white != null && white.getIsOpen() && white.getRule() != null && white.getRule() == 1){
+			// 下面判断用户是否在白名单中
+			Integer count = ctkWhiteDao.checkWhiteList(siteId,userId);
+			if(count != null && count > 0) return true;
+		}
+		return false;
+	}
+
 
 	/**清空对应的缓存*/
 	@Override

+ 1 - 1
ctkcloud-server-service/src/main/resources/bootstrap.yml

@@ -8,7 +8,7 @@ spring:
       discovery:
         enabled: true
         service-id: config-service
-      profile: prod
+      profile: test
       label: master
       username: ctk_miss
       password: actor#config_server