package com.pj.project.relation_type_item;

import java.util.List;

import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import com.pj.utils.sg.*;
import com.pj.project4sp.SP;

import com.pj.current.satoken.StpUserUtil;
import cn.dev33.satoken.annotation.SaCheckPermission;


/**
 * Controller: relation_type_item --
 *
 * @author qzy
 */
@RestController
@RequestMapping("/RelationTypeItem/")
public class RelationTypeItemController {

    /**
     * 底层 Service 对象
     */
    @Autowired
    RelationTypeItemService relationTypeItemService;


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

    @RequestMapping("delete")
    public AjaxJson delete(String id,String typeId) {
        relationTypeItemService.removeRelation(id,typeId);
        return AjaxJson.getSuccess();
    }

    @RequestMapping("setBatch")
    public AjaxJson setBatch() {
        SoMap so = SoMap.getRequestSoMap();
        String typeId = so.getString("typeId");
        String itemIds = so.getString("itemIds");
        relationTypeItemService.setBatch(typeId, itemIds);
        return AjaxJson.getSuccess();
    }

    @RequestMapping("setSingle")
    public AjaxJson setSingle() {
        SoMap so = SoMap.getRequestSoMap();
        String typeId = so.getString("typeId");
        String itemId = so.getString("itemId");
        relationTypeItemService.setSingle(typeId, itemId);
        return AjaxJson.getSuccess();
    }

    @RequestMapping("updateStatus")
    public AjaxJson updateStatus() {
        SoMap so = SoMap.getRequestSoMap();
        String typeId = so.getString("typeId");
        String itemId = so.getString("itemId");
        int need = so.getInt("need");
        relationTypeItemService.updateStatus(typeId, itemId,need);
        return AjaxJson.getSuccess();
    }
    @RequestMapping("updateNum")
    public AjaxJson updateNum() {
        SoMap so = SoMap.getRequestSoMap();
        String typeId = so.getString("typeId");
        String itemId = so.getString("itemId");
        int inc = so.getInt("inc");
        relationTypeItemService.updateNum(typeId, itemId,inc);
        return AjaxJson.getSuccess();
    }
    @RequestMapping("updateRemarkMust")
    public AjaxJson updateRemarkMust() {
        SoMap so = SoMap.getRequestSoMap();
        String typeId = so.getString("typeId");
        String itemId = so.getString("itemId");
        int mustRemark = so.getInt("mustRemark");
        relationTypeItemService.updateRemarkMust(typeId, itemId,mustRemark);
        return AjaxJson.getSuccess();
    }
    @RequestMapping("updateRemarkNeed")
    public AjaxJson updateRemarkNeed() {
        SoMap so = SoMap.getRequestSoMap();
        String typeId = so.getString("typeId");
        String itemId = so.getString("itemId");
        int needRemark = so.getInt("needRemark");
        relationTypeItemService.updateRemarkNeed(typeId, itemId,needRemark);
        return AjaxJson.getSuccess();
    }


}
