package com.pj.project.tb_item_type;

import java.math.BigDecimal;
import java.util.List;

import com.pj.current.config.MyConfig;
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;

import javax.annotation.Resource;


/**
 * Controller: tb_item_type -- 业务项类型
 *
 * @author qzy
 */
@RestController
@RequestMapping("/TbItemType/")
public class TbItemTypeController {

    /**
     * 底层 Service 对象
     */
    @Autowired
    TbItemTypeService tbItemTypeService;
    @Resource
    private MyConfig myConfig;

    /**
     * 增
     */
    @RequestMapping("add")
    @SaCheckPermission(TbItemType.PERMISSION_CODE)
    @Transactional(rollbackFor = Exception.class)
    public AjaxJson add(TbItemType t) {
        tbItemTypeService.save(t);
        return AjaxJson.getSuccess();
    }

    /**
     * 删
     */
    @RequestMapping("delete")
    @SaCheckPermission(TbItemType.PERMISSION_CODE)
    public AjaxJson delete(String id) {
        tbItemTypeService.delete(id);
        return AjaxJson.getSuccess();
    }

    /**
     * 删 - 根据id列表
     */
    @RequestMapping("deleteByIds")
    @SaCheckPermission(TbItemType.PERMISSION_CODE)
    public AjaxJson deleteByIds() {
        List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class);
        int line = SP.publicMapper.deleteByIds(TbItemType.TABLE_NAME, ids);
        return AjaxJson.getByLine(line);
    }

    /**
     * 改
     */
    @RequestMapping("update")
    public AjaxJson update(TbItemType t) {
        tbItemTypeService.updateItemType(t);
        return AjaxJson.getSuccess();
    }


    /**
     * 查 - 根据id
     */
    @RequestMapping("getById")
    public AjaxJson getById(String id) {
        TbItemType t = tbItemTypeService.getById(id);
        return AjaxJson.getSuccessData(t);
    }
    /**
     * 查 - 根据id====灵活业务专用
     */
    @RequestMapping("getItemTypeById")
    public AjaxJson getItemTypeById(String id) {
        TbItemType t = tbItemTypeService.getItemTypeById(id);
        return AjaxJson.getSuccessData(t);
    }

    /**
     * 查集合 - 根据条件（参数为空时代表忽略指定条件）
     */
    @RequestMapping("getList")
    public AjaxJson getList() {
        SoMap so = SoMap.getRequestSoMap();


        List<TbItemType> list = tbItemTypeService.getList(so.startPage());
        return AjaxJson.getPageData(so.getDataCount(), list);
    }

    @RequestMapping("getPayStep")
    public AjaxJson getPayStep() {
        return AjaxJson.getSuccessData(TbItemType.PayStep.getList());
    }

    /**
     * 查集合 - 根据条件（参数为空时代表忽略指定条件）
     */
    @RequestMapping("getQrcode")
    public AjaxJson getQrcode(String id) {
        String url = myConfig.getWebDomain() + "/pages/onely-disinfect/type-business?typeId=" + id;
        return AjaxJson.getSuccessData(url);
    }



    @RequestMapping("getTypeByGoodsId")
    public AjaxJson getTypeByGoodsId(Long goodsId) {
        return AjaxJson.getSuccessData(tbItemTypeService.getTypeByGoodsId(goodsId));
    }


    // ------------------------- 前端接口 -------------------------


}
