From be142537e0604ccc7e92fa62f66ff676d9b760ff Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Tue, 7 May 2019 16:23:36 +0800 Subject: [PATCH] =?UTF-8?q?[=E7=A7=9F=E6=88=B7][=E4=BF=AE=E6=94=B9]:?= =?UTF-8?q?=E7=A7=9F=E6=88=B7=E6=B7=BB=E5=8A=A0=E9=94=80=E5=94=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=8F=8A=E6=9C=89=E6=95=88=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/iformall/config/RedisConfig.java | 18 ++ .../controller/sys/HomeController.java | 96 ++++++--- .../migration/V201905071520__CHANGE_MALL.sql | 4 + .../java/com/iformall/config/RedisConfig.java | 18 ++ .../java/com/iformall/config/RedisConfig.java | 18 ++ .../java/com/iformall/config/RedisConfig.java | 18 ++ .../java/com/iformall/config/RedisConfig.java | 18 ++ .../java/com/iformall/config/RedisConfig.java | 18 ++ .../java/com/iformall/domain/po/WxMall.java | 192 +++--------------- .../com/iformall/mapper/WxMallMapper.java | 3 +- .../service/impl/WxMallServiceImpl.java | 65 +++++- .../java/com/iformall/utils/Constant.java | 3 + .../main/resources/mapper/WxMallMapper.xml | 27 ++- .../java/com/iformall/config/RedisConfig.java | 18 ++ 14 files changed, 314 insertions(+), 202 deletions(-) create mode 100644 mallinkAdmin/src/main/resources/db/migration/V201905071520__CHANGE_MALL.sql diff --git a/mallinkAdmin/src/main/java/com/iformall/config/RedisConfig.java b/mallinkAdmin/src/main/java/com/iformall/config/RedisConfig.java index 0cd431813..7da08a3d9 100644 --- a/mallinkAdmin/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkAdmin/src/main/java/com/iformall/config/RedisConfig.java @@ -2,6 +2,7 @@ package com.iformall.config; import com.iformall.domain.po.PushLimit; import com.iformall.domain.po.WxCUser; +import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxScoreRules; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -142,4 +143,21 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("mallRedisTemplate") + public RedisTemplate getMallRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(WxMall.class); + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + } diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/sys/HomeController.java b/mallinkAdmin/src/main/java/com/iformall/controller/sys/HomeController.java index 5bf399cb3..47e3799e8 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/sys/HomeController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/sys/HomeController.java @@ -72,6 +72,9 @@ public class HomeController extends BaseController { @Autowired private MallUserActionService mallUserActionService; + @Autowired + private WxMallService mallService; + @ApiOperation("验证码") @GetMapping("/captcha.jpg") public void captcha(HttpServletResponse response)throws ServletException, IOException { @@ -138,9 +141,21 @@ public class HomeController extends BaseController { logger.error(e.getMessage()); return new ResultData(ErrorCode.USER_PASSWD_ERR); } + if(isLogin) { MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); info.protectInfos(); + mallUserActionService.saveActionInfo(info.getTenantId(), EnumMallUserAction.CONTROLLER.getCode(), ipaddress, info.getId(), "用户登录"); + + WxMall mall = mallService.getByTenantId(info.getTenantId()); + if(mall == null) { + logger.error("未配置相应的mall"); + return new ResultData(Result.ERROR, "未配置相应的mall"); + } + if(!mall.isValid()) { + logger.error("mall未启用"); + return new ResultData(Result.ERROR, "mall未启用"); + } try { String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); @@ -157,8 +172,6 @@ public class HomeController extends BaseController { logger.error(e.getMessage()); return new ResultData(Result.ERROR, e.getMessage()); } - - mallUserActionService.saveActionInfo(info.getTenantId(), EnumMallUserAction.CONTROLLER.getCode(), ipaddress, info.getId(), "用户登录"); } return data; } @@ -177,25 +190,25 @@ public class HomeController extends BaseController { logger.debug("[" + ipaddress + "] HomeController::bHidLogin"); ResultData data = new ResultData(); // tenantId is appId - if(StringUtils.isBlank(user.getTenantId())) { + if (StringUtils.isBlank(user.getTenantId())) { logger.error("appid信息未提供"); return new ResultData(ErrorCode.MALL_INFO_NOT_FOUND); } WxAppinfo appinfo = appinfoService.getByAppId(user.getTenantId()); - if(appinfo == null) { + if (appinfo == null) { logger.error("appid未找到"); return new ResultData(ErrorCode.MALL_INFO_NOT_FOUND); } - if(StringUtils.isNotBlank(user.getPhone())) { + if (StringUtils.isNotBlank(user.getPhone())) { // 领导登录 user = mallUserInfoService.getByPhone(user.getPhone(), appinfo.getTenantId()); - if(user == null || !isInMobileAdmin(user)) { + if (user == null || !isInMobileAdmin(user)) { return new ResultData(ErrorCode.USER_NO_PERMISSION); } - } else if(StringUtils.isNotBlank(user.getBopenId())) { + } else if (StringUtils.isNotBlank(user.getBopenId())) { // 领导登录 user = mallUserInfoService.getByBOpenId(user.getBopenId(), appinfo.getTenantId()); - if(user == null || !isInMobileAdmin(user)) { + if (user == null || !isInMobileAdmin(user)) { return new ResultData(ErrorCode.USER_NO_PERMISSION); } } else { @@ -205,32 +218,54 @@ public class HomeController extends BaseController { } } + boolean isLogin = false; try { Subject subject = SecurityUtils.getSubject(); UseriFormallToken token = new UseriFormallToken(user.getUsername()); subject.login(token); + isLogin = true; + } catch (UnknownAccountException e) { + logger.error(e.getMessage()); + return new ResultData(ErrorCode.USER_IS_EMPTY); + } catch (DisabledAccountException e) { + logger.error(e.getMessage()); + return new ResultData(ErrorCode.USER_IS_LOCKED); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(ErrorCode.USER_PASSWD_ERR); + } + if (isLogin) { MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); info.protectInfos(); - String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); - Cookie unameCookie = new Cookie("uname", cookieName); - unameCookie.setPath("/"); - unameCookie.setMaxAge(3600); - response.addCookie(unameCookie); + mallUserActionService.saveActionInfo(info.getTenantId(), EnumMallUserAction.CONTROLLER.getCode(), ipaddress, info.getId(), "用户登录"); + + WxMall mall = mallService.getByTenantId(info.getTenantId()); + if (mall == null) { + logger.error("未配置相应的mall"); + return new ResultData(Result.ERROR, "未配置相应的mall"); + } + if (!mall.isValid()) { + logger.error("mall未启用"); + return new ResultData(Result.ERROR, "mall未启用"); + } + try { + String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); + Cookie unameCookie = new Cookie("uname", cookieName); + unameCookie.setPath("/"); + unameCookie.setMaxAge(3600); + response.addCookie(unameCookie); - Map map = new HashMap(); - map.put("username", info.getUsername()); - map.put("withWechat", info.getWithWechat()); - data.data = map; + Map map = new HashMap(); + map.put("username", info.getUsername()); + map.put("withWechat", info.getWithWechat()); + data.data = map; - mallUserActionService.saveActionInfo(info.getTenantId(), EnumMallUserAction.CONTROLLER.getCode(), ipaddress, info.getId(), "用户B端数据塔台登录"); - } catch (MallinkException e) { - logger.error(e.getMessage()); - return new ResultData(e.getErrorCode(), e.getMessage()); - } catch (Exception e) { - logger.error(e.getMessage()); - return new ResultData(ErrorCode.USER_PASSWD_ERR); + } catch(Exception e){ + logger.error(e.getMessage()); + return new ResultData(ErrorCode.USER_PASSWD_ERR); + } } return data; } @@ -304,6 +339,17 @@ public class HomeController extends BaseController { MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); info.protectInfos(); + mallUserActionService.saveActionInfo(info.getTenantId(), EnumMallUserAction.CONTROLLER.getCode(), ipaddress, info.getId(), "用户手机号登录"); + + WxMall mall = mallService.getByTenantId(info.getTenantId()); + if (mall == null) { + logger.error("未配置相应的mall"); + return new ResultData(Result.ERROR, "未配置相应的mall"); + } + if (!mall.isValid()) { + logger.error("mall未启用"); + return new ResultData(Result.ERROR, "mall未启用"); + } String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); Cookie unameCookie = new Cookie("uname", cookieName); @@ -315,8 +361,6 @@ public class HomeController extends BaseController { map.put("username", info.getUsername()); map.put("withWechat", info.getWithWechat()); - mallUserActionService.saveActionInfo(info.getTenantId(), EnumMallUserAction.CONTROLLER.getCode(), ipaddress, info.getId(), "用户手机号登录"); - return new ResultData(map); } catch (MallinkException e) { return new ResultData(e.getErrorCode(), e.getMessage()); diff --git a/mallinkAdmin/src/main/resources/db/migration/V201905071520__CHANGE_MALL.sql b/mallinkAdmin/src/main/resources/db/migration/V201905071520__CHANGE_MALL.sql new file mode 100644 index 000000000..6ea1044b5 --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201905071520__CHANGE_MALL.sql @@ -0,0 +1,4 @@ +ALTER TABLE wx_mall + ADD COLUMN sale_type tinyint(2) DEFAULT '1' COMMENT '销售类型', + ADD COLUMN valid_start DATE default null COMMENT '启用起始时间', + ADD COLUMN valid_end DATE default null COMMENT '启用结束时间'; \ No newline at end of file diff --git a/mallinkBApi/src/main/java/com/iformall/config/RedisConfig.java b/mallinkBApi/src/main/java/com/iformall/config/RedisConfig.java index e337f083e..7e167a93e 100644 --- a/mallinkBApi/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkBApi/src/main/java/com/iformall/config/RedisConfig.java @@ -2,6 +2,7 @@ package com.iformall.config; import com.iformall.domain.po.PushLimit; import com.iformall.domain.po.WxCUser; +import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxScoreRules; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -104,4 +105,21 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("mallRedisTemplate") + public RedisTemplate getMallRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(WxMall.class); + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + } diff --git a/mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java b/mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java index e337f083e..7e167a93e 100644 --- a/mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkCApi/src/main/java/com/iformall/config/RedisConfig.java @@ -2,6 +2,7 @@ package com.iformall.config; import com.iformall.domain.po.PushLimit; import com.iformall.domain.po.WxCUser; +import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxScoreRules; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -104,4 +105,21 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("mallRedisTemplate") + public RedisTemplate getMallRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(WxMall.class); + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + } diff --git a/mallinkCallback/src/main/java/com/iformall/config/RedisConfig.java b/mallinkCallback/src/main/java/com/iformall/config/RedisConfig.java index 0cd431813..7da08a3d9 100644 --- a/mallinkCallback/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkCallback/src/main/java/com/iformall/config/RedisConfig.java @@ -2,6 +2,7 @@ package com.iformall.config; import com.iformall.domain.po.PushLimit; import com.iformall.domain.po.WxCUser; +import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxScoreRules; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -142,4 +143,21 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("mallRedisTemplate") + public RedisTemplate getMallRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(WxMall.class); + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + } diff --git a/mallinkMQConsumer/src/main/java/com/iformall/config/RedisConfig.java b/mallinkMQConsumer/src/main/java/com/iformall/config/RedisConfig.java index 66d012d3f..8f732eb31 100644 --- a/mallinkMQConsumer/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkMQConsumer/src/main/java/com/iformall/config/RedisConfig.java @@ -2,6 +2,7 @@ package com.iformall.config; import com.iformall.domain.po.PushLimit; import com.iformall.domain.po.WxCUser; +import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxScoreRules; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -126,4 +127,21 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("mallRedisTemplate") + public RedisTemplate getMallRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(WxMall.class); + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + } diff --git a/mallinkSchedule/src/main/java/com/iformall/config/RedisConfig.java b/mallinkSchedule/src/main/java/com/iformall/config/RedisConfig.java index 510f03601..9195744e4 100644 --- a/mallinkSchedule/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkSchedule/src/main/java/com/iformall/config/RedisConfig.java @@ -2,6 +2,7 @@ package com.iformall.config; import com.iformall.domain.po.PushLimit; import com.iformall.domain.po.WxCUser; +import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxScoreRules; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -127,4 +128,21 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("mallRedisTemplate") + public RedisTemplate getMallRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(WxMall.class); + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxMall.java b/mallinkService/src/main/java/com/iformall/domain/po/WxMall.java index be2cba662..88d07d92d 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxMall.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxMall.java @@ -1,5 +1,8 @@ package com.iformall.domain.po; +import com.iformall.utils.DateUtils; +import lombok.Data; + import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Transient; @@ -9,6 +12,7 @@ import java.util.Date; import java.util.List; @Table(name = "wx_mall") +@Data public class WxMall implements Serializable { private static final long serialVersionUID = 1L; @@ -41,47 +45,38 @@ public class WxMall implements Serializable { } - - /*租户ID**/ @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") private String tenantId; - /*商场名**/ @io.swagger.annotations.ApiModelProperty(value="商场名",name="name") private String name; - /*集团**/ @io.swagger.annotations.ApiModelProperty(value="集团",name="group") private String group; - /*国家**/ @io.swagger.annotations.ApiModelProperty(value="国家",name="country") private String country; - /*省**/ @io.swagger.annotations.ApiModelProperty(value="省",name="province") private String province; - /*城市**/ @io.swagger.annotations.ApiModelProperty(value="城市",name="city") private String city; - /*地址**/ @io.swagger.annotations.ApiModelProperty(value="地址",name="addr") private String addr; - /*总面积**/ @io.swagger.annotations.ApiModelProperty(value="总面积",name="totalArea") private BigDecimal totalArea; - /*营业面积**/ @io.swagger.annotations.ApiModelProperty(value="营业面积",name="operatingArea") private BigDecimal operatingArea; - /*停车场面积**/ @io.swagger.annotations.ApiModelProperty(value="停车场面积",name="parkArea") private BigDecimal parkArea; - /*车位数**/ @io.swagger.annotations.ApiModelProperty(value="车位数",name="parkPlaceNumber") private Integer parkPlaceNumber; @io.swagger.annotations.ApiModelProperty(value="电话",name="servicePhone") private String servicePhone; @io.swagger.annotations.ApiModelProperty(value="商场图标",name="imgUrl") private String imgUrl; - @io.swagger.annotations.ApiModelProperty(value="商场图标",name="imgUrlH") + @io.swagger.annotations.ApiModelProperty(value="商场图标-H",name="imgUrlH") private String imgUrlH; + @io.swagger.annotations.ApiModelProperty(value="小程序提示",name="weapNote") + private String weapNote; + @io.swagger.annotations.ApiModelProperty(value="小程序二维码",name="imgQrcodeWeapp") private String imgQrcodeWeapp; @io.swagger.annotations.ApiModelProperty(value="公众平台二维码",name="imgQrcodeWemp") @@ -93,159 +88,29 @@ public class WxMall implements Serializable { @io.swagger.annotations.ApiModelProperty(value="分享封面图片",name="weappShareCoverImg") private String weappShareCoverImg; - @io.swagger.annotations.ApiModelProperty(value="小程序提示",name="weapNote") - private String weapNote; + @io.swagger.annotations.ApiModelProperty(value="销售类型",name="saleType") + private Integer saleType; + @io.swagger.annotations.ApiModelProperty(value="启用开始时间",name="validStart") + private Date validStart; + @io.swagger.annotations.ApiModelProperty(value="启用结束时间",name="validEnd") + private Date validEnd; @Transient protected List buildings; - private String imgWeappQrcode; - - public String getImgWeappQrcode() { - return imgWeappQrcode; - } - - public void setImgWeappQrcode(String imgWeappQrcode) { - this.imgWeappQrcode = imgWeappQrcode; - } - - public String getTenantId() { - return tenantId; - } - public void setTenantId(String _tenantId) { - tenantId = _tenantId; - } - public String getName() { - return name; - } - public void setName(String _name) { - name = _name; - } - public String getGroup() { - return group; - } - public void setGroup(String _group) { - group = _group; - } - public String getCountry() { - return country; - } - public void setCountry(String _country) { - country = _country; - } - public String getProvince() { - return province; - } - public void setProvince(String _province) { - province = _province; - } - public String getCity() { - return city; - } - public void setCity(String _city) { - city = _city; - } - public String getAddr() { - return addr; - } - public void setAddr(String _addr) { - addr = _addr; - } - public BigDecimal getTotalArea() { - return totalArea; - } - public void setTotalArea(BigDecimal _totalArea) { - totalArea = _totalArea; - } - public BigDecimal getOperatingArea() { - return operatingArea; - } - public void setOperatingArea(BigDecimal _operatingArea) { - operatingArea = _operatingArea; - } - public BigDecimal getParkArea() { - return parkArea; - } - public void setParkArea(BigDecimal _parkArea) { - parkArea = _parkArea; - } - public Integer getParkPlaceNumber() { - return parkPlaceNumber; - } - public void setParkPlaceNumber(Integer _parkPlaceNumber) { - parkPlaceNumber = _parkPlaceNumber; - } - - public String getServicePhone() { - return servicePhone; - } - - public void setServicePhone(String _servicePhone) { - this.servicePhone = _servicePhone; - } - - public String getImgUrl() { - return imgUrl; - } - - public void setImgUrl(String _imgUrl) { - this.imgUrl = _imgUrl; - } - - public String getImgUrlH() { - return imgUrlH; - } - - public void setImgUrlH(String imgUrlH) { - this.imgUrlH = imgUrlH; - } - - public String getWeapNote() { - return weapNote; - } - - public void setWeapNote(String weapNote) { - this.weapNote = weapNote; - } - - public List getBuildings() { - return buildings; - } - - public void setBuildings(List buildings) { - this.buildings = buildings; - } - - public String getImgQrcodeWeapp() { - return imgQrcodeWeapp; - } - - public void setImgQrcodeWeapp(String imgQrcodeWeapp) { - this.imgQrcodeWeapp = imgQrcodeWeapp; - } - - public String getImgQrcodeWemp() { - return imgQrcodeWemp; - } - - public void setImgQrcodeWemp(String imgQrcodeWemp) { - this.imgQrcodeWemp = imgQrcodeWemp; - } - - public String getWeappShareTitle() { - return weappShareTitle; - } - - public void setWeappShareTitle(String weappShareTitle) { - this.weappShareTitle = weappShareTitle; - } - - public String getWeappShareCoverImg() { - return weappShareCoverImg; - } - - public void setWeappShareCoverImg(String weappShareCoverImg) { - this.weappShareCoverImg = weappShareCoverImg; + public boolean isValid() { + if(saleType != null) { + if(validStart != null && validEnd != null) { + Date curDate = new Date(); + if(curDate.before(validStart) || curDate.after(validEnd)) { + return false; + } else { + return true; + } + } + } + + return true; } public static enum Field @@ -266,6 +131,9 @@ public class WxMall implements Serializable { ,ImgUrl_ASC("`img_url` ASC"),ImgUrl_DESC("`img_url` DESC") ,ImgUrlH_ASC("`img_url_h` ASC"),ImgUrlH_DESC("`img_url_h` DESC") ,WeapNote_ASC("`weap_note` ASC"),WeapNote_DESC("`weap_note` DESC") + ,SaleType_ASC("`sale_type` ASC"),SaleType_DESC("`sale_type` DESC") + ,ValidStart_ASC("`valid_start` ASC"),ValidStart_DESC("`valid_start` DESC") + ,ValidEnd_ASC("`valid_end` ASC"),ValidEnd_DESC("`valid_end` DESC") ; private String value; Field(String value){ diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxMallMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxMallMapper.java index 4786c8064..79eebd6e0 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxMallMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxMallMapper.java @@ -9,7 +9,6 @@ public interface WxMallMapper extends CommonMapper { List findList(WxMall wxMall); - - void updateToken(WxMall wxMall); + WxMall getByTenantId(String tenantId); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxMallServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxMallServiceImpl.java index a3158c77c..61e596267 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxMallServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxMallServiceImpl.java @@ -8,15 +8,19 @@ import com.iformall.domain.po.WxMallFloor; import com.iformall.mapper.WxMallBuildingMapper; import com.iformall.mapper.WxMallFloorMapper; import com.iformall.mapper.WxMallMapper; -import com.iformall.service.WxMallBuildingService; import com.iformall.service.WxMallService; +import com.iformall.utils.Constant; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; import org.springframework.stereotype.Service; import com.iformall.common.IdWorker; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @Service @@ -32,6 +36,10 @@ public class WxMallServiceImpl implements WxMallService { @Autowired WxMallFloorMapper wxMallFloorMapper; + @Autowired + @Qualifier("mallRedisTemplate") + RedisTemplate mallRedisTemplate; + @Override public PageInfo listAsPage(WxMall record, Integer pageIndex, Integer pageSize) { return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxMallMapper.findList(record)); @@ -39,7 +47,20 @@ public class WxMallServiceImpl implements WxMallService { @Override public WxMall getById(Long id) { - return wxMallMapper.selectByPrimaryKey(id); + String key = Constant.MALL_KEY_PREV + String.valueOf(id); + ValueOperations operations = mallRedisTemplate.opsForValue(); + + // 缓存 + boolean hasKey = mallRedisTemplate.hasKey(key); + if(hasKey) { + // 从缓存获取用户信息 + WxMall mall = operations.get(key); + return mall; + } + WxMall mall = wxMallMapper.selectByPrimaryKey(id); + // 插入缓存 + operations.set(key, mall, 3600, TimeUnit.SECONDS); + return mall; } @Override @@ -54,25 +75,53 @@ public class WxMallServiceImpl implements WxMallService { } else { wxMallMapper.updateByPrimaryKeySelective(record); } + + String key = Constant.MALL_KEY_PREV + String.valueOf(record.getId()); + // 缓存已存在,删除 + boolean hasKey = mallRedisTemplate.hasKey(key); + if(hasKey) { + mallRedisTemplate.delete(key); + logger.info("更新mall,从缓存中删除mall token >> " + record.getId()); + } } @Override public void deleteById(Long id) { wxMallMapper.deleteByPrimaryKey(id); + + String key = Constant.MALL_KEY_PREV + String.valueOf(id); + // 缓存已存在,删除 + boolean hasKey = mallRedisTemplate.hasKey(key); + if(hasKey) { + mallRedisTemplate.delete(key); + logger.info("更新mall,从缓存中删除mall token >> " + id); + } } @Override public WxMall getByTenantId(String id) { - WxMall wxMall = new WxMall(); - wxMall.setTenantId(id); - return wxMallMapper.findList(wxMall).get(0); + String key = Constant.MALL_KEY_PREV + String.valueOf(id); + ValueOperations operations = mallRedisTemplate.opsForValue(); + + // 缓存 + boolean hasKey = mallRedisTemplate.hasKey(key); + if(hasKey) { + // 从缓存获取用户信息 + WxMall mall = operations.get(key); + return mall; + } + WxMall mall = wxMallMapper.getByTenantId(id); + // 插入缓存 + operations.set(key, mall, 3600, TimeUnit.SECONDS); + return mall; } @Override public WxMall getByTenantIdExt(String id) { - WxMall wxMallParam = new WxMall(); - wxMallParam.setTenantId(id); - WxMall wxMall = wxMallMapper.findList(wxMallParam).get(0); + WxMall wxMall = wxMallMapper.getByTenantId(id); + if(wxMall == null) { + return null; + } WxMallBuilding wxMallBuilding = new WxMallBuilding(); wxMallBuilding.setTenantId(id); diff --git a/mallinkService/src/main/java/com/iformall/utils/Constant.java b/mallinkService/src/main/java/com/iformall/utils/Constant.java index 347330690..d1794e2f3 100644 --- a/mallinkService/src/main/java/com/iformall/utils/Constant.java +++ b/mallinkService/src/main/java/com/iformall/utils/Constant.java @@ -24,6 +24,9 @@ public class Constant { // 积分规则 key prev public static final String CREDIT_RULES_KEY_PREV = "setting:creditrules1:"; + // 获取mall信息 + public static final String MALL_KEY_PREV = "mall:"; + public static final String fileDirectory = "./uploads/"; public static final String importMemPrev = "importmem/"; public static final String adminPage = "https://admin.malls.iformall.com"; diff --git a/mallinkService/src/main/resources/mapper/WxMallMapper.xml b/mallinkService/src/main/resources/mapper/WxMallMapper.xml index 4bb4916b2..46d357a3f 100644 --- a/mallinkService/src/main/resources/mapper/WxMallMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxMallMapper.xml @@ -22,13 +22,17 @@ + + + `id`,`tenant_id`,`name`,`group`,`country`,`province`,`city`,`addr`, `total_area`,`operating_area`,`park_area`,`park_place_number`,`service_phone`, `img_url`,`img_url_h`, `weap_note`, `img_qrcode_weapp`, `img_qrcode_wemp`, - `weapp_share_title`,`weapp_share_cover_img` + `weapp_share_title`,`weapp_share_cover_img`, + `sale_type`, `valid_start`, `valid_end` @@ -98,6 +102,18 @@ and `img_qrcode_wemp` = #{imgQrcodeWemp} + + and `sale_type` = #{saleType} + + + + and `valid_start` = #{validStart} + + + + and `valid_end` = #{validEnd} + + and id in @@ -114,9 +130,12 @@ - - update wx_mall set token=#{token},expired_time=#{expiredTime} where id=#{id} - + diff --git a/mallinkWebSocketServer/src/main/java/com/iformall/config/RedisConfig.java b/mallinkWebSocketServer/src/main/java/com/iformall/config/RedisConfig.java index 66d012d3f..8f732eb31 100644 --- a/mallinkWebSocketServer/src/main/java/com/iformall/config/RedisConfig.java +++ b/mallinkWebSocketServer/src/main/java/com/iformall/config/RedisConfig.java @@ -2,6 +2,7 @@ package com.iformall.config; import com.iformall.domain.po.PushLimit; import com.iformall.domain.po.WxCUser; +import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxScoreRules; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -126,4 +127,21 @@ public class RedisConfig extends CachingConfigurerSupport { return template; } + @Bean("mallRedisTemplate") + public RedisTemplate getMallRedisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate(); + + Jackson2JsonRedisSerializer j = new Jackson2JsonRedisSerializer(WxMall.class); + // value值的序列化 + template.setValueSerializer(j); + template.setHashKeySerializer(j); + + // key的序列化 + template.setKeySerializer(new StringRedisSerializer()); + template.setHashKeySerializer(new StringRedisSerializer()); + + template.setConnectionFactory(connectionFactory); + return template; + } + }