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

import jj.tech.paolu.repository.mybatis.dao.HistoryG24Mapper;
import jj.tech.paolu.repository.mybatis.entity.HistoryG24;
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/historyG24")
public class HistoryG24Controller {

    @Autowired
    public HistoryG24Mapper historyG24Mapper;

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

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

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

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