| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- package com.ruoyi.app.mendian;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.ruoyi.app.utils.DateUtil;
- import com.ruoyi.app.utils.ImageCompressUtils;
- import com.ruoyi.common.annotation.Anonymous;
- import com.ruoyi.common.annotation.Log;
- import com.ruoyi.common.core.controller.BaseController;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.core.page.TableDataInfo;
- import com.ruoyi.common.enums.BusinessType;
- import com.ruoyi.common.utils.MessageUtils;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.common.utils.poi.ExcelUtil;
- import com.ruoyi.system.domain.*;
- import com.ruoyi.system.mapper.PosStoreMapper;
- import com.ruoyi.system.mapper.SysConfigMapper;
- import com.ruoyi.system.service.*;
- import com.ruoyi.system.utils.Auth;
- import com.ruoyi.system.utils.JwtUtil;
- import io.swagger.models.auth.In;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.bind.annotation.*;
- import jakarta.servlet.http.HttpServletResponse;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Map;
- import java.util.Collections;
- import java.util.concurrent.atomic.AtomicInteger;
- import java.util.stream.Collectors;
- /**
- * posstoreController
- *
- * @author ruoyi
- * @date 2023-05-14
- */
- @RestController
- @RequestMapping("/chanting/store")
- public class PosStoreController extends BaseController {
- @Autowired
- private IPosStoreService posStoreService;
- @Autowired
- private PosStoreMapper posStoreMapper;
- @Autowired
- private IPosCollectService posCollectService;
- @Autowired
- private IPosFenleiService posFenleiService;
- @Autowired
- private IInfoUserService infoUserService;
- @Autowired
- private IPosReviewService posReviewService;
- @Autowired
- private IOperatingHoursService operatingHoursService;
- @Autowired
- private IPosOrderService posOrderService;
- @Autowired
- private SysConfigMapper sysConfigMapper;
- /**
- * 根据评分查旬门店
- *
- * @param longitude
- * @param latitude
- * @param page
- * @param juli
- * @param type
- * @return
- */
- @Anonymous
- @GetMapping("/getPfStore")
- public AjaxResult getPfStore(@RequestParam BigDecimal longitude,
- @RequestParam BigDecimal latitude,
- @RequestParam Integer page,
- @RequestParam Integer juli,
- @RequestParam Integer type) {
- if (type == 0) {
- List<PosStore> list = posStoreMapper.getPingfStore(longitude, latitude, (page - 1) * 10, juli);
- return success(list);
- } else if (type == 1) {
- List<PosStore> list = posStoreMapper.getReduStore(longitude, latitude, (page - 1) * 10, juli);
- return success(list);
- } else {
- List<PosStore> list = posStoreMapper.getNewStore(longitude, latitude, (page - 1) * 10, juli);
- return success(list);
- }
- }
- //删除我的门店
- @Anonymous
- @Auth
- @GetMapping("/delemendian")
- public AjaxResult delemendian(@RequestParam String id) {
- QueryWrapper<PosFenlei> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("mendid", id);
- List<PosFenlei> list = posFenleiService.list(queryWrapper);
- if (list.size() > 0) {
- return error(MessageUtils.message("no.mendian.exist.classify.not.del"));
- } else {
- return toAjax(posStoreService.deletePosStoreById(Long.valueOf(id)));
- }
- }
- /**
- * H5端门店列表
- */
- @Anonymous
- @Auth
- @GetMapping("/storelistlist")
- public AjaxResult storelistlist(@RequestHeader String token,
- @RequestParam Integer page,
- @RequestParam Integer size) {
- JwtUtil jwtUtil = new JwtUtil();
- String id = jwtUtil.getusid(token);
- IPage<PosStore> stlist = new Page<>(page, size);
- QueryWrapper<PosStore> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("user_id", id);
- IPage<PosStore> list = posStoreService.page(stlist, queryWrapper);
- if (!list.getRecords().isEmpty()) {
- QueryWrapper<OperatingHours> wrapper = new QueryWrapper<>();
- wrapper.in("md_id", list.getRecords().stream().map(PosStore::getId).collect(Collectors.toList()));
- List<OperatingHours> hourslist = operatingHoursService.list(wrapper);
- list.getRecords().forEach(posStore -> {
- posStore.setBusinessHours(hourslist);
- });
- }
- return success(list);
- }
- //查询我的门店列表
- @Anonymous
- @Auth
- @GetMapping("/getmystorelist")
- public AjaxResult getmystorelist(@RequestHeader String token) {
- JwtUtil jwtUtil = new JwtUtil();
- String id = jwtUtil.getusid(token);
- QueryWrapper<PosStore> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("user_id", id);
- List<PosStore> list = posStoreService.list(queryWrapper);
- return success(list);
- }
- //查询门店列表
- @Anonymous
- @GetMapping("/getstore")
- public AjaxResult getstore(@RequestHeader(defaultValue = "") String token, @RequestParam Integer id) {
- if (!"".equals(token)) {
- JwtUtil jwtUtil = new JwtUtil();
- String usid = jwtUtil.getusid(token);
- QueryWrapper<PosCollect> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("user_id", usid);
- queryWrapper.eq("md_id", id);
- List<PosCollect> list = posCollectService.list(queryWrapper);
- PosStore posStore = posStoreService.getById(id);
- JSONObject org = new JSONObject();
- org.put("id", posStore.getId());
- org.put("posName", posStore.getPosName());
- org.put("image", posStore.getImage());
- org.put("posPrice", posStore.getPosPrice());
- org.put("area", posStore.getArea());
- org.put("address", posStore.getAddress());
- org.put("longitude", posStore.getLongitude());
- org.put("latitude", posStore.getLatitude());
- org.put("briefIntroduction", posStore.getBriefIntroduction());
- org.put("type", posStore.getType());
- org.put("hygienePermit", posStore.getHygienePermit());
- org.put("hygieneLicence", posStore.getHygieneLicence());
- org.put("openBusiness", posStore.getOpenBusiness());
- org.put("windingUp", posStore.getWindingUp());
- org.put("sort", posStore.getSort());
- org.put("userId", posStore.getUserId());
- org.put("juli", posStore.getJuli());
- org.put("cretim", posStore.getCretim());
- org.put("zhitsj", posStore.getJuli());
- org.put("tgpaixv", posStore.getCretim());
- org.put("state", posStore.getState());
- org.put("serverType", posStore.getServerType());
- org.put("telephone", posStore.getTelephone());
- org.put("Collect", !list.isEmpty() ? 1 : 0);
- org.put("logo", posStore.getLogo());
- org.put("isNightMarket", posStore.getIsNightMarket());
- org.put("nightMarketId", posStore.getNightMarketId());
- QueryWrapper<OperatingHours> wrapper = new QueryWrapper<>();
- wrapper.eq("md_id", posStore.getId());
- List<OperatingHours> hourslist = operatingHoursService.list(wrapper);
- DateUtil dateUtil = new DateUtil();
- Boolean dayang = false;
- //在营业时间范围内返回true
- for (int i = 0; i < hourslist.size(); i++) {
- Boolean sbsj = dateUtil.isLegalTime(hourslist.get(i).getStartTime(), hourslist.get(i).getEndTime());
- if (sbsj == true) {
- dayang = true;
- }
- }
- //不在时间范围内标识为打烊
- if (dayang == false) {
- org.put("state", 1);
- }
- org.put("businessHours", hourslist);
- return success(org);
- } else {
- PosStore posStore = posStoreService.getById(id);
- return success(posStore);
- }
- }
- //根据行业分类查询门店列表
- @Anonymous
- @GetMapping("/getstorelist")
- public AjaxResult getstorelist(@RequestParam BigDecimal longitude,
- @RequestParam BigDecimal latitude,
- @RequestParam Integer page,
- @RequestParam String area,
- @RequestParam Integer juli,
- @RequestParam(defaultValue = "") Integer sort) {
- List<PosStore> list;
- if (sort == null) {
- list = posStoreMapper.getmdlist(longitude, latitude, (page - 1) * 20, "%" + area + "%", juli);
- } else {
- list = posStoreMapper.getdaidiq(longitude, latitude, (page - 1) * 20, "%" + area + "%", juli, sort);
- }
- // 为门店列表设置评分与月售订单数量
- if (!list.isEmpty()) {
- List<Long> mdIds = list.stream()
- .map(store -> store.getId() == null ? null : store.getId().longValue())
- .filter(idVal -> idVal != null)
- .collect(Collectors.toList());
- Map<Long, List<PosReview>> reviewMap = Collections.emptyMap();
- Map<Long, Long> orderCountMap = Collections.emptyMap();
- List<OperatingHours> hourslist=new ArrayList<>();
- if (!mdIds.isEmpty()) {
- // 1. 计算各门店评分
- QueryWrapper<PosReview> reviewWrapper = new QueryWrapper<>();
- reviewWrapper.in("md_id", mdIds);
- List<PosReview> reviews = posReviewService.list(reviewWrapper);
- reviewMap = reviews.stream()
- .collect(Collectors.groupingBy(PosReview::getMdId));
- // 2. 统计各门店本月订单数(按 cretim 当前月份)
- QueryWrapper<PosOrder> orderWrapper = new QueryWrapper<>();
- orderWrapper.in("md_id", mdIds);
- orderWrapper.apply("DATE_FORMAT(cretim,'%Y-%m') = DATE_FORMAT(NOW(),'%Y-%m')");
- List<PosOrder> orders = posOrderService.list(orderWrapper);
- orderCountMap = orders.stream()
- .collect(Collectors.groupingBy(PosOrder::getMdId, Collectors.counting()));
- QueryWrapper<OperatingHours> wrapper = new QueryWrapper<>();
- wrapper.in("md_id", mdIds);
- hourslist = operatingHoursService.list(wrapper);
- }
- DateUtil dateUtil = new DateUtil();
- // 统一循环设置评分与月售(mdIds 为空时使用默认值)
- for (PosStore store : list) {
- Long mdId = store.getId() == null ? null : store.getId().longValue();
- List<PosReview> storeReviews = (mdId == null || reviewMap.isEmpty()) ? null : reviewMap.get(mdId);
- double score;
- if (storeReviews == null || storeReviews.isEmpty()) {
- score = 4.5d;
- } else {
- double avg = storeReviews.stream()
- .mapToLong(PosReview::getScore)
- .average()
- .orElse(4.5d);
- // 平均分按 0.5 分粒度四舍五入,例如 3, 3.5, 4, 4.5
- score = Math.round(avg * 2.0d) / 2.0d;
- }
- store.setPingf(score);
- // 设置本月售出订单数量(ddsl)
- long monthCount = (mdId == null || orderCountMap.isEmpty()) ? 0L : orderCountMap.getOrDefault(mdId, 0L);
- store.setDdsl(monthCount);
- Boolean dayang = false;
- List<OperatingHours> mdHours=hourslist.stream().filter(x-> store.getId().equals(x.getMdId().intValue())).collect(Collectors.toList());
- //在营业时间范围内返回true
- for (int i = 0; i < mdHours.size(); i++) {
- Boolean sbsj = dateUtil.isLegalTime(mdHours.get(i).getStartTime(), mdHours.get(i).getEndTime());
- if (sbsj == true) {
- dayang = true;
- }
- }
- //不在时间范围内标识为打烊
- if (dayang == false) {
- store.setState(1L);
- }
- }
- }
- return success(list);
- }
- //根据服务分类查询门店列表
- @Anonymous
- @GetMapping("/getserverlist")
- public AjaxResult getserverlist(@RequestParam BigDecimal longitude,
- @RequestParam BigDecimal latitude,
- @RequestParam Integer page,
- @RequestParam String area,
- @RequestParam Integer juli,
- @RequestParam(defaultValue = "") String serverType) {
- if (!"".equals(serverType)) {
- List<PosStore> list = posStoreMapper.getserverlist(longitude, latitude, (page - 1) * 20, "%" + area + "%", juli, "%" + serverType + "%");
- return success(list);
- } else {
- List<PosStore> list = posStoreMapper.getmdlist(longitude, latitude, (page - 1) * 20, "%" + area + "%", juli);
- return success(list);
- }
- }
- //添加门店
- @Anonymous
- @PostMapping("/addmendian")
- @Transactional
- public AjaxResult addmendian(@RequestBody PosStore posStore) {
- Boolean org = posStoreService.saveOrUpdate(posStore);
- if (org) {
- QueryWrapper<PosStore> wrapper = new QueryWrapper<>();
- wrapper.eq("pos_name", posStore.getPosName());
- wrapper.eq("user_id", posStore.getUserId());
- PosStore store = posStoreService.getOne(wrapper);
- if (posStore.getBusinessHours() != null && posStore.getBusinessHours().size() > 0) {
- LambdaQueryWrapper<OperatingHours> query = new LambdaQueryWrapper<>();
- query.eq(OperatingHours::getMdId, Long.valueOf(store.getId()));
- operatingHoursService.remove(query);
- posStore.getBusinessHours().forEach(operatingHours -> {
- operatingHours.setMdId(Long.valueOf(store.getId()));
- });
- operatingHoursService.saveBatch(posStore.getBusinessHours());
- }
- return success(MessageUtils.message("no.success"), store);
- } else {
- return error();
- }
- }
- /**
- * 查询posstore列表
- */
- @PreAuthorize("@ss.hasPermi('chanting:store:list')")
- // @Anonymous
- @GetMapping("/list")
- public TableDataInfo list(PosStore posStore) {
- startPage();
- List<PosStore> list = posStoreService.selectPosStoreList(posStore);
- for (PosStore store : list) {
- InfoUser user = infoUserService.getById(store.getUserId());
- store.setUserName(user.getUserName());
- }
- return getDataTable(list);
- }
- /**
- * 导出posstore列表
- */
- @PreAuthorize("@ss.hasPermi('chanting:store:export')")
- @Log(title = "posstore", businessType = BusinessType.EXPORT)
- @PostMapping("/export")
- public void export(HttpServletResponse response, PosStore posStore) {
- List<PosStore> list = posStoreService.selectPosStoreList(posStore);
- ExcelUtil<PosStore> util = new ExcelUtil<PosStore>(PosStore.class);
- util.exportExcel(response, list, MessageUtils.message("no.export.excel.posstore"));
- }
- /**
- * 获取posstore详细信息
- */
- @PreAuthorize("@ss.hasPermi('chanting:store:query')")
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id) {
- return success(posStoreService.selectPosStoreById(id));
- }
- /**
- * 新增posstore
- */
- @PreAuthorize("@ss.hasPermi('chanting:store:add')")
- @Log(title = "posstore", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody PosStore posStore) {
- return toAjax(posStoreService.insertPosStore(posStore));
- }
- /**
- * 修改posstore
- */
- @PreAuthorize("@ss.hasPermi('chanting:store:edit')")
- @Log(title = "posstore", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody PosStore posStore) {
- return toAjax(posStoreService.updatePosStore(posStore));
- }
- /**
- * 修改posstore下架状态
- */
- @Anonymous
- @PutMapping("/changeOffShelf")
- public AjaxResult changeOffShelf(@RequestBody PosStore posStore) {
- Boolean res = posStoreService.saveOrUpdate(posStore);
- if (res) {
- return success();
- } else {
- return error();
- }
- }
- /**
- * 删除posstore
- */
- @PreAuthorize("@ss.hasPermi('chanting:store:remove')")
- @Log(title = "posstore", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids) {
- return toAjax(posStoreService.deletePosStoreByIds(ids));
- }
- /**
- * 压缩图片店铺的商品图片
- */
- @Anonymous
- @GetMapping("/compressStoreImage")
- public AjaxResult compressStoreImage(@RequestParam String idsStr) {
- LambdaQueryWrapper<PosStore> queryWrapper = new LambdaQueryWrapper<>();
- List<Integer> ids = new ArrayList<>();
- if (!StringUtils.isEmpty(idsStr)) {
- ids = Arrays.stream(idsStr.split(","))
- .map(Integer::valueOf)
- .collect(Collectors.toList());
- }
- queryWrapper.in(!ids.isEmpty(), PosStore::getId, ids);
- List<PosStore> list = posStoreService.list(queryWrapper);
- AtomicInteger count = new AtomicInteger();
- list.forEach(food -> {
- String compressImage = ImageCompressUtils.compressImageByWebPath(food.getImage());
- if (!compressImage.equals(food.getImage())) {
- food.setImage(compressImage);
- PosStore posStore = new PosStore();
- posStore.setId(food.getId());
- posStore.setImage(compressImage);
- posStoreService.saveOrUpdate(posStore);
- count.getAndIncrement();
- System.out.println("store成功压缩的图片数量:" + count.get());
- logger.info("store成功压缩的图片数量:" + count.get());
- }
- });
- return success("成功压缩的图片数量:" + count.get());
- }
- }
|