package com.heyu.api.controller.mm;


import com.heyu.api.alibaba.request.mm.FrontManagerSortRequest;
import com.heyu.api.common.annotation.Describe;
import com.heyu.api.data.dao.vv.VvProductDao;
import com.heyu.api.data.entity.vv.VvProductEntity;
import com.heyu.api.data.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/mm/front/manager")
public class AdminFrontManagerController {

    @Autowired
    private VvProductDao vvProductDao;


    /***
     * 排序
     */
    @Describe("首页商品排序")
    @RequestMapping("/sort")
    public R sort(@RequestBody FrontManagerSortRequest sortRequest) {
        List<VvProductEntity> list = vvProductDao.selectVvProductByIds(sortRequest.getProductIds());
        List<Long> categoryIds = sortRequest.getProductIds();
        for (VvProductEntity vvProduct : list) {
            int index = categoryIds.indexOf(vvProduct.getId()) + 1;
            vvProduct.setDefaultSort(index);
            vvProductDao.updateVvProductById(vvProduct);
        }
        return R.ok().setData("保存成功");
    }




}
