智慧农业后台管理
Administrator
2022-05-10 32b0c2663c403998bee7a880f48dff6a6ce2bce4
农场接口修改,新增农场证书接口
7 files modified
7 files added
470 ■■■■■ changed files
src/main/java/org/springblade/modules/farm/controller/FarmController.java 24 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/controller/FarmPaperController.java 122 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/entity/Farm.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/entity/FarmPaper.java 81 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/mapper/FarmMapper.java 16 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/mapper/FarmMapper.xml 29 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/mapper/FarmPaperMapper.java 27 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/mapper/FarmPaperMapper.xml 10 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/service/FarmPaperService.java 26 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/service/FarmService.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/service/impl/FarmPaperServiceImpl.java 30 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/service/impl/FarmServiceImpl.java 40 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/vo/FarmPaperVO.java 18 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/vo/FarmVO.java 21 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farm/controller/FarmController.java
@@ -31,6 +31,7 @@
import org.springblade.modules.farm.vo.FarmVO;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Date;
/**
 * 农场控制器
@@ -52,6 +53,15 @@
    @ApiOperation(value = "详情", notes = "传入farm")
    public R<Farm> detail(Farm farm) {
        Farm detail = farmService.getOne(Condition.getQueryWrapper(farm));
        return R.data(detail);
    }
    /**
     * 详情信息(自定义查询)
     */
    @GetMapping("/details")
    public R<Farm> details(FarmVO farm) {
        Farm detail = farmService.getFarmInfo(farm);
        return R.data(detail);
    }
@@ -84,6 +94,8 @@
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入farm")
    public R save(@Valid @RequestBody Farm farm) {
        farm.setCreateTime(new Date());
        farm.setUpdateTime(new Date());
        return R.status(farmService.save(farm));
    }
@@ -94,7 +106,17 @@
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入farm")
    public R update(@Valid @RequestBody Farm farm) {
        return R.status(farmService.updateById(farm));
        farm.setUpdateTime(new Date());
        //坐标转换
        if (null!=farm.getPosition() && !farm.getPosition().equals("")) {
            //替换逗号为空格
            String sNull = farm.getPosition().replaceAll(",", " ");
            //替换分号为逗号
            String replaceAll = sNull.replaceAll(";", ",");
            farm.setPosition("'POLYGON((" + replaceAll + "))'");
        }
        //更新并返回
        return R.status(farmService.updateFarmById(farm));
    }
    /**
src/main/java/org/springblade/modules/farm/controller/FarmPaperController.java
New file
@@ -0,0 +1,122 @@
/*
 *      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.modules.farm.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
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.modules.farm.entity.FarmPaper;
import org.springblade.modules.farm.service.FarmPaperService;
import org.springblade.modules.farm.vo.FarmPaperVO;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
/**
 * 农场检测报告/证书控制器
 * @since 2022-05-10
 * @author zhongrj
 */
@RestController
@AllArgsConstructor
@RequestMapping("/farmPaper")
public class FarmPaperController extends BladeController {
    private final FarmPaperService farmPaperService;
    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入farmPaper")
    public R<FarmPaper> detail(FarmPaper farmPaper) {
        FarmPaper detail = farmPaperService.getOne(Condition.getQueryWrapper(farmPaper));
        return R.data(detail);
    }
    /**
     * 分页
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入farmPaper")
    public R<IPage<FarmPaper>> list(FarmPaper farmPaper, Query query) {
        IPage<FarmPaper> pages = farmPaperService.page(Condition.getPage(query), Condition.getQueryWrapper(farmPaper));
        return R.data(pages);
    }
    /**
     * 自定义分页
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入farmPaper")
    public R<IPage<FarmPaperVO>> page(FarmPaperVO farmPaper, Query query) {
        IPage<FarmPaperVO> pages = farmPaperService.selectFarmPaperPage(Condition.getPage(query), farmPaper);
        return R.data(pages);
    }
    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入farmPaper")
    public R save(@Valid @RequestBody FarmPaper farmPaper) {
        return R.status(farmPaperService.save(farmPaper));
    }
    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入farmPaper")
    public R update(@Valid @RequestBody FarmPaper farmPaper) {
        return R.status(farmPaperService.updateById(farmPaper));
    }
    /**
     * 新增或修改
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入farmPaper")
    public R submit(@Valid @RequestBody FarmPaper farmPaper) {
        return R.status(farmPaperService.saveOrUpdate(farmPaper));
    }
    /**
     * 删除
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(farmPaperService.removeByIds(Func.toLongList(ids)));
    }
}
src/main/java/org/springblade/modules/farm/entity/Farm.java
@@ -29,7 +29,7 @@
    /**
     * 农场名称
     */
    private Integer farmName;
    private String farmName;
    /**
     * 农场地址
@@ -76,5 +76,16 @@
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    /**
     * 用户id
     */
    private String userId;
}
src/main/java/org/springblade/modules/farm/entity/FarmPaper.java
New file
@@ -0,0 +1,81 @@
package org.springblade.modules.farm.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
 * 农场检测报告/证书实体类
 * @since 2022-05-10
 * @author zhongrj
 */
