/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package org.springblade.jfpt.suser.controller;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import lombok.AllArgsConstructor;
|
import org.springblade.core.boot.ctrl.BladeController;
|
import org.springblade.core.mp.support.Condition;
|
import org.springblade.core.mp.support.Query;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.jfpt.suser.entity.Suser;
|
import org.springblade.jfpt.suser.service.ISuserService;
|
import org.springblade.jfpt.suser.vo.SuserVO;
|
import org.springblade.jfpt.suser.vo.SuserVOs;
|
import org.springblade.jfpt.suser.wrapper.SuserWrapper;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletResponse;
|
import javax.validation.Valid;
|
import java.text.DecimalFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 控制器
|
*
|
* @author BladeX
|
* @since 2020-06-29
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("suser/suser")
|
@Api(value = "", tags = "接口")
|
public class SuserController extends BladeController {
|
|
private final ISuserService suserService;
|
|
/**
|
* 详情
|
*/
|
@GetMapping("/detail")
|
@ApiOperationSupport(order = 1)
|
@ApiOperation(value = "详情", notes = "传入suser")
|
public R<SuserVO> detail(Suser suser, HttpServletResponse response) {
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
|
response.setHeader("Access-Control-Allow-Credentials","true");
|
Suser detail = suserService.getOne(Condition.getQueryWrapper(suser));
|
return R.data(SuserWrapper.build().entityVO(detail));
|
}
|
|
/**
|
* 分页
|
*/
|
@GetMapping("/list")
|
@ApiOperationSupport(order = 2)
|
@ApiOperation(value = "分页", notes = "传入suser")
|
public R<IPage<SuserVO>> list(Suser suser, Query query) {
|
IPage<Suser> pages = suserService.page(Condition.getPage(query), Condition.getQueryWrapper(suser));
|
return R.data(SuserWrapper.build().pageVO(pages));
|
}
|
|
|
/**
|
* 自定义分页
|
*/
|
@GetMapping("/page")
|
@ApiOperationSupport(order = 3)
|
@ApiOperation(value = "分页", notes = "传入suser")
|
public R<IPage<SuserVOs>> page(SuserVOs suser, Query query) {
|
IPage<SuserVOs> pages = suserService.selectSuserPage(Condition.getPage(query), suser);
|
int size = pages.getRecords().size();
|
for(int i=0;i<size;i++){
|
String coordinate = pages.getRecords().get(i).getCoordinate();
|
String substring = coordinate.substring(6, coordinate.length() - 1);
|
//jd
|
String a = substring.substring(0, substring.indexOf(" "));
|
double d=Double.parseDouble(a);
|
DecimalFormat df=new DecimalFormat("#.000000");
|
String jd=df.format(d);
|
|
//wd
|
String b = substring.substring(substring.indexOf(" ")+1, substring.length());
|
double ds=Double.parseDouble(b);
|
String wd=df.format(ds);
|
pages.getRecords().get(i).setJd(jd);
|
pages.getRecords().get(i).setWd(wd);
|
}
|
return R.data(pages);
|
}
|
|
/**
|
* 详情
|
*/
|
@GetMapping("/details")
|
@ApiOperationSupport(order = 1)
|
@ApiOperation(value = "详情", notes = "传入suser")
|
public R<SuserVOs> detail(String id) {
|
SuserVOs detail = suserService.selectInfo(id);
|
String coordinate = detail.getCoordinate();
|
String substring = coordinate.substring(6, coordinate.length() - 1);
|
//jd
|
String jd = substring.substring(0, substring.indexOf(" "));
|
//wd
|
String wd = substring.substring(substring.indexOf(" ")+1, substring.length());
|
detail.setJd(jd);
|
detail.setWd(wd);
|
return R.data(detail);
|
}
|
|
|
/**
|
* 新增
|
*/
|
@PostMapping("/save")
|
@ApiOperationSupport(order = 4)
|
@ApiOperation(value = "新增", notes = "传入suser")
|
public R save(@Valid @RequestBody SuserVO suser) {
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String time = df.format(new Date());
|
String numberForPK = getNumberForPK();
|
String ynumber = numberForPK;
|
String yname = suser.getYname();
|
String phone = suser.getPhone();
|
String address = suser.getAddress();
|
String type = suser.getType();
|
String dj = suser.getDj();
|
String information = suser.getInformation();
|
String jd=suser.getJd();
|
String wd=suser.getWd();
|
String createtime =time;
|
String addvcd=suser.getAddvcd();
|
suserService.s(ynumber, yname, phone, address, type, dj, information, jd, wd,createtime,addvcd);
|
return R.success("成功");
|
}
|
|
/**
|
* 修改
|
*//*
|
@PostMapping("/update")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "修改", notes = "传入suser")
|
public R update(@Valid @RequestBody Suser suser) {
|
return R.status(suserService.updateById(suser));
|
}*/
|
|
/**
|
* 新增或修改
|
*/
|
@PostMapping("/submit")
|
@ApiOperationSupport(order = 6)
|
@ApiOperation(value = "新增或修改", notes = "传入suser")
|
public R submit(@Valid @RequestBody Suser suser) {
|
return R.status(suserService.saveOrUpdate(suser));
|
}
|
|
|
/**
|
* 修改
|
*/
|
@PostMapping("/update")
|
@ApiOperation(value = "新增", notes = "传入suser")
|
public R update(@Valid @RequestBody SuserVO suser) {
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String time = df.format(new Date());
|
Integer id = suser.getId();
|
String numberForPK = getNumberForPK();
|
String ynumber = numberForPK;
|
String yname = suser.getYname();
|
String phone = suser.getPhone();
|
String address = suser.getAddress();
|
String type = suser.getType();
|
String dj = suser.getDj();
|
String information = suser.getInformation();
|
String jd=suser.getJd();
|
String wd=suser.getWd();
|
String createtime =time;
|
String addvcd=suser.getAddvcd();
|
suserService.updateOne(id,ynumber, yname, phone, address, type, dj, information, jd, wd,createtime,addvcd);
|
return R.success("成功");
|
}
|
|
|
/**
|
* 删除
|
*/
|
@PostMapping("/remove")
|
@ApiOperationSupport(order = 8)
|
@ApiOperation(value = "删除", notes = "传入ids")
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
return R.status(suserService.removeByIds(Func.toLongList(ids)));
|
}
|
|
/*public static void main(String[] args) {
|
String a="POINT(126.5 26.35)";
|
String substring = a.substring(6, a.length() - 1);
|
String substring1 = substring.substring(0, substring.indexOf(" "));
|
System.out.println(substring1);
|
String substring2 = substring.substring(substring.indexOf(" ")+1, substring.length());
|
System.out.println(substring2);
|
|
}*/
|
|
@GetMapping("/selectName")
|
public R<List<SuserVOs>> selectName() {
|
return R.data(suserService.selectName());
|
}
|
|
/**
|
* 业主列表信息
|
* @param type
|
* @param dj
|
* @return
|
*/
|
@GetMapping("/selectList")
|
public R selectList(String type, String dj, HttpServletResponse response) {
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
|
response.setHeader("Access-Control-Allow-Credentials","true");
|
return R.data(suserService.selectList(type, dj));
|
}
|
|
public static String getNumberForPK(){
|
|
String id="CLRK";
|
|
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
String temp = sf.format(new Date());
|
|
int random=(int) (Math.random()*10000);
|
|
if(random<1000) {
|
|
String random1 = "0"+random;
|
|
id=id+temp+random1;
|
|
}
|
|
else { id=id+temp+random; }
|
|
return id;
|
}
|
|
}
|