ソースを参照

Merge remote-tracking branch 'origin/master'

ljx 4 年 前
コミット
99f56f5762

+ 16 - 0
src/main/java/com/imed/costaccount/mapper/ProductMapper.java

@@ -0,0 +1,16 @@
+package com.imed.costaccount.mapper;
+
+import com.imed.costaccount.model.Product;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 成本管理表
+ * 
+ * @author huangrui
+ * @date 2021-07-28 18:44:20
+ */
+@Mapper
+public interface ProductMapper extends BaseMapper<Product> {
+	
+}

+ 2 - 0
src/main/java/com/imed/costaccount/model/Accounting.java

@@ -1,6 +1,7 @@
 package com.imed.costaccount.model;
 
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 
 import java.io.Serializable;
@@ -64,6 +65,7 @@ public class Accounting implements Serializable {
 	/**
 	 * 删除时间,如果存在表示已删除13位时间戳
 	 */
+	@TableLogic(value = "0",delval = "UNIX_TIMESTAMP(NOW()) * 1000")
 	private Long deleteTime;
 
 }

+ 57 - 0
src/main/java/com/imed/costaccount/model/Product.java

@@ -0,0 +1,57 @@
+package com.imed.costaccount.model;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+/**
+ * 成本管理表
+ * 
+ * @author huangrui
+ * @email 
+ * @date 2021-07-28 18:44:20
+ */
+@Data
+@Accessors(chain = true)
+@AllArgsConstructor
+@NoArgsConstructor
+@TableName("cost_product")
+public class Product implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 主键
+	 */
+	@TableId
+	private Integer id;
+	/**
+	 * 成本/收入项目名称
+	 */
+	private String productName;
+	/**
+	 * 成本/收入项目代码
+	 */
+	private String productCode;
+	/**
+	 * 医院Id
+	 */
+	private Integer hospId;
+	/**
+	 * 创建时间13位时间戳
+	 */
+	private Long createTime;
+	/**
+	 * 删除时间,如果存在表示已删除13位时间戳
+	 */
+	@TableLogic(value = "0",delval = "UNIX_TIMESTAMP(NOW()) * 1000")
+	private Long deleteTime;
+
+}

+ 17 - 0
src/main/java/com/imed/costaccount/model/ProductDTO.java

@@ -0,0 +1,17 @@
+package com.imed.costaccount.model;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+@ApiModel
+public class ProductDTO {
+
+    @NotNull(message = "成本代码不能为空")
+    private String productCode;
+
+    @NotNull(message = "成本名称不能为空")
+    private String productName;
+}

+ 22 - 0
src/main/java/com/imed/costaccount/model/dto/AccountingEditDTO.java

@@ -0,0 +1,22 @@
+package com.imed.costaccount.model.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
+@Data
+public class AccountingEditDTO {
+
+    @NotNull(message = "id不能为空")
+    private Integer id;
+
+    @NotEmpty(message = "科目代码不能为空")
+    private String accountingCode;
+
+    @NotEmpty(message = "科目名称不能为空")
+    private String accountingName;
+
+    @NotNull(message = "会计科目类型不能为空")
+    private Integer accountingType;
+}

+ 13 - 0
src/main/java/com/imed/costaccount/model/vo/ProductVO.java

@@ -0,0 +1,13 @@
+package com.imed.costaccount.model.vo;
+
+import lombok.Data;
+
+@Data
+public class ProductVO {
+    private Integer id;
+
+    private String productCode;
+
+    private String productName;
+
+}

+ 4 - 3
src/main/java/com/imed/costaccount/model/vo/SelectAccountingVO.java

@@ -9,14 +9,15 @@ import java.util.List;
 @Data
 public class SelectAccountingVO {
 
-    private Integer id;
+    private Integer value;
 
     @JsonIgnore
     private Integer parentId;
 
+    @JsonIgnore
     private String allParentIds;
 
-    private String accountingName;
+    private String label;
 
-    private List<SelectAccountingVO> child;
+    private List<SelectAccountingVO> children;
 }

+ 15 - 0
src/main/java/com/imed/costaccount/service/AccountingService.java