@Data
@TableName("sys_farm_paper")
public class FarmPaper implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 主键id
     */
    @TableId(value = "id",type = IdType.AUTO)
    private Integer id;
    /**
     * 农场名称
     */
    private Integer farmName;
    /**
     * 农场地址
     */
    private String farmAddress;
    /**
     * 土地流转面积
     */
    private String farmArea;
    /**
     * 口号
     */
    private String slogan;
    /**
     * 介绍
     */
    private String introduce;
    /**
     * 农场环境照片(多张)
     */
    private String picture;
    /**
     * 农场位置(面)
     */
    private String position;
    /**
     * 租户id
     */
    private String tenantId;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
}
src/main/java/org/springblade/modules/farm/mapper/FarmMapper.java
@@ -18,6 +18,7 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.farm.entity.Farm;
import org.springblade.modules.farm.vo.FarmVO;
@@ -37,6 +38,19 @@
     * @param farm
     * @return
     */
    List<FarmVO> selectFarmPage(IPage page, FarmVO farm);
    List<FarmVO> selectFarmPage(@Param("page") IPage page,@Param("farm") FarmVO farm);
    /**
     * 更新农场信息
     * @param farm
     * @return
     */
    int updateFarmById(@Param("farm") Farm farm);
    /**
     * 详情信息(自定义查询)
     * @param farm
     * @return
     */
    Farm getFarmInfo(@Param("farm") FarmVO farm);
}
src/main/java/org/springblade/modules/farm/mapper/FarmMapper.xml
@@ -4,7 +4,34 @@
    <!--自定义查询农场分页数据-->
    <select id="selectFarmPage" resultType="org.springblade.modules.farm.vo.FarmVO">
        select * from sys_farm where 1=1
        select
        id,farm_name,farm_address,farm_area,slogan,introduce,picture,ST_ASTEXT(position) as position,user_id
        from
        sys_farm where 1=1
    </select>
    <!--自定义修改电子围栏数据-->
    <update id="updateFarmById">
        update sys_farm set farm_name = #{farm.farmName},
        farm_address = #{farm.farmAddress},
        farm_area = #{farm.farmArea},
        slogan = #{farm.slogan},
        introduce = #{farm.introduce},
        picture = #{farm.picture},
        <if test="farm.position!=null and farm.position!=''">
            position = ST_GeomFromText(${farm.position}),
        </if>
        update_time = #{farm.updateTime}
        where id = #{farm.id}
    </update>
    <!--详情信息(自定义查询)-->
    <select id="getFarmInfo" resultType="org.springblade.modules.farm.vo.FarmVO">
        select
        id,farm_name,farm_address,farm_area,slogan,introduce,picture,ST_ASTEXT(position) as position,user_id
        from
        sys_farm
        where 1=1
        and user_id = #{farm.userId}
    </select>
</mapper>
src/main/java/org/springblade/modules/farm/mapper/FarmPaperMapper.java
New file
@@ -0,0 +1,27 @@
package org.springblade.modules.farm.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.farm.entity.FarmPaper;
import org.springblade.modules.farm.vo.FarmPaperVO;
import java.util.List;
/**
 *  农场检测报告/证书Mapper 接口
 * @since 2022-05-10
 * @author zhongrj
 */
public interface FarmPaperMapper extends BaseMapper<FarmPaper> {
    /**
     * 自定义分页
     *
     * @param page
     * @param farmPaper
     * @return
     */
    List<FarmPaperVO> selectFarmPaperPage(@Param("page") IPage page, @Param("farmPaper") FarmPaperVO farmPaper);
}
src/main/java/org/springblade/modules/farm/mapper/FarmPaperMapper.xml
New file
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.modules.farm.mapper.FarmPaperMapper">
    <!--自定义查询农场检测报告/证书分页数据-->
    <select id="selectFarmPaperPage" resultType="org.springblade.modules.farm.vo.FarmPaperVO">
        select * from sys_farm_paper where 1=1
    </select>
