1
935090232@qq.com
2020-12-01 611146e69aaa62296cf84f2ccb5aca5ebba17677
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
161
package com.matrix.system.hiveErp.action;
 
import com.matrix.component.tools.WxacodeUtil;
import com.matrix.core.anotations.RemoveRequestToken;
import com.matrix.core.anotations.SaveRequestToken;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.LogUtil;
import com.matrix.core.tools.MD5Util;
import com.matrix.core.tools.PropertiesUtil;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.constance.AppConstance;
import com.matrix.system.constance.Dictionary;
import com.matrix.system.constance.SystemConstance;
import com.matrix.system.hive.action.BaseController;
import com.matrix.system.hive.action.util.QueryUtil;
import com.matrix.system.hive.bean.SysShopInfo;
import com.matrix.system.hive.service.SysShopInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
 
/**
 * @Author wzy
 * @Date 2020/3/8
 * @email wangdoubleone@gmail.com
 * @Version V1.0
 **/
@Controller
@RequestMapping("hiveErp/shopInfo")
public class ErpShopInfoController extends BaseController {
    @Resource
    private SysShopInfoService shopInfoService; // 店铺Service
 
 
    @RequestMapping(value = "/showList")
    @ResponseBody
    public AjaxResult showList(SysShopInfo shopInfo, PaginationVO pageVo) {
        QueryUtil.setQueryLimitCom(shopInfo);
        List<SysShopInfo> dataList = shopInfoService.findInPage(shopInfo, pageVo);
        return AjaxResult.buildSuccessInstance(dataList, shopInfoService.findTotal(shopInfo));
 
    }
 
 
    @RequestMapping(value = "/addOrModify")
    @RemoveRequestToken
    public @ResponseBody
    AjaxResult addOrModify(SysShopInfo shopInfo) {
        if (shopInfo.getId() != null) {
 
            return modify(shopInfoService, shopInfo, "门店");
        } else {
 
            return add(shopInfoService, shopInfo, "门店");
        }
    }
 
    @RequestMapping(value = "/del")
    public @ResponseBody
    AjaxResult del(String keys) {
 
        return remove(shopInfoService, keys);
    }
 
    @RequestMapping(value = "/editForm")
    @SaveRequestToken
    public String editForm(Long id, HttpServletRequest request) {
        SysShopInfo shopInfo;
        if (id != null) {
            shopInfo = shopInfoService.findById(id);
            request.setAttribute("obj", shopInfo);
        }
        //src/main/resources/templates/views/admin/hive-erp/shop/shopInfo-list.html
        return "admin/hive-erp/shop/shopInfo-form";
    }
 
    /**
     * 生成门店二维码
     */
    @Transactional(rollbackFor = Exception.class)
    @RequestMapping(value = "/getProductShareQrcode/{shopId}")
    public @ResponseBody
    AjaxResult creteSohopQrcode(@PathVariable("shopId") Long shopId) {
        SysShopInfo shopInfo = shopInfoService.findById(shopId);
        try {
            String qrcodeSavePath = WxacodeUtil.getWxacode(shopId + "", "pages/index/index", MD5Util.strToMD5(shopId + ""));
            LogUtil.debug("qrcodeSavePath={}", qrcodeSavePath);
            // 图片保存目录路径
            String baseSavePath = PropertiesUtil.getString(AppConstance.FILES_TORAGE_PATH);
            // 图片访问URL
            String baseSaveUrl = PropertiesUtil.getString(AppConstance.NGINX_URL);
            String qrcodeImgUrl = qrcodeSavePath.replace(baseSavePath, baseSaveUrl);
            shopInfo.setQrcode(qrcodeImgUrl);
            shopInfoService.modify(shopInfo);
            return AjaxResult.buildSuccessInstance(Arrays.asList(shopInfo));
        } catch (Exception e) {
            LogUtil.error("门店生成二维码错误:{}", e, "");
        }
        return new AjaxResult(AjaxResult.STATUS_FAIL, null);
    }
 
 
    /**
     * =======================================================
     * *******************公共的数据访问方法********************
     * =======================================================
     */
 
    /**
     * 根据角色不一样显示不同的数据 如果角色是店长则只能查出自己的店铺 如果是管理员则显示所有店铺
     *
     * @author 姜友瑶 2016-7-22
     */
    @RequestMapping(value = "/findShopByRole")
    public @ResponseBody
    AjaxResult findShopByRole(SysShopInfo shopInfo) {
        SysUsers user = getMe();
        shopInfo.setCompanyId(user.getCompanyId());
        if(!user.getSuUserType().equals(AppConstance.USER_TYPE_ADMIN) && !user.getShopRole().equals(Dictionary.FLAG_YES_Y)){
            shopInfo.setId(user.getShopId());
        }
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, shopInfoService.findByModel(shopInfo), null);
    }
 
 
 
    /**
     * 查询非总店
     *
     * @author jiangyouyao
     */
    @RequestMapping(value = "/findShops")
    public @ResponseBody
    AjaxResult findShops(SysShopInfo shopInfo) {
 
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, shopInfoService.findShopInfos(getMe().getCompanyId()), null);
    }
 
 
    /**
     * 查询当前登录人所在门店
     *
     * @author jiangyouyao
     */
    @RequestMapping(value = "/findMyShop")
    public @ResponseBody
    AjaxResult findMyShop() {
        SysUsers user = getMe();
        return AjaxResult.buildSuccessInstance(Arrays.asList(shopInfoService.findById(user.getShopId())));
    }
 
 
}