jiangping
2024-07-26 a50adedd851b802b8855ed6ea47ea21a7257f00d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.doumee.api.web;
 
import cn.hutool.http.HttpRequest;
import com.amazonaws.util.Md5Utils;
import com.doumee.biz.system.SystemDataPermissionBiz;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.biz.zbom.ZbomCRMService;
import com.doumee.biz.zbom.ZbomZhongTaiService;
import com.doumee.config.annotation.LoginRequired;
import com.doumee.config.annotation.UserLoginRequired;
import com.doumee.core.annotation.pr.PreventRepeat;
import com.doumee.core.annotation.trace.Trace;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.ApiResponse;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.dao.business.model.News;
import com.doumee.dao.web.reqeust.GenerateQRCodeRequest;
import com.doumee.dao.web.response.DailyUpdatesResponse;
import com.doumee.dao.web.response.ZSZXCatalogResponse;
import com.doumee.service.business.GetZhongTaiDataService;
import com.doumee.service.business.NewsService;
import com.doumee.service.business.SmsEmailService;
import com.doumee.service.business.UsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.digest.Md5Crypt;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.tomcat.util.security.MD5Encoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
 
/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Rk
 * @create 2024/7/10 18:06
 */
@Api(tags = "【B端小程序】客户管理接口")
@Trace(exclude = true)
@RestController
@RequestMapping("/web/customer")
@Slf4j
public class CustomerManageApi extends ApiController{
 
    @Autowired
    public ZbomZhongTaiService zbomZhongTaiService;
 
    @Autowired
    public SmsEmailService smsEmailService;
 
    @Autowired
    public ZbomCRMService zbomCRMService;
 
    @Autowired
    public NewsService newsService;
 
    @Autowired
    public GetZhongTaiDataService getZhongTaiDataService;
 
    @Autowired
    public UsersService usersService;
 
    @Autowired
    public SystemDictDataBiz systemDictDataBiz;
 
 
    @UserLoginRequired
    @LoginRequired
    @ApiOperation(value = "【C端小程序】获取首页志说装修四个模块类目数据", notes = "获取首页志说装修四个模块类目数据,背景图暂时写死,参考UI")
    @PostMapping("/getZSZXCatalogs")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "用户token值", required = true)
    })
    public ApiResponse<ZSZXCatalogResponse> getZSZXCatalogs() {
        return  ApiResponse.success(getZhongTaiDataService.getZSZXCatalogs(getMemberId(),getUserType()));
    }
 
 
 
 
 
 
    @UserLoginRequired
    @ApiOperation(value = "【B端小程序】每日上新数据")
    @GetMapping("/getDailyUpdates")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "用户token值", required = true)
    })
    public ApiResponse<DailyUpdatesResponse> getDailyUpdates() {
        return  ApiResponse.success(newsService.getDailyUpdatesResponse());
    }
 
 
    @UserLoginRequired
    @ApiOperation("【B端小程序】 推广咨询分页")
    @PostMapping("/newsPage")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "用户token值", required = true),
    })
    public ApiResponse<PageData<News>> newsPage (@RequestBody PageWrap<News> pageWrap) {
        pageWrap.getModel().setIsPublish(Constants.ONE);
        return ApiResponse.success(newsService.findPage(pageWrap));
    }
 
    @UserLoginRequired
    @ApiOperation(value = "获取客户管理授权-列表跳转地址", notes = "获取客户管理授权跳转地址")
    @GetMapping("/getCrmAuthUrl")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "用户token值", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "type", value = "类型 0客户列表 1跳转新增意向客户", required = true)
    })
    public ApiResponse<String> getCrmAuthUrl(@RequestParam Integer type) {
        return  ApiResponse.success(zbomCRMService.getCrmGoUrl(this.getLoginUserInfo().getIamUsername(),type));
    }
 
    @PreventRepeat(lockTime = 2000)
    @ApiOperation(value = "生成小程序码", notes = "PAD端")
    @PostMapping("/getQrCode")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "sign", value = "签名(使用timestamp+appkey进行md5加密)", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Long", name = "timestamp", value = "时间戳(当前时间毫秒,2小时内有效)", required = true),
    })
    public void getQrCode(@RequestParam(value = "sign")String sign,
                          @RequestParam(value = "timestamp")Long timestamp,
                          @RequestBody GenerateQRCodeRequest generateQRCodeRequest,HttpServletResponse response) {
        if(StringUtils.isBlank(sign) || timestamp == null){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        String interfaceKey = systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_PAD_INTERFACE_KEY).getCode();
        //判断时间戳是否超过两小时
        if(System.currentTimeMillis()-timestamp > 2 * 60 * 3600 * 1000){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"token已失效!");
        }
        String token = DigestUtils.md5Hex(timestamp+interfaceKey);
        if(!token.equals(sign)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"token已失效!");
        }
        try{
            response.setHeader("Cache-Control", "no-store, no-cache");
            response.setContentType("image/jpeg");
            InputStream inputStream = usersService.getQrCode(generateQRCodeRequest);
            ImageIO.write(ImageIO.read(inputStream),"png",response.getOutputStream());
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}