¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.controller.data; |
| | | |
| | | import com.lf.server.annotation.SysLog; |
| | | import com.lf.server.controller.all.BaseController; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.data.PublishEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.service.data.PublishService; |
| | | import com.lf.server.service.sys.TokenService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * æ°æ®åå¸ |
| | | * @author WWW |
| | | */ |
| | | @Api(tags = "è¿ç»´ç®¡ç\\æ°æ®åå¸") |
| | | @RestController |
| | | @RequestMapping("/publish") |
| | | public class PublishController extends BaseController { |
| | | @Autowired |
| | | PublishService publishService; |
| | | |
| | | @Autowired |
| | | TokenService tokenService; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ¥è¯¢è®°å½æ°") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "åç§°", dataType = "String", paramType = "query", required = false, example = "") |
| | | }) |
| | | @GetMapping({"/selectCount"}) |
| | | public ResponseMsg<Integer> selectCount(String name) { |
| | | try { |
| | | int count = publishService.selectCount(name); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "å页æ¥è¯¢") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "åç§°", dataType = "String", paramType = "query", example = ""), |
| | | @ApiImplicitParam(name = "pageSize", value = "æ¯é¡µæ¡æ°", dataType = "Integer", paramType = "query", example = "10"), |
| | | @ApiImplicitParam(name = "pageIndex", value = "å页æ°ï¼ä»1å¼å§ï¼", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/selectByPage") |
| | | public ResponseMsg<List<PublishEntity>> selectByPage(String name, Integer pageSize, Integer pageIndex) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("æ¯é¡µé¡µæ°æå页æ°å°äº1", null); |
| | | } |
| | | |
| | | List<PublishEntity> rs = publishService.selectByPage(name, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "å页æ¥è¯¢å¹¶è¿åè®°å½æ°") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "åç§°", dataType = "String", paramType = "query", example = ""), |
| | | @ApiImplicitParam(name = "pageSize", value = "æ¯é¡µæ¡æ°", dataType = "Integer", paramType = "query", example = "10"), |
| | | @ApiImplicitParam(name = "pageIndex", value = "å页æ°ï¼ä»1å¼å§ï¼", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/selectByPageAndCount") |
| | | public ResponseMsg<List<PublishEntity>> selectByPageAndCount(String name, Integer pageSize, Integer pageIndex) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("æ¯é¡µé¡µæ°æå页æ°å°äº1", null); |
| | | } |
| | | |
| | | int count = publishService.selectCount(name); |
| | | if (count == 0) { |
| | | return success(0, null); |
| | | } |
| | | |
| | | List<PublishEntity> rs = publishService.selectByPage(name, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(count, rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ¥è¯¢ææ") |
| | | @GetMapping(value = "/selectAll") |
| | | public ResponseMsg<List<PublishEntity>> selectAll() { |
| | | try { |
| | | List<PublishEntity> list = publishService.selectAll(); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ ¹æ®IDæ¥è¯¢") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "ID", dataType = "int", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/selectById") |
| | | public ResponseMsg<PublishEntity> selectById(int id) { |
| | | try { |
| | | PublishEntity entity = publishService.selectById(id); |
| | | |
| | | return success(entity); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æå
¥ä¸æ¡") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "entity", value = "å®ä½ç±»", dataType = "PublishEntity", paramType = "body") |
| | | }) |
| | | @PostMapping(value = "/insert", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> insert(@RequestBody PublishEntity entity, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | entity.setCreateUser(ue.getId()); |
| | | } |
| | | |
| | | int count = publishService.insert(entity); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æå
¥å¤æ¡") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "list", value = "å®ä½ç±»éå", dataType = "PublishEntity", paramType = "body") |
| | | }) |
| | | @PostMapping(value = "/inserts", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> inserts(@RequestBody List<PublishEntity> list, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | for (PublishEntity entity : list) { |
| | | entity.setCreateUser(ue.getId()); |
| | | } |
| | | } |
| | | |
| | | int count = publishService.inserts(list); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "å é¤ä¸æ¡") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/delete") |
| | | public ResponseMsg<Integer> delete(int id) { |
| | | try { |
| | | int count = publishService.delete(id); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "å é¤å¤æ¡") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "ids", value = "IDæ°ç»", dataType = "Integer", paramType = "query", example = "1,2") |
| | | }) |
| | | @GetMapping(value = "/deletes") |
| | | public ResponseMsg<Integer> deletes(@RequestParam List<Integer> ids) { |
| | | try { |
| | | if (ids == null || ids.isEmpty()) { |
| | | return fail("idæ°ç»ä¸è½ä¸ºç©º", -1); |
| | | } |
| | | |
| | | int count = publishService.deletes(ids); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ´æ°ä¸æ¡") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "entity", value = "å®ä½ç±»", dataType = "PublishEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/update", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> update(@RequestBody PublishEntity entity, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | entity.setUpdateUser(ue.getId()); |
| | | } |
| | | |
| | | int count = publishService.update(entity); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ´æ°å¤æ¡") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "list", value = "å®ä½ç±»éå", dataType = "PublishEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/updates", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> updates(@RequestBody List<PublishEntity> list, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | for (PublishEntity entity : list) { |
| | | entity.setUpdateUser(ue.getId()); |
| | | } |
| | | } |
| | | |
| | | int count = publishService.updates(list); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.entity.data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.sql.Timestamp; |
| | | |
| | | /** |
| | | * æ°æ®åå¸ |
| | | * @author WWW |
| | | */ |
| | | public class PublishEntity implements Serializable { |
| | | private static final long serialVersionUID = -386130556178340032L; |
| | | |
| | | private int id; |
| | | |
| | | private String name; |
| | | |
| | | private String url; |
| | | |
| | | private String path; |
| | | |
| | | private String type; |
| | | |
| | | private int status; |
| | | |
| | | private String dirid; |
| | | |
| | | private String depid; |
| | | |
| | | private int min; |
| | | |
| | | private int max; |
| | | |
| | | private String json; |
| | | |
| | | private int createUser; |
| | | |
| | | private Timestamp createTime; |
| | | |
| | | private int updateUser; |
| | | |
| | | private Timestamp updateTime; |
| | | |
| | | private String geom; |
| | | |
| | | private String bak; |
| | | |
| | | public PublishEntity() { |
| | | } |
| | | |
| | | public int getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(int id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getUrl() { |
| | | return url; |
| | | } |
| | | |
| | | public void setUrl(String url) { |
| | | this.url = url; |
| | | } |
| | | |
| | | public String getPath() { |
| | | return path; |
| | | } |
| | | |
| | | public void setPath(String path) { |
| | | this.path = path; |
| | | } |
| | | |
| | | public String getType() { |
| | | return type; |
| | | } |
| | | |
| | | public void setType(String type) { |
| | | this.type = type; |
| | | } |
| | | |
| | | public int getStatus() { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(int status) { |
| | | this.status = status; |
| | | } |
| | | |
| | | public String getDirid() { |
| | | return dirid; |
| | | } |
| | | |
| | | public void setDirid(String dirid) { |
| | | this.dirid = dirid; |
| | | } |
| | | |
| | | public String getDepid() { |
| | | return depid; |
| | | } |
| | | |
| | | public void setDepid(String depid) { |
| | | this.depid = depid; |
| | | } |
| | | |
| | | public int getMin() { |
| | | return min; |
| | | } |
| | | |
| | | public void setMin(int min) { |
| | | this.min = min; |
| | | } |
| | | |
| | | public int getMax() { |
| | | return max; |
| | | } |
| | | |
| | | public void setMax(int max) { |
| | | this.max = max; |
| | | } |
| | | |
| | | public String getJson() { |
| | | return json; |
| | | } |
| | | |
| | | public void setJson(String json) { |
| | | this.json = json; |
| | | } |
| | | |
| | | public int getCreateUser() { |
| | | return createUser; |
| | | } |
| | | |
| | | public void setCreateUser(int createUser) { |
| | | this.createUser = createUser; |
| | | } |
| | | |
| | | public Timestamp getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Timestamp createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | public int getUpdateUser() { |
| | | return updateUser; |
| | | } |
| | | |
| | | public void setUpdateUser(int updateUser) { |
| | | this.updateUser = updateUser; |
| | | } |
| | | |
| | | public Timestamp getUpdateTime() { |
| | | return updateTime; |
| | | } |
| | | |
| | | public void setUpdateTime(Timestamp updateTime) { |
| | | this.updateTime = updateTime; |
| | | } |
| | | |
| | | public String getGeom() { |
| | | return geom; |
| | | } |
| | | |
| | | public void setGeom(String geom) { |
| | | this.geom = geom; |
| | | } |
| | | |
| | | public String getBak() { |
| | | return bak; |
| | | } |
| | | |
| | | public void setBak(String bak) { |
| | | this.bak = bak; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.mapper.data; |
| | | |
| | | import com.lf.server.entity.data.PublishEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * æ°æ®åå¸ |
| | | * @author WWW |
| | | */ |
| | | @Mapper |
| | | @Repository |
| | | public interface PublishMapper { |
| | | /** |
| | | * æ¥è¯¢è®°å½æ° |
| | | * |
| | | * @param name åç§° |
| | | * @return è®°å½æ° |
| | | */ |
| | | public Integer selectCount(String name); |
| | | |
| | | /** |
| | | * å页æ¥è¯¢ |
| | | * |
| | | * @param name åç§° |
| | | * @param limit è®°å½æ° |
| | | * @param offset åç§»é |
| | | * @return å表 |
| | | */ |
| | | public List<PublishEntity> selectByPage(String name, Integer limit, Integer offset); |
| | | |
| | | /** |
| | | * æ¥è¯¢ææ |
| | | * |
| | | * @return |
| | | */ |
| | | public List<PublishEntity> selectAll(); |
| | | |
| | | /** |
| | | * æ ¹æ®IDæ¥è¯¢ |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public PublishEntity selectById(int id); |
| | | |
| | | /** |
| | | * æå
¥ä¸æ¡ |
| | | * |
| | | * @param entity |
| | | * @return |
| | | */ |
| | | public Integer insert(PublishEntity entity); |
| | | |
| | | /** |
| | | * æå
¥å¤æ¡ |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public Integer inserts(List<PublishEntity> list); |
| | | |
| | | /** |
| | | * å é¤ä¸æ¡ |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public Integer delete(int id); |
| | | |
| | | /** |
| | | * å é¤å¤æ¡ |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | public Integer deletes(List<Integer> ids); |
| | | |
| | | /** |
| | | * æ´æ°ä¸æ¡ |
| | | * |
| | | * @param entity |
| | | * @return |
| | | */ |
| | | public Integer update(PublishEntity entity); |
| | | |
| | | /** |
| | | * æ´æ°å¤æ¡ |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public Integer updates(List<PublishEntity> list); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.service.data; |
| | | |
| | | import com.lf.server.entity.data.PublishEntity; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.mapper.data.PublishMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * æ°æ®åå¸ |
| | | * @author WWW |
| | | */ |
| | | @Service |
| | | public class PublishService implements PublishMapper { |
| | | @Autowired |
| | | PublishMapper publishMapper; |
| | | |
| | | @Override |
| | | public Integer selectCount(String name) { |
| | | name = StringHelper.getLikeStr(name); |
| | | |
| | | return publishMapper.selectCount(name); |
| | | } |
| | | |
| | | @Override |
| | | public List<PublishEntity> selectByPage(String name, Integer limit, Integer offset) { |
| | | name = StringHelper.getLikeStr(name); |
| | | |
| | | return publishMapper.selectByPage(name, limit, offset); |
| | | } |
| | | |
| | | @Override |
| | | public List<PublishEntity> selectAll() { |
| | | return publishMapper.selectAll(); |
| | | } |
| | | |
| | | @Override |
| | | public PublishEntity selectById(int id) { |
| | | return publishMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public Integer insert(PublishEntity entity) { |
| | | return publishMapper.insert(entity); |
| | | } |
| | | |
| | | @Override |
| | | public Integer inserts(List<PublishEntity> list) { |
| | | return publishMapper.inserts(list); |
| | | } |
| | | |
| | | @Override |
| | | public Integer delete(int id) { |
| | | return publishMapper.delete(id); |
| | | } |
| | | |
| | | @Override |
| | | public Integer deletes(List<Integer> ids) { |
| | | return publishMapper.deletes(ids); |
| | | } |
| | | |
| | | @Override |
| | | public Integer update(PublishEntity entity) { |
| | | return publishMapper.update(entity); |
| | | } |
| | | |
| | | @Override |
| | | public Integer updates(List<PublishEntity> list) { |
| | | return publishMapper.updates(list); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?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="com.lf.server.mapper.data.PublishMapper"> |
| | | <select id="selectCount" resultType="java.lang.Integer"> |
| | | select count(*) from lf.sys_publish |
| | | <where> |
| | | <if test="name != null"> |
| | | name like #{name} |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="selectByPage" resultType="com.lf.server.entity.data.PublishEntity"> |
| | | select * from lf.sys_publish |
| | | <where> |
| | | <if test="name != null"> |
| | | name like #{name} |
| | | </if> |
| | | </where> |
| | | order by id |
| | | limit #{limit} offset #{offset} |
| | | </select> |
| | | |
| | | <select id="selectAll" resultType="com.lf.server.entity.data.PublishEntity"> |
| | | select * from lf.sys_publish order by id; |
| | | </select> |
| | | |
| | | <select id="selectById" resultType="com.lf.server.entity.data.PublishEntity"> |
| | | select * from lf.sys_publish where id = #{id} |
| | | </select> |
| | | |
| | | <insert id="insert" parameterType="com.lf.server.entity.data.PublishEntity"> |
| | | insert into lf.sys_publish |
| | | (name,url,path,type,status,dirid,depid,min,max,json,create_user,create_time,geom,bak) |
| | | values |
| | | (#{name},#{url},#{path},#{type},#{status},#{dirid},#{depid},#{min},#{max},#{json},#{createUser},now(),#{geom},#{bak}) |
| | | </insert> |
| | | |
| | | <insert id="inserts"> |
| | | insert into lf.sys_publish |
| | | (name,url,path,type,status,dirid,depid,min,max,json,create_user,create_time,geom,bak) |
| | | values |
| | | <foreach collection="list" item="item" index="index" separator=","> |
| | | (#{item.name},#{item.url},#{item.path},#{item.type},#{item.status},#{item.dirid},#{item.depid},#{item.min},#{item.max},#{item.json},#{item.createUser},now(),#{item.geom},#{item.bak}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | <delete id="delete"> |
| | | delete from lf.sys_publish where id = #{id} |
| | | </delete> |
| | | |
| | | <delete id="deletes"> |
| | | delete from lf.sys_publish where id in |
| | | <foreach item="id" collection="ids" index="index" open="(" separator="," close=")"> |
| | | #{id} |
| | | </foreach> |
| | | </delete> |
| | | |
| | | <update id="update"> |
| | | update lf.sys_publish |
| | | set name=#{name},url=#{url},path=#{path},type=#{type},status=#{status},dirid=#{dirid},depid=#{depid},min=#{min},max=#{max},json=#{json},update_user=#{updateUser},update_time=now(),geom=#{geom},bak=#{bak} |
| | | where id=#{id} |
| | | </update> |
| | | |
| | | <update id="updates"> |
| | | <foreach collection="list" item="item" index="index" separator=";"> |
| | | update lf.sys_publish |
| | | <set> |
| | | name=#{item.name},url=#{item.url},path=#{item.path},type=#{item.type},status=#{item.status},dirid=#{item.dirid},depid=#{item.depid},min=#{item.min},max=#{item.max},json=#{item.json},update_user=#{item.updateUser},update_time=now(),geom=#{item.geom},bak=#{item.bak} |
| | | </set> |
| | | where id = #{item.id} |
| | | </foreach> |
| | | </update> |
| | | </mapper> |