| New file |
| | |
| | | package com.battery.business.service; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.util.List; |
| | | import javax.sql.DataSource; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** 待办真实存储;所有查询和写操作都按当前负责人身份约束。 */ |
| | | @Service |
| | | public class TodoService { |
| | | private final JdbcTemplate jdbc; |
| | | public TodoService(DataSource source) { this.jdbc = new JdbcTemplate(source); } |
| | | public record Todo(long id, String content, long ownerId, String owner, String status, String creator, long createdAt, long operatedAt, String handleRemark) {} |
| | | public List<Todo> list(long ownerId) { |
| | | return jdbc.query("select todo_id,content,owner_id,owner_name,status,creator_name,created_at_utc,operated_at_utc,coalesce(handle_remark,'') from t_todo where owner_id=? order by operated_at_utc desc,todo_id desc", (rs, i) -> new Todo(rs.getLong(1),rs.getString(2),rs.getLong(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getTimestamp(7).getTime(),rs.getTimestamp(8).getTime(),rs.getString(9)), ownerId); |
| | | } |
| | | public Todo create(String content, long ownerId, String owner, long creatorId, String creator) { |
| | | Timestamp now = new Timestamp(System.currentTimeMillis()); |
| | | jdbc.update("insert into t_todo(content,owner_id,owner_name,creator_id,creator_name,status,created_at_utc,operated_at_utc,handle_remark) values(?,?,?,?,?,'待处理',?,?,null)", content.trim(), ownerId, owner, creatorId, creator, now, now); |
| | | return jdbc.queryForObject("select todo_id,content,owner_id,owner_name,status,creator_name,created_at_utc,operated_at_utc,coalesce(handle_remark,'') from t_todo where todo_id=last_insert_id()", (rs,i)->new Todo(rs.getLong(1),rs.getString(2),rs.getLong(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getTimestamp(7).getTime(),rs.getTimestamp(8).getTime(),rs.getString(9))); |
| | | } |
| | | public boolean handle(long id,long ownerId,String remark) { return jdbc.update("update t_todo set status='已处理',handle_remark=?,operated_at_utc=? where todo_id=? and owner_id=? and status='待处理'",remark.trim(),new Timestamp(System.currentTimeMillis()),id,ownerId)==1; } |
| | | public boolean remove(long id,long ownerId) { return jdbc.update("delete from t_todo where todo_id=? and owner_id=?",id,ownerId)==1; } |
| | | } |
| New file |
| | |
| | | package com.battery.business.web; |
| | | |
| | | import java.util.List; |
| | | import com.battery.business.service.TodoService; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | /** 待办列表接口;负责人身份由服务端从当前登录会话取得。 */ |
| | | @RestController |
| | | @RequestMapping("/system/todo") |
| | | public class TodoController extends BaseController { |
| | | private final TodoService service; |
| | | public TodoController(TodoService service) { this.service = service; } |
| | | @GetMapping("/list") @PreAuthorize("@ss.hasPermi('todo:list:query')") |
| | | public AjaxResult list() { return success().put("rows", service.list(getUserId())); } |
| | | @PostMapping @PreAuthorize("@ss.hasPermi('todo:list:add')") |
| | | public AjaxResult create(@RequestBody CreateRequest request) { if (request == null || request.content() == null || request.content().trim().isEmpty() || request.ownerId() == null || request.ownerName() == null) return error("待办内容和负责人不能为空"); return success(service.create(request.content(), request.ownerId(), request.ownerName(), getUserId(), getUsername())); } |
| | | @PutMapping("/{id}/handle") @PreAuthorize("@ss.hasPermi('todo:list:handle')") |
| | | public AjaxResult handle(@PathVariable long id,@RequestBody HandleRequest request) { if (request == null || request.remark() == null || request.remark().trim().isEmpty()) return error("处理说明不能为空"); return service.handle(id,getUserId(),request.remark()) ? success() : error("待办不存在、已处理或无权处理"); } |
| | | @DeleteMapping("/{id}") @PreAuthorize("@ss.hasPermi('todo:list:remove')") |
| | | public AjaxResult remove(@PathVariable long id) { return service.remove(id,getUserId()) ? success() : error("待办不存在或无权删除"); } |
| | | public record CreateRequest(String content, Long ownerId, String ownerName) {} |
| | | public record HandleRequest(String remark) {} |
| | | } |
| New file |
| | |
| | | CREATE TABLE IF NOT EXISTS t_todo ( |
| | | todo_id BIGINT AUTO_INCREMENT PRIMARY KEY, |
| | | content VARCHAR(200) NOT NULL, |
| | | owner_id BIGINT NOT NULL, |
| | | owner_name VARCHAR(100) NOT NULL, |
| | | creator_id BIGINT NOT NULL, |
| | | creator_name VARCHAR(100) NOT NULL, |
| | | status VARCHAR(20) NOT NULL DEFAULT '待处理', |
| | | created_at_utc DATETIME(3) NOT NULL, |
| | | operated_at_utc DATETIME(3) NOT NULL, |
| | | handle_remark VARCHAR(500) NULL, |
| | | INDEX idx_todo_owner_status (owner_id, status), |
| | | INDEX idx_todo_operated (operated_at_utc) |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户待办事项'; |