Procházet zdrojové kódy

07 28 04 add accounting codes

hr před 4 roky
rodič
revize
59fa62a061

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

@@ -0,0 +1,16 @@
+package com.imed.costaccount.mapper;
+
+import com.imed.costaccount.model.Accounting;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 会计科目管理表
+ * 
+ * @author huangrui
+ * @date 2021-07-28 13:52:24
+ */
+@Mapper
+public interface AccountingMapper extends BaseMapper<Accounting> {
+	
+}

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

@@ -0,0 +1,69 @@
+package com.imed.costaccount.model;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+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 13:52:24
+ */
+@Data
+@Accessors(chain = true)
+@AllArgsConstructor
+@NoArgsConstructor
+@TableName("cost_accounting")
+public class Accounting implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 主键
+	 */
+	@TableId
+	private Integer id;
+	/**
+	 * 会计科目名称
+	 */
+	private String accountingName;
+	/**
+	 * 会计科目代码
+	 */
+	private String accountingCode;
+	/**
+	 * 会计科目类型1.收入,2.支出
+	 */
+	private Integer accountingType;
+	/**
+	 * 是否固定成本 0.不是,1.是
+	 */
+	private Integer isBaseCost;
+	/**
+	 * 医院Id
+	 */
+	private Integer hospId;
+	/**
+	 * 会计科目父级id
+	 */
+	private Integer parentId;
+
+	private String allParentIds;
+	/**
+	 * 创建时间13位时间戳
+	 */
+	private Long createTime;
+	/**
+	 * 删除时间,如果存在表示已删除13位时间戳
+	 */
+	private Long deleteTime;
+
+}

+ 24 - 0
src/main/java/com/imed/costaccount/model/dto/AccountingSaveDTO.java

@@ -0,0 +1,24 @@
+package com.imed.costaccount.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
+@Data
+@ApiModel
+public class AccountingSaveDTO {
+
+    @NotNull(message = "层级id不能为空,顶层传0")
+    private Integer id;
+
+    @NotEmpty(message = "新增科目代码不能为空")
+    private String accountingCode;
+
+    @NotEmpty(message = "新增科目名称不能为空")
+    private String accountingName;
+
+    @NotNull(message = "会计科目类型不能为空")
+    private Integer accountingType;
+}

+ 27 - 0
src/main/java/com/imed/costaccount/model/vo/AccountVO.java

@@ -0,0 +1,27 @@
+package com.imed.costaccount.model.vo;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+@ApiModel
+public class AccountVO {
+
+    private Integer id;
+
+    private String accountingName;
+
+    private String accountingCode;
+
+    @JsonIgnore
+    private Integer parentId;
+
+    private Integer isBaseCost;
+
+    private List<AccountVO> child;
+
+
+}

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

@@ -0,0 +1,35 @@
+package com.imed.costaccount.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.dto.AccountingSaveDTO;
+import com.imed.costaccount.model.vo.AccountVO;
+import com.imed.costaccount.model.Accounting;
+
+import java.util.List;
+
+/**
+ * 会计科目管理表
+ *
+ * @author huangrui
+ * @email 
+ * @date 2021-07-28 13:52:24
+ */
+public interface AccountingService extends IService<Accounting> {
+
+    /**
+     * 获取会计科目列表按收入支出类型
+     * @param accountType  会计科目类型1.收入,2.支出
+     * @param user
+     * @return
+     */
+    List<AccountVO> getListByAccountType(Integer accountType, User user);
+
+    /**
+     * 保存会计科目
+     * @param accountingSaveDTO
+     * @param user
+     */
+    void saveAccounting(AccountingSaveDTO accountingSaveDTO, User user);
+}
+

+ 135 - 0
src/main/java/com/imed/costaccount/service/impl/AccountingServiceImpl.java