</mapper>
src/main/java/org/springblade/modules/farm/service/FarmPaperService.java
New file
@@ -0,0 +1,26 @@
package org.springblade.modules.farm.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.modules.farm.entity.FarmPaper;
import org.springblade.modules.farm.vo.FarmPaperVO;
/**
 * 农场检测报告/证书服务类
 * @since 2022-05-10
 * @author zhongrj
 */
public interface FarmPaperService extends IService<FarmPaper> {
    /**
     * 自定义分页
     *
     * @param page
     * @param farmPaper
     * @return
     */
    IPage<FarmPaperVO> selectFarmPaperPage(IPage<FarmPaperVO> page, FarmPaperVO farmPaper);
}
src/main/java/org/springblade/modules/farm/service/FarmService.java
@@ -23,4 +23,17 @@
    IPage<FarmVO> selectFarmPage(IPage<FarmVO> page, FarmVO farm);
    /**
     * 更新农场信息
     * @param farm
     * @return
     */
    boolean updateFarmById(Farm farm);
    /**
     * 详情信息(自定义查询)
     * @param farm
     * @return
     */
    Farm getFarmInfo(FarmVO farm);
}
src/main/java/org/springblade/modules/farm/service/impl/FarmPaperServiceImpl.java
New file
@@ -0,0 +1,30 @@
package org.springblade.modules.farm.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.modules.farm.entity.FarmPaper;
import org.springblade.modules.farm.mapper.FarmPaperMapper;
import org.springblade.modules.farm.vo.FarmPaperVO;
import org.springframework.stereotype.Service;
import org.springblade.modules.farm.service.FarmPaperService;
/**
 * 农场检测报告/证书服务实现类
 * @since 2022-05-10
 * @author zhongrj
 */
@Service
public class FarmPaperServiceImpl extends ServiceImpl<FarmPaperMapper, FarmPaper> implements FarmPaperService {
    /**
     * 自定义分页
     * @param page
     * @param farm
     * @return
     */
    @Override
    public IPage<FarmPaperVO> selectFarmPaperPage(IPage<FarmPaperVO> page, FarmPaperVO farm) {
        return page.setRecords(baseMapper.selectFarmPaperPage(page, farm));
    }
}
src/main/java/org/springblade/modules/farm/service/impl/FarmServiceImpl.java
@@ -1,19 +1,3 @@
/*
 *      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.modules.farm.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -42,4 +26,28 @@
        return page.setRecords(baseMapper.selectFarmPage(page, farm));
    }
    /**
     * 更新农场信息
     * @param farm
     * @return
     */
    @Override
    public boolean updateFarmById(Farm farm) {
        //更新
        int i = baseMapper.updateFarmById(farm);
        if (i>0){
            return true;
        }
        return false;
    }
    /**
     * 详情信息(自定义查询)
     * @param farm
     * @return
     */
    @Override
    public Farm getFarmInfo(FarmVO farm) {
        return baseMapper.getFarmInfo(farm);
    }
}
src/main/java/org/springblade/modules/farm/vo/FarmPaperVO.java
New file
@@ -0,0 +1,18 @@
package org.springblade.modules.farm.vo;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.modules.farm.entity.FarmPaper;
import org.springblade.modules.resource.entity.Oss;
/**
 * 农场检测报告/证书VO
 * @since 2022-05-10
 * @author zhongrj
 */
@Data
public class FarmPaperVO extends FarmPaper {
    private static final long serialVersionUID = 1L;
}
src/main/java/org/springblade/modules/farm/vo/FarmVO.java
@@ -3,27 +3,16 @@
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.modules.farm.entity.Farm;
import org.springblade.modules.resource.entity.Oss;
/**
 * OssVO
 *
 * @author Chill
 * 农场VO
 * @since 2022-05-10
 * @author zhongrj
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "OssVO对象", description = "对象存储表")
public class FarmVO extends Oss {
public class FarmVO extends Farm {
    private static final long serialVersionUID = 1L;
    /**
     * 分类名
     */
    private String categoryName;
    /**
     * 是否启用
     */
    private String statusName;
}