@@ -2,6 +2,7 @@ package com.imed.costaccount.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.dto.AccountingEditDTO;
 import com.imed.costaccount.model.dto.AccountingSaveDTO;
 import com.imed.costaccount.model.vo.AccountVO;
 import com.imed.costaccount.model.Accounting;
@@ -39,5 +40,19 @@ public interface AccountingService extends IService<Accounting> {
      * @return
      */
     List<SelectAccountingVO> selectAccounting(User user);
+
+    /**
+     * 编辑科目代码
+     * @param accountingEditDTO
+     * @param user
+     */
+    void updateAccount(AccountingEditDTO accountingEditDTO, User user);
+
+    /**
+     * 删除
+     * @param id
+     * @param user
+     */
+    void deleteAccount(Integer id, User user);
 }
 

+ 35 - 0
src/main/java/com/imed/costaccount/service/ProductService.java

@@ -0,0 +1,35 @@
+package com.imed.costaccount.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.imed.costaccount.common.util.PageUtils;
+import com.imed.costaccount.model.Product;
+import com.imed.costaccount.model.ProductDTO;
+import com.imed.costaccount.model.User;
+
+/**
+ * 成本管理表
+ *
+ * @author huangrui
+ * @email 
+ * @date 2021-07-28 18:44:20
+ */
+public interface ProductService extends IService<Product> {
+
+    /**
+     * 分页查询
+     * @param page
+     * @param pageSize
+     * @param name
+     * @param user
+     * @return
+     */
+    PageUtils selectList(Integer page, Integer pageSize, String name, User user);
+
+    /**
+     * 保存成本项目
+     * @param productDTO
+     * @param user
+     */
+    void saveProduct(ProductDTO productDTO, User user);
+}
+

+ 139 - 10
src/main/java/com/imed/costaccount/service/impl/AccountingServiceImpl.java

@@ -8,23 +8,21 @@ import com.imed.costaccount.common.exception.CostException;
 import com.imed.costaccount.mapper.AccountingMapper;
 import com.imed.costaccount.model.Accounting;
 import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.dto.AccountingEditDTO;
 import com.imed.costaccount.model.dto.AccountingSaveDTO;
 import com.imed.costaccount.model.vo.AccountVO;
 import com.imed.costaccount.model.vo.SelectAccountingVO;
 import com.imed.costaccount.service.AccountingService;
 import com.imed.costaccount.utils.BeanUtil;
-import org.apache.commons.beanutils.BeanUtilsBean;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
-
+@Slf4j
 @Service("accountingService")
 public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Accounting> implements AccountingService {
 
@@ -150,7 +148,15 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
             return Collections.emptyList();
         }
         // 所有的
-        List<SelectAccountingVO> all = list.stream().map(i -> BeanUtil.convertObj(i, SelectAccountingVO.class)).collect(Collectors.toList());
+        List<SelectAccountingVO> all = list.stream().map(i ->{
+            SelectAccountingVO vo = new SelectAccountingVO();
+            vo.setValue(i.getId());
+            vo.setLabel(i.getAccountingName());
+            vo.setChildren(null);
+            vo.setParentId(i.getParentId());
+            vo.setAllParentIds(i.getAllParentIds());
+            return vo;
+        }).collect(Collectors.toList());
         // 顶层的
         List<SelectAccountingVO> parents = all.stream().filter(i -> i.getParentId() == 0).collect(Collectors.toList());
         List<SelectAccountingVO> accountVOS = new ArrayList<>();
