2
0
hr 4 лет назад
Родитель
Сommit
5a71265035

+ 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;
 
 }

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

@@ -47,5 +47,12 @@ public interface AccountingService extends IService<Accounting> {
      * @param user
      */
     void updateAccount(AccountingEditDTO accountingEditDTO, User user);
+
+    /**
+     * 删除
+     * @param id
+     * @param user
+     */
+    void deleteAccount(Integer id, User user);
 }
 

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

@@ -15,7 +15,6 @@ import com.imed.costaccount.model.vo.SelectAccountingVO;
 import com.imed.costaccount.service.AccountingService;
 import com.imed.costaccount.utils.BeanUtil;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.beanutils.BeanUtilsBean;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
@@ -187,18 +186,81 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
      * @param user
      */
     @Override
+    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
     public void updateAccount(AccountingEditDTO accountingEditDTO, User user) {
         Integer id = accountingEditDTO.getId();
-        List<Accounting> accounts = new ArrayList<>();
+        this.checkAccountingCode(accountingEditDTO.getAccountingCode(), user.getHospId());
         Accounting byId = this.getById(id);
-        // TODO: 2021/7/28 校验
-        accounts.add(byId);
-        // 如果是顶层的修改
-        getAndAllChild(Arrays.asList(id), user.getHospId(), accounts);
-        log.info("得到所有的这个下面的列表:{}", accounts);
-        Map<Integer, List<Accounting>> map = accounts.stream().collect(Collectors.groupingBy(Accounting::getId));
-        // 删除所有的列表
-//        this.remove
+        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);
     }
 
     /**
@@ -220,4 +282,23 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
         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);
+    }
 }

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

@@ -69,19 +69,19 @@ public class AccountingController {
     /**
      * 修改
      */
-    @RequestMapping("/edit")
+    @ApiOperation("编辑")
+    @PostMapping("/edit")
     public Result update(@RequestBody @Valid AccountingEditDTO accountingEditDTO){
         User user = (User) SecurityUtils.getSubject().getPrincipal();
 		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();
     }