mirror of
https://gitee.com/elegant_wings/dbd-meeting.git
synced 2025-06-21 17:09:36 +08:00
1、修改小程序登录相关接口,改为企业内部用户接口
2、增加访客数据表合相关接口,访客和企业员工共用一张表
This commit is contained in:
parent
16c50b373c
commit
21d0b3d54f
@ -54,6 +54,11 @@
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml-schemas</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.11.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -19,7 +19,7 @@ import java.util.Date;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/staff")
|
||||
public class IcsCustomerStaffController extends BaseController {
|
||||
public class CustomerStaffController extends BaseController {
|
||||
|
||||
private final static String ACCESS_USERID = Constants.ACCESS_USERID;
|
||||
|
||||
@ -41,7 +41,8 @@ public class IcsCustomerStaffController extends BaseController {
|
||||
@GetMapping("list")
|
||||
public R list(IcsCustomerStaff icsCustomerStaff) {
|
||||
startPage();
|
||||
icsCustomerStaff.setIcsCustomerId(1L);//临时设置
|
||||
icsCustomerStaff.setIcsCustomerId(1L);//临时设置,需要从用户信息中获取
|
||||
icsCustomerStaff.setDataType(Constants.CUSTOMER_STAFF);
|
||||
return result(icsCustomerStaffService.selectIcsCustomerStaffList(icsCustomerStaff));
|
||||
}
|
||||
|
||||
@ -55,6 +56,7 @@ public class IcsCustomerStaffController extends BaseController {
|
||||
icsCustomerStaff.setIcsCustomerId(1L);
|
||||
icsCustomerStaff.setCreateTime(new Date());
|
||||
icsCustomerStaff.setCreateBy(getLoginName());
|
||||
icsCustomerStaff.setDataType(Constants.CUSTOMER_STAFF);
|
||||
return toAjax(icsCustomerStaffService.insertIcsCustomerStaff(icsCustomerStaff));
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.ics.admin.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ics.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 企业员工对象 ics_customer_staff
|
||||
*
|
||||
@ -39,4 +42,36 @@ public class IcsCustomerStaff extends BaseEntity<IcsCustomerStaff> {
|
||||
/** 园区ID */
|
||||
private Long parkId;
|
||||
|
||||
/**证件类型*/
|
||||
private String cardType;
|
||||
|
||||
/**证件号码**/
|
||||
private String cardNo;
|
||||
|
||||
/**来访时间*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date visitTime;
|
||||
|
||||
/**离开时间**/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date leaveTime;
|
||||
|
||||
/**来访是由*/
|
||||
private String visitContent;
|
||||
|
||||
/**被访问人姓名**/
|
||||
private String toName;
|
||||
|
||||
/**被访问人号码*/
|
||||
private String toPhone;
|
||||
|
||||
/**被访问单位名称*/
|
||||
private String toCustomer;
|
||||
|
||||
/**被访问单位id**/
|
||||
private String toCustomerId;
|
||||
|
||||
/**数据类型,1企业员工,2临时访客*/
|
||||
private String dataType;
|
||||
|
||||
}
|
||||
|
@ -19,10 +19,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="gender" column="gender" />
|
||||
<result property="status" column="status" />
|
||||
<result property="parkId" column="park_id" />
|
||||
<result property="cardNo" column="card_no" />
|
||||
<result property="visitTime" column="visit_time" />
|
||||
<result property="leaveTime" column="leave_time" />
|
||||
<result property="visitContent" column="visit_content" />
|
||||
<result property="toName" column="to_name" />
|
||||
<result property="toPhone" column="to_phone" />
|
||||
<result property="toCustomer" column="to_customer" />
|
||||
<result property="toCustomerId" column="to_customer_id" />
|
||||
<result property="dataType" column="data_type" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectIcsCustomerStaffVo">
|
||||
SELECT id, username, mobile, create_by, create_time, update_by, update_time, delete_flag, ics_customer_id, openid, avatar, gender, status, park_id FROM ics_customer_staff
|
||||
SELECT id, username, mobile, create_by, create_time, update_by, update_time, delete_flag, ics_customer_id, 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
|
||||
FROM ics_customer_staff
|
||||
</sql>
|
||||
|
||||
<select id="selectIcsCustomerStaffList" parameterType="IcsCustomerStaff" resultMap="IcsCustomerStaffResult">
|
||||
@ -56,6 +67,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="gender != null and gender != ''">gender,</if>
|
||||
<if test="status != null and status != ''">status,</if>
|
||||
<if test="parkId != null ">park_id,</if>
|
||||
<if test="cardNo != null and cardNo !=''">,</if>
|
||||
<if test="visitTime != null ">,</if>
|
||||
<if test="leaveTime != null ">,</if>
|
||||
<if test="visitContent != null and visitContent !=''">,</if>
|
||||
<if test="toName != null and toName!=''">,</if>
|
||||
<if test="toPhone != null and toPhone!=''">,</if>
|
||||
<if test="toCustomer != null and toCustomer!=''">,</if>
|
||||
<if test="toCustomerId != null and toCustomerId!=''">,</if>
|
||||
<if test="dataType != null dataType!=''">,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null ">#{id},</if>
|
||||
@ -73,6 +93,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="gender != null and gender != ''">#{gender},</if>
|
||||
<if test="status != null and status != ''">#{status},</if>
|
||||
<if test="parkId != null ">#{parkId},</if>
|
||||
<if test="cardNo != null and cardNo !=''">#{cardNo}</if>
|
||||
<if test="visitTime != null ">#{visitTime}</if>
|
||||
<if test="leaveTime != null ">#{leaveTime}</if>
|
||||
<if test="visitContent != null and visitContent !=''">#{visitContent}</if>
|
||||
<if test="toName != null and toName!=''">#{toName}</if>
|
||||
<if test="toPhone != null and toPhone!=''">#{toPhone}</if>
|
||||
<if test="toCustomer != null and toCustomer!=''">#{toCustomer}</if>
|
||||
<if test="toCustomerId != null and toCustomerId!=''">#{toCustomerId}</if>
|
||||
<if test="dataType != null dataType!=''">#{dataType}</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@ -93,6 +122,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="gender != null and gender != ''">gender = #{gender},</if>
|
||||
<if test="status != null and status != ''">status = #{status},</if>
|
||||
<if test="parkId != null ">park_id = #{parkId},</if>
|
||||
<if test="cardNo != null and cardNo !=''">card_no = #{cardNo}</if>
|
||||
<if test="visitTime != null ">visit_time = #{visitTime}</if>
|
||||
<if test="leaveTime != null ">leave_time = #{leaveTime}</if>
|
||||
<if test="visitContent != null and visitContent !=''">visit_content = #{visitContent}</if>
|
||||
<if test="toName != null and toName!=''">to_name = #{toName}</if>
|
||||
<if test="toPhone != null and toPhone!=''">to_phone = #{toPhone}</if>
|
||||
<if test="toCustomer != null and toCustomer!=''">to_customer = #{toCustomer}</if>
|
||||
<if test="toCustomerId != null and toCustomerId!=''">to_customer_id = #{toCustomerId}</if>
|
||||
</trim>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
@ -116,4 +116,13 @@ public class Constants {
|
||||
*/
|
||||
public static final String COMPLAINTS = "TS";
|
||||
|
||||
/**
|
||||
* 企业员工
|
||||
*/
|
||||
public static final String CUSTOMER_STAFF = "1";
|
||||
|
||||
/**
|
||||
* 企业访客
|
||||
*/
|
||||
public static final String CUSTOMER_VISIT = "2";
|
||||
}
|
||||
|
@ -5,7 +5,9 @@ import com.google.common.collect.Maps;
|
||||
|
||||
import com.ics.admin.domain.Activity;
|
||||
import com.ics.admin.domain.ActivityDetail;
|
||||
import com.ics.admin.domain.IcsCustomerStaff;
|
||||
import com.ics.admin.domain.Park;
|
||||
import com.ics.admin.service.IIcsCustomerStaffService;
|
||||
import com.ics.admin.service.IParkService;
|
||||
import com.ics.service.IActivityDetailService;
|
||||
import com.ics.service.IActivityService;
|
||||
@ -42,6 +44,9 @@ public class ActivityAPIController extends BaseController {
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
|
||||
@Autowired
|
||||
private IIcsCustomerStaffService icsCustomerStaffService;
|
||||
|
||||
@Autowired
|
||||
private IParkService parkService;
|
||||
|
||||
@ -99,12 +104,13 @@ public class ActivityAPIController extends BaseController {
|
||||
return R.error("请选择园区!!");
|
||||
}
|
||||
Park park = parkService.selectParkById(parkId);
|
||||
User user = userService.selectUserById(activityDetail.getUserId());
|
||||
if (user == null) {
|
||||
//User user = userService.selectUserById(activityDetail.getUserId());
|
||||
IcsCustomerStaff icsCustomerStaff = icsCustomerStaffService.selectIcsCustomerStaffById(activityDetail.getUserId());
|
||||
if (icsCustomerStaff == null) {
|
||||
return R.error("用户不存在");
|
||||
}
|
||||
activityDetail.setSignDate(DateUtils.getNowDate());
|
||||
activityDetail.setPhone(user.getMobile());
|
||||
activityDetail.setPhone(icsCustomerStaff.getMobile());
|
||||
activityDetail.setCreateBy(getLoginName());
|
||||
activityDetail.setParkId(park.getId());
|
||||
activityDetail.setTenantId(park.getTenantId());
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.ics.controller.mobile;
|
||||
|
||||
|
||||
import com.ics.admin.domain.IcsCustomerStaff;
|
||||
import com.ics.admin.mapper.IcsCustomerStaffMapper;
|
||||
import com.ics.admin.service.IIcsCustomerStaffService;
|
||||
import com.ics.common.core.domain.R;
|
||||
import com.ics.common.utils.bean.BeanUtils;
|
||||
import com.ics.system.domain.User;
|
||||
import com.ics.system.domain.form.LoginForm;
|
||||
import com.ics.system.service.IAccessTokenService;
|
||||
@ -12,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
@ -26,12 +32,23 @@ public class LoginAPIController {
|
||||
@Autowired
|
||||
private ISysLoginService sysLoginService;
|
||||
|
||||
@Autowired
|
||||
private IIcsCustomerStaffService icsCustomerStaffService;
|
||||
|
||||
|
||||
@PostMapping("login")
|
||||
public R login(@RequestBody LoginForm form) {
|
||||
// 用户登录
|
||||
User user = sysLoginService.login(form.getUsername(), form.getPassword());
|
||||
// 获取登录token
|
||||
return R.ok(tokenService.createToken(user));
|
||||
IcsCustomerStaff icsCustomerStaff = new IcsCustomerStaff();
|
||||
icsCustomerStaff.setMobile(form.getMobile());
|
||||
List<IcsCustomerStaff> list = icsCustomerStaffService.selectIcsCustomerStaffList(icsCustomerStaff);
|
||||
if(list.size()>0){
|
||||
User user = new User();
|
||||
BeanUtils.copyBeanProp(user,list.get(0));
|
||||
return R.ok(tokenService.createToken(user));
|
||||
}else {
|
||||
return R.error("登录失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package com.ics.controller.mobile;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.ics.admin.domain.IcsCustomerStaff;
|
||||
import com.ics.admin.domain.Park;
|
||||
import com.ics.admin.service.IIcsCustomerStaffService;
|
||||
import com.ics.admin.service.IParkService;
|
||||
import com.ics.common.annotation.LoginUser;
|
||||
import com.ics.common.core.controller.BaseController;
|
||||
@ -38,7 +40,7 @@ public class ParkAPIController extends BaseController {
|
||||
private IParkService parkService;
|
||||
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
private IIcsCustomerStaffService icsCustomerStaffService;
|
||||
|
||||
@Autowired
|
||||
private ITenantService tenantService;
|
||||
@ -88,15 +90,12 @@ public class ParkAPIController extends BaseController {
|
||||
|
||||
/**
|
||||
* 根据选择园区绑定注册用户
|
||||
* @param deptId
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("member:center:view")
|
||||
@PostMapping("selectParkByDeptId")
|
||||
public R selectParkByDeptId(Long deptId, @LoginUser User user){
|
||||
user.setDeptId(deptId);
|
||||
return toAjax(userService.updateUserInfo(user));
|
||||
public R selectParkByDeptId(Long parkId, @LoginUser IcsCustomerStaff icsCustomerStaff){
|
||||
icsCustomerStaff.setParkId(parkId);
|
||||
return toAjax(icsCustomerStaffService.updateIcsCustomerStaff(icsCustomerStaff));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,9 +3,11 @@ package com.ics.controller.mobile;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.ics.admin.domain.IcsCustomerStaff;
|
||||
import com.ics.admin.domain.Park;
|
||||
import com.ics.admin.domain.ServiceManage;
|
||||
import com.ics.admin.domain.ServiceOrder;
|
||||
import com.ics.admin.service.IIcsCustomerStaffService;
|
||||
import com.ics.admin.service.IParkService;
|
||||
import com.ics.service.IServiceManageService;
|
||||
import com.ics.service.IServiceOrderService;
|
||||
@ -46,7 +48,7 @@ public class ServiceManagerAPIController extends BaseController {
|
||||
private IServiceOrderService serviceOrderService;
|
||||
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
private IIcsCustomerStaffService icsCustomerStaffService;
|
||||
|
||||
@Autowired
|
||||
private ISmsService smsService;
|
||||
@ -124,20 +126,20 @@ public class ServiceManagerAPIController extends BaseController {
|
||||
Park park = parkService.selectParkById(parkId);
|
||||
ServiceOrder serviceOrder = new ServiceOrder();
|
||||
serviceOrder.setMemberId(memberId);
|
||||
User user = userService.selectUserById(memberId);
|
||||
if (user == null) {
|
||||
IcsCustomerStaff icsCustomerStaff = icsCustomerStaffService.selectIcsCustomerStaffById(memberId);
|
||||
if (icsCustomerStaff == null) {
|
||||
return R.error("用户不存在!");
|
||||
}
|
||||
serviceOrder.setSupplierId(supplierId);
|
||||
serviceOrder.setServiceId(serviceId);
|
||||
serviceOrder.setParkId(park.getId());
|
||||
serviceOrder.setTenantId(park.getTenantId());
|
||||
serviceOrder.setCreateBy(user.getUsername());
|
||||
serviceOrder.setCreateBy(icsCustomerStaff.getUsername());
|
||||
if (!smsService.verify(mobile, code, SmsType.APPLY_SERVICE)) {
|
||||
return R.error("验证码错误或已过期!");
|
||||
}
|
||||
serviceOrder.setMobile(mobile);
|
||||
serviceOrder.setName(user.getUsername());
|
||||
serviceOrder.setName(icsCustomerStaff.getUsername());
|
||||
return toAjax(serviceOrderService.insertServiceOrder(serviceOrder));
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,121 @@
|
||||
package com.ics.controller.mobile;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import okhttp3.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SmallWxOkHttp {
|
||||
|
||||
static String APP_ID = "wxa29895567831500a";
|
||||
static String SECRET = "46a11f73665fffaa888061d806661a93";
|
||||
|
||||
public static JSONObject sendGet(String url , Map<String, String> map){
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
// 创建url
|
||||
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
|
||||
// 添加参数
|
||||
if(map != null){
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
// 创建请求
|
||||
Request request = new Request.Builder()
|
||||
.url(urlBuilder.build().toString())
|
||||
.build();
|
||||
try {
|
||||
Response response = client.newCall(request).execute();
|
||||
String resultStr = response.body().string();
|
||||
System.out.println(resultStr);
|
||||
return JSON.parseObject(resultStr);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static JSONObject sendPost(String url, Map<String , String> paramMap) {
|
||||
if(paramMap == null){
|
||||
paramMap = new HashMap<>();
|
||||
}
|
||||
String jsonString = JSON.toJSONString(paramMap);
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().build();
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonString);
|
||||
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();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取AccessToken
|
||||
*/
|
||||
public static String getAccessToken(){
|
||||
// url
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/token";
|
||||
// 参数
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("grant_type", "client_credential");
|
||||
map.put("appid", APP_ID);
|
||||
map.put("secret", SECRET);
|
||||
// 发送请求
|
||||
JSONObject jsonObject = sendGet(url, map);
|
||||
String accessToken = jsonObject.getString("access_token");
|
||||
String expiresIn = jsonObject.getString("expires_in");
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序登录
|
||||
*/
|
||||
public static JSONObject code2Session(String jsCode){
|
||||
// url
|
||||
String url = "https://api.weixin.qq.com/sns/jscode2session";
|
||||
// 参数
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("appid", APP_ID);
|
||||
map.put("secret", SECRET);
|
||||
map.put("js_code", jsCode);
|
||||
map.put("grant_type", "authorization_code");
|
||||
// 发送请求
|
||||
JSONObject jsonObject = sendGet(url, map);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取手机号
|
||||
*/
|
||||
public static JSONObject getPhoneNumber(String code, String openid, String accessToken){
|
||||
// url
|
||||
String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + accessToken;
|
||||
// 参数
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("code", code);
|
||||
map.put("openid", openid);
|
||||
// 发送请求
|
||||
JSONObject jsonObject = sendPost(url, map);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// getAccessToken();
|
||||
getPhoneNumber("", "", "74_NGF_xru4Mt5gDVperBd9LYwtMjWaXGb7JNleZ-nqSOSGvtW3vIGYKkFY0ymMFn2aLYZaN9d1rAZ65X5X-mGX556bWQWFy1mawkWUorOvz37QH34q2YBJjsDCih8FYOfAHAWPF");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.ics.controller.mobile;
|
||||
|
||||
import com.ics.admin.domain.IcsCustomerStaff;
|
||||
import com.ics.admin.service.IIcsCustomerStaffService;
|
||||
import com.ics.common.constant.Constants;
|
||||
import com.ics.common.core.controller.BaseController;
|
||||
import com.ics.common.core.domain.R;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 访客信息接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user/visitor")
|
||||
public class VisitorApiController extends BaseController {
|
||||
@Autowired
|
||||
private IIcsCustomerStaffService icsCustomerStaffService;
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
* @param icsCustomerStaff
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("list")
|
||||
public R list(IcsCustomerStaff icsCustomerStaff) {
|
||||
startPage();
|
||||
icsCustomerStaff.setIcsCustomerId(1L);//临时设置,需要从用户信息中获取
|
||||
icsCustomerStaff.setDataType(Constants.CUSTOMER_VISIT);
|
||||
return result(icsCustomerStaffService.selectIcsCustomerStaffList(icsCustomerStaff));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增保存访客信息
|
||||
*/
|
||||
@PostMapping("save")
|
||||
public R addSave(@RequestBody IcsCustomerStaff icsCustomerStaff) {
|
||||
icsCustomerStaff.setIcsCustomerId(1L);//临时设置,需要从用户信息中获取
|
||||
icsCustomerStaff.setCreateTime(new Date());
|
||||
icsCustomerStaff.setCreateBy(getLoginName());
|
||||
icsCustomerStaff.setDataType(Constants.CUSTOMER_VISIT);
|
||||
return toAjax(icsCustomerStaffService.insertIcsCustomerStaff(icsCustomerStaff));
|
||||
}
|
||||
|
||||
/***
|
||||
* 更新
|
||||
* @param icsCustomerStaff
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("update")
|
||||
public R editSave(@RequestBody IcsCustomerStaff icsCustomerStaff) {
|
||||
icsCustomerStaff.setUpdateTime(new Date());
|
||||
icsCustomerStaff.setUpdateBy(getLoginName());
|
||||
return toAjax(icsCustomerStaffService.updateIcsCustomerStaff(icsCustomerStaff));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("remove")
|
||||
public R remove(String ids) {
|
||||
return toAjax(icsCustomerStaffService.deleteIcsCustomerStaffByIds(ids));
|
||||
}
|
||||
|
||||
/***
|
||||
* 查看访客信息
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("get/{id}")
|
||||
public IcsCustomerStaff get(@PathVariable("id") Long id) {
|
||||
return icsCustomerStaffService.selectIcsCustomerStaffById(id);
|
||||
}
|
||||
|
||||
}
|
@ -9,12 +9,15 @@ import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ics.admin.domain.IcsCustomerStaff;
|
||||
import com.ics.admin.service.IIcsCustomerStaffService;
|
||||
import com.ics.common.constant.Constants;
|
||||
import com.ics.common.core.domain.R;
|
||||
import com.ics.common.utils.DateUtils;
|
||||
import com.ics.common.utils.MessageUtils;
|
||||
import com.ics.common.utils.RandomUtil;
|
||||
import com.ics.common.utils.StringUtils;
|
||||
import com.ics.common.utils.bean.BeanUtils;
|
||||
import com.ics.service.IWxAppLoginService;
|
||||
import com.ics.system.domain.User;
|
||||
import com.ics.system.domain.form.LoginRequest;
|
||||
@ -25,12 +28,16 @@ import com.ics.system.util.PasswordUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
@ -43,7 +50,7 @@ import java.util.Objects;
|
||||
public class WxLoginAPIController {
|
||||
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
private IIcsCustomerStaffService icsCustomerStaffService;
|
||||
|
||||
@Autowired
|
||||
private IAccessTokenService tokenService;
|
||||
@ -51,76 +58,78 @@ public class WxLoginAPIController {
|
||||
@Autowired
|
||||
private WxMaService wxMaService;
|
||||
|
||||
@PostMapping("/social_user_login/login")
|
||||
public R social(@RequestBody LoginRequest request) {
|
||||
if (ObjectUtil.isEmpty(request)) {
|
||||
return R.error("empty jscode");
|
||||
}
|
||||
try {
|
||||
WxMaJscode2SessionResult session = wxMaService.getUserService().getSessionInfo(request.getCode());
|
||||
log.info(session.getSessionKey());
|
||||
log.info(session.getOpenid());
|
||||
// 检查是否是否存在
|
||||
User user = userService.selectUserByOpenid(session.getOpenid());
|
||||
// 不存在则注册
|
||||
if (user == null) {
|
||||
user = new User();
|
||||
JSONObject jsonObject = JSON.parseObject(request.getRawData());
|
||||
// 忽略保存昵称的头像信息
|
||||
String mobile = RandomUtil.randomInt(11);
|
||||
user.setUsername(mobile);
|
||||
user.setNickname(jsonObject.getString("nickName"));
|
||||
user.setMobile(mobile);
|
||||
user.setGender(jsonObject.getString("gender"));
|
||||
user.setAvatar(jsonObject.getString("avatarUrl"));
|
||||
user.setCreateBy("system");
|
||||
user.setCreateTime(DateUtils.getNowDate());
|
||||
user.setSalt(RandomUtil.randomStr(6));
|
||||
user.setOpenid(session.getOpenid());
|
||||
user.setPassword(PasswordUtils.encryptPassword(user.getUsername(), "000000", user.getSalt()));
|
||||
userService.insertAppUser(user);
|
||||
}
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
// 登记在线信息
|
||||
PublishFactory.recordLoginInfo(user.getUsername(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
return R.ok(tokenService.createToken(user));
|
||||
} catch (WxErrorException e) {
|
||||
|
||||
String smallWxAccessTokenKey = "smallWxAccessToken";
|
||||
String smallWxUserPassword = "123456";
|
||||
|
||||
@PostMapping("/social_user_login/login")
|
||||
public R social(@RequestBody Map<String, String> paramMap) {
|
||||
try {
|
||||
// 参数
|
||||
String code = paramMap.get("code");
|
||||
String openid = paramMap.get("openid");
|
||||
// 必填
|
||||
if (StringUtils.isBlank(code)) {
|
||||
throw new RuntimeException("请传递code");
|
||||
}
|
||||
if (StringUtils.isBlank(openid)) {
|
||||
throw new RuntimeException("请传递openid");
|
||||
}
|
||||
// 获取微信小程序 AccessToken
|
||||
String smallWxAccessToken = getSmallWxAccessToken();
|
||||
// 获取手机号
|
||||
JSONObject jsonObj = SmallWxOkHttp.getPhoneNumber(code, openid, smallWxAccessToken);
|
||||
JSONObject phoneInfo = jsonObj.getJSONObject("phone_info");
|
||||
// 手机号
|
||||
String phoneNumber = phoneInfo.getString("phoneNumber");
|
||||
IcsCustomerStaff icsCustomerStaff = new IcsCustomerStaff();
|
||||
icsCustomerStaff.setMobile(phoneNumber);
|
||||
List<IcsCustomerStaff> list = icsCustomerStaffService.selectIcsCustomerStaffList(icsCustomerStaff);
|
||||
if(list.size()>0){
|
||||
User user = new User();
|
||||
PublishFactory.recordLoginInfo(list.get(0).getUsername(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
BeanUtils.copyBeanProp(user,list.get(0));
|
||||
return R.ok(tokenService.createToken(user));
|
||||
}else {
|
||||
return R.error("登录失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return R.error("获取微信用户数据失败");
|
||||
} finally {
|
||||
WxMaConfigHolder.remove();//清理ThreadLocal
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 获取微信小程序AccessToken
|
||||
*/
|
||||
public String getSmallWxAccessToken() {
|
||||
// 从缓存获取微信小程序 AccessToken
|
||||
String smallWxAccessToken = redisTemplate.opsForValue().get(smallWxAccessTokenKey);
|
||||
if (StringUtils.isBlank(smallWxAccessToken)) {
|
||||
smallWxAccessToken = SmallWxOkHttp.getAccessToken();
|
||||
redisTemplate.opsForValue().set(smallWxAccessTokenKey, smallWxAccessToken, 7200, TimeUnit.SECONDS);
|
||||
}
|
||||
return smallWxAccessToken;
|
||||
}
|
||||
|
||||
@PostMapping("/wx/login")
|
||||
public R login(@RequestBody User userInfo) {
|
||||
public R login(@RequestBody String mobile) {
|
||||
try {
|
||||
// 检查是否是否存在
|
||||
User user = userService.selectUserByOpenid(userInfo.getOpenid());
|
||||
// 不存在则注册
|
||||
if (user == null) {
|
||||
// 设置默认信息
|
||||
user = new User();
|
||||
String nickname = userInfo.getUsername() ;
|
||||
// 忽略保存昵称的头像信息
|
||||
String mobile = RandomUtil.randomInt(11);
|
||||
user.setUsername(mobile);
|
||||
user.setNickname(nickname);
|
||||
user.setMobile(mobile);
|
||||
user.setGender(userInfo.getGender());
|
||||
user.setAvatar(userInfo.getAvatar());
|
||||
user.setCreateBy(nickname);
|
||||
user.setCreateTime(DateUtils.getNowDate());
|
||||
user.setSalt(RandomUtil.randomStr(6));
|
||||
user.setOpenid(userInfo.getOpenid());
|
||||
user.setPassword(PasswordUtils.encryptPassword(user.getUsername(), "000000", user.getSalt()));
|
||||
|
||||
userService.insertAppUser(user);
|
||||
//检查是否是否存在
|
||||
IcsCustomerStaff icsCustomerStaff = new IcsCustomerStaff();
|
||||
icsCustomerStaff.setMobile(mobile);
|
||||
List<IcsCustomerStaff> list = icsCustomerStaffService.selectIcsCustomerStaffList(icsCustomerStaff);
|
||||
if(list.size()>0){
|
||||
User user = new User();
|
||||
PublishFactory.recordLoginInfo(list.get(0).getUsername(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
BeanUtils.copyBeanProp(user,list.get(0));
|
||||
return R.ok(tokenService.createToken(user));
|
||||
}else {
|
||||
return R.error("登录失败");
|
||||
}
|
||||
|
||||
// 登记在线信息
|
||||
PublishFactory.recordLoginInfo(user.getUsername(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
return R.ok(tokenService.createToken(user));
|
||||
} catch (Exception e) {
|
||||
log.error("调用微信服务器出现异常", e);
|
||||
return R.error("获取微信用户数据失败");
|
||||
|
@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.ics.admin.domain.IcsCustomerStaff;
|
||||
import com.ics.admin.service.IIcsCustomerStaffService;
|
||||
import com.ics.common.annotation.LoginUser;
|
||||
import com.ics.common.constant.Constants;
|
||||
import com.ics.common.constant.UserConstants;
|
||||
@ -32,6 +34,8 @@ public class ProfileAPIController extends BaseController {
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
@Autowired
|
||||
private IIcsCustomerStaffService icsCustomerStaffService;
|
||||
@Autowired
|
||||
private IConfigService configService;
|
||||
|
||||
|
||||
@ -39,38 +43,43 @@ public class ProfileAPIController extends BaseController {
|
||||
/**
|
||||
* 当前用户信息
|
||||
*/
|
||||
@RequiresPermissions("member:center:view")
|
||||
@GetMapping
|
||||
public R index(@LoginUser User user) {
|
||||
public R index(@LoginUser IcsCustomerStaff icsCustomerStaff) {
|
||||
String jsonConfig = configService.selectConfigByKey("sys.setting.siteUrl");
|
||||
JSONObject jsonObject = JSON.parseObject(jsonConfig);
|
||||
String siteUrl = jsonObject.getString("siteUrl");
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
user = userService.selectUserById(user.getId());
|
||||
map.put("userId", user.getId());
|
||||
map.put("mobile", user.getMobile());
|
||||
if (user.getAvatar().contains(Constants.RESOURCE_PREFIX)) {
|
||||
map.put("avatar", siteUrl + user.getAvatar());
|
||||
icsCustomerStaff = icsCustomerStaffService.selectIcsCustomerStaffById(icsCustomerStaff.getId());
|
||||
if (icsCustomerStaff.getAvatar().contains(Constants.RESOURCE_PREFIX)) {
|
||||
icsCustomerStaff.setAvatar(siteUrl + icsCustomerStaff.getAvatar());
|
||||
} else {
|
||||
map.put("avatar", user.getAvatar());
|
||||
icsCustomerStaff.setAvatar(icsCustomerStaff.getAvatar());
|
||||
}
|
||||
map.put("username", user.getUsername());
|
||||
map.put("nickname", user.getNickname());
|
||||
map.put("sex", user.getGender());
|
||||
return R.data(map);
|
||||
/* map.put("userId", icsCustomerStaff.getId());
|
||||
map.put("mobile", icsCustomerStaff.getMobile());
|
||||
if (icsCustomerStaff.getAvatar().contains(Constants.RESOURCE_PREFIX)) {
|
||||
map.put("avatar", siteUrl + icsCustomerStaff.getAvatar());
|
||||
} else {
|
||||
map.put("avatar", icsCustomerStaff.getAvatar());
|
||||
}
|
||||
map.put("username", icsCustomerStaff.getUsername());
|
||||
map.put("sex", icsCustomerStaff.getGender());
|
||||
map.put("dataType",icsCustomerStaff.getDataType());
|
||||
map.put("parkId",icsCustomerStaff.getParkId());
|
||||
map.put("cardType",icsCustomerStaff.getCardType());*/
|
||||
|
||||
return R.data(icsCustomerStaff);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前用户
|
||||
*/
|
||||
@RequiresPermissions("member:center:view")
|
||||
@PostMapping("/update")
|
||||
public R update(@RequestBody User user, @LoginUser User currentUser) {
|
||||
BeanUtils.copyBeanProp(currentUser, user);
|
||||
if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkMobileUnique(currentUser))) {
|
||||
public R update(@RequestBody IcsCustomerStaff icsCustomerStaff, @LoginUser IcsCustomerStaff currentUser) {
|
||||
BeanUtils.copyBeanProp(currentUser, icsCustomerStaff);
|
||||
if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(icsCustomerStaffService.checkMobileUnique(currentUser))) {
|
||||
return R.error("修改用户'" + currentUser.getUsername()+ "'失败,手机号码已存在");
|
||||
}
|
||||
currentUser.setUpdateBy(getLoginName());
|
||||
return toAjax(userService.updateUser(currentUser));
|
||||
return toAjax(icsCustomerStaffService.updateIcsCustomerStaff(currentUser));
|
||||
}
|
||||
}
|
||||
|
15
pom.xml
15
pom.xml
@ -166,6 +166,14 @@
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.26</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
@ -343,6 +351,13 @@
|
||||
<artifactId>poi-ooxml-schemas</artifactId>
|
||||
<version>${poi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.11.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user