java110
2022-10-11 6a360ee796b8ee8b2b8ed6059b16b759d7be8e18
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
package com.java110.store.cmd.store;
 
import com.alibaba.fastjson.JSONObject;
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.parkingCouponShop.ParkingCouponShopDto;
import com.java110.dto.shopCommunity.ShopCommunityDto;
import com.java110.dto.storeShopCommunity.StoreShopCommunityDto;
import com.java110.intf.acct.IParkingCouponShopV1InnerServiceSMO;
import com.java110.intf.mall.IShopCommunityInnerServiceSMO;
import com.java110.intf.store.IStoreShopCommunityV1InnerServiceSMO;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
 
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
 
 
@Java110CmdDoc(title = "查询周围店铺",
        description = "根据小区ID查询周围店铺,设计此接口主要 用于停车卷 商家购买 停车卷时 查询小区周边 商铺,比如 饭店等",
        httpMethod = "get",
        url = "http://{ip}:{port}/app/store.listCommunityStoreShop",
        resource = "storeDoc",
        author = "吴学文",
        serviceCode = "store.listCommunityStoreShop"
)
 
@Java110ParamsDoc(params = {
        @Java110ParamDoc(name = "communityId", 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 = "描述"),
        }
)
 
@Java110ExampleDoc(
        reqBody = "http://{ip}:{port}/app/store.listCommunityStoreShop?communityId=123123&page=1&row=10",
        resBody = "{'code':0,'msg':'成功'}"
)
 
@Java110Cmd(serviceCode = "store.listCommunityStoreShop")
public class ListCommunityStoreShopCmd extends Cmd {
 
    @Autowired(required = false)
    private IShopCommunityInnerServiceSMO shopCommunityInnerServiceSMOImpl;
 
    @Autowired
    private IStoreShopCommunityV1InnerServiceSMO storeShopCommunityV1InnerServiceSMOImpl;
 
    @Autowired
    private IParkingCouponShopV1InnerServiceSMO parkingCouponShopV1InnerServiceSMOImpl;
 
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        super.validatePageInfo(reqJson);
        Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区ID");
 
    }
 
    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
 
        StoreShopCommunityDto storeShopCommunityDto = BeanConvertUtil.covertBean(reqJson, StoreShopCommunityDto.class);
        List<ShopCommunityDto> storeShopCommunityDtos = null;
        int count = 0;
        if ("ON".equals(MappingCache.getValue("HAS_HC_MALL"))) {
            count = shopCommunityInnerServiceSMOImpl.queryShopCommunitysCount(storeShopCommunityDto);
            if (count > 0) {
                storeShopCommunityDtos = shopCommunityInnerServiceSMOImpl.queryShopCommunitys(storeShopCommunityDto);
            } else {
                storeShopCommunityDtos = new ArrayList<>();
            }
        } else {
            count = storeShopCommunityV1InnerServiceSMOImpl.queryStoreShopCommunitysCount(storeShopCommunityDto);
            if (count > 0) {
                storeShopCommunityDtos = storeShopCommunityV1InnerServiceSMOImpl.queryStoreShopCommunitys(storeShopCommunityDto);
            } else {
                storeShopCommunityDtos = new ArrayList<>();
            }
        }
 
 
        freshParkingCoupon(storeShopCommunityDtos);
 
 
        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) reqJson.getInteger("row")), count, storeShopCommunityDtos);
 
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
 
        context.setResponseEntity(responseEntity);
 
    }
 
    private void freshParkingCoupon(List<ShopCommunityDto> storeShopCommunityDtos) {
        /**
         * 刷入停车卷数
         */
        if (storeShopCommunityDtos == null || storeShopCommunityDtos.size() < 1) {
            return;
        }
 
        if (storeShopCommunityDtos.size() > 20) {
            return;
        }
 
        List<String> shopIds = new ArrayList<>();
 
        for (ShopCommunityDto shopCommunityDto : storeShopCommunityDtos) {
            shopIds.add(shopCommunityDto.getShopId());
        }
 
        ParkingCouponShopDto parkingCouponShopDto = new ParkingCouponShopDto();
        parkingCouponShopDto.setShopIds(shopIds.toArray(new String[shopIds.size()]));
        List<ParkingCouponShopDto> parkingCouponShopDtos = parkingCouponShopV1InnerServiceSMOImpl.queryParkingCouponShopStatistics(parkingCouponShopDto);
 
        for (ShopCommunityDto shopCommunityDto : storeShopCommunityDtos) {
            for (ParkingCouponShopDto parkingCouponShopDto1 : parkingCouponShopDtos) {
                if (!parkingCouponShopDto1.getShopId().equals(shopCommunityDto.getShopId())) {
                    continue;
                }
 
                shopCommunityDto.setParkingCouponCount(parkingCouponShopDto1.getQuantity());
            }
        }
    }
}