Commit c0cb71fe by HlQ

[add]

1.用户表添加状态字段,用于判断用户是否可以登录平台
2.添加微信公众号提交工单,自动绑定 openid 功能
3.添加预工单编辑接口
1 parent 2efd82d5
......@@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.dto.BaseDTO;
import vion.model.Account;
import vion.service.IAccountService;
......@@ -18,9 +19,8 @@ public class AccountController {
private final IAccountService accountService;
@GetMapping("/accounts")
public Page<Account> getAccountList(@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
return accountService.page(Page.of(pageNum, pageSize));
public Page<Account> getAccountList(BaseDTO dto) {
return accountService.page(Page.of(dto.getPageNum(), dto.getPageSize()));
}
@GetMapping("/account")
......
......@@ -85,4 +85,4 @@ public class ServiceOrderController {
public String sendOrder(Long id) {
return serviceOrderService.sendOrder(id);
}
}
}
\ No newline at end of file
package vion.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.ding.WechatMod;
import vion.dto.TaskTempDTO;
import vion.model.TaskTemp;
import vion.service.ITaskTempService;
import vion.vo.TaskTempVO;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* 预工单
*/
@RestController
@RequestMapping(Global.BASE_URL)
@RequiredArgsConstructor
......@@ -19,6 +25,8 @@ import vion.vo.TaskTempVO;
public class TaskTempController {
private final ITaskTempService taskTempService;
private final WechatMod wechatMod;
private final Converter converter;
@GetMapping("/taskTemps")
public Page<TaskTempVO> getTaskTempList(TaskTempDTO data) {
......@@ -31,8 +39,25 @@ public class TaskTempController {
}
@PostMapping("/taskTemp")
public String saveOrUpdateTaskTemp(TaskTempDTO data) {
public Object saveOrUpdateTaskTemp(TaskTempDTO data) {
return taskTempService.saveOrUpdTaskTemp(data);
}
}
@GetMapping("/taskTemp/wechatCallback")
public Object wechatCallback(String code, HttpServletResponse res) throws IOException {
Object obj = wechatMod.wechatCallback(code);
if (obj instanceof String) {
res.sendRedirect("https://yunwei.vionyun.com:8443/wap/?openid=" + obj);
} else {
return obj;
}
return "success";
}
@PostMapping("/taskTemp/{id}")
public String upd(@PathVariable(name = "id") Long id, TaskTempDTO data) {
TaskTemp taskTemp = converter.convert(data, new TaskTemp());
taskTemp.setId(id);
return taskTempService.updateById(taskTemp) ? "更新成功" : "更新失败";
}
}
\ No newline at end of file
......@@ -225,7 +225,10 @@ public class DingMod {
return useridObj;
}
String userid = useridObj.getJSONObject("result").getStr("userid");
User user = userService.lambdaQuery().select(User::getId, User::getUserid, User::getUsername, User::getPhone).eq(User::getUserid, userid).one();
User user = userService.lambdaQuery().select(User::getId, User::getUserid, User::getUsername, User::getPhone, User::getStatus).eq(User::getUserid, userid).one();
if (user.getStatus() == 1) {
return "该用户禁止登录系统,请联系管理员!";
}
user.setToken(accessToken);
Global.USERNAME_MAP.put(accessToken, user);
return user;
......@@ -277,11 +280,8 @@ public class DingMod {
HMac hMac = SecureUtil.hmacSha256(appSecret);
byte[] signBytes = hMac.digest(timestamp);
String sign = Base64.encode(signBytes);
String encode = null;
encode = URLEncoder.encode(sign, "UTF-8");
String encode = URLEncoder.encode(sign, "UTF-8");
String encodeSign = encode.replace("+", "%20").replace("*", "%2A").replace("~", "%7E").replace("/", "%2F").replace("=", "%3D");
return StrUtil.format("https://oapi.dingtalk.com/sns/getuserinfo_bycode?accessKey=dingkrzwks0jpi2di3uo&timestamp={}&signature={}", timestamp, encodeSign);
} catch (UnsupportedEncodingException e) {
log.error("通过appSecret计算出来的签名值失败", e);
......
......@@ -29,7 +29,7 @@ public class WechatMod {
/**
* 微信扫码获取用户 openid
*
* @param code
* @param code 授权码
* @return java.lang.Object
*/
public Object wechatCallback(String code) {
......@@ -45,10 +45,11 @@ public class WechatMod {
/**
* 生成微信网页授权链接
*
* @param taskTempId 预工单 id
* @return java.lang.String
*/
public String genCodeUrl(Long taskTempId) {
public String genQRCodeUrl(Long taskTempId) {
String url = StrUtil.format("https://yunwei.vionyun.com/yunwei/api/wechat/callback?taskTempId={}", taskTempId);
return wxMpService.getOAuth2Service().buildAuthorizationUrl(url, WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
}
......@@ -69,4 +70,4 @@ public class WechatMod {
}
return "微信公众号消息推送失败";
}
}
}
\ No newline at end of file
......@@ -5,10 +5,8 @@ import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.multipart.MultipartFile;
import vion.model.FileInfo;
import java.util.Date;
import java.util.List;
@Getter
@Setter
......@@ -29,9 +27,9 @@ public class TaskTempDTO extends BaseDTO {
private String repairPhone;
/** 状态(1待确认、2已确认) */
private Integer status;
/** 附件信息 */
private List<FileInfo> fileList;
private String remark;
private String openid;
private MultipartFile[] files;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
......
......@@ -16,7 +16,8 @@ public class InterceptorConfig implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(interceptor)
.addPathPatterns("/api/**")
.excludePathPatterns("/api/taskTemp", "/api/upLoadFile", "/api/ding/callback/**", "/api/wechat/**", "/error")
.excludePathPatterns("/api/order/sign/*");
.excludePathPatterns("/api/upLoadFile", "/api/ding/callback/**", "/api/wechat/**", "/error")
.excludePathPatterns("/api/order/sign/*")
.excludePathPatterns("/api/taskTemp", "/api/taskTemp/wechatCallback");
}
}
......@@ -33,6 +33,9 @@ public class User {
/** 员工状态 2:试用期 3:正式 5:待离职 -1:无状态 */
private Integer employeeStatus;
/* 状态 0:正常 1:禁用 */
private Integer status;
@TableField(exist = false)
private String token;
}
\ No newline at end of file
......@@ -11,5 +11,5 @@ public interface ITaskTempService extends IService<TaskTemp> {
Page<TaskTempVO> getTaskTempList(TaskTempDTO data);
TaskTempVO getTaskTempById(Long id);
String saveOrUpdTaskTemp(TaskTempDTO data);
Object saveOrUpdTaskTemp(TaskTempDTO data);
}
......@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONArray;
......@@ -187,7 +188,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
String pushRes = dingMod.sendMessage(msg);
// todo 异步微信公众号消息推送
if (task.getStatus() != 5) {
if (task.getStatus() == 3) {
Opt.ofNullable(existTask.getTaskTempId())
.map(taskTempId -> taskTempService.getById(taskTempId).getOpenid())
.ifPresent(openid -> {
......@@ -199,7 +200,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
.build();
List<WxMpTemplateData> wxMpTemplateDataList = ListUtil.of(
new WxMpTemplateData("character_string1", existTask.getUuid()),
new WxMpTemplateData("thing7", user.getUsername() + "(" + user.getPhone() + ")"),
new WxMpTemplateData("thing7", DesensitizedUtil.chineseName(user.getUsername())),
new WxMpTemplateData("time4", DateUtil.formatDateTime(new Date())),
new WxMpTemplateData("const3", statusMap.get(existTask.getStatus())));
String sentMsg = wechatMod.sendMsg("ueJlVya7uOfYhFlIv28pC0kiHPe1b6Q-gkWsYKkoRWo", openid, wxMpTemplateDataList, null);
......
......@@ -4,6 +4,7 @@ import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
......@@ -70,7 +71,7 @@ public class TaskTempServiceImpl extends ServiceImpl<TaskTempMapper, TaskTemp> i
}
@Override
public String saveOrUpdTaskTemp(TaskTempDTO data) {
public Object saveOrUpdTaskTemp(TaskTempDTO data) {
TaskTemp taskTemp = converter.convert(data, TaskTemp.class);
this.save(taskTemp);
......@@ -107,7 +108,11 @@ public class TaskTempServiceImpl extends ServiceImpl<TaskTempMapper, TaskTemp> i
String userids = userList.stream().map(User::getUserid).collect(Collectors.joining(","));
dingMod.sendMessage(buildMsg(userids, taskTemp));
return wechatMod.genCodeUrl(taskTemp.getId());
if (StrUtil.isNotBlank(data.getOpenid())) {
return "工单提交成功!";
} else {
return wechatMod.genQRCodeUrl(taskTemp.getId());
}
}
JSONObject buildMsg(String userid, TaskTemp taskTemp) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!