xuhy
7 天以前 52ecada52074ace2252ff6c94738244402f8902b
诊所列表接口
5个文件已修改
304 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmClinicController.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/WxLoginController.java 208 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-applet/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/query/TCrmClinicQuery.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/resources/mapper/system/TCrmClinicMapper.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmClinicController.java
@@ -8,6 +8,7 @@
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TCrmClinicAuditDTO;
import com.ruoyi.system.dto.TCrmClinicDTO;
import com.ruoyi.system.model.*;
@@ -46,8 +47,9 @@
    private final TCrmSalespersonService crmSalespersonService;
    private final ISysUserService sysUserService;
    private final TCrmDeviceService crmDeviceService;
    private final TokenService tokenService;
    @Autowired
    public TCrmClinicController(TCrmClinicService crmClinicService, TCrmSupplierService crmSupplierService, TCrmBranchService crmBranchService, TCrmWarehouseService crmWarehouseService, TCrmSalespersonService crmSalespersonService, ISysUserService sysUserService, TCrmDeviceService crmDeviceService) {
    public TCrmClinicController(TCrmClinicService crmClinicService, TCrmSupplierService crmSupplierService, TCrmBranchService crmBranchService, TCrmWarehouseService crmWarehouseService, TCrmSalespersonService crmSalespersonService, ISysUserService sysUserService, TCrmDeviceService crmDeviceService, TokenService tokenService) {
        this.crmClinicService = crmClinicService;
        this.crmSupplierService = crmSupplierService;
        this.crmBranchService = crmBranchService;
@@ -55,6 +57,7 @@
        this.crmSalespersonService = crmSalespersonService;
        this.sysUserService = sysUserService;
        this.crmDeviceService = crmDeviceService;
        this.tokenService = tokenService;
    }
    /**
@@ -63,6 +66,12 @@
    @ApiOperation(value = "获取crm诊所管理分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TCrmClinicVO>> pageList(@RequestBody TCrmClinicQuery query) {
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        Long userId = tokenService.getLoginUser().getUserId();
        if(roleType == 2 || roleType == 3){
            query.setUserId(userId);
            query.setRoleType(roleType);
        }
        return R.ok(crmClinicService.pageList(query));
    }
ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/WxLoginController.java
@@ -63,74 +63,74 @@
    private TokenService tokenService;
    @Autowired
    private SysLoginService loginService;
    /**
     * 账号密码登录
     *
     * @param loginBody 登录信息
     * @return 结果
     */
    @ApiOperation(value = "账号密码登录",notes = "管理员账号密码登录")
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody loginBody)
    {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        LoginUser loginUser = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
                loginBody.getUuid());
        ajax.put(Constants.TOKEN, tokenService.createToken(loginUser));
        List<SysRole> roles = loginUser.getUser().getRoles();
        if(CollectionUtils.isEmpty(roles)){
            return AjaxResult.error("请关联角色!");
        }
        if(roles.get(0).getStatus() == 1){
            return AjaxResult.error("该账号角色已被禁用!");
        }
        return ajax;
    }
    @ApiOperation(value = "通过code获得openid,获取用户信息",tags = {"微信小程序登录"})
    @PostMapping("/openIdByJsCode")
    public R<Map<String, Object>> openIdByJsCode(@RequestBody AppletUserEncrypteData data) {
        log.info("<<<<<<<<换取openid开始<<<<<<<<:{}", data.getCode());
        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig, redisService);
        Code2SessionRespBody body = appletTools.getOpenIdByJscode2session(new Code2SessionResqBody().build(data.getCode()));
        String openid = body.getOpenid();
        String sessionKey = body.getSessionKey();
        // 用户信息解密 数据验签
