wuxw
2022-11-25 1b4d69a02aae3a8cc2a8b8f5bc50ae7571c11abd
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
package com.java110.acct.cmd.couponProperty;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.acct.coupon.ICouponAdapt;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.doc.annotation.*;
import com.java110.dto.couponPropertyUser.CouponPropertyUserDto;
import com.java110.dto.couponPropertyUser.CouponQrCodeDto;
import com.java110.intf.acct.ICouponPropertyUserV1InnerServiceSMO;
import com.java110.utils.exception.CmdException;
import com.java110.utils.factory.ApplicationContextFactory;
import com.java110.utils.util.Assert;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
 
import java.text.ParseException;
import java.util.List;
 
 
 
@Java110CmdDoc(title = "生成核销码",
        description = "供业主端生成优惠券核销码",
        httpMethod = "post",
        url = "http://{ip}:{port}/app/couponProperty.generatorCouponQrcode",
        resource = "acctDoc",
        author = "吴学文",
        serviceCode = "couponProperty.generatorCouponQrcode"
)
 
@Java110ParamsDoc(params = {
        @Java110ParamDoc(name = "couponId", length = 30, remark = "优惠券ID"),
})
 
@Java110ResponseDoc(
        params = {
                @Java110ParamDoc(name = "code", type = "int", length = 11, defaultValue = "0", remark = "返回编号,0 成功 其他失败"),
                @Java110ParamDoc(name = "msg", type = "String", length = 250, defaultValue = "成功", remark = "描述"),
                @Java110ParamDoc(name = "data", type = "Object", remark = "有效数据"),
                @Java110ParamDoc(parentNodeName = "data", name = "qrCode", type = "String", remark = "二维码信息"),
                @Java110ParamDoc(parentNodeName = "data", name = "remark", type = "String", remark = "优惠券核销说明"),
        }
)
 
@Java110ExampleDoc(
        reqBody = "{'couponId':'123123'}",
        resBody = "{'code':0,'msg':'成功','data':{'qrCode':'123123','remark':'nihao'}}"
)
 
@Java110Cmd(serviceCode = "couponProperty.generatorCouponQrcode")
public class GeneratorCouponQrcodeCmd extends Cmd {
 
    @Autowired
    private ICouponPropertyUserV1InnerServiceSMO couponPropertyUserV1InnerServiceSMOImpl;
 
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        Assert.hasKeyAndValue(reqJson, "couponId", "未包含优惠券ID");
 
    }
 
    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
 
        String userId = context.getReqHeaders().get("user-id");
 
        //校验优惠券是否存在
 
        CouponPropertyUserDto couponPropertyUserDto = new CouponPropertyUserDto();
        couponPropertyUserDto.setCouponId(reqJson.getString("couponId"));
        couponPropertyUserDto.setCouponUserId(userId);
        couponPropertyUserDto.setState(CouponPropertyUserDto.STATE_WAIT);
 
        List<CouponPropertyUserDto> couponPropertyUserDtos = couponPropertyUserV1InnerServiceSMOImpl.queryCouponPropertyUsers(couponPropertyUserDto);
 
        if (couponPropertyUserDtos == null || couponPropertyUserDtos.size() < 1) {
            throw new CmdException("优惠券不存在");
        }
 
        if (!"Y".equals(couponPropertyUserDtos.get(0).getIsExpire())) {
            throw new CmdException("优惠券已过期");
        }
 
 
        String toType = couponPropertyUserDtos.get(0).getToType();
 
        ICouponAdapt couponAdapt = ApplicationContextFactory.getBean(ICouponAdapt.COUPON_PRE+toType,ICouponAdapt.class);
 
        if(couponAdapt == null){
            throw new CmdException("优惠券不支持生成二维码");
        }
 
        CouponQrCodeDto couponQrCodeDto = couponAdapt.generatorQrcode(couponPropertyUserDtos.get(0));
 
        context.setResponseEntity(ResultVo.createResponseEntity(couponQrCodeDto));
    }
}