package com.fjhx.controller.factory;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.constants.RedisConstant;
import com.fjhx.entity.factory.FactoryProduct;
import com.fjhx.params.factory.FactoryProductVo;
import com.fjhx.service.factory.FactoryProductService;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.tool.api.R;
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;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-12-14
 */
@RestController
@RequestMapping("/factoryProduct")
public class FactoryProductController {

    @Autowired
    private FactoryProductService factoryProductService;

    @Resource
    private BladeRedis redisCache;

    @PostMapping("/getData")
    public R getData(@RequestBody FactoryProduct factoryProduct) {
        Object data = redisCache.get(RedisConstant.DEVICE_PREFIX + factoryProduct.getEquipmentNo());
        return R.success(data);
    }

    @PostMapping("/list")
    public R list(@RequestBody Map<String, Object> condition) {
        List<FactoryProduct> list = factoryProductService.list();
        return R.success(list);
    }

    @PostMapping("/page")
    public R page(@RequestBody Map<String, Object> condition) {
        Page<FactoryProduct> result = factoryProductService.getPage(condition);
        return R.success(result);
    }

    @PostMapping("/add")
    public R add(@RequestBody FactoryProductVo factoryProductVo) {
        factoryProductService.add(factoryProductVo);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody FactoryProductVo factoryProductVo) {
        factoryProductService.edit(factoryProductVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody FactoryProductVo factoryProductVo) {
        factoryProductService.delete(factoryProductVo);
        return R.success();
    }

}