//        if (StringUtils.isNotBlank(data.getSignature())) {
//            WxUtils.verifySignature(data.getRawData(), sessionKey, data.getSignature());
//    /**
//     * 账号密码登录
//     *
//     * @param loginBody 登录信息
//     * @return 结果
//     */
//    @ApiOperation(value = "账号密码登录",notes = "管理员账号密码登录")
//    @PostMapping("/login")
//    public AjaxResult login(@RequestBody LoginBody loginBody)
//    {
//        AjaxResult ajax = AjaxResult.success();
//        // 生成令牌
//        LoginUser loginUser = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
//                loginBody.getUuid());
//        ajax.put(Constants.TOKEN, tokenService.createToken(loginUser));
//        List<SysRole> roles = loginUser.getUser().getRoles();
//        if(CollectionUtils.isEmpty(roles)){
//            return AjaxResult.error("请关联角色!");
//        }
        if(StringUtils.isEmpty(data.getEncryptedData()) || StringUtils.isEmpty(data.getIv())){
            return R.fail("已拒绝授权");
        }
        AppletUserDecodeData appletUserDecodeData = WxUtils.encryptedData(data.getEncryptedData(), sessionKey,  data.getIv());
        appletUserDecodeData.setOpenId(openid);
        // 先使用openId和当前手机号进行查询
        TSysAppUser sysAppUser = sysAppUserService.getOne(Wrappers.lambdaQuery(TSysAppUser.class)
                .and(e->e.eq(TSysAppUser::getOpenId, appletUserDecodeData.getOpenId()).or()
                .eq(TSysAppUser::getPhone, appletUserDecodeData.getPhoneNumber())));
        if (sysAppUser==null){
//            appUser.setTenantAttributes();
//            appUser.setTenantType();
            sysAppUser = new TSysAppUser();
            sysAppUser.setPhone(appletUserDecodeData.getPhoneNumber());
//            sysAppUser.setAccount(appletUserDecodeData.getPhoneNumber());
//            sysAppUser.setPassword(SecurityUtils.encryptPassword(appletUserDecodeData.getPhoneNumber().substring(5)));
            sysAppUser.setOpenId(appletUserDecodeData.getOpenId());
            // 手机号中间四位替换为*
            sysAppUser.setNickName(appletUserDecodeData.getPhoneNumber().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));
            sysAppUserService.save(sysAppUser);
        }
        LoginUserApplet loginUserApplet = new LoginUserApplet();
        TSysUserResp sysUserResp = new TSysUserResp();
        BeanUtils.copyProperties(sysAppUser, sysUserResp);
        loginUserApplet.setUser(sysUserResp);
        loginUserApplet.setUserId(sysAppUser.getId());
        Map<String, Object> tokenInfos = new HashMap<>();
        tokenInfos.put("token",tokenService.createTokenApplet(loginUserApplet));
        tokenInfos.put("info",loginUserApplet);
        return R.ok(tokenInfos);
    }
//        if(roles.get(0).getStatus() == 1){
//            return AjaxResult.error("该账号角色已被禁用!");
//        }
//        return ajax;
//    }
//
//    @ApiOperation(value = "通过code获得openid,获取用户信息",tags = {"微信小程序登录"})
//    @PostMapping("/openIdByJsCode")
//    public R<Map<String, Object>> openIdByJsCode(@RequestBody AppletUserEncrypteData data) {
//        log.info("<<<<<<<<换取openid开始<<<<<<<<:{}", data.getCode());
//        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig, redisService);
//        Code2SessionRespBody body = appletTools.getOpenIdByJscode2session(new Code2SessionResqBody().build(data.getCode()));
//        String openid = body.getOpenid();
//        String sessionKey = body.getSessionKey();
//        // 用户信息解密 数据验签
////        if (StringUtils.isNotBlank(data.getSignature())) {
////            WxUtils.verifySignature(data.getRawData(), sessionKey, data.getSignature());
////        }
//        if(StringUtils.isEmpty(data.getEncryptedData()) || StringUtils.isEmpty(data.getIv())){
//            return R.fail("已拒绝授权");
//        }
//        AppletUserDecodeData appletUserDecodeData = WxUtils.encryptedData(data.getEncryptedData(), sessionKey,  data.getIv());
//        appletUserDecodeData.setOpenId(openid);
//        // 先使用openId和当前手机号进行查询
//        TSysAppUser sysAppUser = sysAppUserService.getOne(Wrappers.lambdaQuery(TSysAppUser.class)
//                .and(e->e.eq(TSysAppUser::getOpenId, appletUserDecodeData.getOpenId()).or()
//                .eq(TSysAppUser::getPhone, appletUserDecodeData.getPhoneNumber())));
//        if (sysAppUser==null){
////            appUser.setTenantAttributes();
////            appUser.setTenantType();
//            sysAppUser = new TSysAppUser();
//            sysAppUser.setPhone(appletUserDecodeData.getPhoneNumber());
////            sysAppUser.setAccount(appletUserDecodeData.getPhoneNumber());
////            sysAppUser.setPassword(SecurityUtils.encryptPassword(appletUserDecodeData.getPhoneNumber().substring(5)));
//            sysAppUser.setOpenId(appletUserDecodeData.getOpenId());
//            // 手机号中间四位替换为*
//            sysAppUser.setNickName(appletUserDecodeData.getPhoneNumber().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));
//            sysAppUserService.save(sysAppUser);
//        }
//        LoginUserApplet loginUserApplet = new LoginUserApplet();
//        TSysUserResp sysUserResp = new TSysUserResp();
//        BeanUtils.copyProperties(sysAppUser, sysUserResp);
//        loginUserApplet.setUser(sysUserResp);
//        loginUserApplet.setUserId(sysAppUser.getId());
//        Map<String, Object> tokenInfos = new HashMap<>();
//        tokenInfos.put("token",tokenService.createTokenApplet(loginUserApplet));
//        tokenInfos.put("info",loginUserApplet);
//        return R.ok(tokenInfos);
//    }
    
    
@@ -204,41 +204,41 @@
    }
    
    
    /**
     * 敏感词检测
     * @param content
     * @param openid
     * @return
     */
    @PostMapping("/sensitiveWordDetection")
    public R<Boolean> sensitiveWordDetection (@RequestParam("content") String content, @RequestParam("openid") String openid){
        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig, redisService);
        String accessToken = appletTools.getAccessToken("");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("content", content);
        jsonObject.put("version", 2);
        jsonObject.put("scene", 2);
        jsonObject.put("openid", openid);
        String post = HttpUtils.post("https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + accessToken, jsonObject.toString());
        JSONObject object = JSONObject.parseObject(post);
        Integer errcode = object.getInteger("errcode");
        if(0 != errcode){
            throw new RuntimeException(object.getString("errmsg"));
        }
        JSONArray detail = object.getJSONArray("detail");
        for (int i = 0; i < detail.size(); i++) {
            JSONObject jsonObject1 = detail.getJSONObject(i);
            Integer errcode1 = jsonObject1.getInteger("errcode");
            if(0 == errcode1){
                String suggest = jsonObject1.getString("suggest");
                Integer label = jsonObject1.getInteger("label");
                String keyword = jsonObject1.getString("keyword");
                Integer prob = jsonObject1.getInteger("prob");
                if(("risky".equals(suggest) || "review".equals(suggest)) && 100 != label && com.ruoyi.common.utils.StringUtils.isNotEmpty(keyword) && 80 <= prob){
                    return R.ok(true);
                }
            }
        }
        return R.ok(false);
    }
