¶Ô±ÈÐÂÎļþ |
| | |
| | | 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.TaskEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.service.data.TaskService; |
| | | 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("/task") |
| | | public class TaskController extends BaseController { |
| | | @Autowired |
| | | TaskService taskService; |
| | | |
| | | @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 = taskService.selectCount(name); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex, -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<TaskEntity>> selectByPage(String name, Integer pageSize, Integer pageIndex) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("æ¯é¡µé¡µæ°æå页æ°å°äº1", null); |
| | | } |
| | | |
| | | List<TaskEntity> rs = taskService.selectByPage(name, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex, 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<TaskEntity>> selectByPageAndCount(String name, Integer pageSize, Integer pageIndex) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("æ¯é¡µé¡µæ°æå页æ°å°äº1", null); |
| | | } |
| | | |
| | | int count = taskService.selectCount(name); |
| | | if (count == 0) { |
| | | return success(0, null); |
| | | } |
| | | |
| | | List<TaskEntity> rs = taskService.selectByPage(name, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(count, rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ¥è¯¢ææ") |
| | | @GetMapping(value = "/selectAll") |
| | | public ResponseMsg<List<TaskEntity>> selectAll() { |
| | | try { |
| | | List<TaskEntity> list = taskService.selectAll(); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ ¹æ®IDæ¥è¯¢") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "ID", dataType = "int", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/selectById") |
| | | public ResponseMsg<TaskEntity> selectById(int id) { |
| | | try { |
| | | TaskEntity entity = taskService.selectById(id); |
| | | |
| | | return success(entity); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æå
¥ä¸æ¡") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "entity", value = "å®ä½ç±»", dataType = "TaskEntity", paramType = "body") |
| | | }) |
| | | @PostMapping(value = "/insert", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> insert(@RequestBody TaskEntity entity, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | entity.setCreateUser(ue.getId()); |
| | | } |
| | | |
| | | int count = taskService.insert(entity); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æå
¥å¤æ¡") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "list", value = "å®ä½ç±»éå", dataType = "TaskEntity", paramType = "body") |
| | | }) |
| | | @PostMapping(value = "/inserts", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> inserts(@RequestBody List<TaskEntity> list, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | for (TaskEntity entity : list) { |
| | | entity.setCreateUser(ue.getId()); |
| | | } |
| | | } |
| | | |
| | | int count = taskService.inserts(list); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex, -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 = taskService.delete(id); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex, -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 = taskService.deletes(ids); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ´æ°ä¸æ¡") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "entity", value = "å®ä½ç±»", dataType = "TaskEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/update", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> update(@RequestBody TaskEntity entity, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | entity.setUpdateUser(ue.getId()); |
| | | } |
| | | |
| | | int count = taskService.update(entity); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ´æ°å¤æ¡") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "list", value = "å®ä½ç±»éå", dataType = "TaskEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/updates", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> updates(@RequestBody List<TaskEntity> list, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | for (TaskEntity entity : list) { |
| | | entity.setUpdateUser(ue.getId()); |
| | | } |
| | | } |
| | | |
| | | int count = taskService.updates(list); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.entity.data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.sql.Timestamp; |
| | | |
| | | /** |
| | | * ä»»å¡ |
| | | * @author WWW |
| | | */ |
| | | public class TaskEntity implements Serializable { |
| | | private static final long serialVersionUID = -198008027485575520L; |
| | | |
| | | private int id; |
| | | |
| | | private String name; |
| | | |
| | | private int status; |
| | | |
| | | private String type; |
| | | |
| | | private String descr; |
| | | |
| | | private String err; |
| | | |
| | | private String ip; |
| | | |
| | | private int pid; |
| | | |
| | | private String gids; |
| | | |
| | | private String depcode; |
| | | |
| | | private String dircode; |
| | | |
| | | private int createUser; |
| | | |
| | | private Timestamp createTime; |
| | | |
| | | private int updateUser; |
| | | |
| | | private Timestamp updateTime; |
| | | |
| | | public TaskEntity() { |
| | | } |
| | | |
| | | 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 int getStatus() { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(int status) { |
| | | this.status = status; |
| | | } |
| | | |
| | | public String getType() { |
| | | return type; |
| | | } |
| | | |
| | | public void setType(String type) { |
| | | this.type = type; |
| | | } |
| | | |
| | | public String getDescr() { |
| | | return descr; |
| | | } |
| | | |
| | | public void setDescr(String descr) { |
| | | this.descr = descr; |
| | | } |
| | | |
| | | public String getErr() { |
| | | return err; |
| | | } |
| | | |
| | | public void setErr(String err) { |
| | | this.err = err; |
| | | } |
| | | |
| | | public String getIp() { |
| | | return ip; |
| | | } |
| | | |
| | | public void setIp(String ip) { |
| | | this.ip = ip; |
| | | } |
| | | |
| | | public int getPid() { |
| | | return pid; |
| | | } |
| | | |
| | | public void setPid(int pid) { |
| | | this.pid = pid; |
| | | } |
| | | |
| | | public String getGids() { |
| | | return gids; |
| | | } |
| | | |
| | | public void setGids(String gids) { |
| | | this.gids = gids; |
| | | } |
| | | |
| | | public String getDepcode() { |
| | | return depcode; |
| | | } |
| | | |
| | | public void setDepcode(String depcode) { |
| | | this.depcode = depcode; |
| | | } |
| | | |
| | | public String getDircode() { |
| | | return dircode; |
| | | } |
| | | |
| | | public void setDircode(String dircode) { |
| | | this.dircode = dircode; |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.mapper.data; |
| | | |
| | | import com.lf.server.entity.data.TaskEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ä»»å¡ |
| | | * @author WWW |
| | | */ |
| | | @Mapper |
| | | @Repository |
| | | public interface TaskMapper { |
| | | /** |
| | | * æ¥è¯¢è®°å½æ° |
| | | * |
| | | * @param name ä»»å¡åç§° |
| | | * @return è®°å½æ° |
| | | */ |
| | | public Integer selectCount(String name); |
| | | |
| | | /** |
| | | * å页æ¥è¯¢ |
| | | * |
| | | * @param name ä»»å¡åç§° |
| | | * @param limit è®°å½æ° |
| | | * @param offset åç§»é |
| | | * @return å表 |
| | | */ |
| | | public List<TaskEntity> selectByPage(String name, Integer limit, Integer offset); |
| | | |
| | | /** |
| | | * æ¥è¯¢ææ |
| | | * |
| | | * @return |
| | | */ |
| | | public List<TaskEntity> selectAll(); |
| | | |
| | | /** |
| | | * æ ¹æ®IDæ¥è¯¢ |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public TaskEntity selectById(int id); |
| | | |
| | | /** |
| | | * æå
¥ä¸æ¡ |
| | | * |
| | | * @param entity |
| | | * @return |
| | | */ |
| | | public Integer insert(TaskEntity entity); |
| | | |
| | | /** |
| | | * æå
¥å¤æ¡ |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public Integer inserts(List<TaskEntity> list); |
| | | |
| | | /** |
| | | * å é¤ä¸æ¡ |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public Integer delete(int id); |
| | | |
| | | /** |
| | | * å é¤å¤æ¡ |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | public Integer deletes(List<Integer> ids); |
| | | |
| | | /** |
| | | * æ´æ°ä¸æ¡ |
| | | * |
| | | * @param entity |
| | | * @return |
| | | */ |
| | | public Integer update(TaskEntity entity); |
| | | |
| | | /** |
| | | * æ´æ°å¤æ¡ |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public Integer updates(List<TaskEntity> list); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.service.data; |
| | | |
| | | import com.lf.server.entity.data.TaskEntity; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.mapper.data.TaskMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ä»»å¡ |
| | | * @author WWW |
| | | */ |
| | | @Service |
| | | public class TaskService implements TaskMapper { |
| | | @Autowired |
| | | TaskMapper taskMapper; |
| | | |
| | | @Override |
| | | public Integer selectCount(String name) { |
| | | name = StringHelper.getLikeUpperStr(name); |
| | | |
| | | return taskMapper.selectCount(name); |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskEntity> selectByPage(String name, Integer limit, Integer offset) { |
| | | name = StringHelper.getLikeUpperStr(name); |
| | | |
| | | return taskMapper.selectByPage(name, limit, offset); |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskEntity> selectAll() { |
| | | return taskMapper.selectAll(); |
| | | } |
| | | |
| | | @Override |
| | | public TaskEntity selectById(int id) { |
| | | return taskMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public Integer insert(TaskEntity entity) { |
| | | return taskMapper.insert(entity); |
| | | } |
| | | |
| | | @Override |
| | | public Integer inserts(List<TaskEntity> list) { |
| | | return taskMapper.inserts(list); |
| | | } |
| | | |
| | | @Override |
| | | public Integer delete(int id) { |
| | | return taskMapper.delete(id); |
| | | } |
| | | |
| | | @Override |
| | | public Integer deletes(List<Integer> ids) { |
| | | return taskMapper.deletes(ids); |
| | | } |
| | | |
| | | @Override |
| | | public Integer update(TaskEntity entity) { |
| | | return taskMapper.update(entity); |
| | | } |
| | | |
| | | @Override |
| | | public Integer updates(List<TaskEntity> list) { |
| | | return taskMapper.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.TaskMapper"> |
| | | <select id="selectCount" resultType="java.lang.Integer"> |
| | | select count(*) from lf.sys_task |
| | | <where> |
| | | <if test="name != null"> |
| | | upper(name) like #{name} |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="selectByPage" resultType="com.lf.server.entity.data.TaskEntity"> |
| | | select * from lf.sys_task |
| | | <where> |
| | | <if test="name != null"> |
| | | upper(name) like #{name} |
| | | </if> |
| | | </where> |
| | | order by id desc |
| | | limit #{limit} offset #{offset} |
| | | </select> |
| | | |
| | | <select id="selectAll" resultType="com.lf.server.entity.data.TaskEntity"> |
| | | select * from lf.sys_task order by id desc; |
| | | </select> |
| | | |
| | | <select id="selectById" resultType="com.lf.server.entity.data.TaskEntity"> |
| | | select * from lf.sys_task where id = #{id} |
| | | </select> |
| | | |
| | | <insert id="insert" parameterType="com.lf.server.entity.data.TaskEntity"> |
| | | insert into lf.sys_task |
| | | (name,status,type,descr,err,ip,pid,gids,depcode,dircode,create_user,create_time) |
| | | values |
| | | (#{name},#{status},#{type},#{descr},#{err},#{ip},#{pid},#{gids},#{depcode},#{dircode},#{createUser},now()) |
| | | </insert> |
| | | |
| | | <insert id="inserts"> |
| | | insert into lf.sys_task |
| | | (name,status,type,descr,err,ip,pid,gids,depcode,dircode,create_user,create_time) |
| | | values |
| | | <foreach collection="list" item="item" index="index" separator=","> |
| | | (#{item.name},#{item.status},#{item.type},#{item.descr},#{item.err},#{item.ip},#{item.pid},#{item.gids},#{item.depcode},#{item.dircode},#{item.createUser},now()) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | <delete id="delete"> |
| | | delete from lf.sys_task where id = #{id} |
| | | </delete> |
| | | |
| | | <delete id="deletes"> |
| | | delete from lf.sys_task where id in |
| | | <foreach item="id" collection="ids" index="index" open="(" separator="," close=")"> |
| | | #{id} |
| | | </foreach> |
| | | </delete> |
| | | |
| | | <update id="update"> |
| | | update lf.sys_task |
| | | set name=#{name},status=#{status},type=#{type},descr=#{descr},err=#{err},ip=#{ip},pid=#{pid},gids=#{gids},depcode=#{depcode},dircode=#{dircode},update_user=#{updateUser},update_time=now() |
| | | where id=#{id} |
| | | </update> |
| | | |
| | | <update id="updates"> |
| | | <foreach collection="list" item="item" index="index" separator=";"> |
| | | update lf.sys_task |
| | | set name=#{item.name},status=#{item.status},type=#{item.type},descr=#{item.descr},err=#{item.err},ip=#{item.ip},pid=#{item.pid},gids=#{item.gids},depcode=#{item.depcode},dircode=#{item.dircode},update_user=#{item.updateUser},update_time=now() |
| | | where id = #{item.id} |
| | | </foreach> |
| | | </update> |
| | | </mapper> |