@@ -165,13 +171,13 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
         List<SelectAccountingVO> accountVOS = new ArrayList<>();
         for (SelectAccountingVO account : all) {
             // 如果是父子关系
-            if (parent.getId().equals(account.getParentId())) {
-                List<SelectAccountingVO> child = parent.getChild();
+            if (parent.getValue().equals(account.getParentId())) {
+                List<SelectAccountingVO> child = parent.getChildren();
                 if (CollUtil.isEmpty(child)) {
                     child = new ArrayList<>();
                 }
                 child.add(account);
-                parent.setChild(child);
+                parent.setChildren(child);
                 // 处理子节点
                 this.getSelectAccountTree(account, all);
 
@@ -180,4 +186,127 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
         }
         return accountVOS;
     }
+
+    /**
+     * 编辑科目代码
+     *
+     * @param accountingEditDTO
+     * @param user
+     */
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
+    public void updateAccount(AccountingEditDTO accountingEditDTO, User user) {
+        Integer id = accountingEditDTO.getId();
+        this.checkAccountingCode(accountingEditDTO.getAccountingCode(), user.getHospId());
+        Accounting byId = this.getById(id);
+        if (Objects.isNull(byId)) {
+            throw new CostException(500, "当前选中会计科目已被移除");
+        }
+        // 直接修改
+        byId.setAccountingCode(accountingEditDTO.getAccountingCode());
+        byId.setAccountingName(accountingEditDTO.getAccountingName());
+        byId.setCreateTime(System.currentTimeMillis());
+        byId.setAccountingType(accountingEditDTO.getAccountingType());
+        this.updateById(byId);
+//        this.removeById(id);
+//        Accounting accounting = BeanUtil.convertObj(byId, Accounting.class);
+//        saveAccount(accountingEditDTO, user, byId, accounting);
+//        List<Accounting> list = new ArrayList<>();
+//        this.getAndAllChild(Arrays.asList(id), user.getHospId(), list);
+//        log.info("list:{}", list);
+//        if (CollUtil.isEmpty(list)) {
+//            return;
+//        }
+//        // 第一个子节点
+//        List<Accounting> childList = list.stream().filter(i -> i.getParentId().equals(id)).collect(Collectors.toList());
+//        if (CollUtil.isEmpty(childList)) {
+//            throw new CostException(500, "数据异常");
+//        }
+//        childList.forEach(i -> {
+//            i.setParentId(accounting.getId());
+//            String allParentIds = setAllParentIds(byId);
+//            i.setAllParentIds(allParentIds);
+//        });
+//        this.updateBatchById(childList);
+//
+//
+    }
+
+//    private String setAllParentIds(Accounting byId) {
+//        Integer parentId = byId.getParentId();
+//        // 不是顶层的
+//        String allParentIds = "0";
+//        if (parentId != 0) {
+//            String oldParentIds = byId.getAllParentIds();
+//            if ("0".equals(oldParentIds)) {
+//                allParentIds = parentId + "";
+//            } else {
+//                allParentIds = oldParentIds + "-" + parentId;
+//            }
+//        }
+//        return allParentIds;
+//    }
+
+    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
+    public void saveAccount(AccountingEditDTO accountingEditDTO, User user, Accounting byId, Accounting accounting) {
+        this.checkAccountingCode(accountingEditDTO.getAccountingCode(), user.getHospId());
+        accounting.setAccountingCode(accounting.getAccountingCode());
+        accounting.setCreateTime(System.currentTimeMillis());
+        // 新增逻辑
+        Integer parentId = byId.getParentId();
+        // 不是顶层的
+        String allParentIds = "0";
+        if (parentId != 0) {
+            String oldParentIds = byId.getAllParentIds();
+            if ("0".equals(oldParentIds)) {
+                allParentIds = parentId + "";
+            } else {
+                allParentIds = oldParentIds + "-" + parentId;
+            }
+        }
+        accounting.setHospId(user.getHospId());
+        accounting.setParentId(parentId);
+        accounting.setAllParentIds(allParentIds);
+        accounting.setCreateTime(System.currentTimeMillis());
+        this.save(accounting);
+    }
+
+    /**
+     * 得到自己还有所有的子节点
+     * @param ids
+     * @param accounts
+     * @return
+     */
+    private List<Accounting> getAndAllChild(List<Integer> ids, Integer hospId, List<Accounting> accounts) {
+
+        List<Accounting> list = this.list(
+                new LambdaQueryWrapper<Accounting>()
+                        .in(Accounting::getParentId, ids).eq(Accounting::getHospId,hospId)
+        );
+        if (CollUtil.isEmpty(list)) {
+            return accounts;
+        }
+        accounts.addAll(list);
+        this.getAndAllChild(list.stream().map(Accounting::getId).collect(Collectors.toList()), hospId, accounts);
+        return accounts;
+    }
+
+    /**
+     * 删除
+     *
+     * @param id
+     * @param user
+     */
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
+    public void deleteAccount(Integer id, User user) {
+        List<Accounting> list = new ArrayList<>();
+        List<Accounting> andAllChild = this.getAndAllChild(Arrays.asList(id), user.getHospId(), list);
+        if (CollUtil.isEmpty(andAllChild)) {
+            this.removeById(id);
+        }
+        List<Integer> collect = andAllChild.stream().map(Accounting::getId).collect(Collectors.toList());
+        collect.add(id);
+        this.removeByIds(collect);
+    }
 }