//    /**
//     * 敏感词检测
//     * @param content
//     * @param openid
//     * @return
//     */
//    @PostMapping("/sensitiveWordDetection")
//    public R<Boolean> sensitiveWordDetection (@RequestParam("content") String content, @RequestParam("openid") String openid){
//        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig, redisService);
//        String accessToken = appletTools.getAccessToken("");
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("content", content);
//        jsonObject.put("version", 2);
//        jsonObject.put("scene", 2);
//        jsonObject.put("openid", openid);
//        String post = HttpUtils.post("https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + accessToken, jsonObject.toString());
//        JSONObject object = JSONObject.parseObject(post);
//        Integer errcode = object.getInteger("errcode");
//        if(0 != errcode){
//            throw new RuntimeException(object.getString("errmsg"));
//        }
//        JSONArray detail = object.getJSONArray("detail");
//        for (int i = 0; i < detail.size(); i++) {
//            JSONObject jsonObject1 = detail.getJSONObject(i);
//            Integer errcode1 = jsonObject1.getInteger("errcode");
//            if(0 == errcode1){
//                String suggest = jsonObject1.getString("suggest");
//                Integer label = jsonObject1.getInteger("label");
//                String keyword = jsonObject1.getString("keyword");
//                Integer prob = jsonObject1.getInteger("prob");
//                if(("risky".equals(suggest) || "review".equals(suggest)) && 100 != label && com.ruoyi.common.utils.StringUtils.isNotEmpty(keyword) && 80 <= prob){
//                    return R.ok(true);
//                }
//            }
//        }
//        return R.ok(false);
//    }
}
ruoyi-applet/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java
@@ -1,17 +1,34 @@
package com.ruoyi.web.controller.system;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.TSysUserResp;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.domain.model.LoginUserApplet;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.model.TSysAppUser;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.TSysAppUserService;
import com.ruoyi.system.utils.wx.body.resp.Code2SessionRespBody;
import com.ruoyi.system.utils.wx.body.resq.Code2SessionResqBody;
import com.ruoyi.system.utils.wx.model.WeixinProperties;
import com.ruoyi.system.utils.wx.pojo.AppletUserDecodeData;
import com.ruoyi.system.utils.wx.pojo.AppletUserEncrypteData;
import com.ruoyi.system.utils.wx.tools.WxAppletTools;
import com.ruoyi.system.utils.wx.tools.WxUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -25,12 +42,16 @@
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.framework.web.service.SysPermissionService;
import com.ruoyi.system.service.ISysMenuService;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
/**
 * 登录验证
 * 
 * @author ruoyi
 */
