| 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.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 com.matrix.system.shopXcx.api.WeChatApiTools; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| 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 | 
|   | 
|   | 
|     @Autowired | 
|     WeChatApiTools weChatApiTools; | 
|   | 
|     @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 + "") | 
|                     ,weChatApiTools.getAppid(shopInfo.getCompanyId()),weChatApiTools.getSecret(shopInfo.getCompanyId())); | 
|             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()))); | 
|     } | 
|   | 
|   | 
| } |