+ 77 - 0
src/main/java/com/imed/costaccount/service/impl/ProductServiceImpl.java

@@ -0,0 +1,77 @@
+package com.imed.costaccount.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.imed.costaccount.common.util.PageUtils;
+import com.imed.costaccount.model.ProductDTO;
+import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.vo.ProductVO;
+import com.imed.costaccount.utils.BeanUtil;
+import io.swagger.models.auth.In;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import com.imed.costaccount.mapper.ProductMapper;
+import com.imed.costaccount.model.Product;
+import com.imed.costaccount.service.ProductService;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+
+@Service("productService")
+public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
+
+
+    /**
+     * 分页查询
+     *
+     * @param page
+     * @param pageSize
+     * @param name
+     * @param user
+     * @return
+     */
+    @Override
+    public PageUtils selectList(Integer page, Integer pageSize, String name, User user) {
+        Page<Product> productPage = new Page<>(page, pageSize);
+        Page<Product> pages = this.page(productPage,
+                new LambdaQueryWrapper<Product>()
+                        .eq(Product::getHospId, user.getHospId())
+                        .eq(StrUtil.isNotBlank(name), Product::getProductName, name)
+        );
+        PageUtils pageUtils = new PageUtils(pages);
+        List<Product> records = pages.getRecords();
+        List<ProductVO> list = BeanUtil.convertList(records, ProductVO.class);
+        pageUtils.setList(list);
+        return pageUtils;
+    }
+
+    /**
+     * 保存成本项目
+     *
+     * @param productDTO
+     * @param user
+     */
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
+    public void saveProduct(ProductDTO productDTO, User user) {
+        // 校验code
+
+    }
+
+    private void checkProductCode(Integer code, Integer hospId) {
+        List<Product> list = this.list(
+                new LambdaQueryWrapper<Product>()
+                        .eq(Product::getProductCode, code)
+                        .eq(Product::getHospId, hospId)
+        );
+        if (CollUtil.isNotEmpty(list)) {
+            
+        }
+    }
+}

+ 5 - 1
src/main/java/com/imed/costaccount/service/impl/ResponsibilityDepartmentServiceImpl.java

