diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java index 8bf31d8a9..82683ea80 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java @@ -5,6 +5,7 @@ import com.stdiet.common.constant.HttpStatus; import com.stdiet.common.core.controller.BaseController; import com.stdiet.common.core.domain.AjaxResult; import com.stdiet.common.core.domain.entity.SysDictData; +import com.stdiet.common.core.domain.entity.SysUser; import com.stdiet.common.core.page.TableDataInfo; import com.stdiet.common.exception.file.FileNameLengthLimitExceededException; import com.stdiet.common.utils.AliyunVideoUtils; @@ -19,6 +20,7 @@ import com.stdiet.custom.dto.response.*; import com.stdiet.custom.page.WxLogInfo; import com.stdiet.custom.service.*; import com.stdiet.system.service.ISysDictTypeService; +import com.stdiet.system.service.ISysUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -84,6 +86,8 @@ public class WechatAppletController extends BaseController { private ISysCustomerHealthyService sysCustomerHealthyService; @Autowired private ISysCustomerPhysicalSignsService sysCustomerPhysicalSignsService; + @Autowired + private ISysUserService iSysUserService; /** * 查询微信小程序中展示的客户案例 @@ -193,7 +197,18 @@ public class WechatAppletController extends BaseController { @PostMapping(value = "/addPunchLog") public AjaxResult addPunchLog(@RequestBody SysWxUserLog sysWxUserLog) { if (sysWxUserLog.getId() == null) { - return toAjax(sysWxUserLogService.insertSysWxUserLog(sysWxUserLog)); + int row = sysWxUserLogService.insertSysWxUserLog(sysWxUserLog); + if (row > 0) { + Long cusId = Long.parseLong(AesUtils.decrypt(sysWxUserLog.getCusId())); + SysCustomer sysCustomer = iSysCustomerService.selectSysCustomerById(cusId); + if (StringUtils.isNotNull(sysCustomer)) { + SysUser sysUser = iSysUserService.selectUserById(sysCustomer.getAfterDietitian()); + if (StringUtils.isNotNull(sysUser)) { + iWechatAppletService.postCustomerPunchNotice(sysCustomer.getName(), sysUser.getWxPublicOpenid()); + } + } + } + return toAjax(row); } return toAjax(sysWxUserLogService.updateSysWxUserLog(sysWxUserLog)); } @@ -455,9 +470,13 @@ public class WechatAppletController extends BaseController { SysCustomerPhysicalSigns customerPhysicalSigns = sysCustomerPhysicalSignsService.selectSysCustomerPhysicalSignsByCusId(curWxUserInfo.getCusId()); if (customerPhysicalSigns != null) { curWxUserInfo.setSex(customerPhysicalSigns.getSex().toString()); + curWxUserInfo.setHeight(customerPhysicalSigns.getTall()); + curWxUserInfo.setAge(customerPhysicalSigns.getAge()); } } else { curWxUserInfo.setSex(customerHealthy.getSex().toString()); + curWxUserInfo.setHeight(customerHealthy.getTall()); + curWxUserInfo.setAge(Math.toIntExact(customerHealthy.getAge())); } curWxUserInfo.setCustomerId(AesUtils.encrypt(curWxUserInfo.getCusId().toString())); diff --git a/stdiet-common/src/main/java/com/stdiet/common/core/domain/entity/SysUser.java b/stdiet-common/src/main/java/com/stdiet/common/core/domain/entity/SysUser.java index 82d4a717d..9c725970c 100644 --- a/stdiet-common/src/main/java/com/stdiet/common/core/domain/entity/SysUser.java +++ b/stdiet-common/src/main/java/com/stdiet/common/core/domain/entity/SysUser.java @@ -133,6 +133,16 @@ public class SysUser extends BaseEntity { @Excel(name = "岗位") private String postName; + private String wxPublicOpenid; + + public void setWxPublicOpenid(String wxPublicOpenid) { + this.wxPublicOpenid = wxPublicOpenid; + } + + public String getWxPublicOpenid() { + return wxPublicOpenid; + } + public SysUser() { } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysWxUserInfo.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysWxUserInfo.java index c6e8e3a27..b0bab61ef 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysWxUserInfo.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysWxUserInfo.java @@ -24,6 +24,10 @@ public class SysWxUserInfo { private String customerId; + private Integer height; + + private Integer age; + /** * 昵称 */ diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysWxUserLog.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysWxUserLog.java index 5402663c8..1f0dd9e47 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysWxUserLog.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysWxUserLog.java @@ -26,6 +26,8 @@ public class SysWxUserLog extends BaseEntity { */ private String openid; + private String cusId; + /** * 体重 */ diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java index 9dc1cda90..1b966d9e6 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java @@ -7,4 +7,6 @@ public interface IWechatAppletService { public Integer postSubscribeMessage(Long cusId, Long planId, String name, String startDate, String endDate, String remark); public Integer postSms(Long cusId, Long planId, String plan); + + public Integer postCustomerPunchNotice(String name, String toUser); } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java index a148731fe..079b765ea 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java @@ -27,7 +27,9 @@ import java.util.concurrent.TimeUnit; @Service public class WeChartAppletServiceImp implements IWechatAppletService { - static final String WX_TEM_ID = "Ow0j0Jt4OJhjy6GruBstOMLTGjAVagM4hTZRLAaxqJo"; + static final String WX_LITE_SUBSCRIBE_TEM_ID = "Ow0j0Jt4OJhjy6GruBstOMLTGjAVagM4hTZRLAaxqJo"; + + static final String WX_PUBLIC_CUSTOMER_PUNCH_NOTICE_TEM_ID = "XapMBz6KsPW6_rK5__oxxaY8cSLyVYyoSljstZsITyo"; @Autowired private RedisCache redisCache; @@ -51,6 +53,8 @@ public class WeChartAppletServiceImp implements IWechatAppletService { String appSecret = ""; if (appId.equals("wx26be9b2aa525fc1e")) { appSecret = "de436c17e42e6fc0637bd0de169ea0c1"; + } else if (appId.equals("wx4a9c1fc9dba53202")) { + appSecret = "fff029ade5d3575df755f4cf9e52f8da"; } String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={appId}&secret={appSecret}"; Map param = new HashMap<>(); @@ -86,7 +90,7 @@ public class WeChartAppletServiceImp implements IWechatAppletService { JSONObject param = new JSONObject(); param.put("access_token", accessToken); param.put("touser", sysWxUserInfo.getOpenid()); - param.put("template_id", WX_TEM_ID); + param.put("template_id", WX_LITE_SUBSCRIBE_TEM_ID); param.put("page", "pages/recipes/index"); @@ -114,7 +118,7 @@ public class WeChartAppletServiceImp implements IWechatAppletService { postLog.setSendTime(DateUtils.getNowDate()); postLog.setPlanId(planId); // - dataParam.put("tmpId", WX_TEM_ID); + dataParam.put("tmpId", WX_LITE_SUBSCRIBE_TEM_ID); postLog.setData(dataParam); wxSubscribePostLogService.insertWxSubscribePostLog(postLog); @@ -155,5 +159,52 @@ public class WeChartAppletServiceImp implements IWechatAppletService { return -1; } + @Override + public Integer postCustomerPunchNotice(String name, String toUser) { + String accessToken = getAccessToken("wx4a9c1fc9dba53202"); + if (StringUtils.isNull(accessToken)) { + return -1; + } + String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken; + + JSONObject param = new JSONObject(); + param.put("touser", toUser); + param.put("template_id", WX_PUBLIC_CUSTOMER_PUNCH_NOTICE_TEM_ID); +// param.put("url", "pages/recipes/index"); +// JSONObject miniData = new JSONObject(); +// miniData.put("appid", ""); +// miniData.put("pagepath", ""); +// param.put("miniprogram", miniData); + + JSONObject dataParam = new JSONObject(); + dataParam.put("first", JSONObject.parse("{\"value\":\"完成打卡\"}")); + dataParam.put("keyword1", JSONObject.parse("{\"value\":\"" + name + "\"}")); + dataParam.put("keyword2", JSONObject.parse("{\"value\":\"" + DateUtils.getTime() + "\"}")); + dataParam.put("keyword3", JSONObject.parse("{\"value\":\"成功\"}")); + dataParam.put("remark", JSONObject.parse("{\"value\":\" \"}")); + + param.put("data", dataParam); + + restTemplate.getMessageConverters() + .add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8)); + ResponseEntity entity = restTemplate.postForEntity(url, param.toJSONString(), String.class); + + JSONObject resultObj = JSONObject.parseObject(entity.getBody()); + + WxSubscribePostLog postLog = new WxSubscribePostLog(); + postLog.setAppid("wx4a9c1fc9dba53202"); + postLog.setOpenid(toUser); + int errCode = resultObj.getInteger("errcode"); + postLog.setType(2); + postLog.setResult(resultObj); + postLog.setSendTime(DateUtils.getNowDate()); + // + dataParam.put("tmpId", WX_PUBLIC_CUSTOMER_PUNCH_NOTICE_TEM_ID); + postLog.setData(dataParam); + wxSubscribePostLogService.insertWxSubscribePostLog(postLog); + + return errCode; + } + } diff --git a/stdiet-system/src/main/resources/mapper/system/SysUserMapper.xml b/stdiet-system/src/main/resources/mapper/system/SysUserMapper.xml index ce1f92365..5c5ad9d31 100644 --- a/stdiet-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/stdiet-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -28,6 +28,7 @@ +