package com.pj.ht_trade_settlement;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pj.api.dto.TradeSettlementDto;
import com.pj.current.dto.APPLoginUserInfo;
import com.pj.current.satoken.StpAPPUserUtil;
import com.pj.project4sp.SP;
import com.pj.tb_order.TbOrderService;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 * Controller: ht_trade_settlement -- 航通交易结算表
 *
 * @author yzs
 */
@RestController
@RequestMapping("/app/HtTradeSettlement/")
public class HtTradeSettlementApi {

    /**
     * 底层 Service 对象
     */
    @Autowired
    HtTradeSettlementService htTradeSettlementService;
    @Resource
    private TbOrderService tbOrderService;

    /**
     * 查 - 根据id
     */
    @RequestMapping("getById")
    public AjaxJson getById(String id) {
        StpAPPUserUtil.isLogin();
        HtTradeSettlement h = htTradeSettlementService.getById(id);
        return AjaxJson.getSuccessData(h);
    }
   @RequestMapping("getByIds")
    public AjaxJson getByIds() {
        StpAPPUserUtil.isLogin();
       List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class);
        List<HtTradeSettlement> list = htTradeSettlementService.listByIds(ids);
        list.forEach(htTradeSettlement -> {
           double upPrice= tbOrderService.sumUpPrice(htTradeSettlement.getId());
           htTradeSettlement.setSumUpPrice(upPrice+"");
        });
        return AjaxJson.getSuccessData(list);
    }

    /**
     * 查集合 - 根据条件（参数为空时代表忽略指定条件）
     */
    @RequestMapping("getList")
    public AjaxJson getList() {
        if (!StpAPPUserUtil.isLogin()) {
            return AjaxJson.getError("未登录");
        }
        SoMap so = SoMap.getRequestSoMap();
        List<HtTradeSettlement> list = htTradeSettlementService.getList(so.startPage());
        return AjaxJson.getPageData(so.getDataCount(), list);
    }

    /**
     * 获取整车在售列表
     *
     * @return
     */
    @RequestMapping("getOnSaleList")
    public AjaxJson getOnSaleList() {
        if (!StpAPPUserUtil.isLogin()) {
            return AjaxJson.getError("用户未登录");
        }
        SoMap so = SoMap.getRequestSoMap();
        List<HtTradeSettlement> list = htTradeSettlementService.getOnSaleList(so.startPage());
        return AjaxJson.getPageData(so.getDataCount(), list);
    }


}