@@ -0,0 +1,135 @@
+package com.imed.costaccount.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+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.AccountingSaveDTO;
+import com.imed.costaccount.model.vo.AccountVO;
+import com.imed.costaccount.service.AccountingService;
+import com.imed.costaccount.utils.BeanUtil;
+import org.apache.commons.beanutils.BeanUtilsBean;
+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.stream.Collectors;
+
+
+@Service("accountingService")
+public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Accounting> implements AccountingService {
+
+
+    /**
+     * 获取会计科目列表按收入支出类型
+     *
+     * @param accountType 会计科目类型1.收入,2.支出
+     * @param user
+     * @return
+     */
+    @Override
+    public List<AccountVO> getListByAccountType(Integer accountType, User user) {
+        // 1. 得到所有的会计科目
+        List<Accounting> list = this.list(
+                new LambdaQueryWrapper<Accounting>()
+                        .eq(Accounting::getHospId, user.getHospId())
+        );
+        if (CollUtil.isEmpty(list)) {
+            return Collections.emptyList();
+        }
+        // 所有的
+        List<AccountVO> all = list.stream().map(i -> BeanUtil.convertObj(i, AccountVO.class)).collect(Collectors.toList());
+        // 顶层的
+        List<AccountVO> parents = all.stream().filter(i -> i.getParentId() == 0).collect(Collectors.toList());
+        List<AccountVO> accountVOS = new ArrayList<>();
+        for (AccountVO parent : parents) {
+            List<AccountVO> accountTree = this.getAccountTree(parent, all);
+            accountVOS.addAll(accountTree);
+        }
+        return accountVOS;
+    }
+
+    /**
+     * 递归处理
+     * @param accountVO
+     * @param list
+     * @return
+     */
+    private List<AccountVO> getAccountTree(AccountVO accountVO, List<AccountVO> list) {
+        List<AccountVO> accountVOS = new ArrayList<>();
+        for (AccountVO account : list) {
+            // 如果是父子关系
+            if (accountVO.getId().equals(account.getParentId())) {
+                List<AccountVO> child = accountVO.getChild();
+                if (CollUtil.isEmpty(child)) {
+                    child = new ArrayList<>();
+                }
+                child.add(account);
+                accountVO.setChild(child);
+                // 处理子节点
+                this.getAccountTree(account, list);
+
+                accountVOS.add(accountVO);
+            }
+        }
+        return accountVOS;
+    }
+
+
+    /**
+     * 保存会计科目
+     *
+     * @param accountingSaveDTO
+     * @param user
+     */
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED)
+    public void saveAccounting(AccountingSaveDTO accountingSaveDTO, User user) {
+        // 校验会计科目代码
+        this.checkAccountingCode(accountingSaveDTO.getAccountingCode(), user.getHospId());
+
+        // 新增逻辑
+        Integer parentId = accountingSaveDTO.getId();
+        // 不是顶层的
+        String allParentIds = "0";
+        if (parentId != 0) {
+            Accounting byId = this.getById(parentId);
+            if (Objects.isNull(byId)) {
+                throw new CostException(500, "上层级别会计科目已被移除");
+            }
+            String oldParentIds = byId.getAllParentIds();
+            if ("0".equals(oldParentIds)) {
+                allParentIds = parentId + "";
+            } else {
+                allParentIds = oldParentIds + "-" + parentId;
+            }
+        }
+        Accounting accounting = BeanUtil.convertObj(accountingSaveDTO, Accounting.class);
+        accounting.setHospId(user.getHospId());
+        accounting.setParentId(parentId);
+        accounting.setAllParentIds(allParentIds);
+        accounting.setCreateTime(System.currentTimeMillis());
+        this.save(accounting);
+
+    }
+
+
+    private void checkAccountingCode(String code, Integer hospId) {
+        List<Accounting> list = this.baseMapper.selectList(
+                new QueryWrapper<Accounting>().lambda().select(Accounting::getId)
+                        .eq(Accounting::getAccountingCode, code)
+                        .eq(Accounting::getHospId, hospId)
+        );
+        if (CollUtil.isNotEmpty(list)) {
+            throw new CostException(500, "会计科目代码已存在,请重新生成");
+        }
+    }
+}

+ 89 - 0
src/main/java/com/imed/costaccount/web/AccountingController.java

