|
@@ -8,12 +8,15 @@ import lombok.AllArgsConstructor;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.mp.support.Condition;
|
|
|
import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.manager.dto.WbsTreeContractDTO;
|
|
|
import org.springblade.manager.dto.ProjectInfoDTO;
|
|
|
import org.springblade.manager.entity.ContractInfo;
|
|
|
+import org.springblade.manager.entity.UserProjectInfoCollect;
|
|
|
import org.springblade.manager.service.*;
|
|
|
import org.springblade.manager.vo.*;
|
|
|
import org.springframework.dao.EmptyResultDataAccessException;
|
|
@@ -26,8 +29,10 @@ import org.springblade.manager.wrapper.ProjectInfoWrapper;
|
|
|
import org.springblade.core.boot.ctrl.BladeController;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@AllArgsConstructor
|
|
@@ -258,5 +263,110 @@ public class ProjectInfoController extends BladeController {
|
|
|
List<Map<String, Object>> result = wbsTreeService.findProjectAndContractList(userId);
|
|
|
return R.data(result);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 分页 项目表
|
|
|
+ */
|
|
|
+ @GetMapping("/pageList")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "分页", notes = "传入projectInfo")
|
|
|
+ public R<IPage<ProjectInfoVO>> pageList(ProjectInfoVO3 vo, Query query) {
|
|
|
+ // 名称搜索,项目状态,收藏夹 排序
|
|
|
+ vo.setUserId(AuthUtil.getUserId());
|
|
|
+ IPage<ProjectInfoVO> pages = projectInfoService.pageList(Condition.getPage(query), vo);
|
|
|
+ return R.data(pages);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收藏项目、取消收藏项目
|
|
|
+ */
|
|
|
+ @PostMapping("/collectProject")
|
|
|
+ @ApiOperationSupport(order = 14)
|
|
|
+ @ApiOperation(value = "收藏项目、取消收藏项目", notes = "传入项目id")
|
|
|
+ public R<Boolean> collectProject(@RequestBody Long projectId) {
|
|
|
+ Long userId = AuthUtil.getUserId();
|
|
|
+ if (userId == null) {
|
|
|
+ return R.fail("用户未登录");
|
|
|
+ }
|
|
|
+ if (projectId == null || projectId <= 0) {
|
|
|
+ return R.fail("项目不存在");
|
|
|
+ }
|
|
|
+ ProjectInfo projectInfo = projectInfoService.getById(projectId);
|
|
|
+ if (projectInfo == null || projectInfo.getIsDeleted() == 1) {
|
|
|
+ return R.fail("项目不存在或者已被删除");
|
|
|
+ }
|
|
|
+ List<UserProjectInfoCollect> query = jdbcTemplate.query("select * from m_user_project_collect where project_id = ? and user_id = ?", new Object[]{projectId, userId}, new BeanPropertyRowMapper<>(UserProjectInfoCollect.class));
|
|
|
+ if (query.isEmpty()) {
|
|
|
+ // 收藏该项目
|
|
|
+ String sql = "insert into m_user_project_collect (id,project_id,user_id,create_user,update_user) values (?,?,?,?,?)";
|
|
|
+ int result = jdbcTemplate.update(sql,SnowFlakeUtil.getId(), projectId, userId, userId, userId);
|
|
|
+ return R.data(result > 0);
|
|
|
+ } else {
|
|
|
+ UserProjectInfoCollect collect = query.get(0);
|
|
|
+ String sql = "update m_user_project_collect set is_deleted = if(is_deleted = 0, 1, 0), update_user = ? where id = ?";
|
|
|
+ int result = jdbcTemplate.update(sql, userId, collect.getId());
|
|
|
+ return R.data(result > 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目排序
|
|
|
+ */
|
|
|
+ @PostMapping("/sortProject")
|
|
|
+ @ApiOperationSupport(order = 14)
|
|
|
+ @ApiOperation(value = "项目排序", notes = "传入排序好的项目ids")
|
|
|
+ public R<Boolean> sortProject(@RequestBody List<Long> projectIds) {
|
|
|
+ int sort = 0;
|
|
|
+ if (projectIds == null || projectIds.isEmpty()) {
|
|
|
+ return R.data(false);
|
|
|
+ }
|
|
|
+ List<ProjectInfo> updateList = new ArrayList<>(projectIds.size());
|
|
|
+ Long userId = AuthUtil.getUserId();
|
|
|
+ for (Long id : projectIds) {
|
|
|
+ ProjectInfo temp = new ProjectInfo();
|
|
|
+ temp.setSort(++sort);
|
|
|
+ temp.setUpdateUser(userId);
|
|
|
+ temp.setUpdateTime(new Date());
|
|
|
+ temp.setId(id);
|
|
|
+ updateList.add(temp);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ boolean result = projectInfoService.updateBatchById(updateList);
|
|
|
+ return R.data(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return R.fail(200, "排序保存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收藏项目排序
|
|
|
+ */
|
|
|
+ @PostMapping("/sortProjectCollect")
|
|
|
+ @ApiOperationSupport(order = 14)
|
|
|
+ @ApiOperation(value = "收藏项目排序", notes = "传入排序好的项目ids")
|
|
|
+ public R<Boolean> sortProjectCollect(@RequestBody List<Long> projectIds) {
|
|
|
+ int sort = 0;
|
|
|
+ if (projectIds == null || projectIds.isEmpty()) {
|
|
|
+ return R.data(false);
|
|
|
+ }
|
|
|
+ String ids = projectIds.stream().filter(id -> id != null && id > 0).map(id -> id + "").collect(Collectors.joining(","));
|
|
|
+ Long userId = AuthUtil.getUserId();
|
|
|
+ List<UserProjectInfoCollect> query = jdbcTemplate.query("select id, project_id, user_id from m_user_project_collect where user_id = " + userId + " and project_id in (" + ids + ")",
|
|
|
+ new BeanPropertyRowMapper<>(UserProjectInfoCollect.class));
|
|
|
+ Map<Long, Long> map = query.stream().collect(Collectors.toMap(UserProjectInfoCollect::getProjectId, UserProjectInfoCollect::getId, (key1, key2) -> key2));
|
|
|
+ List<Object[]> batchArgs = new ArrayList<>(map.size());
|
|
|
+ for (Long id : projectIds) {
|
|
|
+ Long l = map.get(id);
|
|
|
+ if (l == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Object[] args = new Object[]{sort, userId, new Date(), l};
|
|
|
+ batchArgs.add(args);
|
|
|
+ }
|
|
|
+ if (!batchArgs.isEmpty()) {
|
|
|
+ jdbcTemplate.batchUpdate("update m_user_project_collect set sort = ?, update_user = ?, update_time = ? where id = ?", batchArgs);
|
|
|
+ }
|
|
|
+ return R.data(true);
|
|
|
+ }
|
|
|
|
|
|
}
|