package com.sysu.admin.site.lz;

import com.sysu.admin.controller.lz.group.LzGroup;
import com.sysu.admin.controller.lz.group.LzGroupService;
import com.sysu.admin.utils.shape.GeoCastUtil;
import com.xiesx.fastboot.base.result.BaseResult;
import com.xiesx.fastboot.base.result.R;
import org.locationtech.jts.geom.Point;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/site/lz_group")
@RestController
public class LzGroupController {

    @Autowired
    private LzGroupService lzGroupService;

    @RequestMapping("/list")
    public BaseResult list(){
        List<LzGroup> list = lzGroupService.findAll();
        list.forEach(lzGroup -> {
            lzGroup.setWkt(GeoCastUtil.geomToWkt(lzGroup.getPoint()));
        });
        return R.succ(list);
    }

    @RequestMapping("/save")
    public BaseResult save(@RequestBody LzGroup bean){
        bean.setPoint((Point) GeoCastUtil.wktToGeom(bean.getWkt()));
        lzGroupService.save(bean);
        return R.succ();
    }

}
