Pu Zhibing
2025-04-03 1f09f6daaf73bc83cceb4ae22b862b7b365635cf
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopPointController.java
@@ -1,25 +1,25 @@
package com.ruoyi.other.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.ShopPoint;
import com.ruoyi.other.excel.ShopPointEX;
import com.ruoyi.other.api.domain.ShopPointCopy;
import com.ruoyi.other.mapper.ShopPointCopyMapper;
import com.ruoyi.other.service.ShopPointService;
import com.ruoyi.other.vo.ShopPointStatistics;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.feignClient.SysUserClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
/**
@@ -37,7 +37,11 @@
    @Resource
    private ShopPointService shopPointService;
    @Resource
    private ShopPointCopyMapper shopPointCopyMapper;
    @Resource
    private TokenService tokenService;
    @Resource
    private SysUserClient sysUserClient;
    /**
@@ -53,16 +57,18 @@
    @GetMapping("/shop/statistics")
    @ApiOperation(value = "门店积分统计", notes = "门店积分统计", tags = {"门店后台"})
    public R<ShopPointStatistics> shopstatistics(ShopPoint shopPoint) {
        Integer objectId = tokenService.getLoginUser().getSysUser().getObjectId();
        shopPoint.setShopId(objectId);
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userid).getData();
        shopPoint.setShopId(sysUser.getObjectId());
        ShopPointStatistics statistics = shopPointService.statistics(Page.of(shopPoint.getPageNum(), shopPoint.getPageSize()), shopPoint);
        return R.ok(statistics);
    }
    @GetMapping("/shop/statistics/list")
    @ApiOperation(value = "门店积分统计列表", notes = "门店积分统计", tags = {"门店后台"})
    public R<Page<ShopPoint>> shopstatisticslist(ShopPoint shopPoint,Integer pageNum,Integer pageSize) {
        Integer objectId = tokenService.getLoginUser().getSysUser().getObjectId();
        Page<ShopPoint> page = shopPointService.lambdaQuery().eq(ShopPoint::getShopId, objectId).eq(shopPoint.getType()!=null,ShopPoint::getType, shopPoint.getType())
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userid).getData();
        Page<ShopPoint> page = shopPointService.lambdaQuery().eq(ShopPoint::getShopId, sysUser.getObjectId()).eq(shopPoint.getType()!=null,ShopPoint::getType, shopPoint.getType())
                .like(shopPoint.getOrderNum()!=null,ShopPoint::getOrderNum, shopPoint.getOrderNum())
                .orderByDesc(ShopPoint::getCreateTime)
                .page(Page.of(pageNum, pageSize));
@@ -70,11 +76,9 @@
    }
    @GetMapping("/statistics/list")
    @ApiOperation(value = "门店积分明细必传门店id", tags = {"后台"})
    public R<Page<ShopPoint>> statisticslist(ShopPoint shopPoint,Integer pageNum,Integer pageSize) {
        Page<ShopPoint> page = shopPointService.lambdaQuery().eq(ShopPoint::getShopId, shopPoint.getShopId()).eq(shopPoint.getType()!=null,ShopPoint::getType, shopPoint.getType())
                .like(shopPoint.getOrderNum()!=null,ShopPoint::getOrderNum, shopPoint.getOrderNum())
                .orderByDesc(ShopPoint::getCreateTime)
                .page(Page.of(pageNum, pageSize));
    public R<IPage<ShopPoint>> statisticslist(ShopPoint shopPoint,Integer pageNum,Integer pageSize) {
        IPage<ShopPoint> page = shopPointService.getShopPointPage(Page.of(pageNum, pageSize), shopPoint);
        page.getRecords().forEach(s->s.setVariablePoint(s.getVariablePoint() * s.getChangeDirection()));
        return R.ok(page);
    }
@@ -88,37 +92,49 @@
        ShopPointStatistics statistics = shopPointService.statistics(Page.of(1, Integer.MAX_VALUE), shopPoint);
        if (statistics!=null){
            IPage<ShopPoint> shopPointIPage = statistics.getShopPointIPage();
            List<ShopPointEX> shopPointEXList = new ArrayList<>();
            if (shopPointIPage!=null){
                List<ShopPoint> records = shopPointIPage.getRecords();
                if (records!=null){
                    for (ShopPoint record : records) {
                        ShopPointEX shopPointEX = new ShopPointEX();
                        BeanUtils.copyBeanProp(shopPointEX, record);
                        Integer type = record.getType();
                        switch (type) {
                            case 1:
                                shopPointEX.setType("门店业绩");
                                break;
                            case 2:
                                shopPointEX.setType("门店返佣");
                                break;
                            default:
                                shopPointEX.setType("下级门店返佣");
                                break;
                        }
                        shopPointEXList.add(shopPointEX);
                    }
                }
                ExcelUtil<ShopPointEX> util = new ExcelUtil<>(ShopPointEX.class);
                util.exportExcel(response, shopPointEXList, "用户积分统计");
            }
            ExcelUtil<ShopPoint> util = new ExcelUtil<>(ShopPoint.class);
            util.exportExcel(response, shopPointIPage.getRecords(), "用户积分统计");
        }
    }
    /**
     * 保存门店积分流水
     * @param shopPoint
     */
    @PostMapping("/saveShopPoint")
    public void saveShopPoint(@RequestBody ShopPoint shopPoint){
        shopPointService.save(shopPoint);
    }
    /**
     * 保存门店积分流水
     * @param shopPoint
     */
    @PostMapping("/saveShopPointCopy")
    public void saveShopPointCopy(@RequestBody ShopPointCopy shopPoint){
        shopPointCopyMapper.insert(shopPoint);
    }
    @DeleteMapping("/deleteShopPointCopy")
    public void deleteShopPointCopy(@RequestParam("orderId") Long orderId, @RequestParam("type") List<Integer> type){
        shopPointCopyMapper.delete(new LambdaQueryWrapper<ShopPointCopy>().in(ShopPointCopy::getType, type)
                .eq(ShopPointCopy::getObjectId, orderId));
    }
    @DeleteMapping("/deleteShopPointCopyByIds")
    public void deleteShopPointCopyByIds(@RequestParam("ids") List<Long> ids){
        shopPointCopyMapper.deleteBatchIds(ids);
    }
    @PostMapping("/getShopPointCopy")
    public R<List<ShopPointCopy>> getShopPointCopy(@RequestParam("orderId") Long orderId, @RequestParam("type") List<Integer> type){
        List<ShopPointCopy> shopPointCopies = shopPointCopyMapper.selectList(new LambdaQueryWrapper<ShopPointCopy>().in(ShopPointCopy::getType, type)
                .eq(ShopPointCopy::getObjectId, orderId));
        return R.ok(shopPointCopies);
    }
}