From 34680627069e0895237e806f979a51650aa1c5f5 Mon Sep 17 00:00:00 2001 From: lujiang Date: Sun, 8 Sep 2024 01:43:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=8F=B7=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/RepairController.java | 2 +- .../com/ics/admin/domain/RepairRemind.java | 13 +- .../admin/mapper/IcsCustomerStaffMapper.java | 7 + .../ics/admin/mapper/RepairRemindMapper.java | 13 ++ .../service/IIcsCustomerStaffService.java | 12 +- .../admin/service/IRepairRemindService.java | 14 ++ .../impl/IcsCustomerStaffServiceImpl.java | 4 + .../{ => impl}/RepairHisServiceImpl.java | 3 +- .../service/impl/RepairRemindServiceImpl.java | 19 +++ .../admin/service/impl/RepairServiceImpl.java | 33 ++-- .../mapper/admin/IcsCustomerStaffMapper.xml | 12 +- .../mapper/admin/RepairAddressFloorMapper.xml | 2 +- .../mapper/admin/RepairRemindMapper.xml | 13 ++ .../common/core/domain/IcsCustomerStaff.java | 3 + .../system/handlers/MyParkLineHandler.java | 2 +- .../system/handlers/MyTenantLineHandler.java | 2 +- .../controller/mobile/WxBindController.java | 128 ++++++++++++++++ .../ics/service/RepairRemindPushService.java | 12 ++ .../impl/RepairRemindPushServiceImpl.java | 142 ++++++++++++++++++ .../com/ics/task/RepairRemindPushTask.java | 27 ++++ .../src/main/resources/application-dev.yml | 12 +- .../src/main/resources/application-prod.yml | 8 +- .../src/main/resources/application-server.yml | 8 +- .../ics-web/src/main/resources/phoneBind.html | 96 ++++++++++++ 24 files changed, 557 insertions(+), 30 deletions(-) rename shoot-hand/ics-admin/src/main/java/com/ics/admin/service/{ => impl}/RepairHisServiceImpl.java (92%) create mode 100644 shoot-hand/ics-web/src/main/java/com/ics/controller/mobile/WxBindController.java create mode 100644 shoot-hand/ics-web/src/main/java/com/ics/service/RepairRemindPushService.java create mode 100644 shoot-hand/ics-web/src/main/java/com/ics/service/impl/RepairRemindPushServiceImpl.java create mode 100644 shoot-hand/ics-web/src/main/java/com/ics/task/RepairRemindPushTask.java create mode 100644 shoot-hand/ics-web/src/main/resources/phoneBind.html diff --git a/shoot-hand/ics-admin/src/main/java/com/ics/admin/controller/RepairController.java b/shoot-hand/ics-admin/src/main/java/com/ics/admin/controller/RepairController.java index 720157c..62f47ad 100644 --- a/shoot-hand/ics-admin/src/main/java/com/ics/admin/controller/RepairController.java +++ b/shoot-hand/ics-admin/src/main/java/com/ics/admin/controller/RepairController.java @@ -58,7 +58,7 @@ public class RepairController extends BaseController { @PostMapping("flow/start") public R startFlow(@RequestBody RepairDTO repairDTO) { Long userId = getLoginStaffId(); - if (!repairService.submitCheck(userId.toString())) return R.error("报修过于频繁,请稍后再试."); + //if (!repairService.submitCheck(userId.toString())) return R.error("报修过于频繁,请稍后再试."); String result = repairService.handleFlow(repairDTO.getRepair(), userId, repairDTO.getFiles(), null, null); return IRepairService.OK.equals(result) ? R.ok() : R.error(result); } diff --git a/shoot-hand/ics-admin/src/main/java/com/ics/admin/domain/RepairRemind.java b/shoot-hand/ics-admin/src/main/java/com/ics/admin/domain/RepairRemind.java index ae97892..bf3b493 100644 --- a/shoot-hand/ics-admin/src/main/java/com/ics/admin/domain/RepairRemind.java +++ b/shoot-hand/ics-admin/src/main/java/com/ics/admin/domain/RepairRemind.java @@ -48,7 +48,7 @@ public class RepairRemind extends BaseEntity { private Date readTime; /** - * 扩展1 + * 扩展1 值 1,需要微信推送模板消息, 3 推送成功 5,推送失败 */ private String ext1; @@ -76,4 +76,15 @@ public class RepairRemind extends BaseEntity { this.setCreateTime(createTime); } + public RepairRemind(Long repairId, Long userId, String content, Long createBy, Date createTime, String ext1) { + this.typeId = 0; + this.repairId = repairId; + this.userId = userId; + this.content = content; + this.read = 0; + this.setDeleteFlag(0); + this.setCreateBy(createBy + ""); + this.setCreateTime(createTime); + this.ext1 = ext1; + } } diff --git a/shoot-hand/ics-admin/src/main/java/com/ics/admin/mapper/IcsCustomerStaffMapper.java b/shoot-hand/ics-admin/src/main/java/com/ics/admin/mapper/IcsCustomerStaffMapper.java index e76c0ae..0387a76 100644 --- a/shoot-hand/ics-admin/src/main/java/com/ics/admin/mapper/IcsCustomerStaffMapper.java +++ b/shoot-hand/ics-admin/src/main/java/com/ics/admin/mapper/IcsCustomerStaffMapper.java @@ -79,4 +79,11 @@ public interface IcsCustomerStaffMapper extends BaseMapper { IcsCustomerStaff selectUserByMobileAndParkId(@Param("mobile") String phoneNumber, @Param("parkId") String parkId); + /** + * 绑定用户的微信公众号openid + * @param mobile 手机号 + * @param openid 微信公众号openid + * @return + */ + int updateGzhOpenid(@Param("mobile") String mobile,@Param("openid") String openid); } diff --git a/shoot-hand/ics-admin/src/main/java/com/ics/admin/mapper/RepairRemindMapper.java b/shoot-hand/ics-admin/src/main/java/com/ics/admin/mapper/RepairRemindMapper.java index 57e1fa0..2ec6c37 100644 --- a/shoot-hand/ics-admin/src/main/java/com/ics/admin/mapper/RepairRemindMapper.java +++ b/shoot-hand/ics-admin/src/main/java/com/ics/admin/mapper/RepairRemindMapper.java @@ -93,4 +93,17 @@ public interface RepairRemindMapper { * @return 结果 */ int deleteRepairRemindByIds(String[] ids); + + /** + * 获取待推送的提醒 + */ + List getWxPushRepairRemind(); + + /** + * 推送后更新提醒消息 + * @param state + * @param ids + * @return + */ + int afterWxPush(@Param("state") String state, @Param("ids") List ids); } \ No newline at end of file diff --git a/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/IIcsCustomerStaffService.java b/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/IIcsCustomerStaffService.java index cf49719..380c6fe 100644 --- a/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/IIcsCustomerStaffService.java +++ b/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/IIcsCustomerStaffService.java @@ -63,6 +63,7 @@ public interface IIcsCustomerStaffService extends IService { /** * 检查手机号码是否唯一 + * * @return */ String checkMobileUnique(String mobile); @@ -82,7 +83,7 @@ public interface IIcsCustomerStaffService extends IService { List selectCustomerStaffList(IcsCustomerStaff icsCustomerStaff); - String importCustomerStaff(List userList,Long customerId); + String importCustomerStaff(List userList, Long customerId); List getUserList(IcsCustomerStaff customerStaff); @@ -92,7 +93,14 @@ public interface IIcsCustomerStaffService extends IService { List selectUserListByType(String phone); - + /** + * 绑定用户的微信公众号openid + * + * @param mobile 手机号 + * @param openid 微信公众号openid + * @return + */ + int updateGzhOpenid(String mobile, String openid); // IcsCustomerStaff selectUserByMobileAndParkId(String phoneNumber, String parkId); } diff --git a/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/IRepairRemindService.java b/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/IRepairRemindService.java index 3d221de..3c1107a 100644 --- a/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/IRepairRemindService.java +++ b/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/IRepairRemindService.java @@ -75,4 +75,18 @@ public interface IRepairRemindService { * @return 结果 */ int deleteRepairRemindByIds(String ids); + + /** + * 获取待推送微信公众号的提醒 + */ + List getWxPushRepairRemind(); + + /** + * 微信公众号推送后更新提醒消息 + * + * @param success 推送成功的id + * @param failed 推送失败的id + * @return + */ + int afterWxPush(List success, List failed); } diff --git a/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/impl/IcsCustomerStaffServiceImpl.java b/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/impl/IcsCustomerStaffServiceImpl.java index 92ab164..15f9001 100644 --- a/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/impl/IcsCustomerStaffServiceImpl.java +++ b/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/impl/IcsCustomerStaffServiceImpl.java @@ -351,4 +351,8 @@ public class IcsCustomerStaffServiceImpl extends ServiceImpl getWxPushRepairRemind() { + return repairRemindMapper.getWxPushRepairRemind(); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public int afterWxPush(List success, List failed) { + int a = 0, b = 0; + if (success != null && success.size() > 0) { + a = repairRemindMapper.afterWxPush("3", success); + } + if (failed != null && failed.size() > 0) { + b = repairRemindMapper.afterWxPush("5", failed); + } + return a + b; + } } diff --git a/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/impl/RepairServiceImpl.java b/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/impl/RepairServiceImpl.java index 2016d0f..b29e8ec 100644 --- a/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/impl/RepairServiceImpl.java +++ b/shoot-hand/ics-admin/src/main/java/com/ics/admin/service/impl/RepairServiceImpl.java @@ -218,61 +218,62 @@ public class RepairServiceImpl implements IRepairService { Date now = new Date(); String remind = repair.getAddress() + "/" + repair.getFloor() + " " + repair.getRoom() + " / " + repair.getTypeName(); if (from == 0) {//报修 - if (to == 1) + if (to == 1) { //提醒派单员 - rList.add(new RepairRemind(0L, nextUser.getId(), String.format(repairRemindContent.getP1(), remind), currentUser.getId(), now)); - //提醒楼层管理员 - rList.add(new RepairRemind(0L, adminId, String.format(repairRemindContent.getFloor01(), remind), currentUser.getId(), now)); + rList.add(new RepairRemind(0L, nextUser.getId(), String.format(repairRemindContent.getP1(), remind), currentUser.getId(), now, "1")); + //提醒楼层管理员 + rList.add(new RepairRemind(0L, adminId, String.format(repairRemindContent.getFloor01(), remind), currentUser.getId(), now, "1")); + } if (to == 5) //提醒维修工 - rList.add(new RepairRemind(0L, nextUser.getId(), String.format(repairRemindContent.getW1(), remind), currentUser.getId(), now)); + rList.add(new RepairRemind(0L, nextUser.getId(), String.format(repairRemindContent.getW1(), remind), currentUser.getId(), now, "1")); } else if (from == 1) {//派单 if (to == 5) { //提醒维修工 - rList.add(new RepairRemind(repair.getId(), nextUser.getId(), String.format(repairRemindContent.getW1(), remind), currentUser.getId(), now)); + rList.add(new RepairRemind(repair.getId(), nextUser.getId(), String.format(repairRemindContent.getW1(), remind), currentUser.getId(), now, "1")); //提醒发起人 rList.add(new RepairRemind(repair.getId(), Long.valueOf(repair.getCreateBy()), String.format(repairRemindContent.getR15(), remind), currentUser.getId(), now)); //提醒楼层管理员 - rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor15(), remind), currentUser.getId(), now)); + rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor15(), remind), currentUser.getId(), now, "1")); } if (to == 3) { //提醒管理员 - rList.add(new RepairRemind(repair.getId(), nextUser.getId(), String.format(repairRemindContent.getM1(), remind, StringUtils.isBlank(content) ? "" : content), currentUser.getId(), now)); + rList.add(new RepairRemind(repair.getId(), nextUser.getId(), String.format(repairRemindContent.getM1(), remind, StringUtils.isBlank(content) ? "" : content), currentUser.getId(), now, "1")); //提醒发起人 - rList.add(new RepairRemind(repair.getId(), Long.valueOf(repair.getCreateBy()), String.format(repairRemindContent.getR1(), remind), currentUser.getId(), now)); + rList.add(new RepairRemind(repair.getId(), Long.valueOf(repair.getCreateBy()), String.format(repairRemindContent.getR1(), remind), currentUser.getId(), now, "1")); } if (to == 11) { //提醒发起人 rList.add(new RepairRemind(repair.getId(), Long.valueOf(repair.getCreateBy()), String.format(repairRemindContent.getR2(), remind, StringUtils.isBlank(content) ? "" : content), currentUser.getId(), now)); //提醒楼层管理员 - rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor111(), remind, StringUtils.isBlank(content) ? "" : content), currentUser.getId(), now)); + rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor111(), remind, StringUtils.isBlank(content) ? "" : content), currentUser.getId(), now, "1")); } } else if (from == 3) {//重新派单 //提醒派单员 - rList.add(new RepairRemind(repair.getId(), nextUser.getId(), String.format(repairRemindContent.getP2(), remind), currentUser.getId(), now)); + rList.add(new RepairRemind(repair.getId(), nextUser.getId(), String.format(repairRemindContent.getP2(), remind), currentUser.getId(), now, "1")); //提醒楼层管理员 - rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor31(), remind), currentUser.getId(), now)); + rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor31(), remind), currentUser.getId(), now, "1")); } else if (from == 5) {//修理工是否接收 if (to == 1) { //提醒派单员 - rList.add(new RepairRemind(repair.getId(), nextUser.getId(), String.format(repairRemindContent.getP3(), remind, currentUser.getUsername(), StringUtils.isBlank(content) ? "" : content), currentUser.getId(), now)); + rList.add(new RepairRemind(repair.getId(), nextUser.getId(), String.format(repairRemindContent.getP3(), remind, currentUser.getUsername(), StringUtils.isBlank(content) ? "" : content), currentUser.getId(), now, "1")); //提醒发起人 rList.add(new RepairRemind(repair.getId(), Long.valueOf(repair.getCreateBy()), String.format(repairRemindContent.getR3(), remind), currentUser.getId(), now)); //提醒楼层管理员 - rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor51(), remind, currentUser.getUsername()), currentUser.getId(), now)); + rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor51(), remind, currentUser.getUsername()), currentUser.getId(), now, "1")); } if (to == 7) { //提醒发起人 rList.add(new RepairRemind(repair.getId(), Long.valueOf(repair.getCreateBy()), String.format(repairRemindContent.getR4(), remind, nextUser.getUsername()), currentUser.getId(), now)); //提醒楼层管理员 - rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor57(), remind), currentUser.getId(), now)); + rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor57(), remind), currentUser.getId(), now, "1")); } } else if (from == 7) {//修理反馈 //提醒发起人 rList.add(new RepairRemind(repair.getId(), Long.valueOf(repair.getCreateBy()), String.format(repairRemindContent.getR5(), remind), currentUser.getId(), now)); //提醒楼层管理员 String result = repair.getResolve() == 0 ? "未解决" : "已解决"; - rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor79(), remind, result), currentUser.getId(), now)); + rList.add(new RepairRemind(repair.getId(), adminId, String.format(repairRemindContent.getFloor79(), remind, result), currentUser.getId(), now, "1")); } return rList; } diff --git a/shoot-hand/ics-admin/src/main/resources/mapper/admin/IcsCustomerStaffMapper.xml b/shoot-hand/ics-admin/src/main/resources/mapper/admin/IcsCustomerStaffMapper.xml index b17c589..b98d33a 100644 --- a/shoot-hand/ics-admin/src/main/resources/mapper/admin/IcsCustomerStaffMapper.xml +++ b/shoot-hand/ics-admin/src/main/resources/mapper/admin/IcsCustomerStaffMapper.xml @@ -21,6 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -38,7 +39,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - SELECT id, username, mobile, create_by, create_time, update_by,name,photo,address,email,degree,urgent, update_time, delete_flag, ics_customer_id, openid, avatar, gender, status, park_id,card_no, visit_time, + SELECT id, username, mobile, create_by, create_time, update_by,name,photo,address,email,degree,urgent, update_time, delete_flag, ics_customer_id, openid, gzh_openid, avatar, gender, status, park_id,card_no, visit_time, leave_time,visit_content,to_name,to_phone,to_customer,to_customer_id,data_type,park_id,tenant_id FROM ics_customer_staff @@ -86,6 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete_flag, ics_customer_id, openid, + gzh_openid, avatar, gender, status, @@ -118,6 +120,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{deleteFlag}, #{icsCustomerId}, #{openid}, + #{gzhOpenid}, #{avatar}, #{gender}, #{status}, @@ -153,6 +156,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete_flag = #{deleteFlag}, ics_customer_id = #{icsCustomerId}, openid = #{openid}, + gzh_openid=#{gzhOpenid}, avatar = #{avatar}, gender = #{gender}, status = #{status}, @@ -218,5 +222,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where mobile = #{mobile} and park_id = #{parkId} + + + '1' + ]]> + diff --git a/shoot-hand/ics-admin/src/main/resources/mapper/admin/RepairAddressFloorMapper.xml b/shoot-hand/ics-admin/src/main/resources/mapper/admin/RepairAddressFloorMapper.xml index afa7a75..4d61203 100644 --- a/shoot-hand/ics-admin/src/main/resources/mapper/admin/RepairAddressFloorMapper.xml +++ b/shoot-hand/ics-admin/src/main/resources/mapper/admin/RepairAddressFloorMapper.xml @@ -9,7 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + diff --git a/shoot-hand/ics-admin/src/main/resources/mapper/admin/RepairRemindMapper.xml b/shoot-hand/ics-admin/src/main/resources/mapper/admin/RepairRemindMapper.xml index f6a1ae9..c085ca1 100644 --- a/shoot-hand/ics-admin/src/main/resources/mapper/admin/RepairRemindMapper.xml +++ b/shoot-hand/ics-admin/src/main/resources/mapper/admin/RepairRemindMapper.xml @@ -129,4 +129,17 @@ + + + + update ics_repair_remind set ext1 = #{state} where id in + + #{id} + + + + \ No newline at end of file diff --git a/shoot-hand/ics-common/ics-common-core/src/main/java/com/ics/common/core/domain/IcsCustomerStaff.java b/shoot-hand/ics-common/ics-common-core/src/main/java/com/ics/common/core/domain/IcsCustomerStaff.java index bef7fcb..911182f 100644 --- a/shoot-hand/ics-common/ics-common-core/src/main/java/com/ics/common/core/domain/IcsCustomerStaff.java +++ b/shoot-hand/ics-common/ics-common-core/src/main/java/com/ics/common/core/domain/IcsCustomerStaff.java @@ -58,6 +58,9 @@ public class IcsCustomerStaff extends BaseEntity { /** 微信openid */ private String openid; + /** 微信公众号openid */ + private String gzhOpenid; + /** 用户头像 */ private String avatar; diff --git a/shoot-hand/ics-system/src/main/java/com/ics/system/handlers/MyParkLineHandler.java b/shoot-hand/ics-system/src/main/java/com/ics/system/handlers/MyParkLineHandler.java index a53e807..edeaee1 100644 --- a/shoot-hand/ics-system/src/main/java/com/ics/system/handlers/MyParkLineHandler.java +++ b/shoot-hand/ics-system/src/main/java/com/ics/system/handlers/MyParkLineHandler.java @@ -24,7 +24,7 @@ public class MyParkLineHandler implements TenantLineHandler { "sys_sn", "sys_user_role", "sys_dept", "ics_customer_contract_room", "ics_park", "ics_apply_room", "ics_customer_contract_refund_room", "ics_apply_park_file", "ics_apply_settle_file", "ics_apply_move_in_file", "ics_activity","ics_customer_staff","tb_customer_ticket","tb_reservation","tb_reservation_person", "tb_room_content","tb_room_item","tb_room_item_by_room","tb_room_serve_by_room","tb_room_serve","tb_equipment","tb_staff_customer", - "tb_room_equipment","tb_room_record","tb_room_serve","tb_showroom","tb_showroom_record","tb_ticket","tb_user_equipment","tb_visitor_person","ics_repair","ics_repair_remind" + "tb_room_equipment","tb_room_record","tb_room_serve","tb_showroom","tb_showroom_record","tb_ticket","tb_user_equipment","tb_visitor_person","ics_repair","ics_repair_remind","ics_repair_address_floor" }; /** diff --git a/shoot-hand/ics-system/src/main/java/com/ics/system/handlers/MyTenantLineHandler.java b/shoot-hand/ics-system/src/main/java/com/ics/system/handlers/MyTenantLineHandler.java index c2dd33f..5dc8d76 100644 --- a/shoot-hand/ics-system/src/main/java/com/ics/system/handlers/MyTenantLineHandler.java +++ b/shoot-hand/ics-system/src/main/java/com/ics/system/handlers/MyTenantLineHandler.java @@ -24,7 +24,7 @@ public class MyTenantLineHandler implements TenantLineHandler { "sys_sn", "sys_user_role", "ics_customer_contract_room", "ics_apply_room", "ics_customer_contract_refund_room", "ics_apply_park_file", "ics_apply_settle_file", "ics_apply_move_in_file", "ics_activity","ics_customer_staff","tb_customer_ticket","tb_reservation","tb_reservation_person", "tb_room_content","tb_room_item","tb_room_item_by_room","tb_room_serve_by_room","tb_room_serve","tb_equipment","tb_staff_customer", - "tb_room_equipment","tb_room_record","tb_room_serve","tb_showroom","tb_showroom_record","tb_ticket","tb_user_equipment","tb_visitor_person","ics_repair","ics_repair_remind" + "tb_room_equipment","tb_room_record","tb_room_serve","tb_showroom","tb_showroom_record","tb_ticket","tb_user_equipment","tb_visitor_person","ics_repair","ics_repair_remind","ics_repair_address_floor" }; /** diff --git a/shoot-hand/ics-web/src/main/java/com/ics/controller/mobile/WxBindController.java b/shoot-hand/ics-web/src/main/java/com/ics/controller/mobile/WxBindController.java new file mode 100644 index 0000000..1e08cea --- /dev/null +++ b/shoot-hand/ics-web/src/main/java/com/ics/controller/mobile/WxBindController.java @@ -0,0 +1,128 @@ +package com.ics.controller.mobile; + +import com.alibaba.fastjson.JSONObject; +import com.ics.admin.service.IIcsCustomerStaffService; +import com.ics.common.utils.StringUtils; +import com.ics.service.RepairRemindPushService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.ClassPathResource; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; +import org.wf.jwtp.annotation.Ignore; + +import javax.servlet.http.HttpServletResponse; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URLEncoder; + +/** + * 微信公众号openid 绑定手机号 + * created at 2024-9-7 12:17 + * + * @author lujiang + * @version 1.0.0 + * @since 1.0.0 + */ +@RestController +@RequestMapping("/wxbind") +public class WxBindController { + + @Value("${webchatGZH.appid}") + private String appid; + + @Value("${webchatGZH.secret}") + private String secret; + + @Value("${webchatGZH.access}") + private String access; + + private static String html; + + @Autowired + private IIcsCustomerStaffService customerStaffService; + + @Autowired + private RepairRemindPushService repairRemindPushService; + + + //微信公众号网页授权地址 + private final static String OAUTH2_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=sh0907#wechat_redirect"; + + private final static String OAUTH2_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code"; + + /** + * 网页授权引导 + */ + @Ignore + @RequestMapping("/index") + public void index(HttpServletResponse response) throws IOException { + String redirectUrl = access + "/wxbind/page"; + String encodedUrl = URLEncoder.encode(redirectUrl, "UTF-8"); + String url = String.format(OAUTH2_URL, appid, encodedUrl); + response.sendRedirect(url); + } + + /** + * 获取公众号openid,返回输入手机号绑定页面 + */ + @Ignore + @ResponseBody + @RequestMapping(value = "/page", produces = "text/html;charset=utf-8") + public String page(String code, String state) { + if (!"sh0907".equals(state)) return ""; + String url = String.format(OAUTH2_TOKEN, appid, secret, code); + JSONObject result = SmallWxOkHttp.sendGet(url, null); + String openid = result.getString("openid"); + String page = readHtml(); + String submitUrl = access + "/wxbind/bind";//绑定按钮的提交地址 + return String.format(page, submitUrl, openid); + } + + /** + * 绑定手机号 + * + * @param phone 手机号 + * @param openid 公众号openid + * @return + */ + @Ignore + @ResponseBody + @PostMapping(value = "/bind", produces = "text/html;charset=utf-8") + public String bind(String phone, String openid) { + String resultHtml = "

%s

"; + int row = customerStaffService.updateGzhOpenid(phone, openid); + return String.format(resultHtml, row > 0 ? "绑定成功" : "绑定失败"); + } + + + @Ignore + @ResponseBody + @RequestMapping(value = "/send", produces = "text/html;charset=utf-8") + public String send() { + return repairRemindPushService.pushWxTemplateMsg()+""; + } + + /** + * 获取绑定页面 + */ + private static String readHtml() { + if (StringUtils.isNotBlank(html)) return html; + StringBuilder sb = new StringBuilder(); + ClassPathResource resource = new ClassPathResource("phoneBind.html"); + try (BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream()))) { + String line; + while ((line = br.readLine()) != null) { + sb.append(line); + } + } catch (IOException e) { + e.printStackTrace(); + } + html = sb.toString(); + return html; + } + +} diff --git a/shoot-hand/ics-web/src/main/java/com/ics/service/RepairRemindPushService.java b/shoot-hand/ics-web/src/main/java/com/ics/service/RepairRemindPushService.java new file mode 100644 index 0000000..9ae9b7c --- /dev/null +++ b/shoot-hand/ics-web/src/main/java/com/ics/service/RepairRemindPushService.java @@ -0,0 +1,12 @@ +package com.ics.service; + +public interface RepairRemindPushService { + + /** + * 发送微信模板消息 + * + * @return + */ + public int pushWxTemplateMsg(); + +} diff --git a/shoot-hand/ics-web/src/main/java/com/ics/service/impl/RepairRemindPushServiceImpl.java b/shoot-hand/ics-web/src/main/java/com/ics/service/impl/RepairRemindPushServiceImpl.java new file mode 100644 index 0000000..f70bb90 --- /dev/null +++ b/shoot-hand/ics-web/src/main/java/com/ics/service/impl/RepairRemindPushServiceImpl.java @@ -0,0 +1,142 @@ +package com.ics.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.ics.admin.domain.RepairRemind; +import com.ics.admin.service.IIcsCustomerStaffService; +import com.ics.admin.service.IRepairRemindService; +import com.ics.common.core.domain.IcsCustomerStaff; +import com.ics.common.utils.DateUtils; +import com.ics.common.utils.StringUtils; +import com.ics.controller.mobile.SmallWxOkHttp; +import com.ics.service.RepairRemindPushService; +import okhttp3.Call; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * created at 2024-9-7 22:42 + * + * @author lujiang + * @version 1.0.0 + * @since 1.0.0 + */ +@Service +public class RepairRemindPushServiceImpl implements RepairRemindPushService { + @Autowired + private IRepairRemindService repairRemindService; + + @Autowired + private IIcsCustomerStaffService customerStaffService; + + @Autowired + private RedisTemplate redisTemplate; + + @Value("${webchatGZH.templateId}") + private String templateId; + + @Value("${webchatGZH.appid}") + private String appid; + + @Value("${webchatGZH.secret}") + private String secret; + + private final static String SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s"; + + private final static String WX_SMALL_APP_ID = "wxe043ce243cd9de5b"; //小程序id + + private final static String WX_SMALL_APP_PAGE = "/pages/index/index"; //小程序页面 + + + private String getAccessToken() { + String key = "webchatGZH"; + // 从缓存获取微信公众号 AccessToken + String accessToken = redisTemplate.opsForValue().get(key); + if (StringUtils.isBlank(accessToken)) { + accessToken = SmallWxOkHttp.getAccessToken(appid, secret); + redisTemplate.opsForValue().set(key, accessToken, 6000, TimeUnit.SECONDS); + } + return accessToken; + } + + @Override + public int pushWxTemplateMsg() { + String accessToken = getAccessToken(); + String url = String.format(SEND_URL, accessToken); + List list = repairRemindService.getWxPushRepairRemind(); + List success = new ArrayList<>(); + List failed = new ArrayList<>(); + + for (RepairRemind repairRemind : list) { + IcsCustomerStaff customerStaff = customerStaffService.selectIcsCustomerStaffById(repairRemind.getUserId()); + if (customerStaff == null || StringUtils.isBlank(customerStaff.getGzhOpenid())) { + failed.add(repairRemind.getId()); + } else { + String openid = customerStaff.getGzhOpenid(); + String time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, repairRemind.getCreateTime()); + String content = repairRemind.getContent(); + + Map param = new HashMap<>(); + param.put("touser", openid); + param.put("template_id", templateId); + param.put("touser", openid); + +// JSONObject miniprogram = new JSONObject(); +// miniprogram.put("appid", WX_SMALL_APP_ID); +// miniprogram.put("pagepath", WX_SMALL_APP_PAGE); +// param.put("miniprogram", miniprogram); + + + JSONObject dataTime = new JSONObject(); + dataTime.put("value", time); + JSONObject msg = new JSONObject(); + msg.put("value", content); + + JSONObject data = new JSONObject(); + data.put("time38", dataTime); + data.put("thing37", msg); + param.put("data", data); + JSONObject result = send(url, JSON.toJSONString(param)); + if (result == null || result.getInteger("errcode") == null || result.getInteger("errcode") != 0) { + failed.add(repairRemind.getId()); + } else { + success.add(repairRemind.getId()); + } + } + + } + return repairRemindService.afterWxPush(success, failed); + } + + + private static JSONObject send(String url, String param) { + OkHttpClient client = new OkHttpClient().newBuilder().build(); + RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), param); + Request request = new Request.Builder().post(body).url(url).build(); + Call call = client.newCall(request); + //返回请求结果 + try { + Response response = call.execute(); + String resultStr = response.body().string(); + System.out.println(resultStr); + return JSON.parseObject(resultStr); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/shoot-hand/ics-web/src/main/java/com/ics/task/RepairRemindPushTask.java b/shoot-hand/ics-web/src/main/java/com/ics/task/RepairRemindPushTask.java new file mode 100644 index 0000000..0953772 --- /dev/null +++ b/shoot-hand/ics-web/src/main/java/com/ics/task/RepairRemindPushTask.java @@ -0,0 +1,27 @@ +package com.ics.task; + +import com.ics.common.utils.spring.SpringUtils; +import com.ics.service.RepairRemindPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * created at 2024-9-8 0:07 + * + * @author lujiang + * @version 1.0.0 + * @since 1.0.0 + */ + +@Slf4j +@Service("repairRemindPushTask") +public class RepairRemindPushTask { + /** + * 工单提醒推送公众号 + */ + public void remindPush() { + RepairRemindPushService repairRemindPushService = SpringUtils.getBean(RepairRemindPushService.class); + int num = repairRemindPushService.pushWxTemplateMsg(); + log.info("推送公众号" + num + "个工单提醒"); + } +} diff --git a/shoot-hand/ics-web/src/main/resources/application-dev.yml b/shoot-hand/ics-web/src/main/resources/application-dev.yml index c491e86..a2769c9 100644 --- a/shoot-hand/ics-web/src/main/resources/application-dev.yml +++ b/shoot-hand/ics-web/src/main/resources/application-dev.yml @@ -53,7 +53,7 @@ spring: enabled: true statViewServlet: enabled: true - # 设置白名单,不填则允许所有访问 + # 设置白名单,不填则允许所有访问. allow: url-pattern: /monitor/druid/* filter: @@ -72,8 +72,8 @@ dfs: #path: /Users/lihongyuan/IdeaProjects/saas-ics/ics/ # domain: http://222.184.49.22:9227 # path: D:/ruoyi/uploadPath - domain: http://192.168.0.11:9227 - path: F:/ruoyi/uploadPath + domain: http://127.0.0.1:9227 + path: E:/ruoyi/uploadPath # 公众号配置(必填) wx: @@ -142,3 +142,9 @@ weixin: key: CHANGYANGKONGGUhenanjianandianzi # APIv3密钥 domain: https://api.mch.weixin.qq.com # 微信服务器地址 notify-domain: http://b8pyta.natappfree.cc # 回调,自己的回调地址 + +webchatGZH: #微信公众号用户绑定及模板消息推送相关配置 + appid: wxf164eab7ad1d9075 + secret: 199fc64445882192ae798816d949be0d + access: https://company.haxy.com.cn:4443/shoot-hand #pc后端访问地址 + templateId: 3VU7ZY8RgiR9hcPysc34y-S2PxKQU2JrIT8v_mhkuic #模板消息模板id diff --git a/shoot-hand/ics-web/src/main/resources/application-prod.yml b/shoot-hand/ics-web/src/main/resources/application-prod.yml index efaff65..74c7c34 100644 --- a/shoot-hand/ics-web/src/main/resources/application-prod.yml +++ b/shoot-hand/ics-web/src/main/resources/application-prod.yml @@ -131,4 +131,10 @@ weixin: mch-id: 1665472343 # 商户号 key: CHANGYANGKONGGUhenanjianandianzi # APIv3密钥 domain: https://api.mch.weixin.qq.com # 微信服务器地址 - notify-domain: http://b8pyta.natappfree.cc # 回调,自己的回调地址 \ No newline at end of file + notify-domain: http://b8pyta.natappfree.cc # 回调,自己的回调地址 + +webchatGZH: #微信公众号用户绑定及模板消息推送相关配置 + appid: wxf164eab7ad1d9075 + secret: 199fc64445882192ae798816d949be0d + access: https://company.haxy.com.cn:4443/shoot-hand #pc后端访问地址 + templateId: 3VU7ZY8RgiR9hcPysc34y-S2PxKQU2JrIT8v_mhkuic #模板消息模板id \ No newline at end of file diff --git a/shoot-hand/ics-web/src/main/resources/application-server.yml b/shoot-hand/ics-web/src/main/resources/application-server.yml index 4f1de53..a13d5df 100644 --- a/shoot-hand/ics-web/src/main/resources/application-server.yml +++ b/shoot-hand/ics-web/src/main/resources/application-server.yml @@ -131,4 +131,10 @@ weixin: mch-id: 1665472343 # 商户号 key: CHANGYANGKONGGUhenanjianandianzi # APIv3密钥 domain: https://api.mch.weixin.qq.com # 微信服务器地址 - notify-domain: http://b8pyta.natappfree.cc # 回调,自己的回调地址 \ No newline at end of file + notify-domain: http://b8pyta.natappfree.cc # 回调,自己的回调地址 + +webchatGZH: #微信公众号用户绑定及模板消息推送相关配置 + appid: wx88c3ba1d01b33b8b + secret: db375b6db9c7b87b1daa48375b45731e + access: https://baoxiu.jsgdha.com/shoot-hand #pc后端访问地址 + templateId: 4jgtzPfyX546n5ZDPHbN69YSSFf8NSOQUDJuPb6bYwA #模板消息模板id \ No newline at end of file diff --git a/shoot-hand/ics-web/src/main/resources/phoneBind.html b/shoot-hand/ics-web/src/main/resources/phoneBind.html new file mode 100644 index 0000000..3092a4a --- /dev/null +++ b/shoot-hand/ics-web/src/main/resources/phoneBind.html @@ -0,0 +1,96 @@ + + + + + + + 工作人员绑定 + + + + +
+ +
+ + +