@@ -0,0 +1,41 @@ | |||
package com.tuoheng.api.controller; | |||
import com.tuoheng.api.entity.request.TextMessageRuleRequest; | |||
import com.tuoheng.api.service.TextMessageService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
/** | |||
* @Description 短信通知设置模块 | |||
* @Author douzhenjun | |||
* @DATE 2023/4/12 | |||
**/ | |||
@RestController | |||
@RequestMapping("/textMessage") | |||
@Slf4j | |||
public class TextMessageController { | |||
@Autowired | |||
private TextMessageService textMessageService; | |||
/** | |||
* @Description: 发送短信(测试) | |||
* @Param: | |||
* @return: | |||
*/ | |||
@PostMapping("/sendMessage") | |||
public Integer sendMessage(@RequestBody TextMessageRuleRequest textMessageRuleRequest) { | |||
String phones = textMessageRuleRequest.getSendPhone(); | |||
List<String> phoneList = Arrays.stream(phones.split(",")).collect(Collectors.toList()); | |||
return textMessageService.sendMessage(phoneList); | |||
} | |||
} |
@@ -39,7 +39,7 @@ public class WestreamUserController { | |||
* @return | |||
*/ | |||
@PostMapping("/login") | |||
public JsonResult login(@RequestBody WestreamUser westreamUser){ | |||
public JsonResult login(@RequestBody WestreamUser westreamUser) { | |||
return westreamUserService.login(westreamUser); | |||
} | |||
@@ -50,7 +50,7 @@ public class WestreamUserController { | |||
* @return | |||
*/ | |||
@GetMapping("/userInfo") | |||
public JsonResult userInfo(WestreamUserQuery westreamUserQuery){ | |||
public JsonResult userInfo(WestreamUserQuery westreamUserQuery) { | |||
return westreamUserService.userInfo(westreamUserQuery); | |||
} | |||
@@ -61,8 +61,18 @@ public class WestreamUserController { | |||
* @return | |||
*/ | |||
@PutMapping("/editInfo") | |||
public JsonResult editInfo(@RequestBody WestreamUser westreamUser){ | |||
public JsonResult editInfo(@RequestBody WestreamUser westreamUser) { | |||
return westreamUserService.editInfo(westreamUser); | |||
} | |||
/** | |||
* 获取对应活动及其设置的积分 | |||
* @return | |||
*/ | |||
@GetMapping("getIntegralInfo") | |||
public JsonResult getIntegralInfo(WestreamUserQuery westreamUserQuery) { | |||
return westreamUserService.getIntegralInfo(westreamUserQuery); | |||
} | |||
} |
@@ -56,4 +56,14 @@ public class WxController { | |||
return wxService.subUserPoints(wxSubUserPointsRequest); | |||
} | |||
/** | |||
* 增加用户积分 | |||
* @param wxSubUserPointsRequest | |||
* @return | |||
*/ | |||
@PostMapping("/addUserPoints") | |||
public JsonResult addUserPoints(@Validated @RequestBody WxSubUserPointsRequest wxSubUserPointsRequest) { | |||
return wxService.addUserPoints(wxSubUserPointsRequest); | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.tuoheng.api.entity.request; | |||
import lombok.Data; | |||
/** | |||
* @Description | |||
* @Author douzhenjun | |||
* @DATE 2023/4/12 | |||
**/ | |||
@Data | |||
public class DspSmsRequest { | |||
private String phoneNumbers; | |||
private String templateCode; | |||
private String signName; | |||
// private final Map<String, Object> templateParam = new HashMap<>(); | |||
private String templateParam; | |||
} |
@@ -0,0 +1,27 @@ | |||
package com.tuoheng.api.entity.request; | |||
import lombok.Data; | |||
import javax.validation.constraints.NotBlank; | |||
import javax.validation.constraints.NotNull; | |||
/** | |||
* @Description | |||
* @Author douzhenjun | |||
* @DATE 2023/4/12 | |||
**/ | |||
@Data | |||
public class TextMessageRuleRequest { | |||
//发送超时时间 | |||
@NotNull(message = "发送配置不能为空") | |||
private Integer sendRule; | |||
//发送起始时间 | |||
@NotBlank(message = "发送起始时间不能为空") | |||
private String startTime; | |||
//发送频率, 以时为单位 | |||
@NotNull(message = "发送频率不能为空") | |||
private Integer sendRate; | |||
//发送手机号,每个手机号有11个数字,超过一个用逗号拼接 | |||
@NotBlank(message = "发送手机号不能为空") | |||
private String sendPhone; | |||
} |
@@ -21,4 +21,9 @@ public class WxSubUserPointsRequest { | |||
@NotNull(message = "points can not be null") | |||
private Integer points; | |||
/** | |||
* 商铺名称 | |||
*/ | |||
private String shopName; | |||
} |
@@ -0,0 +1,25 @@ | |||
package com.tuoheng.api.enums; | |||
import lombok.Getter; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/7/10 9:27 | |||
*/ | |||
public enum DictDateEnum { | |||
VOLUNTEER_ACTIVITY("volunteer_activity", "志愿者活动"), | |||
TIKTOK("tiktok", "关注抖音"), | |||
VIDEO("video", "学习视频"); | |||
DictDateEnum(String code, String description) { | |||
this.code = code; | |||
this.description = description; | |||
} | |||
@Getter | |||
private String code; | |||
@Getter | |||
private String description; | |||
} |
@@ -14,4 +14,6 @@ public interface IWestreamUserService extends IBaseService<WestreamUser> { | |||
JsonResult userInfo(WestreamUserQuery westreamUserQuery); | |||
JsonResult editInfo(WestreamUser westreamUser); | |||
JsonResult getIntegralInfo(WestreamUserQuery westreamUserQuery); | |||
} |
@@ -13,4 +13,5 @@ public interface IWxService { | |||
JsonResult subUserPoints(WxSubUserPointsRequest wxSubUserPointsRequest); | |||
JsonResult addUserPoints(WxSubUserPointsRequest wxSubUserPointsRequest); | |||
} |
@@ -0,0 +1,14 @@ | |||
package com.tuoheng.api.service; | |||
import java.util.List; | |||
/** | |||
* @Description | |||
* @Author douzhenjun | |||
* @DATE 2023/4/23 | |||
**/ | |||
public interface TextMessageService { | |||
//发送短信 | |||
Integer sendMessage(List<String> phoneList); | |||
} |
@@ -0,0 +1,77 @@ | |||
package com.tuoheng.api.service.impl; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.api.entity.request.DspSmsRequest; | |||
import com.tuoheng.api.service.TextMessageService; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.http.HttpEntity; | |||
import org.springframework.http.HttpMethod; | |||
import org.springframework.http.ResponseEntity; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
import java.util.List; | |||
/** | |||
* @Description | |||
* @Author douzhenjun | |||
* @DATE 2023/4/23 | |||
**/ | |||
@Slf4j | |||
@Service | |||
public class TextMessageServiceImpl implements TextMessageService { | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
@Value("${tuoheng.dsp-domain-url}") | |||
private String dspUrl; | |||
//向dsp短信通知平台发送的请求体对象 | |||
private static DspSmsRequest request; | |||
//初始化短信通知请求中的固定模板 | |||
static { | |||
request = new DspSmsRequest(); | |||
request.setSignName("智慧河湖"); | |||
//todo 变更 | |||
request.setTemplateCode("SMS_276426880"); | |||
} | |||
/** | |||
* @Description: 发送问题通知短信 | |||
* @Param: | |||
* @return: 发送成功的条数 | |||
*/ | |||
@Override | |||
public Integer sendMessage(List<String> phoneList) { | |||
Integer success = 0; | |||
for (String phone : phoneList) { | |||
//判断是否符合格式,如不符合直接报错 | |||
if (!phone.matches("^[1][3,4,5,7,8][0-9]{9}$")) { | |||
log.error("不存在的电话号码!"); | |||
continue; | |||
} | |||
request.setPhoneNumbers(phone); | |||
//占位符数据以key-value存放于map集合,再以string类型存入 | |||
JSONObject templateParam = new JSONObject(); | |||
request.setTemplateParam(templateParam.toJSONString()); | |||
//发送http请求 | |||
HttpEntity<DspSmsRequest> httpEntity = new HttpEntity<>(request); | |||
String dspSmsUrl = dspUrl + "api/web/sms/sendSyncSms"; | |||
ResponseEntity<JsonResult> response = restTemplate.exchange(dspSmsUrl, HttpMethod.POST, httpEntity, JsonResult.class); | |||
if (response == null || !response.hasBody() || response.getBody().getCode() != JsonResult.SUCCESS) { | |||
log.error("短信向手机号: {} 发送失败", phone); | |||
continue; | |||
} | |||
success++; | |||
} | |||
return success; | |||
} | |||
} |
@@ -57,6 +57,9 @@ public class UserPointsDetailServiceImpl extends BaseServiceImpl<UserPointsDetai | |||
.orderByDesc(UserPointsDetail::getCreateTime)); | |||
for (UserPointsDetail record : pageData.getRecords()) { | |||
if(StringUtils.isNotEmpty(record.getOperatorName())){ | |||
record.setShopsName(record.getOperatorName()); | |||
} | |||
if(null != record.getOperatorId()){ | |||
//查询商铺信息 | |||
Merchant merchant = merchantMapper.selectOne(new LambdaQueryWrapper<Merchant>() |
@@ -1,21 +1,37 @@ | |||
package com.tuoheng.api.service.impl; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.api.entity.domain.Tenant; | |||
import com.tuoheng.api.entity.domain.User; | |||
import com.tuoheng.api.entity.domain.WestreamActivityApply; | |||
import com.tuoheng.api.entity.request.WestreamActivityQuery; | |||
import com.tuoheng.api.mapper.TenantMapper; | |||
import com.tuoheng.api.mapper.UserMapper; | |||
import com.tuoheng.api.mapper.WestreamActivityApplyMapper; | |||
import com.tuoheng.api.service.IWestreamActivityApplyService; | |||
import com.tuoheng.api.service.TextMessageService; | |||
import com.tuoheng.common.common.BaseServiceImpl; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
@Service | |||
public class WestreamActivityApplyServiceImpl extends BaseServiceImpl<WestreamActivityApplyMapper, WestreamActivityApply> implements IWestreamActivityApplyService { | |||
@Autowired | |||
private WestreamActivityApplyMapper westreamActivityApplyMapper; | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
private UserMapper userMapper; | |||
@Autowired | |||
private TextMessageService textMessageService; | |||
@Override | |||
public JsonResult submit(WestreamActivityApply entity) { | |||
@@ -31,13 +47,22 @@ public class WestreamActivityApplyServiceImpl extends BaseServiceImpl<WestreamAc | |||
.eq(WestreamActivityApply::getActivityId, entity.getActivityId()) | |||
.eq(WestreamActivityApply::getTenantId, entity.getTenantId()) | |||
.eq(WestreamActivityApply::getOpenid, entity.getOpenid()) | |||
.in(WestreamActivityApply::getStatus, 1,2) | |||
.in(WestreamActivityApply::getStatus, 1, 2) | |||
.eq(WestreamActivityApply::getMark, 1)); | |||
if(count > 0){ | |||
if (count > 0) { | |||
return JsonResult.error("您已参加该活动!"); | |||
} | |||
super.add(entity); | |||
//向对应的审批人发送短信,获取手机号 | |||
Tenant tenant = tenantMapper.selectById(entity.getTenantId()); | |||
User user = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, tenant.getUsername()).eq(User::getMark, 1)); | |||
String mobile = user.getMobile(); | |||
if (StringUtils.isNotEmpty(mobile)) { | |||
List<String> list = Arrays.stream(mobile.split(",")).collect(Collectors.toList()); | |||
//发送短信 | |||
textMessageService.sendMessage(list); | |||
} | |||
return JsonResult.success(); | |||
} |
@@ -1,19 +1,25 @@ | |||
package com.tuoheng.api.service.impl; | |||
import cn.hutool.core.date.DateUtil; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.api.entity.domain.Identity; | |||
import com.tuoheng.api.entity.domain.Tenant; | |||
import com.tuoheng.api.entity.domain.User; | |||
import com.tuoheng.api.entity.domain.WestreamSuggest; | |||
import com.tuoheng.api.entity.domain.WestreamUser; | |||
import com.tuoheng.api.mapper.TenantMapper; | |||
import com.tuoheng.api.mapper.UserMapper; | |||
import com.tuoheng.api.mapper.WestreamSuggestMapper; | |||
import com.tuoheng.api.service.IWestreamSuggestService; | |||
import com.tuoheng.common.common.BaseEntity; | |||
import com.tuoheng.api.service.TextMessageService; | |||
import com.tuoheng.common.common.BaseServiceImpl; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
/** | |||
* 全民护河保护河建议表 服务实现类 | |||
* | |||
@@ -25,6 +31,14 @@ import org.springframework.stereotype.Service; | |||
public class WestreamSuggestServiceImpl extends BaseServiceImpl<WestreamSuggestMapper, WestreamSuggest> implements IWestreamSuggestService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
private UserMapper userMapper; | |||
@Autowired | |||
private TextMessageService textMessageService; | |||
/** | |||
* 提交护河建议 | |||
* | |||
@@ -40,7 +54,15 @@ public class WestreamSuggestServiceImpl extends BaseServiceImpl<WestreamSuggestM | |||
if (StringUtils.isEmpty(entity.getOpenid())) { | |||
return JsonResult.error("openid为空!"); | |||
} | |||
//向对应的审批人发送短信,获取手机号 | |||
Tenant tenant = tenantMapper.selectById(entity.getTenantId()); | |||
User user = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, tenant.getUsername()).eq(User::getMark, 1)); | |||
String mobile = user.getMobile(); | |||
if (StringUtils.isNotEmpty(mobile)) { | |||
List<String> list = Arrays.stream(mobile.split(",")).collect(Collectors.toList()); | |||
//发送短信 | |||
textMessageService.sendMessage(list); | |||
} | |||
return super.add(entity); | |||
} | |||
@@ -3,10 +3,12 @@ package com.tuoheng.api.service.impl; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.api.constants.DictConstants; | |||
import com.tuoheng.api.entity.domain.*; | |||
import com.tuoheng.api.entity.request.OnlineNumQuery; | |||
import com.tuoheng.api.entity.request.WestreamUserQuery; | |||
import com.tuoheng.api.enums.DictDateEnum; | |||
import com.tuoheng.api.mapper.*; | |||
import com.tuoheng.api.service.IWestreamUserService; | |||
import com.tuoheng.api.utils.PointsTitleConstants; | |||
@@ -19,8 +21,11 @@ import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.ArrayList; | |||
import java.util.Date; | |||
import java.util.List; | |||
import java.util.Random; | |||
import java.util.stream.Collectors; | |||
/** | |||
@@ -157,4 +162,53 @@ public class WestreamUserServiceImpl extends BaseServiceImpl<WestreamUserMapper, | |||
westreamUserMapper.updateById(westreamUser); | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 获取对应活动及其设置的积分 | |||
* | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getIntegralInfo(WestreamUserQuery westreamUserQuery) { | |||
if (null == westreamUserQuery.getTenantId() || StringUtils.isEmpty(westreamUserQuery.getOpenid())) { | |||
return JsonResult.error("参数为空!"); | |||
} | |||
List<ThDictData> thDictData = new ArrayList<>(); | |||
//获取对应租户的积分规则字典表单 | |||
ThDict thDict = dictMapper.selectOne(new LambdaQueryWrapper<ThDict>() | |||
.eq(ThDict::getTenantId, westreamUserQuery.getTenantId()) | |||
.eq(ThDict::getCode, DictConstants.POINTS_RULE_CODE) | |||
.eq(ThDict::getMark, 1)); | |||
if (StringUtils.isNull(thDict)) { | |||
ThDictData param1 = new ThDictData(); | |||
ThDictData param2 = new ThDictData(); | |||
ThDictData param3 = new ThDictData(); | |||
param1.setName(DictDateEnum.TIKTOK.getDescription()); | |||
param2.setName(DictDateEnum.VIDEO.getDescription()); | |||
param3.setName(DictDateEnum.VOLUNTEER_ACTIVITY.getDescription()); | |||
thDictData.add(param1); | |||
thDictData.add(param2); | |||
thDictData.add(param3); | |||
return JsonResult.success(thDictData); | |||
} | |||
//对应每一条积分及其明细 | |||
thDictData = dictDataMapper.selectList(Wrappers.<ThDictData>lambdaQuery() | |||
.eq(ThDictData::getTenantId, westreamUserQuery.getTenantId()) | |||
.eq(ThDictData::getDictId, thDict.getId()) | |||
.eq(ThDictData::getMark, 1)); | |||
for (ThDictData thDictDatum : thDictData) { | |||
if (DictDateEnum.TIKTOK.getCode().equals(thDictDatum.getName())) { | |||
thDictDatum.setNote(DictDateEnum.TIKTOK.getDescription()); | |||
} | |||
if (DictDateEnum.VIDEO.getCode().equals(thDictDatum.getName())) { | |||
thDictDatum.setNote(DictDateEnum.VIDEO.getDescription()); | |||
} | |||
if (DictDateEnum.VOLUNTEER_ACTIVITY.getCode().equals(thDictDatum.getName())) { | |||
thDictDatum.setNote(DictDateEnum.VOLUNTEER_ACTIVITY.getDescription()); | |||
} | |||
} | |||
thDictData = thDictData.stream().filter(t -> StringUtils.isNotEmpty(t.getNote())).collect(Collectors.toList()); | |||
return JsonResult.success(thDictData); | |||
} | |||
} |
@@ -119,7 +119,9 @@ public class WxServiceImpl implements IWxService { | |||
UserPointsDetail userPointsDetail = new UserPointsDetail(); | |||
userPointsDetail.setTenantId(tenant.getId()); | |||
userPointsDetail.setOpenid(westreamUser.getOpenid()); | |||
userPointsDetail.setNickname(westreamUser.getNickname()); | |||
userPointsDetail.setPointsChange(wxSubUserPointsRequest.getPoints()); | |||
userPointsDetail.setOperatorName(wxSubUserPointsRequest.getShopName()); | |||
userPointsDetail.setChangeName("积分兑换"); | |||
userPointsDetail.setPointsTime(new Date()); | |||
userPointsDetail.setType(2); | |||
@@ -128,6 +130,48 @@ public class WxServiceImpl implements IWxService { | |||
WxSubUserPointsDto wxSubUserPointsDto = new WxSubUserPointsDto() | |||
.setTenantCode(wxSubUserPointsRequest.getTenantCode()) | |||
.setUnionId(wxSubUserPointsRequest.getUnionId()) | |||
.setPoints(wxSubUserPointsRequest.getPoints()) | |||
.setOptResult(true); | |||
return JsonResult.success(wxSubUserPointsDto); | |||
} | |||
@Override | |||
@Transactional | |||
public JsonResult addUserPoints(WxSubUserPointsRequest wxSubUserPointsRequest) { | |||
Tenant tenant = tenantMapper.selectOne(new LambdaQueryWrapper<Tenant>() | |||
.eq(Tenant::getCode, wxSubUserPointsRequest.getTenantCode()) | |||
.eq(Tenant::getMark, 1).last("limit 1")); | |||
if(ObjectUtil.isNull(tenant)){ | |||
return JsonResult.error("租户不存在"); | |||
} | |||
//查询用户 | |||
WestreamUser westreamUser = westreamUserMapper.selectOne(new LambdaQueryWrapper<WestreamUser>() | |||
.eq(WestreamUser::getTenantId, tenant.getId()) | |||
.eq(WestreamUser::getUnionid, wxSubUserPointsRequest.getUnionId()) | |||
.eq(WestreamUser::getMark, 1)); | |||
westreamUser.setMallPoints(westreamUser.getMallPoints() + wxSubUserPointsRequest.getPoints()); | |||
westreamUserMapper.updateById(westreamUser); | |||
//积分明细入库 | |||
UserPointsDetail userPointsDetail = new UserPointsDetail(); | |||
userPointsDetail.setTenantId(tenant.getId()); | |||
userPointsDetail.setOpenid(westreamUser.getOpenid()); | |||
userPointsDetail.setNickname(westreamUser.getNickname()); | |||
userPointsDetail.setPointsChange(wxSubUserPointsRequest.getPoints()); | |||
userPointsDetail.setOperatorName(wxSubUserPointsRequest.getShopName()); | |||
userPointsDetail.setChangeName("积分返还"); | |||
userPointsDetail.setPointsTime(new Date()); | |||
userPointsDetail.setType(1); | |||
userPointsDetail.setCreateTime(new Date()); | |||
userPointsDetailMapper.insert(userPointsDetail); | |||
WxSubUserPointsDto wxSubUserPointsDto = new WxSubUserPointsDto() | |||
.setTenantCode(wxSubUserPointsRequest.getTenantCode()) | |||
.setUnionId(wxSubUserPointsRequest.getUnionId()) |