@@ -43,7 +43,11 @@ public class ResponsibilityDepartmentServiceImpl
     public List<CenterDepartmentVO> getCenterDepart(User user) {
         List<CenterDepartmentVO> list = responsibilityService.getParentSon(user);
         for (CenterDepartmentVO centerDepartmentVO : list) {
-            for (CenterDepartmentVO departmentVO : centerDepartmentVO.getChild()) {
+            List<CenterDepartmentVO> child = centerDepartmentVO.getChild();
+            if (CollUtil.isEmpty(child)) {
+                child = new ArrayList<>();
+            }
+            for (CenterDepartmentVO departmentVO : child) {
                 List<DepartVO> departVOS = baseMapper.getDepartByCenterId(departmentVO.getResponsibilityId());
                 departmentVO.setDepartments(departVOS);
             }

+ 11 - 9
src/main/java/com/imed/costaccount/web/AccountingController.java

@@ -3,8 +3,10 @@ package com.imed.costaccount.web;
 import com.imed.costaccount.common.util.Result;
 import com.imed.costaccount.model.Accounting;
 import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.dto.AccountingEditDTO;
 import com.imed.costaccount.model.dto.AccountingSaveDTO;
 import com.imed.costaccount.model.vo.AccountVO;
+import com.imed.costaccount.model.vo.SelectAccountingVO;
 import com.imed.costaccount.service.AccountingService;
 import com.imed.costaccount.utils.PageUtils;
 import io.swagger.annotations.Api;
@@ -67,19 +69,19 @@ public class AccountingController {
     /**
      * 修改
      */
-    @RequestMapping("/update")
-    public Result update(@RequestBody Accounting accounting){
+    @ApiOperation("编辑")
+    @PostMapping("/edit")
+    public Result update(@RequestBody @Valid AccountingEditDTO accountingEditDTO){
         User user = (User) SecurityUtils.getSubject().getPrincipal();
-//		accountingService.updateById(accounting,user);
+		accountingService.updateAccount(accountingEditDTO,user);
         return Result.ok();
     }
 
-    /**
-     * 删除
-     */
-    @RequestMapping("/delete")
-    public Result delete(@RequestBody Integer[] ids){
-		accountingService.removeByIds(Arrays.asList(ids));
+    @ApiOperation("删除")
+    @PostMapping("/delete")
+    public Result delete(@RequestParam Integer id){
+        User user = (User) SecurityUtils.getSubject().getPrincipal();
+        accountingService.deleteAccount(id,user);
         return Result.ok();
     }
 

+ 75 - 0
src/main/java/com/imed/costaccount/web/ProductController.java

@@ -0,0 +1,75 @@
+package com.imed.costaccount.web;
+
+import com.imed.costaccount.common.util.PageUtils;
+import com.imed.costaccount.common.util.Result;
+import com.imed.costaccount.model.Product;
+import com.imed.costaccount.model.ProductDTO;
+import com.imed.costaccount.model.User;
+import com.imed.costaccount.service.ProductService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.shiro.SecurityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.Arrays;
+
+
+/**
+ * 成本管理表
+ *
+ * @author huangrui
+ * @date 2021-07-28 18:44:20
+ */
+@Api(tags = "收入及成本项目管理")
+@RestController
+@RequestMapping("/costAccount/product")
+public class ProductController {
+
+    private final ProductService productService;
+
+    public ProductController(ProductService productService) {
+        this.productService = productService;
+    }
+
+    /**
+     * 分页查询列表
+     */
+    @ApiOperation("成本项目列表")
+    @GetMapping("/list")
+    public Result list(@RequestParam(defaultValue = "1", value = "page") Integer page,
+                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
+                       @RequestParam(value = "name", required = false) String name){
+        User user = (User) SecurityUtils.getSubject().getPrincipal();
+        PageUtils pageUtils = productService.selectList(page, pageSize,name, user);
+        return Result.ok(pageUtils);
+    }
+
+    @ApiOperation("新增成本项目")
+    @PostMapping("/save")
+    public Result save(@RequestBody @Valid ProductDTO productDTO){
+        User user = (User) SecurityUtils.getSubject().getPrincipal();
+		productService.saveProduct(productDTO,user);
+        return Result.ok();
+    }
+
+    /**
+     * 修改
+     */
+    @RequestMapping("/update")
+    public Result update(@RequestBody Product product){
+		productService.updateById(product);
+        return Result.ok();
+    }
+
+    /**
+     * 删除
+     */
+    @RequestMapping("/delete")
+    public Result delete(@RequestBody Integer[] ids){
+		productService.removeByIds(Arrays.asList(ids));
+        return Result.ok();
+    }
+
+}

+ 1 - 1
src/main/resources/banner.txt

@@ -19,7 +19,7 @@ ${AnsiColor.BRIGHT_YELLOW}
 //      ========`-.____`-.___\_____/___.-`____.-'========         //
 //                           `=---='                              //
 //      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
-//            佛祖保佑       永不宕机     永无BUG                  //
+//            佛祖保佑       永不宕机     永无BUG                     //
 ////////////////////////////////////////////////////////////////////
 ${AnsiColor.BRIGHT_RED}
 Application Version: ${application.version}${application.formatted-version}

+ 17 - 0
src/main/resources/mapper/ProductMapper.xml

@@ -0,0 +1,17 @@
+<?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.imed.costaccount.mapper.ProductMapper">
+
+	<!-- 可根据自己的需求,是否要使用 -->
+    <resultMap type="com.imed.costaccount.model.Product" id="productMap">
+        <result property="id" column="id"/>
+        <result property="productName" column="product_name"/>
+        <result property="productCode" column="product_code"/>
+        <result property="hospId" column="hosp_id"/>
+        <result property="createTime" column="create_time"/>
+        <result property="deleteTime" column="delete_time"/>
+    </resultMap>
+
+
+</mapper>