From aaacb230112076535206fa94d4839f9731a1c550 Mon Sep 17 00:00:00 2001
From: 赵士淞 <zhaoss@yhzhg.cn>
Date: Fri, 13 Jan 2023 07:07:53 +0000
Subject: [PATCH] 成本管理
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/domain/Cost.java | 79 +++++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/repository/CostRepository.java | 28 ++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/impl/CostServiceImpl.java | 142 ++++++++++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/mapstruct/CostMapper.java | 32 ++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/dto/CostDto.java | 60 ++++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/CostService.java | 83 +++++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/dto/CostQueryCriteria.java | 37 ++
eladmin-web-master/src/api/cost/cost.js | 35 ++
eladmin-web-master/src/views/cost/cost/index.vue | 208 ++++++++++++++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/rest/CostController.java | 95 ++++++
10 files changed, 799 insertions(+), 0 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/domain/Cost.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/domain/Cost.java
new file mode 100644
index 0000000..3b20267
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/domain/Cost.java
@@ -0,0 +1,79 @@
+/*
+* Copyright 2019-2020 Zheng Jie
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package me.zhengjie.modules.cost.domain;
+
+import lombok.Data;
+import cn.hutool.core.bean.BeanUtil;
+import io.swagger.annotations.ApiModelProperty;
+import cn.hutool.core.bean.copier.CopyOptions;
+import me.zhengjie.base.BaseEntity;
+
+import javax.persistence.*;
+import javax.validation.constraints.*;
+import java.sql.Timestamp;
+import java.math.BigDecimal;
+import java.io.Serializable;
+
+/**
+* @website https://eladmin.vip
+* @description /
+* @author 赵士淞
+* @date 2023-01-13
+**/
+@Entity
+@Data
+@Table(name="cost")
+public class Cost extends BaseEntity implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "`id`")
+ @ApiModelProperty(value = "ID")
+ private Long id;
+
+ @Column(name = "`project_id`",nullable = false)
+ @NotNull
+ @ApiModelProperty(value = "项目ID")
+ private Long projectId;
+
+ @Column(name = "`user_id`",nullable = false)
+ @NotNull
+ @ApiModelProperty(value = "用户ID")
+ private Long userId;
+
+ @Column(name = "`enter_project_time`",nullable = false)
+ @NotNull
+ @ApiModelProperty(value = "进入项目时间")
+ private Timestamp enterProjectTime;
+
+ @Column(name = "`exit_project_time`",nullable = false)
+ @NotNull
+ @ApiModelProperty(value = "退出项目时间")
+ private Timestamp exitProjectTime;
+
+ @Column(name = "`project_cost`",nullable = false)
+ @NotNull
+ @ApiModelProperty(value = "项目成本")
+ private BigDecimal projectCost;
+
+ @Column(name = "`remarks`")
+ @ApiModelProperty(value = "备注")
+ private String remarks;
+
+ public void copy(Cost source){
+ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
+ }
+}
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/repository/CostRepository.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/repository/CostRepository.java
new file mode 100644
index 0000000..4eac73d
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/repository/CostRepository.java
@@ -0,0 +1,28 @@
+/*
+* Copyright 2019-2020 Zheng Jie
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package me.zhengjie.modules.cost.repository;
+
+import me.zhengjie.modules.cost.domain.Cost;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+/**
+* @website https://eladmin.vip
+* @author 赵士淞
+* @date 2023-01-13
+**/
+public interface CostRepository extends JpaRepository<Cost, Long>, JpaSpecificationExecutor<Cost> {
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/rest/CostController.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/rest/CostController.java
new file mode 100644
index 0000000..503aee0
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/rest/CostController.java
@@ -0,0 +1,95 @@
+/*
+* Copyright 2019-2020 Zheng Jie
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package me.zhengjie.modules.cost.rest;
+
+import me.zhengjie.annotation.Log;
+import me.zhengjie.modules.cost.domain.Cost;
+import me.zhengjie.modules.cost.service.CostService;
+import me.zhengjie.modules.cost.service.dto.CostQueryCriteria;
+import org.springframework.data.domain.Pageable;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import io.swagger.annotations.*;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+* @website https://eladmin.vip
+* @author 赵士淞
+* @date 2023-01-13
+**/
+@RestController
+@RequiredArgsConstructor
+@Api(tags = "成本管理")
+@RequestMapping("/api/cost")
+public class CostController {
+
+ private final CostService costService;
+
+ @Log("导出数据")
+ @ApiOperation("导出数据")
+ @GetMapping(value = "/download")
+ @PreAuthorize("@el.check('cost:download')")
+ public void exportCost(HttpServletResponse response, CostQueryCriteria criteria) throws IOException {
+ costService.download(costService.queryAll(criteria), response);
+ }
+
+ @GetMapping
+ @Log("查询成本")
+ @ApiOperation("查询成本")
+ @PreAuthorize("@el.check('cost:list')")
+ public ResponseEntity<Object> queryCost(CostQueryCriteria criteria, Pageable pageable){
+ return new ResponseEntity<>(costService.queryAll(criteria,pageable),HttpStatus.OK);
+ }
+
+ @GetMapping(value = "/all")
+ @Log("查询成本")
+ @ApiOperation("查询成本")
+ @PreAuthorize("@el.check('cost:list')")
+ public ResponseEntity<Object> queryCost(CostQueryCriteria criteria){
+ return new ResponseEntity<>(costService.queryAll(criteria),HttpStatus.OK);
+ }
+
+ @PostMapping
+ @Log("新增成本")
+ @ApiOperation("新增成本")
+ @PreAuthorize("@el.check('cost:add')")
+ public ResponseEntity<Object> createCost(@Validated @RequestBody Cost resources){
+ return new ResponseEntity<>(costService.create(resources),HttpStatus.CREATED);
+ }
+
+ @PutMapping
+ @Log("修改成本")
+ @ApiOperation("修改成本")
+ @PreAuthorize("@el.check('cost:edit')")
+ public ResponseEntity<Object> updateCost(@Validated @RequestBody Cost resources){
+ costService.update(resources);
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ }
+
+ @DeleteMapping
+ @Log("删除成本")
+ @ApiOperation("删除成本")
+ @PreAuthorize("@el.check('cost:del')")
+ public ResponseEntity<Object> deleteCost(@RequestBody Long[] ids) {
+ costService.deleteAll(ids);
+ return new ResponseEntity<>(HttpStatus.OK);
+ }
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/CostService.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/CostService.java
new file mode 100644
index 0000000..1749956
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/CostService.java
@@ -0,0 +1,83 @@
+/*
+* Copyright 2019-2020 Zheng Jie
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package me.zhengjie.modules.cost.service;
+
+import me.zhengjie.modules.cost.domain.Cost;
+import me.zhengjie.modules.cost.service.dto.CostDto;
+import me.zhengjie.modules.cost.service.dto.CostQueryCriteria;
+import org.springframework.data.domain.Pageable;
+import java.util.Map;
+import java.util.List;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+* @website https://eladmin.vip
+* @description 服务接口
+* @author 赵士淞
+* @date 2023-01-13
+**/
+public interface CostService {
+
+ /**
+ * 查询数据分页
+ * @param criteria 条件
+ * @param pageable 分页参数
+ * @return Map<String,Object>
+ */
+ Map<String,Object> queryAll(CostQueryCriteria criteria, Pageable pageable);
+
+ /**
+ * 查询所有数据不分页
+ * @param criteria 条件参数
+ * @return List<CostDto>
+ */
+ List<CostDto> queryAll(CostQueryCriteria criteria);
+
+ /**
+ * 根据ID查询
+ * @param id ID
+ * @return CostDto
+ */
+ CostDto findById(Long id);
+
+ /**
+ * 创建
+ * @param resources /
+ * @return CostDto
+ */
+ CostDto create(Cost resources);
+
+ /**
+ * 编辑
+ * @param resources /
+ */
+ void update(Cost resources);
+
+ /**
+ * 多选删除
+ * @param ids /
+ */
+ void deleteAll(Long[] ids);
+
+ /**
+ * 导出数据
+ * @param all 待导出的数据
+ * @param response /
+ * @throws IOException /
+ */
+ void download(List<CostDto> all, HttpServletResponse response) throws IOException;
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/dto/CostDto.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/dto/CostDto.java
new file mode 100644
index 0000000..f3214a8
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/dto/CostDto.java
@@ -0,0 +1,60 @@
+/*
+* Copyright 2019-2020 Zheng Jie
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package me.zhengjie.modules.cost.service.dto;
+
+import lombok.Data;
+import me.zhengjie.base.BaseDTO;
+
+import java.sql.Timestamp;
+import java.math.BigDecimal;
+import java.io.Serializable;
+
+/**
+* @website https://eladmin.vip
+* @description /
+* @author 赵士淞
+* @date 2023-01-13
+**/
+@Data
+public class CostDto extends BaseDTO implements Serializable {
+
+ /** ID */
+ private Long id;
+
+ /** 项目ID */
+ private Long projectId;
+
+ /** 用户ID */
+ private Long userId;
+
+ /** 进入项目时间 */
+ private Timestamp enterProjectTime;
+
+ /** 退出项目时间 */
+ private Timestamp exitProjectTime;
+
+ /** 项目成本 */
+ private BigDecimal projectCost;
+
+ /** 备注 */
+ private String remarks;
+
+ /** 项目名称 */
+ private String projectName;
+
+ /** 用户昵称 */
+ private String userNickName;
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/dto/CostQueryCriteria.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/dto/CostQueryCriteria.java
new file mode 100644
index 0000000..4c4ca07
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/dto/CostQueryCriteria.java
@@ -0,0 +1,37 @@
+/*
+* Copyright 2019-2020 Zheng Jie
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package me.zhengjie.modules.cost.service.dto;
+
+import lombok.Data;
+import java.util.List;
+import me.zhengjie.annotation.Query;
+
+/**
+* @website https://eladmin.vip
+* @author 赵士淞
+* @date 2023-01-13
+**/
+@Data
+public class CostQueryCriteria{
+
+ /** 精确 */
+ @Query
+ private Long projectId;
+
+ /** 精确 */
+ @Query
+ private Long userId;
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/impl/CostServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/impl/CostServiceImpl.java
new file mode 100644
index 0000000..7c4396f
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/impl/CostServiceImpl.java
@@ -0,0 +1,142 @@
+/*
+* Copyright 2019-2020 Zheng Jie
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package me.zhengjie.modules.cost.service.impl;
+
+import me.zhengjie.modules.cost.domain.Cost;
+import me.zhengjie.modules.project.domain.Project;
+import me.zhengjie.modules.project.repository.ProjectRepository;
+import me.zhengjie.modules.system.domain.User;
+import me.zhengjie.modules.system.repository.UserRepository;
+import me.zhengjie.utils.ValidationUtil;
+import me.zhengjie.utils.FileUtil;
+import lombok.RequiredArgsConstructor;
+import me.zhengjie.modules.cost.repository.CostRepository;
+import me.zhengjie.modules.cost.service.CostService;
+import me.zhengjie.modules.cost.service.dto.CostDto;
+import me.zhengjie.modules.cost.service.dto.CostQueryCriteria;
+import me.zhengjie.modules.cost.service.mapstruct.CostMapper;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import me.zhengjie.utils.PageUtil;
+import me.zhengjie.utils.QueryHelp;
+import java.util.List;
+import java.util.Map;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.function.Function;
+
+/**
+* @website https://eladmin.vip
+* @description 服务实现
+* @author 赵士淞
+* @date 2023-01-13
+**/
+@Service
+@RequiredArgsConstructor
+public class CostServiceImpl implements CostService {
+
+ private final CostRepository costRepository;
+ private final CostMapper costMapper;
+ private final ProjectRepository projectRepository;
+ private final UserRepository userRepository;
+
+ @Override
+ public Map<String,Object> queryAll(CostQueryCriteria criteria, Pageable pageable){
+ Page<Cost> page = costRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
+ // 将实体类转换为DTO(重写)
+ Function<Cost, CostDto> func = new Function<Cost, CostDto>(){
+ @Override
+ public CostDto apply(Cost t) {
+ // 将实体类转换成DTO
+ CostDto costDto = costMapper.toDto(t);
+ // 根据项目ID查询项目信息
+ Project project = projectRepository.findById(costDto.getProjectId()).orElseGet(Project::new);
+ ValidationUtil.isNull(project.getId(),"Project","id",costDto.getProjectId());
+ // 项目名称
+ costDto.setProjectName(project.getName());
+ // 根据用户ID查询用户信息
+ User user = userRepository.findById(costDto.getUserId()).orElseGet(User::new);
+ ValidationUtil.isNull(user.getId(),"User","id",costDto.getUserId());
+ // 用户昵称
+ costDto.setUserNickName(user.getNickName());
+ // 返回处理好的DTO
+ return costDto;
+ }
+ };
+ return PageUtil.toPage(page.map(func));
+ }
+
+ @Override
+ public List<CostDto> queryAll(CostQueryCriteria criteria){
+ return costMapper.toDto(costRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
+ }
+
+ @Override
+ @Transactional
+ public CostDto findById(Long id) {
+ Cost cost = costRepository.findById(id).orElseGet(Cost::new);
+ ValidationUtil.isNull(cost.getId(),"Cost","id",id);
+ return costMapper.toDto(cost);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public CostDto create(Cost resources) {
+ return costMapper.toDto(costRepository.save(resources));
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void update(Cost resources) {
+ Cost cost = costRepository.findById(resources.getId()).orElseGet(Cost::new);
+ ValidationUtil.isNull( cost.getId(),"Cost","id",resources.getId());
+ cost.copy(resources);
+ costRepository.save(cost);
+ }
+
+ @Override
+ public void deleteAll(Long[] ids) {
+ for (Long id : ids) {
+ costRepository.deleteById(id);
+ }
+ }
+
+ @Override
+ public void download(List<CostDto> all, HttpServletResponse response) throws IOException {
+ List<Map<String, Object>> list = new ArrayList<>();
+ for (CostDto cost : all) {
+ String projectName = cost.getProjectId() != null ? projectRepository.findById(cost.getProjectId()).orElseGet(Project::new).getName() : "";
+ String nickName = cost.getUserId() != null ? userRepository.findById(cost.getUserId()).orElseGet(User::new).getNickName() : "";
+ Map<String,Object> map = new LinkedHashMap<>();
+ map.put("项目名称", projectName);
+ map.put("用户昵称", nickName);
+ map.put("进入项目时间", cost.getEnterProjectTime());
+ map.put("退出项目时间", cost.getExitProjectTime());
+ map.put("项目成本", cost.getProjectCost());
+ map.put("备注", cost.getRemarks());
+ map.put("创建者", cost.getCreateBy());
+ map.put("创建时间", cost.getCreateTime());
+ map.put("更新者", cost.getUpdateBy());
+ map.put("更新时间", cost.getUpdateTime());
+ list.add(map);
+ }
+ FileUtil.downloadExcel(list, response);
+ }
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/mapstruct/CostMapper.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/mapstruct/CostMapper.java
new file mode 100644
index 0000000..8f3f0b9
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/cost/service/mapstruct/CostMapper.java
@@ -0,0 +1,32 @@
+/*
+* Copyright 2019-2020 Zheng Jie
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package me.zhengjie.modules.cost.service.mapstruct;
+
+import me.zhengjie.base.BaseMapper;
+import me.zhengjie.modules.cost.domain.Cost;
+import me.zhengjie.modules.cost.service.dto.CostDto;
+import org.mapstruct.Mapper;
+import org.mapstruct.ReportingPolicy;
+
+/**
+* @website https://eladmin.vip
+* @author 赵士淞
+* @date 2023-01-13
+**/
+@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
+public interface CostMapper extends BaseMapper<CostDto, Cost> {
+
+}
\ No newline at end of file
diff --git a/eladmin-web-master/src/api/cost/cost.js b/eladmin-web-master/src/api/cost/cost.js
new file mode 100644
index 0000000..f01b1ef
--- /dev/null
+++ b/eladmin-web-master/src/api/cost/cost.js
@@ -0,0 +1,35 @@
+import request from '@/utils/request'
+
+export function getAll(params) {
+ return request({
+ url: 'api/cost/all',
+ method: 'get',
+ params
+ })
+}
+
+export function add(data) {
+ return request({
+ url: 'api/cost',
+ method: 'post',
+ data
+ })
+}
+
+export function del(ids) {
+ return request({
+ url: 'api/cost/',
+ method: 'delete',
+ data: ids
+ })
+}
+
+export function edit(data) {
+ return request({
+ url: 'api/cost',
+ method: 'put',
+ data
+ })
+}
+
+export default { getAll, add, edit, del }
diff --git a/eladmin-web-master/src/views/cost/cost/index.vue b/eladmin-web-master/src/views/cost/cost/index.vue
new file mode 100644
index 0000000..1a89dbd
--- /dev/null
+++ b/eladmin-web-master/src/views/cost/cost/index.vue
@@ -0,0 +1,208 @@
+<template>
+ <div class="app-container">
+ <!--工具栏-->
+ <div class="head-container">
+ <div v-if="crud.props.searchToggle">
+ <!-- 搜索 -->
+ <el-select v-model="query.projectId" filterable clearable placeholder="所属项目" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
+ <el-option
+ v-for="item in projects"
+ :key="item.id"
+ :label="item.name"
+ :value="item.id"
+ />
+ </el-select>
+ <el-select v-model="query.userId" filterable clearable placeholder="所属员工" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
+ <el-option
+ v-for="item in users"
+ :key="item.id"
+ :label="item.nickName"
+ :value="item.id"
+ />
+ </el-select>
+ <rrOperation :crud="crud" />
+ </div>
+ <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
+ <crudOperation :permission="permission" />
+ <!--表单组件-->
+ <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
+ <el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">
+ <el-form-item label="所属项目" prop="projectId">
+ <el-select v-model="form.projectId" filterable clearable placeholder="请选择" style="width: 340px;">
+ <el-option
+ v-for="item in projects"
+ :key="item.id"
+ :label="item.name"
+ :value="item.id"
+ />
+ </el-select>
+ </el-form-item>
+ <el-form-item label="所属员工" prop="userId">
+ <el-select v-model="form.userId" filterable clearable placeholder="请选择" style="width: 340px;">
+ <el-option
+ v-for="item in users"
+ :key="item.id"
+ :label="item.nickName"
+ :value="item.id"
+ :disabled="!item.enabled"
+ />
+ </el-select>
+ </el-form-item>
+ <el-form-item label="进入项目时间" prop="enterProjectTime">
+ <el-date-picker v-model="form.enterProjectTime" type="datetime" style="width: 340px;" />
+ </el-form-item>
+ <el-form-item label="退出项目时间" prop="exitProjectTime">
+ <el-date-picker v-model="form.exitProjectTime" type="datetime" style="width: 340px;" />
+ </el-form-item>
+ <el-form-item label="项目成本" prop="projectCost">
+ <money-input :key="random" v-model="form.projectCost" :width="340" />
+ </el-form-item>
+ <el-form-item label="备注">
+ <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 340px;" />
+ </el-form-item>
+ </el-form>
+ <div slot="footer" class="dialog-footer">
+ <el-button type="text" @click="crud.cancelCU">取消</el-button>
+ <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
+ </div>
+ </el-dialog>
+ <!--表格渲染-->
+ <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
+ <el-table-column type="selection" width="55" />
+ <el-table-column :show-overflow-tooltip="true" prop="projectId" label="所属项目">
+ <template slot-scope="scope">
+ <el-tag>{{ scope.row.projectName }}</el-tag>
+ </template>
+ </el-table-column>
+ <el-table-column :show-overflow-tooltip="true" prop="userNickName" label="所属员工">
+ <template slot-scope="scope">
+ <el-tag>{{ scope.row.userNickName }}</el-tag>
+ </template>
+ </el-table-column>
+ <el-table-column :show-overflow-tooltip="true" prop="enterProjectTime" label="进入项目时间" />
+ <el-table-column :show-overflow-tooltip="true" prop="exitProjectTime" label="退出项目时间" />
+ <el-table-column :show-overflow-tooltip="true" prop="projectCost" label="项目成本">
+ <template slot-scope="scope">
+ {{ crud.toMoney(scope.row.projectCost) }}
+ </template>
+ </el-table-column>
+ <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注" />
+ <el-table-column :show-overflow-tooltip="true" prop="createTime" label="创建时间" />
+ <el-table-column v-if="checkPer(['admin','cost:edit','cost:del'])" label="操作" width="150px" align="center">
+ <template slot-scope="scope">
+ <udOperation
+ :data="scope.row"
+ :permission="permission"
+ />
+ </template>
+ </el-table-column>
+ </el-table>
+ <!--分页组件-->
+ <pagination />
+ </div>
+ </div>
+</template>
+
+<script>
+import crudCost from '@/api/cost/cost'
+import CRUD, { presenter, header, form, crud } from '@crud/crud'
+import rrOperation from '@crud/RR.operation'
+import crudOperation from '@crud/CRUD.operation'
+import udOperation from '@crud/UD.operation'
+import pagination from '@crud/Pagination'
+import constant from '../../../utils/constant'
+import crudProject from '@/api/project/project'
+import crudUser from '@/api/system/user'
+import moneyInput from '../../assembly/moneyInput/index.vue'
+
+const defaultForm = { id: null, projectId: null, userId: null, enterProjectTime: null, exitProjectTime: null, projectCost: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
+export default {
+ name: 'Cost',
+ components: { pagination, crudOperation, rrOperation, udOperation, moneyInput },
+ mixins: [presenter(), header(), form(defaultForm), crud()],
+ cruds() {
+ return CRUD({ title: '成本', url: 'api/cost', idField: 'id', sort: 'id,desc', crudMethod: { ...crudCost }})
+ },
+ data() {
+ // 工资(千万内)验证
+ var wageValidate = (rule, value, callback) => {
+ if (value != null && value !== '' && (isNaN(value) || Number(value) < 0 || Number(value) > 10000000)) {
+ callback(new Error('请输入 一千万 以内的正整数或两位小数'))
+ } else {
+ callback()
+ }
+ }
+ return {
+ permission: {
+ add: ['admin', 'cost:add'],
+ edit: ['admin', 'cost:edit'],
+ del: ['admin', 'cost:del'],
+ download: ['admin', 'cost:download']
+ },
+ rules: {
+ projectId: [
+ { required: true, message: '所属项目不能为空', trigger: 'change' }
+ ],
+ userId: [
+ { required: true, message: '所属员工不能为空', trigger: 'change' }
+ ],
+ enterProjectTime: [
+ { required: true, message: '进入项目时间不能为空', trigger: 'change' }
+ ],
+ exitProjectTime: [
+ { required: true, message: '退出项目时间不能为空', trigger: 'change' }
+ ],
+ projectCost: [
+ { required: true, message: '项目成本不能为空', trigger: 'blur' },
+ { validator: wageValidate, trigger: 'blur' }
+ ]
+ },
+ queryTypeOptions: [
+ { key: 'projectId', display_name: '所属项目' },
+ { key: 'userId', display_name: '所属员工' }
+ ],
+ // 项目列表
+ projects: [],
+ // 用户列表
+ users: [],
+ // 随机数
+ random: 0
+ }
+ },
+ methods: {
+ // 钩子:在获取表格数据之前执行,false 则代表不获取数据
+ [CRUD.HOOK.beforeRefresh]() {
+ // 获取项目
+ this.getProject()
+ // 获取用户
+ this.getUser()
+ return true
+ },
+ // 获取项目
+ getProject() {
+ // 获取项目
+ crudProject.getAll({ approveStatus: constant.APPROVE_STATUS_ACKNOWLEDGED }).then(res => {
+ // 项目列表
+ this.projects = res
+ })
+ },
+ // 获取用户
+ getUser() {
+ // 获取用户
+ crudUser.getAll().then(res => {
+ // 用户列表
+ this.users = res
+ })
+ },
+ // 钩子: 开始 "新建/编辑" - 之前
+ [CRUD.HOOK.beforeToCU]() {
+ // 随机数
+ this.random = Math.random()
+ }
+ }
+}
+</script>
+
+<style scoped>
+
+</style>
--
Gitblit v1.9.3