@@ -0,0 +1,89 @@
+package com.imed.costaccount.web;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import com.imed.costaccount.common.util.Result;
+import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.dto.AccountingSaveDTO;
+import com.imed.costaccount.model.vo.AccountVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import com.imed.costaccount.model.Accounting;
+import com.imed.costaccount.service.AccountingService;
+import com.imed.costaccount.utils.PageUtils;
+
+import javax.validation.Valid;
+
+
+/**
+ * 会计科目管理表
+ *
+ * @author huangrui
+ * @date 2021-07-28 13:52:24
+ */
+@Api(tags = "会计科目")
+@RestController
+@RequestMapping("/costAccount/accounting")
+public class AccountingController {
+    private final AccountingService accountingService;
+
+    public AccountingController(AccountingService accountingService) {
+        this.accountingService = accountingService;
+    }
+
+    @ApiOperation("获取会计科目列表按收入支出类型")
+    @GetMapping("/list")
+    @ApiImplicitParam(name = "accountType",value = "会计科目类型1.收入,2.支出")
+    public Result list(@RequestParam Integer accountType){
+        User user = (User) SecurityUtils.getSubject().getPrincipal();
+        List<AccountVO> list = accountingService.getListByAccountType(accountType, user);
+        PageUtils pageUtils = new PageUtils(list, 0, 0, 0);
+        return Result.ok(pageUtils);
+    }
+
+
+
+    @ApiOperation("保存会计科目")
+    @PostMapping("/save")
+    public Result save(@RequestBody @Valid AccountingSaveDTO accountingSaveDTO){
+        User user = (User) SecurityUtils.getSubject().getPrincipal();
+		accountingService.saveAccounting(accountingSaveDTO,user);
+        return Result.ok();
+    }
+
+
+//    @ApiOperation("选择会计科目列表")
+//    @PostMapping("/selectAccounting")
+//    public Result selectAccounting(){
+//        User user = (User) SecurityUtils.getSubject().getPrincipal();
+//        List<SelectAccountingVO> list = accountingService.selectAccounting(accountingSaveDTO,user);
+//        return Result.ok();
+//    }
+    /**
+     * 修改
+     */
+    @RequestMapping("/update")
+    public Result update(@RequestBody Accounting accounting){
+        User user = (User) SecurityUtils.getSubject().getPrincipal();
+//		accountingService.updateById(accounting,user);
+        return Result.ok();
+    }
+
+    /**
+     * 删除
+     */
+    @RequestMapping("/delete")
+    public Result delete(@RequestBody Integer[] ids){
+		accountingService.removeByIds(Arrays.asList(ids));
+        return Result.ok();
+    }
+
+}

+ 2 - 2
src/main/java/com/imed/costaccount/web/LoginController.java

@@ -18,8 +18,8 @@ import java.util.List;
 @RequestMapping("/costAccount")
 public class LoginController {
 
-    private UserService userService;
-    private HospitalService hospitalService;
+    private final UserService userService;
+    private final HospitalService hospitalService;
 
     public LoginController(UserService userService, HospitalService hospitalService) {
         this.userService = userService;

+ 5 - 0
src/main/java/com/imed/costaccount/web/test.json

@@ -0,0 +1,5 @@
+{
+  "id": 1,
+  "accountingCode": "10002342",
+  "accountingName": "234234"
+}

+ 21 - 0
src/main/resources/mapper/AccountingMapper.xml

@@ -0,0 +1,21 @@
+<?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.AccountingMapper">
+
+	<!-- 可根据自己的需求,是否要使用 -->
+    <resultMap type="com.imed.costaccount.model.Accounting" id="accountingMap">
+        <result property="id" column="id"/>
+        <result property="accountingName" column="accounting_name"/>
+        <result property="accountingCode" column="accounting_code"/>
+        <result property="accountingType" column="accounting_type"/>
+        <result property="isBaseCost" column="is_base_cost"/>
+        <result property="hospId" column="hosp_id"/>
+        <result property="parentId" column="parent_id"/>
+        <result property="allParentIds" column="all_parent_ids"/>
+        <result property="createTime" column="create_time"/>
+        <result property="deleteTime" column="delete_time"/>
+    </resultMap>
+
+
+</mapper>