PosStoreController.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. package com.ruoyi.app.mendian;
  2. import cn.hutool.json.JSONObject;
  3. import cn.hutool.json.JSONUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  7. import com.baomidou.mybatisplus.core.metadata.IPage;
  8. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  9. import com.ruoyi.app.order.dto.OrderCreatItem;
  10. import com.ruoyi.app.order.dto.OrderCreateInput;
  11. import com.ruoyi.app.order.dto.OrderPushBodyDto;
  12. import com.ruoyi.app.service.UserService;
  13. import com.ruoyi.app.utils.DateUtil;
  14. import com.ruoyi.app.utils.ImageCompressUtils;
  15. import com.ruoyi.app.user.dto.StoreOutput;
  16. import com.ruoyi.app.utils.PayPush;
  17. import com.ruoyi.common.annotation.Anonymous;
  18. import com.ruoyi.common.annotation.Log;
  19. import com.ruoyi.common.core.controller.BaseController;
  20. import com.ruoyi.common.core.domain.AjaxResult;
  21. import com.ruoyi.common.core.page.TableDataInfo;
  22. import com.ruoyi.common.enums.BusinessType;
  23. import com.ruoyi.common.exception.ServiceException;
  24. import com.ruoyi.common.utils.MessageUtils;
  25. import com.ruoyi.common.utils.StringUtils;
  26. import com.ruoyi.common.utils.poi.ExcelUtil;
  27. import com.ruoyi.framework.manager.AsyncManager;
  28. import com.ruoyi.system.domain.*;
  29. import com.ruoyi.system.domain.vo.StoreOperatOutput;
  30. import com.ruoyi.system.mapper.PosStoreMapper;
  31. import com.ruoyi.system.mapper.SysConfigMapper;
  32. import com.ruoyi.system.service.*;
  33. import com.ruoyi.system.utils.Auth;
  34. import com.ruoyi.system.utils.AuthContext;
  35. import com.ruoyi.system.utils.JwtUtil;
  36. import io.swagger.models.auth.In;
  37. import org.springframework.beans.BeanUtils;
  38. import org.springframework.beans.factory.annotation.Autowired;
  39. import org.springframework.security.access.prepost.PreAuthorize;
  40. import org.springframework.transaction.annotation.Transactional;
  41. import org.springframework.web.bind.annotation.*;
  42. import jakarta.servlet.http.HttpServletResponse;
  43. import java.math.BigDecimal;
  44. import java.text.SimpleDateFormat;
  45. import java.util.*;
  46. import java.util.concurrent.atomic.AtomicInteger;
  47. import java.util.stream.Collectors;
  48. /**
  49. * posstoreController
  50. *
  51. * @author ruoyi
  52. * @date 2023-05-14
  53. */
  54. @RestController
  55. @RequestMapping("/chanting/store")
  56. public class PosStoreController extends BaseController {
  57. @Autowired
  58. private IPosStoreService posStoreService;
  59. @Autowired
  60. private PosStoreMapper posStoreMapper;
  61. @Autowired
  62. private IPosCollectService posCollectService;
  63. @Autowired
  64. private IPosFenleiService posFenleiService;
  65. @Autowired
  66. private IInfoUserService infoUserService;
  67. @Autowired
  68. private IOperatingHoursService operatingHoursService;
  69. @Autowired
  70. private PosStoreEnrichService posStoreEnrichService;
  71. @Autowired
  72. private SysConfigMapper sysConfigMapper;
  73. @Autowired
  74. private IOrderParentService orderParentService;
  75. @Autowired
  76. private IPosOrderService posOrderService;
  77. @Autowired
  78. private IPosStoreEzpayService posStoreEzpayService;
  79. @Autowired
  80. private UserService userService;
  81. @Autowired
  82. private MerchantStoreAccessService merchantStoreAccessService;
  83. @Autowired
  84. private IMerchantSubaccountStoreService merchantSubaccountStoreService;
  85. /**
  86. * 根据评分查旬门店
  87. *
  88. * @param longitude
  89. * @param latitude
  90. * @param page
  91. * @param juli
  92. * @param type
  93. * @return
  94. */
  95. @Anonymous
  96. @GetMapping("/getPfStore")
  97. public AjaxResult getPfStore(@RequestParam BigDecimal longitude,
  98. @RequestParam BigDecimal latitude,
  99. @RequestParam Integer page,
  100. @RequestParam Integer juli,
  101. @RequestParam Integer type) {
  102. if (type == 0) {
  103. List<PosStore> list = posStoreMapper.getPingfStore(longitude, latitude, (page - 1) * 10, juli);
  104. return success(list);
  105. } else if (type == 1) {
  106. List<PosStore> list = posStoreMapper.getReduStore(longitude, latitude, (page - 1) * 10, juli);
  107. return success(list);
  108. } else {
  109. List<PosStore> list = posStoreMapper.getNewStore(longitude, latitude, (page - 1) * 10, juli);
  110. return success(list);
  111. }
  112. }
  113. //删除我的门店
  114. @Anonymous
  115. @Auth
  116. @Transactional(rollbackFor = Exception.class)
  117. @GetMapping("/delemendian")
  118. public AjaxResult delemendian(@RequestHeader String token, @RequestParam String id) {
  119. Long userId = AuthContext.requireUserId();
  120. merchantStoreAccessService.requireOwner(userId);
  121. merchantStoreAccessService.requireStoreAccess(userId, Long.valueOf(id));
  122. QueryWrapper<PosFenlei> queryWrapper = new QueryWrapper<>();
  123. queryWrapper.eq("mendid", id);
  124. List<PosFenlei> list = posFenleiService.list(queryWrapper);
  125. if (list.size() > 0) {
  126. return error(MessageUtils.message("no.mendian.exist.classify.not.del"));
  127. } else {
  128. int rows = posStoreService.deletePosStoreById(Long.valueOf(id));
  129. if (rows > 0) {
  130. merchantSubaccountStoreService.deleteByStoreId(Long.valueOf(id));
  131. }
  132. return toAjax(rows);
  133. }
  134. }
  135. /**
  136. * H5端门店列表
  137. */
  138. @Anonymous
  139. @Auth
  140. @GetMapping("/storelistlist")
  141. public AjaxResult storelistlist(@RequestHeader String token,
  142. @RequestParam Integer page,
  143. @RequestParam Integer size) {
  144. Long id = AuthContext.requireUserId();
  145. IPage<PosStore> stlist = new Page<>(page, size);
  146. QueryWrapper<PosStore> queryWrapper = new QueryWrapper<>();
  147. // 判断是否为摊位主(type=4),摊位主通过 storeId 关联摊位
  148. InfoUser loginUser = infoUserService.selectInfoUserByUserId(Long.valueOf(id));
  149. if ("4".equals(loginUser.getUserType())) {
  150. if (loginUser.getStoreId() != null) {
  151. queryWrapper.eq("id", loginUser.getStoreId());
  152. } else {
  153. queryWrapper.eq("id", -1); // 无关联摊位,返回空列表
  154. }
  155. } else {
  156. Set<Long> storeIds = merchantStoreAccessService.getAccessibleStoreIds(id);
  157. if (storeIds.isEmpty()) {
  158. queryWrapper.eq("id", -1);
  159. } else {
  160. queryWrapper.in("id", storeIds);
  161. }
  162. }
  163. IPage<PosStore> list = posStoreService.page(stlist, queryWrapper);
  164. if (!list.getRecords().isEmpty()) {
  165. QueryWrapper<OperatingHours> wrapper = new QueryWrapper<>();
  166. wrapper.in("md_id", list.getRecords().stream().map(PosStore::getId).collect(Collectors.toList()));
  167. List<OperatingHours> hourslist = operatingHoursService.list(wrapper);
  168. list.getRecords().forEach(posStore -> {
  169. posStore.setBusinessHours(getStoreOperatOutput(hourslist, Long.valueOf(posStore.getId())));
  170. // 回显统一编号(统编),供商家端编辑门店时显示
  171. posStore.setUbn(posStoreEzpayService.getUbn(Long.valueOf(posStore.getId())));
  172. });
  173. }
  174. return success(list);
  175. }
  176. //查询我的门店列表
  177. @Anonymous
  178. @Auth
  179. @GetMapping("/getmystorelist")
  180. public AjaxResult getmystorelist(@RequestHeader String token) {
  181. Long id = AuthContext.requireUserId();
  182. QueryWrapper<PosStore> queryWrapper = new QueryWrapper<>();
  183. InfoUser loginUser = infoUserService.selectInfoUserByUserId(id);
  184. if (loginUser != null && "4".equals(loginUser.getUserType())) {
  185. queryWrapper.eq("id", loginUser.getStoreId() == null ? -1 : loginUser.getStoreId());
  186. } else {
  187. Set<Long> storeIds = merchantStoreAccessService.getAccessibleStoreIds(id);
  188. if (storeIds.isEmpty()) {
  189. queryWrapper.eq("id", -1);
  190. } else {
  191. queryWrapper.in("id", storeIds);
  192. }
  193. }
  194. List<PosStore> list = posStoreService.list(queryWrapper);
  195. return success(list);
  196. }
  197. //查询门店列表
  198. @Anonymous
  199. @GetMapping("/getstore")
  200. public AjaxResult getstore(@RequestHeader(defaultValue = "") String token, @RequestParam Integer id) {
  201. List<PosCollect> list = new ArrayList<>();
  202. if (!"".equals(token)) {
  203. JwtUtil jwtUtil = new JwtUtil();
  204. String usid = jwtUtil.getusid(token);
  205. QueryWrapper<PosCollect> queryWrapper = new QueryWrapper<>();
  206. queryWrapper.eq("user_id", usid);
  207. queryWrapper.eq("md_id", id);
  208. list = posCollectService.list(queryWrapper);
  209. }
  210. PosStore posStore = posStoreService.getById(id);
  211. // 回显统一编号(统编),实存于 pos_store_ezpay.ubn
  212. posStore.setUbn(posStoreEzpayService.getUbn(id.longValue()));
  213. List<PosStore> stores=new ArrayList<>();
  214. stores.add(posStore);
  215. posStoreEnrichService.enrichStoreList(stores);
  216. StoreOutput storeOutput = new StoreOutput();
  217. BeanUtils.copyProperties(stores.getFirst(), storeOutput);
  218. storeOutput.setCollect(!list.isEmpty() ? 1 : 0);
  219. return success(storeOutput);
  220. }
  221. /**
  222. * 商家收款账户(線下轉賬收银台展示用):门店 到 所属商家主账号 到 审核资料银行三字段
  223. * 商家级数据,连锁门店共享同一收款账户;任一字段为空返回 data=null,客户端据此隐藏線下支付选项
  224. */
  225. @Anonymous
  226. @GetMapping("/bankInfo")
  227. public AjaxResult bankInfo(@RequestParam Integer id) {
  228. PosStore store = posStoreService.getById(id);
  229. if (store == null || store.getUserId() == null) {
  230. return success(null);
  231. }
  232. InfoUser merchant = infoUserService.selectInfoUserByUserId(store.getUserId());
  233. if (merchant == null || StringUtils.isBlank(merchant.getBankAccountName())
  234. || StringUtils.isBlank(merchant.getBankName()) || StringUtils.isBlank(merchant.getBankAccountNo())) {
  235. return success(null);
  236. }
  237. JSONObject data = new JSONObject();
  238. data.put("accountName", merchant.getBankAccountName().trim());
  239. data.put("bankName", merchant.getBankName().trim());
  240. data.put("accountNo", merchant.getBankAccountNo().trim());
  241. return success(data);
  242. }
  243. //根据行业分类查询门店列表
  244. @Anonymous
  245. @GetMapping("/getstorelist")
  246. public AjaxResult getstorelist(@RequestParam BigDecimal longitude,
  247. @RequestParam BigDecimal latitude,
  248. @RequestParam Integer page,
  249. @RequestParam String area,
  250. @RequestParam Integer juli,
  251. @RequestParam(defaultValue = "") Integer sort,
  252. @RequestParam(defaultValue = "zh-TW", required = false) String language) {
  253. List<PosStore> list;
  254. if (sort == null) {
  255. list = posStoreMapper.getmdlist(longitude, latitude, (page - 1) * 20, "%" + area + "%", juli);
  256. } else {
  257. list = posStoreMapper.getdaidiq(longitude, latitude, (page - 1) * 20, "%" + area + "%", juli, sort);
  258. }
  259. posStoreEnrichService.enrichStoreList(list);
  260. // total 必须是符合条件总数,不能用当前页行数充当,否则客户端按 total 判断会误判"已加载完"导致翻页失效
  261. long total = sort == null
  262. ? posStoreMapper.getmdlistCount("%" + area + "%")
  263. : posStoreMapper.getdaidiqCount("%" + area + "%", sort);
  264. Page<StoreOutput> result = posStoreEnrichService.buildStoreOutputPage(list, language, page, total);
  265. return success(result);
  266. }
  267. //根据服务分类查询门店列表
  268. @Anonymous
  269. @GetMapping("/getserverlist")
  270. public AjaxResult getserverlist(@RequestParam BigDecimal longitude,
  271. @RequestParam BigDecimal latitude,
  272. @RequestParam Integer page,
  273. @RequestParam String area,
  274. @RequestParam Integer juli,
  275. @RequestParam(defaultValue = "") String serverType) {
  276. if (!"".equals(serverType)) {
  277. List<PosStore> list = posStoreMapper.getserverlist(longitude, latitude, (page - 1) * 20, "%" + area + "%", juli, "%" + serverType + "%");
  278. return success(list);
  279. } else {
  280. List<PosStore> list = posStoreMapper.getmdlist(longitude, latitude, (page - 1) * 20, "%" + area + "%", juli);
  281. return success(list);
  282. }
  283. }
  284. //添加门店
  285. @Anonymous
  286. @Auth
  287. @PostMapping("/addmendian")
  288. @Transactional
  289. public AjaxResult addmendian(@RequestHeader String token, @RequestBody PosStore posStore) {
  290. Long loginUserId = AuthContext.requireUserId();
  291. InfoUser loginUser = infoUserService.selectInfoUserByUserId(loginUserId);
  292. if (posStore.getId() == null) {
  293. merchantStoreAccessService.requireOwner(loginUserId);
  294. userService.checkUserStatus(loginUserId);
  295. posStore.setUserId(loginUserId);
  296. } else {
  297. requireStoreAccess(loginUserId, loginUser, posStore.getId().longValue());
  298. PosStore existing = posStoreService.getById(posStore.getId());
  299. if (existing == null) {
  300. throw new ServiceException(MessageUtils.message("merchant.store.access.denied"));
  301. }
  302. posStore.setUserId(existing.getUserId());
  303. }
  304. try {
  305. // 1. 先保存门店信息
  306. Boolean org = posStoreService.saveOrUpdate(posStore);
  307. if (!org) {
  308. return error();
  309. }
  310. // 2. 查询保存后的门店信息(使用ID查询,避免锁等待)
  311. PosStore store;
  312. if (posStore.getId() != null) {
  313. store = posStoreService.getById(posStore.getId());
  314. } else {
  315. // 如果是新增,通过名称和用户ID查询
  316. QueryWrapper<PosStore> wrapper = new QueryWrapper<>();
  317. wrapper.eq("pos_name", posStore.getPosName());
  318. wrapper.eq("user_id", posStore.getUserId());
  319. store = posStoreService.getOne(wrapper);
  320. }
  321. if (store == null) {
  322. return error("门店信息保存失败");
  323. }
  324. // 3. 处理营业时间信息
  325. handlerBusinessHours(posStore, store);
  326. // 4. 统一保存统一编号(统编)到 pos_store_ezpay(不再走独立 saveUbn 接口)
  327. if (posStore.getUbn() != null) {
  328. posStoreEzpayService.uploadUbn(store.getId().longValue(), posStore.getUbn());
  329. }
  330. return success(MessageUtils.message("no.success"), store);
  331. } catch (ServiceException exception) {
  332. throw exception;
  333. } catch (Exception exception) {
  334. logger.error("保存商家门店失败,userId:{},storeId:{}", loginUserId, posStore.getId(), exception);
  335. return error(MessageUtils.message("no.system.error"));
  336. }
  337. }
  338. // 统一编号(统编)已并入 addmendian 保存、storelistlist 回显(存于 pos_store_ezpay),不再有独立 saveUbn/getUbn 接口
  339. /**
  340. * 更新门店信息处理营业时间
  341. * @param input
  342. * @param store
  343. */
  344. private void handlerBusinessHours(PosStore input, PosStore store) {
  345. if (input.getBusinessHours() != null && !input.getBusinessHours().isEmpty()) {
  346. // 先删除旧的营业时间记录
  347. LambdaQueryWrapper<OperatingHours> query = new LambdaQueryWrapper<>();
  348. query.eq(OperatingHours::getMdId, store.getId());
  349. operatingHoursService.remove(query);
  350. // 批量插入新的营业时间记录
  351. List<OperatingHours> operatingHours = new ArrayList<>();
  352. input.getBusinessHours().forEach(o -> {
  353. o.getTimeSlots().forEach(time -> {
  354. OperatingHours op = new OperatingHours();
  355. op.setStartTime(time.getStartTime());
  356. op.setEndTime(time.getEndTime());
  357. op.setDayOfWeek(time.getDayOfWeek());
  358. op.setIsOpen(o.getIsOpen());
  359. op.setMdId(Long.valueOf(store.getId()));
  360. operatingHours.add(op);
  361. });
  362. });
  363. if (!operatingHours.isEmpty()) {
  364. operatingHoursService.saveBatch(operatingHours);
  365. }
  366. }
  367. }
  368. /**
  369. * (商家端app使用)获取门店营业时间
  370. * @param mdId 门店id
  371. * @return
  372. */
  373. @Anonymous
  374. @Auth
  375. @GetMapping("/getMdBusinessHours")
  376. public AjaxResult getMdBusinessHours(@RequestHeader String token, @RequestParam Long mdId){
  377. Long userId = AuthContext.requireUserId();
  378. requireStoreAccess(userId, infoUserService.selectInfoUserByUserId(userId), mdId);
  379. LambdaQueryWrapper<OperatingHours> query=new LambdaQueryWrapper<>();
  380. query.eq(OperatingHours::getMdId,mdId);
  381. List<OperatingHours> list = operatingHoursService.list(query);
  382. List<StoreOperatOutput> data = new ArrayList<>();
  383. if(!list.isEmpty()){
  384. data = getStoreOperatOutput(list,mdId);
  385. }
  386. return success(data);
  387. }
  388. /**
  389. * 商家端app更新门店营业时间
  390. * @param businessHours
  391. * @return
  392. */
  393. @Anonymous
  394. @Auth
  395. @PostMapping("/saveMdBusinessHours")
  396. public AjaxResult saveMdBusinessHours(@RequestHeader String token,
  397. @RequestBody List<StoreOperatOutput> businessHours) {
  398. if(businessHours == null || businessHours.isEmpty()) {
  399. throw new ServiceException(MessageUtils.message("no.mendian.not.set.business.hours"));
  400. }
  401. Long mdId = businessHours.get(0).getMdId();
  402. Long userId = AuthContext.requireUserId();
  403. requireStoreAccess(userId, infoUserService.selectInfoUserByUserId(userId), mdId);
  404. if (businessHours.stream().anyMatch(item -> !Objects.equals(mdId, item.getMdId()))) {
  405. throw new ServiceException(MessageUtils.message("merchant.store.access.denied"));
  406. }
  407. PosStore store = posStoreService.getById(businessHours.get(0).getMdId());
  408. // 先删除旧的营业时间记录
  409. LambdaQueryWrapper<OperatingHours> query = new LambdaQueryWrapper<>();
  410. query.eq(OperatingHours::getMdId, store.getId());
  411. operatingHoursService.remove(query);
  412. // 批量插入新的营业时间记录
  413. List<OperatingHours> operatingHours = new ArrayList<>();
  414. businessHours.forEach(o -> {
  415. o.getTimeSlots().forEach(time -> {
  416. OperatingHours op = new OperatingHours();
  417. op.setStartTime(time.getStartTime());
  418. op.setEndTime(time.getEndTime());
  419. op.setDayOfWeek(time.getDayOfWeek());
  420. op.setIsOpen(o.getIsOpen());
  421. op.setMdId(Long.valueOf(store.getId()));
  422. operatingHours.add(op);
  423. });
  424. });
  425. if(!operatingHours.isEmpty()) {
  426. operatingHoursService.saveBatch(operatingHours);
  427. }
  428. return success();
  429. }
  430. private void requireStoreAccess(Long loginUserId, InfoUser loginUser, Long storeId) {
  431. if (loginUser != null && "4".equals(loginUser.getUserType())) {
  432. if (!Objects.equals(loginUser.getStoreId(), storeId)) {
  433. throw new ServiceException(MessageUtils.message("merchant.store.access.denied"));
  434. }
  435. return;
  436. }
  437. merchantStoreAccessService.requireStoreAccess(loginUserId, storeId);
  438. }
  439. //返回营业时间(按星期分组)
  440. private List<StoreOperatOutput> getStoreOperatOutput(List<OperatingHours> list, Long mdId){
  441. List<StoreOperatOutput> data= new ArrayList<>();
  442. list=list.stream().filter(x-> x.getMdId().equals(mdId)).collect(Collectors.toList());
  443. if(!list.isEmpty()){
  444. Map<Integer,List<OperatingHours>> map = list.stream().collect(Collectors.groupingBy(OperatingHours::getDayOfWeek));
  445. map.forEach((k,v)->{
  446. data.add(new StoreOperatOutput(){
  447. {
  448. setMdId(mdId);
  449. setDayOfWeek(k);
  450. setIsOpen(v.get(0).getIsOpen());
  451. setTimeSlots(v);
  452. }
  453. });
  454. });
  455. }
  456. return data;
  457. }
  458. /**
  459. * 查询posstore列表
  460. */
  461. @PreAuthorize("@ss.hasPermi('chanting:store:list')")
  462. // @Anonymous
  463. @GetMapping("/list")
  464. public TableDataInfo list(PosStore posStore) {
  465. startPage();
  466. List<PosStore> list = posStoreService.selectPosStoreList(posStore);
  467. for (PosStore store : list) {
  468. InfoUser user = infoUserService.getById(store.getUserId());
  469. store.setUserName(user.getUserName());
  470. }
  471. return getDataTable(list);
  472. }
  473. /**
  474. * 导出posstore列表
  475. */
  476. @PreAuthorize("@ss.hasPermi('chanting:store:export')")
  477. @Log(title = "posstore", businessType = BusinessType.EXPORT)
  478. @PostMapping("/export")
  479. public void export(HttpServletResponse response, PosStore posStore) {
  480. List<PosStore> list = posStoreService.selectPosStoreList(posStore);
  481. ExcelUtil<PosStore> util = new ExcelUtil<PosStore>(PosStore.class);
  482. util.exportExcel(response, list, MessageUtils.message("no.export.excel.posstore"));
  483. }
  484. /**
  485. * 获取posstore详细信息
  486. */
  487. @PreAuthorize("@ss.hasPermi('chanting:store:query')")
  488. @GetMapping(value = "/{id:\\d+}")
  489. public AjaxResult getInfo(@PathVariable("id") Long id) {
  490. PosStore posStore = posStoreService.selectPosStoreById(id);
  491. // 回显营业时间(按周几分组的 timeSlots)与统一编号(统编),供门店审核页显示
  492. if (posStore != null) {
  493. LambdaQueryWrapper<OperatingHours> wrapper = new LambdaQueryWrapper<>();
  494. wrapper.eq(OperatingHours::getMdId, id);
  495. posStore.setBusinessHours(getStoreOperatOutput(operatingHoursService.list(wrapper), id));
  496. // 统编实存于 pos_store_ezpay.ubn
  497. posStore.setUbn(posStoreEzpayService.getUbn(id));
  498. }
  499. return success(posStore);
  500. }
  501. /**
  502. * 新增posstore
  503. */
  504. @PreAuthorize("@ss.hasPermi('chanting:store:add')")
  505. @Log(title = "posstore", businessType = BusinessType.INSERT)
  506. @PostMapping
  507. public AjaxResult add(@RequestBody PosStore posStore) {
  508. return toAjax(posStoreService.insertPosStore(posStore));
  509. }
  510. /**
  511. * 修改posstore
  512. */
  513. @PreAuthorize("@ss.hasPermi('chanting:store:edit')")
  514. @Log(title = "posstore", businessType = BusinessType.UPDATE)
  515. @PutMapping
  516. public AjaxResult edit(@RequestBody PosStore posStore) {
  517. return toAjax(posStoreService.updatePosStore(posStore));
  518. }
  519. /**
  520. * 修改posstore下架状态
  521. */
  522. @Anonymous
  523. @PutMapping("/changeOffShelf")
  524. public AjaxResult changeOffShelf(@RequestBody PosStore posStore) {
  525. Boolean res = posStoreService.saveOrUpdate(posStore);
  526. if (res) {
  527. return success();
  528. } else {
  529. return error();
  530. }
  531. }
  532. /**
  533. * 删除posstore
  534. */
  535. @PreAuthorize("@ss.hasPermi('chanting:store:remove')")
  536. @Log(title = "posstore", businessType = BusinessType.DELETE)
  537. @DeleteMapping("/{ids}")
  538. public AjaxResult remove(@PathVariable Long[] ids) {
  539. return toAjax(posStoreService.deletePosStoreByIds(ids));
  540. }
  541. /**
  542. * 压缩图片店铺的商品图片
  543. */
  544. @Anonymous
  545. @GetMapping("/compressStoreImage")
  546. public AjaxResult compressStoreImage(@RequestParam String idsStr) {
  547. LambdaQueryWrapper<PosStore> queryWrapper = new LambdaQueryWrapper<>();
  548. List<Integer> ids = new ArrayList<>();
  549. if (!StringUtils.isEmpty(idsStr)) {
  550. ids = Arrays.stream(idsStr.split(","))
  551. .map(Integer::valueOf)
  552. .collect(Collectors.toList());
  553. }
  554. queryWrapper.in(!ids.isEmpty(), PosStore::getId, ids);
  555. List<PosStore> list = posStoreService.list(queryWrapper);
  556. AtomicInteger count = new AtomicInteger();
  557. list.forEach(food -> {
  558. String compressImage = ImageCompressUtils.compressImageByWebPath(food.getImage());
  559. if (!compressImage.equals(food.getImage())) {
  560. food.setImage(compressImage);
  561. PosStore posStore = new PosStore();
  562. posStore.setId(food.getId());
  563. posStore.setImage(compressImage);
  564. posStoreService.saveOrUpdate(posStore);
  565. count.getAndIncrement();
  566. System.out.println("store成功压缩的图片数量:" + count.get());
  567. logger.info("store成功压缩的图片数量:" + count.get());
  568. }
  569. });
  570. return success("成功压缩的图片数量:" + count.get());
  571. }
  572. }