mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 23:11:24 +08:00
temp 2023/5/2
This commit is contained in:
@@ -1,7 +1,21 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.cfive.pinnacle.entity.User;
|
||||
import com.cfive.pinnacle.entity.UserWork;
|
||||
import com.cfive.pinnacle.entity.Work;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.IWorkService;
|
||||
import com.cfive.pinnacle.service.impl.UserWorkServiceImpl;
|
||||
import com.cfive.pinnacle.service.impl.WorkServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -11,8 +25,45 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/work")
|
||||
public class WorkController {
|
||||
@Autowired
|
||||
private WorkServiceImpl workService;
|
||||
@Autowired
|
||||
private UserWorkServiceImpl userWorkService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAll() {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SELECT_OK, "success", workService.getAll());
|
||||
}
|
||||
|
||||
@GetMapping("/todo/{userId}")
|
||||
public ResponseResult getTodo(@PathVariable Long userId) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SELECT_OK, "success", workService.getTodo(userId));
|
||||
}
|
||||
|
||||
@GetMapping("/complete/{userId}")
|
||||
public ResponseResult getComplete(@PathVariable Long userId) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SELECT_OK, "success", workService.getComplete(userId));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseResult addWork(@RequestBody Work work) {
|
||||
System.out.println(work);
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_OK, "success", workService.addWork(work));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseResult deleteById(@PathVariable long id) {
|
||||
System.out.println(id);
|
||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_OK, "success", workService.deleteByWorkId(id));
|
||||
}
|
||||
|
||||
@PutMapping("/setComplete")
|
||||
public ResponseResult updateWork(@RequestBody UserWork userWork) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_OK, "success", userWorkService.updateById(userWork));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.annotation.Version;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -35,12 +37,14 @@ public class UserWork implements Serializable {
|
||||
* 用户
|
||||
*/
|
||||
@TableField("user_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 工作事项
|
||||
*/
|
||||
@TableField("work_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long workId;
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,11 @@ import com.baomidou.mybatisplus.annotation.Version;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -30,6 +34,7 @@ public class Work implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
@@ -44,6 +49,9 @@ public class Work implements Serializable {
|
||||
@TableField("publisher_id")
|
||||
private Long publisherId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String publisherName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@@ -81,4 +89,10 @@ public class Work implements Serializable {
|
||||
@TableField("version")
|
||||
@Version
|
||||
private Integer version;
|
||||
@TableField(exist = false)
|
||||
private List<UserWork> userWorkList;
|
||||
@TableField(exist = false)
|
||||
private List<User> worker;
|
||||
@TableField(exist = false)
|
||||
private double progress;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.cfive.pinnacle.entity.Work;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 工作事项 Mapper 接口
|
||||
@@ -14,5 +16,10 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
*/
|
||||
@Mapper
|
||||
public interface WorkMapper extends BaseMapper<Work> {
|
||||
List<Work> getAll();
|
||||
|
||||
List<Work> getTodo(Long userId);
|
||||
|
||||
List<Work> getComplete(Long userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.cfive.pinnacle.service;
|
||||
import com.cfive.pinnacle.entity.Work;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 工作事项 服务类
|
||||
@@ -12,5 +14,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface IWorkService extends IService<Work> {
|
||||
List<Work> getAll();
|
||||
List<Work> getTodo(Long userId);
|
||||
List<Work> getComplete(Long userId);
|
||||
|
||||
double getProgress(Long workId);
|
||||
|
||||
String getUserName(Long userId);
|
||||
boolean addWork(Work work);
|
||||
boolean deleteByWorkId(Long wid);
|
||||
}
|
||||
|
||||
@@ -17,4 +17,5 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class UserWorkServiceImpl extends ServiceImpl<UserWorkMapper, UserWork> implements IUserWorkService {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
package com.cfive.pinnacle.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.cfive.pinnacle.entity.User;
|
||||
import com.cfive.pinnacle.entity.UserWork;
|
||||
import com.cfive.pinnacle.entity.Work;
|
||||
import com.cfive.pinnacle.mapper.UserMapper;
|
||||
import com.cfive.pinnacle.mapper.UserWorkMapper;
|
||||
import com.cfive.pinnacle.mapper.WorkMapper;
|
||||
import com.cfive.pinnacle.service.IWorkService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 工作事项 服务实现类
|
||||
@@ -16,5 +24,74 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Service
|
||||
public class WorkServiceImpl extends ServiceImpl<WorkMapper, Work> implements IWorkService {
|
||||
@Autowired
|
||||
private WorkMapper workMapper;
|
||||
@Autowired
|
||||
private UserWorkMapper userWorkMapper;
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
@Override
|
||||
public List<Work> getAll() {
|
||||
List<Work> workList = workMapper.getAll();
|
||||
for (Work work:
|
||||
workList) {
|
||||
work.setProgress(getProgress(work.getId()));
|
||||
work.setPublisherName(getUserName(work.getPublisherId()));
|
||||
}
|
||||
return workList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Work> getTodo(Long userId) {
|
||||
return workMapper.getTodo(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Work> getComplete(Long userId) {
|
||||
return workMapper.getComplete(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getProgress(Long workId) {
|
||||
double workNum = userWorkMapper.selectCount(new QueryWrapper<UserWork>().eq("work_id",workId));
|
||||
double completeNum = userWorkMapper.selectCount(new QueryWrapper<UserWork>().eq("work_id",workId).eq("status",1));
|
||||
double progress = 0;
|
||||
progress = (completeNum / workNum) * 100;
|
||||
return progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserName(Long userId) {
|
||||
return userMapper.selectById(userId).getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addWork(Work work) {
|
||||
boolean flag = false;
|
||||
if (workMapper.insert(work) > 0) {
|
||||
flag = true;
|
||||
}
|
||||
long workId = work.getId();
|
||||
for (User user :
|
||||
work.getWorker()) {
|
||||
UserWork userWork = new UserWork();
|
||||
userWork.setWorkId(workId);
|
||||
userWork.setUserId(user.getId());
|
||||
if (userWorkMapper.insert(userWork) <= 0) {
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteByWorkId(Long workId) {
|
||||
boolean flag = false;
|
||||
if (userWorkMapper.delete(new QueryWrapper<UserWork>().eq("work_id", workId)) > 0 && workMapper.deleteById(workId) > 0) {
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user