package jj.tech.paolu.repository.mybatis.control;

import jj.tech.paolu.repository.mybatis.dao.CurrentG24Mapper;
import jj.tech.paolu.repository.mybatis.entity.CurrentG24;
import jj.tech.paolu.utils.IDHelp;
import jj.tech.paolu.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("mybatis/currentG24")
public class CurrentG24Controller {

    @Autowired
    public CurrentG24Mapper currentG24Mapper;

    @PostMapping("findById/{id}")
    public Object findById(@PathVariable("id") String id) {
        return R.SUCCESS(currentG24Mapper.selectByPrimaryKey(id).orElse(null));
    }

    @PostMapping("delete/{id}")
    public Object delete(@PathVariable("id") String id) {
        return R.SUCCESS(currentG24Mapper.deleteByPrimaryKey(id));
    }

    @PostMapping("save")
    public Object save(@RequestBody CurrentG24 record) {
        record.setId(IDHelp.getInstance().nextId());
        return R.SUCCESS(currentG24Mapper.insertSelective(record));
    }

    @PostMapping("update")
    public Object update(@RequestBody CurrentG24 record) {
        return R.SUCCESS(currentG24Mapper.updateByPrimaryKeySelective(record));
    }
}