@Slf4j
@Api(tags = "登录")
@RestController
public class SysLoginController
@@ -49,7 +70,14 @@
    private TokenService tokenService;
    @Autowired
    private ISysRoleService roleService;
    @Autowired
    private WeixinProperties wxConfig;
    @Autowired
    private RestTemplate wxRestTemplate;
    @Resource
    private RedisService redisService;
    @Resource
    private TSysAppUserService sysAppUserService;
    /**
     * 账号密码登录
     * 
@@ -81,6 +109,50 @@
        return ajax;
    }
    @ApiOperation(value = "通过code获得openid,获取用户信息",tags = {"微信小程序登录"})
    @PostMapping("/openIdByJsCode")
    public R<Map<String, Object>> openIdByJsCode(@RequestBody AppletUserEncrypteData data) {
        log.info("<<<<<<<<换取openid开始<<<<<<<<:{}", data.getCode());
        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig, redisService);
        Code2SessionRespBody body = appletTools.getOpenIdByJscode2session(new Code2SessionResqBody().build(data.getCode()));
        String openid = body.getOpenid();
        String sessionKey = body.getSessionKey();
        // 用户信息解密 数据验签
//        if (StringUtils.isNotBlank(data.getSignature())) {
//            WxUtils.verifySignature(data.getRawData(), sessionKey, data.getSignature());
//        }
        if(StringUtils.isEmpty(data.getEncryptedData()) || StringUtils.isEmpty(data.getIv())){
            return R.fail("已拒绝授权");
        }
        AppletUserDecodeData appletUserDecodeData = WxUtils.encryptedData(data.getEncryptedData(), sessionKey,  data.getIv());
        appletUserDecodeData.setOpenId(openid);
        // 先使用openId和当前手机号进行查询
        TSysAppUser sysAppUser = sysAppUserService.getOne(Wrappers.lambdaQuery(TSysAppUser.class)
                .and(e->e.eq(TSysAppUser::getOpenId, appletUserDecodeData.getOpenId()).or()
                        .eq(TSysAppUser::getPhone, appletUserDecodeData.getPhoneNumber())));
        if (sysAppUser==null){
//            appUser.setTenantAttributes();
//            appUser.setTenantType();
            sysAppUser = new TSysAppUser();
            sysAppUser.setPhone(appletUserDecodeData.getPhoneNumber());
//            sysAppUser.setAccount(appletUserDecodeData.getPhoneNumber());
//            sysAppUser.setPassword(SecurityUtils.encryptPassword(appletUserDecodeData.getPhoneNumber().substring(5)));
            sysAppUser.setOpenId(appletUserDecodeData.getOpenId());
            // 手机号中间四位替换为*
            sysAppUser.setNickName(appletUserDecodeData.getPhoneNumber().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));
            sysAppUserService.save(sysAppUser);
        }
        LoginUserApplet loginUserApplet = new LoginUserApplet();
        TSysUserResp sysUserResp = new TSysUserResp();
        BeanUtils.copyProperties(sysAppUser, sysUserResp);
        loginUserApplet.setUser(sysUserResp);
        loginUserApplet.setUserId(sysAppUser.getId());
        Map<String, Object> tokenInfos = new HashMap<>();
        tokenInfos.put("token",tokenService.createTokenApplet(loginUserApplet));
        tokenInfos.put("info",loginUserApplet);
        return R.ok(tokenInfos);
    }
    /**
     * 账号密码登录
     *
ruoyi-system/src/main/java/com/ruoyi/system/query/TCrmClinicQuery.java
@@ -30,4 +30,9 @@
    @ApiModelProperty(value = "状态 1=待审核 2=已拒绝 3=使用中 4=冻结")
    private Integer status;
    @ApiModelProperty(value = "前端忽略")
    private Long userId;
    @ApiModelProperty(value = "前端忽略")
    private Integer roleType;
}
ruoyi-system/src/main/resources/mapper/system/TCrmClinicMapper.xml
@@ -61,6 +61,12 @@
            <if test="query.status != null">
                and tcc.status = #{query.status}
            </if>
            <if test="query.userId != null and query.userId == 2">
                and tcc.branch_id = #{query.userId}
            </if>
            <if test="query.userId != null and query.userId == 3">
                and tcc.salesperson_id = #{query.userId}
            </if>
            AND tcc.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        ORDER BY tcc.create_time DESC