Bladeren bron

往来账款 增删改查功能;企业查询共通方法

dudm 3 jaren geleden
bovenliggende
commit
d0fddbc208

+ 13 - 1
sc-service/src/main/java/com/huyi/service/base/entity/ZcBillInf.java

@@ -15,7 +15,7 @@ import lombok.experimental.Accessors;
  * </p>
  *
  * @author xuefy
- * @since 2021-08-16
+ * @since 2021-08-20
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -32,6 +32,12 @@ public class ZcBillInf implements Serializable {
     private String zbiId;
 
     /**
+     * 账款编号
+     */
+    @TableField("zbi_number")
+    private String zbiNumber;
+
+    /**
      * 账款名称
      */
     @TableField("zbi_name")
@@ -92,6 +98,12 @@ public class ZcBillInf implements Serializable {
     private String zbiDistributor;
 
     /**
+     * 状态(00:正常, 80:初始化, 99:删除)
+     */
+    @TableField("zbi_status")
+    private String zbiStatus;
+
+    /**
      * 备注
      */
     @TableField("zbi_remark")

+ 1 - 1
sc-service/src/main/java/com/huyi/service/base/mapper/ZcBillInfMapper.java

@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * </p>
  *
  * @author xuefy
- * @since 2021-08-16
+ * @since 2021-08-20
  */
 public interface ZcBillInfMapper extends BaseMapper<ZcBillInf> {
 

+ 1 - 1
sc-service/src/main/java/com/huyi/service/base/service/IZcBillInfService.java

@@ -17,7 +17,7 @@ import java.util.List;
  * Company: keao
  *
  * @author xuefy
- * @version v1.0.0    2021-08-16  xuefy    由Generator自动创建
+ * @version v1.0.0    2021-08-20  xuefy    由Generator自动创建
  */
 public interface IZcBillInfService extends IService<ZcBillInf> {
     /**

+ 1 - 1
sc-service/src/main/java/com/huyi/service/base/service/impl/ZcBillInfServiceImpl.java

@@ -24,7 +24,7 @@ import java.util.List;
  * Company: keao
  *
  * @author xuefy
- * @version v1.0.0    2021-08-16  xuefy    由Generator自动创建
+ * @version v1.0.0    2021-08-20  xuefy    由Generator自动创建
  */
 @Service
 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)

+ 427 - 48
sc-service/src/main/java/com/huyi/service/bill/controller/OwnBillController.java

@@ -1,35 +1,40 @@
 package com.huyi.service.bill.controller;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huyi.service.base.entity.ZcBillFileRel;
 import com.huyi.service.base.entity.ZcBillInf;
+import com.huyi.service.base.entity.ZcBillInvoiceRel;
 import com.huyi.service.base.entity.ZcInvoiceInf;
-import com.huyi.service.base.service.IZcBillInfService;
-import com.huyi.service.base.service.IZcInvoiceInfService;
+import com.huyi.service.base.service.*;
 import com.huyi.service.bill.service.IOwnBillService;
 import com.keao.tianhu.starter.mybatis.plus.entity.QueryRequest;
 import com.tianhu.common.core.constant.SalaryConstants;
 import com.tianhu.common.core.domain.R;
-import com.tianhu.common.core.utils.CommonUtil;
-import com.tianhu.common.core.utils.DateUtils;
-import com.tianhu.common.core.utils.SecurityUtils;
-import com.tianhu.common.core.utils.ServletUtils;
+import com.tianhu.common.core.utils.*;
 import com.tianhu.common.core.web.controller.BaseController;
+import com.tianhu.common.core.web.domain.AjaxResult;
+import com.tianhu.common.log.annotation.Log;
+import com.tianhu.common.log.enums.BusinessType;
+import com.tianhu.common.security.annotation.PreAuthorize;
 import com.tianhu.common.security.service.TokenService;
 import com.tianhu.system.api.RemoteFileService;
 import com.tianhu.system.api.domain.PubFileInf;
 import com.tianhu.system.api.domain.SysUser;
 import com.tianhu.system.api.model.LoginUser;
+import lombok.SneakyThrows;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cglib.beans.BeanMap;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 往来账款管理
@@ -59,23 +64,36 @@ public class OwnBillController extends BaseController {
     private  IZcInvoiceInfService iZcInvoiceInfService;
 
     @Autowired
+    private IZcBillInvoiceRelService iZcBillInvoiceRelService;
+
+    @Autowired
+    private IZcBillFileRelService iZcBillFileRelService;
+
+    @Autowired
+    private IPubFileInfService iPubFileInfService;
+
+    @Autowired
     private RemoteFileService remoteFileService;
 
     /**
      * 往来账款列表
      *
      * @param zbiName           账款名称
-     * @param zbiContractNo     合同编号
+     * @param zbiNumber         账款编号
      * @param payerName         应付方
      * @param payeeName         应收方
+     * @param zbiType           账款类型
+     * @param zbiStatus         账款状态
      * @return
      */
     @GetMapping("/billList")
     public R list(
             @RequestParam(required=false) String zbiName,
-            @RequestParam(required=false) String zbiContractNo,
+            @RequestParam(required=false) String zbiNumber,
             @RequestParam(required=false) String payerName,
             @RequestParam(required=false) String payeeName,
+            @RequestParam(required=false) String zbiType,
+            @RequestParam(required=false) String zbiStatus,
             QueryRequest request) {
         //查询当前操作员
         LoginUser userInfo = tokenService.getLoginUser();
@@ -83,62 +101,153 @@ public class OwnBillController extends BaseController {
         //获取企业
         String companyId = user.getCompanyId();
         Map map = new HashMap();
+        //账款类型
+        if("00".equals(zbiType)){
+            map.put("payerId", companyId);
+        }else if ("01".equals(zbiType)){
+            map.put("payeeId", companyId);
+        }
         if (!SalaryConstants.OPEX.equals(companyId)) {
             map.put("companyId", companyId);
         }
         //账款名称
         map.put("zbiName", zbiName);
-        //合同编号
-        map.put("zbiContractNo", zbiContractNo);
+        //账款编号
+        map.put("zbiNumber", zbiNumber);
         //应付方
         map.put("payerName", payerName);
         //应收方
         map.put("payeeName", payeeName);
+        //账款状态
+        map.put("zbiStatus", zbiStatus);
         IPage<Map> list = iOwnBillService.selectBillInfList(map,request);
         return R.ok(list);
     }
 
+    /**
+     * 获取往来账款明细信息
+     */
+    @GetMapping(value = "/{zbiId}")
+    public AjaxResult getBillInf(@PathVariable("zbiId") String zbiId) {
+        //获取用户信息
+        LoginUser userInfo = tokenService.getLoginUser();
+        //企业id
+        String companyId = userInfo.getSysUser().getCompanyId();
+        //查询往来账款
+        ZcBillInf zcBillInf = iZcBillInfService.getById(zbiId);
+        return AjaxResult.success(zcBillInf);
+    }
 
     /**
-     * 新增账款信息
+     * 初始化账款信息
      *
      * @param map    账款信息
      * @return
      */
+    @Log(title = "初始化往来账款信息", businessType = BusinessType.UPDATE)
     @PostMapping("/add")
-    public R add(Map map) throws ParseException {
+    public R add(@RequestBody Map map) throws ParseException {
         //获取登录用户
         LoginUser user = tokenService.getLoginUser();
+        ZcBillInf zcBillInf = new ZcBillInf();
+        //账款名称
+        String zbiId = CommonUtil.objToString(map.get("zbiId"));
         //账款名称
         String zbiName = CommonUtil.objToString(map.get("zbiName"));
+        zcBillInf.setZbiName(zbiName);
         //应付方
         String zbiPayerId = CommonUtil.objToString(map.get("zbiPayerId"));
+        zcBillInf.setZbiPayerId(zbiPayerId);
         //应收方
         String zbiPayeeId = CommonUtil.objToString(map.get("zbiPayeeId"));
+        zcBillInf.setZbiPayeeId(zbiPayeeId);
         //时间格式化
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         //贸易日期
         String zbiDate = CommonUtil.objToString(map.get("zbiDate"));
         Date date = sdf.parse(zbiDate);
+        zcBillInf.setZbiDate(date);
         //预计收付款日期
         String zbiPayDate = CommonUtil.objToString(map.get("zbiPayDate"));
         Date payDate = sdf.parse(zbiPayDate);
+        zcBillInf.setZbiPayDate(payDate);
         //贸易金额
         String zbiAmount = CommonUtil.objToString(map.get("zbiAmount"));
+        zcBillInf.setZbiAmount(zbiAmount);
         //合同编号
         String zbiContractNo = CommonUtil.objToString(map.get("zbiContractNo"));
+        zcBillInf.setZbiContractNo(zbiContractNo);
         //账款服务
         String zbiService = CommonUtil.objToString(map.get("zbiService"));
+        zcBillInf.setZbiService(zbiService);
         //配送订单
         String zbiOrderNo = CommonUtil.objToString(map.get("zbiOrderNo"));
+        zcBillInf.setZbiOrderNo(zbiOrderNo);
         //配送企业
         String zbiDistributor = CommonUtil.objToString(map.get("zbiDistributor"));
+        zcBillInf.setZbiDistributor(zbiDistributor);
         //备注
         String zbiRemark = CommonUtil.objToString(map.get("zbiRemark"));
-        ZcBillInf zcBillInf = new ZcBillInf();
-        iZcBillInfService.createZcBillInf(zcBillInf);
-        //TODO
-        return R.ok();
+        zcBillInf.setZbiRemark(zbiRemark);
+        //创建人
+        zcBillInf.setCreateBy(user.getUserid().toString());
+        //创建时间
+        zcBillInf.setCreateTime(DateUtils.getNowDate());
+        if(CommonUtil.isEmpty(zbiId)){
+            //主键
+            zbiId = IdUtils.fastSimpleUUID();
+            zcBillInf.setZbiId(zbiId);
+            //编号
+            String number = "ASSET1121" + System.currentTimeMillis();
+            zcBillInf.setZbiNumber(number);
+            iZcBillInfService.createZcBillInf(zcBillInf);
+        }else{
+            zcBillInf.setZbiId(zbiId);
+            iZcBillInfService.updateZcBillInf(zcBillInf);
+        }
+        Map res = new HashMap();
+        //返回账款id
+        res.put("zbiId", zbiId);
+        return R.ok(res);
+    }
+
+    /**
+     * 获取往来账款发票信息
+     */
+    @GetMapping(value = "getInvoice/{zbiId}")
+    public AjaxResult getBillInvoice(@PathVariable("zbiId") String zbiId) {
+        //获取用户信息
+        LoginUser userInfo = tokenService.getLoginUser();
+        //企业id
+        String companyId = userInfo.getSysUser().getCompanyId();
+        //查询关联往来账款的发票
+        LambdaQueryWrapper<ZcBillInvoiceRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+        //往来账款id
+        lambdaQueryWrapper.eq(ZcBillInvoiceRel::getZbirBillId,zbiId);
+        List<ZcBillInvoiceRel> relList = iZcBillInvoiceRelService.findZcBillInvoiceRels(lambdaQueryWrapper);
+        List<Map> list = new ArrayList<>();
+        for (ZcBillInvoiceRel zcBillInvoiceRel : relList) {
+            //查询发票
+            ZcInvoiceInf zcInvoiceInf = iZcInvoiceInfService.getById(zcBillInvoiceRel.getZbirInvoiceId());
+            Map map = new HashMap();
+            if (zcInvoiceInf != null) {
+                com.huyi.service.base.entity.PubFileInf pubFileInf = iPubFileInfService.getById(zcInvoiceInf.getZiiFile());
+                BeanMap beanMap = BeanMap.create(zcInvoiceInf);
+                for (Object key : beanMap.keySet()) {
+                    map.put(key+"", beanMap.get(key));
+                }
+                //文件名称
+                map.put("name",pubFileInf.getPfiFileName());
+                //文件url
+                map.put("url",pubFileInf.getPfiFileUrl());
+                //时间格式化
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                String date = sdf.format(map.get("ziiDate"));
+                map.put("ziiDate",date);
+            }
+            list.add(map);
+        }
+        return AjaxResult.success(list);
     }
 
     /**
@@ -147,8 +256,13 @@ public class OwnBillController extends BaseController {
      * @param file    文件
      * @return
      */
+    @Transactional(rollbackFor=Exception.class)
+    @Log(title = "上传往来账款发票", businessType = BusinessType.INSERT)
     @PostMapping("/getInvoiceText")
-    public ZcInvoiceInf getInvoiceText(MultipartFile file) {
+    public R getInvoiceText(@RequestParam("file")MultipartFile file, @RequestParam("zbiId") String zbiId) {
+        if(CommonUtil.isEmpty(zbiId)){
+            R.fail(500,"未获取到要上传发票的账款");
+        }
         //获取登录用户
         LoginUser user = tokenService.getLoginUser();
         String companyId = user.getSysUser().getCompanyId();
@@ -159,49 +273,314 @@ public class OwnBillController extends BaseController {
         queryWrapper.eq(ZcInvoiceInf::getZiiNo,zcInvoiceInf.getZiiNo());
         //发票号码
         queryWrapper.eq(ZcInvoiceInf::getZiiNumber,zcInvoiceInf.getZiiNumber());
+        //发票状态
+        queryWrapper.eq(ZcInvoiceInf::getZiiStatus,"00");
         List<ZcInvoiceInf> list = iZcInvoiceInfService.findZcInvoiceInfs(queryWrapper);
+        String id = IdUtils.fastSimpleUUID();
+        zcInvoiceInf.setZiiId(id);
+        zcInvoiceInf.setZiiCompanyId(companyId);
+        zcInvoiceInf.setCreateBy(user.getUserid().toString());
+        zcInvoiceInf.setCreateTime(DateUtils.getNowDate());
         //不重复则储存发票并上传
         if(list.size() == 0){
-            iZcInvoiceInfService.createZcInvoiceInf(zcInvoiceInf);
-            //TODO 只验真部分发票
-            //验真发票
-            zcInvoiceInf = iOwnBillService.invoiceVerification(zcInvoiceInf);
-            zcInvoiceInf.setCreateBy(user.getUserid().toString());
-            zcInvoiceInf.setCreateTime(DateUtils.getNowDate());
-            //验真通过发票上传到文件服务器
-            if(CHECK_SUCCESS.equals(zcInvoiceInf.getZiiCheckStt())){
-                //获取上传文件token
-                String token = SecurityUtils.getToken(ServletUtils.getRequest());
-                //文件传输
-                R<PubFileInf> fileResult = remoteFileService.uploadFile(file,"01","04","00", companyId, token);
-                zcInvoiceInf.setZiiFile(fileResult.getData().getPfiFileId());
-            }
+            zcInvoiceInf.setZiiCheckStt("0");
         }else{
-            zcInvoiceInf.setZiiId(list.get(0).getZiiId());
+            zcInvoiceInf.setZiiCheckStt("3");
+        }
+        //获取上传文件token
+        String token = SecurityUtils.getToken(ServletUtils.getRequest());
+        //文件传输
+        R<PubFileInf> fileResult = remoteFileService.uploadFile(file,"01","04","00", companyId, token);
+        zcInvoiceInf.setZiiFile(fileResult.getData().getPfiFileId());
+        //创建发票
+        iZcInvoiceInfService.createZcInvoiceInf(zcInvoiceInf);
+        //创建账款发票关联
+        ZcBillInvoiceRel zcBillInvoiceRel = new ZcBillInvoiceRel();
+        zcBillInvoiceRel.setZbirBillId(zbiId);
+        zcBillInvoiceRel.setZbirInvoiceId(id);
+        iZcBillInvoiceRelService.createZcBillInvoiceRel(zcBillInvoiceRel);
+        Map map = new HashMap();
+        map.put("name",fileResult.getData().getPfiFileName());
+        map.put("url",fileResult.getData().getPfiFileUrl());
+        //将发票对象转换成Map集合重新组合
+        if (zcInvoiceInf != null) {
+            BeanMap beanMap = BeanMap.create(zcInvoiceInf);
+            for (Object key : beanMap.keySet()) {
+                map.put(key+"", beanMap.get(key));
+            }
+            //时间格式化
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            String date = sdf.format(map.get("ziiDate"));
+            map.put("ziiDate",date);
         }
+
         //返回发票信息
-        return zcInvoiceInf;
+        return R.ok(map);
     }
 
     /**
      * 重新验真
      *
-     * @param zcInvoiceInf    发票信息
+     * @param fileList    发票信息列表
      * @return
      */
+    @SneakyThrows
+    @Transactional(rollbackFor=Exception.class)
+    @Log(title = "往来账款发票验真", businessType = BusinessType.UPDATE)
     @PostMapping("/invoiceVerification")
-    public ZcInvoiceInf invoiceVerification(ZcInvoiceInf zcInvoiceInf) {
+    public List<ZcInvoiceInf> invoiceVerification(@RequestParam(required = false,value = "fileList") String fileList) {
+        JSONArray jsonArray = JSONArray.parseArray(fileList);
         //获取登录用户
         LoginUser user = tokenService.getLoginUser();
-        if(CommonUtil.isEmpty(zcInvoiceInf.getZiiId())){
-            return zcInvoiceInf;
+        //默认第二条
+        int checkNum = 1;
+        //大于3条则获取随机一条
+        if(jsonArray.size() > 3){
+            Random random = new Random();
+            int num = random.nextInt(jsonArray.size());
+            //如果不是第一条或最后一条则使用随机数
+            if(num != 0 && num != (jsonArray.size() - 1)){
+                checkNum = num;
+            }
         }
-        //验真发票
-        zcInvoiceInf = iOwnBillService.invoiceVerification(zcInvoiceInf);
-        zcInvoiceInf.setUpdateBy(user.getUserid().toString());
-        zcInvoiceInf.setUpdateTime(DateUtils.getNowDate());
-        //修改发票信息
-        iZcInvoiceInfService.updateZcInvoiceInf(zcInvoiceInf);
-        return zcInvoiceInf;
+        List<ZcInvoiceInf> zcInvoiceInfs = new ArrayList<>();
+        //批量验真
+        for (int i = 0; i < jsonArray.size(); i++){
+            JSONObject jsonObject = jsonArray.getJSONObject(i);
+            ZcInvoiceInf zcInvoiceInf = iZcInvoiceInfService.getById(jsonObject.getString("ziiId"));
+
+            LambdaQueryWrapper<ZcInvoiceInf> queryWrapper = new LambdaQueryWrapper<>();
+            //发票代码
+            queryWrapper.eq(ZcInvoiceInf::getZiiNo,jsonObject.getString("ziiNo"));
+            //发票号码
+            queryWrapper.eq(ZcInvoiceInf::getZiiNumber,jsonObject.getString("ziiNumber"));
+            //发票主键
+            queryWrapper.ne(ZcInvoiceInf::getZiiId,jsonObject.getString("ziiId"));
+            //发票状态
+            queryWrapper.eq(ZcInvoiceInf::getZiiStatus,"00");
+            List<ZcInvoiceInf> list = iZcInvoiceInfService.findZcInvoiceInfs(queryWrapper);
+            //不重复则储存发票并上传
+            if(list.size() == 0){
+                if(i != 0 && i != (jsonArray.size() - 1) && i != checkNum){
+                    //没有验真的默认成功
+                    zcInvoiceInf.setZiiCheckStt("1");
+                }else{
+                    //验真发票
+                    zcInvoiceInf = iOwnBillService.invoiceVerification(zcInvoiceInf);
+                }
+            }else{
+                zcInvoiceInf.setZiiCheckStt("3");
+            }
+            zcInvoiceInf.setUpdateBy(user.getUserid().toString());
+            zcInvoiceInf.setUpdateTime(DateUtils.getNowDate());
+            //修改发票信息
+            iZcInvoiceInfService.updateZcInvoiceInf(zcInvoiceInf);
+            zcInvoiceInfs.add(zcInvoiceInf);
+        }
+        return zcInvoiceInfs;
     }
+
+    /**
+     * 删除发票
+     *
+     * @param ziiIds    发票id集合
+     * @return
+     */
+    @SneakyThrows
+    @Transactional(rollbackFor=Exception.class)
+    @Log(title = "删除往来账款发票", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ziiIds}")
+    public R delete(@PathVariable("ziiIds") String[] ziiIds) {
+        //获取登录用户
+        LoginUser user = tokenService.getLoginUser();
+        String companyId = user.getSysUser().getCompanyId();
+        //获取上传文件token
+        String token = SecurityUtils.getToken(ServletUtils.getRequest());
+        for (String ziiId : ziiIds) {
+            ZcInvoiceInf zcInvoiceInf = iZcInvoiceInfService.getById(ziiId);
+            zcInvoiceInf.setZiiStatus("99");
+            //删除发票
+            iZcInvoiceInfService.updateZcInvoiceInf(zcInvoiceInf);
+            LambdaQueryWrapper<ZcBillInvoiceRel> queryWrapper = new LambdaQueryWrapper<>();
+            //发票id
+            queryWrapper.eq(ZcBillInvoiceRel::getZbirInvoiceId, ziiId);
+            //删除发票关联
+            iZcBillInvoiceRelService.deleteZcBillInvoiceRel(queryWrapper);
+            //删除附件
+            remoteFileService.delete(zcInvoiceInf.getZiiFile(), companyId, token);
+        }
+        return R.ok();
+    }
+
+    /**
+     * 上传合同物流附件
+     *
+     * @param file    文件
+     * @return
+     */
+    @Transactional(rollbackFor=Exception.class)
+    @Log(title = "上传往来账款附件", businessType = BusinessType.INSERT)
+    @PostMapping("/uploadBillFile")
+    public R uploadBillFile(@RequestParam("file")MultipartFile file, @RequestParam("zbiId") String zbiId, @RequestParam("type") String type) {
+        if(CommonUtil.isEmpty(zbiId)){
+            R.fail(500,"未获取到要上传发票的账款");
+        }
+        //获取登录用户
+        LoginUser user = tokenService.getLoginUser();
+        String companyId = user.getSysUser().getCompanyId();
+        //获取上传文件token
+        String token = SecurityUtils.getToken(ServletUtils.getRequest());
+        //文件传输
+        R<PubFileInf> fileResult = remoteFileService.uploadFile(file,"01","04","00", companyId, token);
+        //创建账款附件关联
+        ZcBillFileRel zcBillFileRel = new ZcBillFileRel();
+        zcBillFileRel.setZbfrBillId(zbiId);
+        zcBillFileRel.setZbfrFileId(fileResult.getData().getPfiFileId());
+        zcBillFileRel.setZbfrType(type);
+        iZcBillFileRelService.createZcBillFileRel(zcBillFileRel);
+        Map map = new HashMap();
+        map.put("id",fileResult.getData().getPfiFileId());
+        map.put("name",fileResult.getData().getPfiFileName());
+        map.put("url",fileResult.getData().getPfiFileUrl());
+        //返回附件信息
+        return R.ok(map);
+    }
+
+    /**
+     * 获取往来账款附件信息
+     */
+    @GetMapping(value = "getFile/{type}/{zbiId}")
+    public AjaxResult getFile(@PathVariable("type") String type, @PathVariable("zbiId") String zbiId) {
+        //获取用户信息
+        LoginUser userInfo = tokenService.getLoginUser();
+        //企业id
+        String companyId = userInfo.getSysUser().getCompanyId();
+        //查询关联往来账款的发票
+        LambdaQueryWrapper<ZcBillFileRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+        //往来账款id
+        lambdaQueryWrapper.eq(ZcBillFileRel::getZbfrBillId,zbiId);
+        //附件类型
+        lambdaQueryWrapper.eq(ZcBillFileRel::getZbfrType,type);
+        List<ZcBillFileRel> relList = iZcBillFileRelService.findZcBillFileRels(lambdaQueryWrapper);
+        List<Map> list = new ArrayList<>();
+        for (ZcBillFileRel zcBillFileRel : relList) {
+            //查询发票
+            Map map = new HashMap();
+            com.huyi.service.base.entity.PubFileInf pubFileInf = iPubFileInfService.getById(zcBillFileRel.getZbfrFileId());
+            //文件id
+            map.put("id",zcBillFileRel.getZbfrFileId());
+            //文件名称
+            map.put("name",pubFileInf.getPfiFileName());
+            //文件url
+            map.put("url",pubFileInf.getPfiFileUrl());
+            list.add(map);
+        }
+        return AjaxResult.success(list);
+    }
+
+    /**
+     * 删除附件
+     *
+     * @param ids    发票id集合
+     * @return
+     */
+    @SneakyThrows
+    @Transactional(rollbackFor=Exception.class)
+    @Log(title = "删除往来账款附件", businessType = BusinessType.DELETE)
+    @DeleteMapping("delFile/{ids}")
+    public R delFile(@PathVariable("ids") String[] ids) {
+        //获取登录用户
+        LoginUser user = tokenService.getLoginUser();
+        String companyId = user.getSysUser().getCompanyId();
+        //获取上传文件token
+        String token = SecurityUtils.getToken(ServletUtils.getRequest());
+        for (String id : ids) {
+            LambdaQueryWrapper<ZcBillFileRel> queryWrapper = new LambdaQueryWrapper<>();
+            //附件id
+            queryWrapper.eq(ZcBillFileRel::getZbfrFileId, id);
+            //删除附件关联
+            iZcBillFileRelService.deleteZcBillFileRel(queryWrapper);
+            //删除附件
+            remoteFileService.delete(id, companyId, token);
+        }
+        return R.ok();
+    }
+
+    /**
+     * 提交账款信息
+     *
+     * @param zbiId    账款id
+     * @return
+     */
+    @PostMapping("/commitBill/{zbiId}")
+    @Log(title = "提交往来账款信息", businessType = BusinessType.UPDATE)
+    public R commitBill(@PathVariable("zbiId") String zbiId) throws ParseException {
+        //获取登录用户
+        LoginUser user = tokenService.getLoginUser();
+        ZcBillInf zcBillInf = new ZcBillInf();
+        zcBillInf.setZbiId(zbiId);
+        //创建人
+        zcBillInf.setUpdateBy(user.getUserid().toString());
+        //创建时间
+        zcBillInf.setUpdateTime(DateUtils.getNowDate());
+        //修改为正常状态
+        zcBillInf.setZbiStatus("00");
+        iZcBillInfService.updateZcBillInf(zcBillInf);
+        return R.ok();
+    }
+
+    /**
+     * 删除往来账款信息
+     *
+     * @param zbiIds    往来账款id集合
+     * @return
+     */
+    @SneakyThrows
+    @PreAuthorize(hasPermi = "service:bill:del")
+    @Transactional(rollbackFor=Exception.class)
+    @Log(title = "删除往来账款信息", businessType = BusinessType.DELETE)
+    @DeleteMapping("deleteBill/{zbiIds}")
+    public R deleteBill(@PathVariable("zbiIds") String[] zbiIds) {
+        //获取登录用户
+        LoginUser user = tokenService.getLoginUser();
+        String companyId = user.getSysUser().getCompanyId();
+        //获取上传文件token
+        String token = SecurityUtils.getToken(ServletUtils.getRequest());
+        for (String zbiId : zbiIds) {
+            ZcBillInf zcBillInf = iZcBillInfService.getById(zbiId);
+            zcBillInf.setZbiStatus("99");
+            zcBillInf.setUpdateBy(user.getUserid().toString());
+            zcBillInf.setUpdateTime(DateUtils.getNowDate());
+            //删除往来账款
+            iZcBillInfService.updateZcBillInf(zcBillInf);
+
+            LambdaQueryWrapper<ZcBillFileRel> queryWrapper = new LambdaQueryWrapper<>();
+            //往来账款id
+            queryWrapper.eq(ZcBillFileRel::getZbfrBillId, zbiId);
+            List<ZcBillFileRel> billFileRels = iZcBillFileRelService.findZcBillFileRels(queryWrapper);
+            for (ZcBillFileRel zcBillFileRel : billFileRels) {
+                //删除附件
+                remoteFileService.delete(zcBillFileRel.getZbfrFileId(), companyId, token);
+            }
+            //删除附件关联
+            iZcBillFileRelService.deleteZcBillFileRel(queryWrapper);
+
+            LambdaQueryWrapper<ZcBillInvoiceRel> queryWrapperInvoice = new LambdaQueryWrapper<>();
+            //往来账款id
+            queryWrapperInvoice.eq(ZcBillInvoiceRel::getZbirBillId, zbiId);
+            List<ZcBillInvoiceRel>  billInvoiceRels = iZcBillInvoiceRelService.findZcBillInvoiceRels(queryWrapperInvoice);
+            for (ZcBillInvoiceRel zcBillInvoiceRel : billInvoiceRels) {
+                ZcInvoiceInf zcInvoiceInf = iZcInvoiceInfService.getById(zcBillInvoiceRel.getZbirInvoiceId());
+                zcInvoiceInf.setZiiStatus("99");
+                //删除发票
+                iZcInvoiceInfService.updateZcInvoiceInf(zcInvoiceInf);
+                //删除附件
+                remoteFileService.delete(zcInvoiceInf.getZiiFile(), companyId, token);
+            }
+            //删除发票关联
+            iZcBillInvoiceRelService.deleteZcBillInvoiceRel(queryWrapperInvoice);
+        }
+        return R.ok();
+    }
+
 }

+ 12 - 5
sc-service/src/main/java/com/huyi/service/bill/service/impl/OwnBillServiceImpl.java

@@ -99,7 +99,7 @@ public class OwnBillServiceImpl implements IOwnBillService {
         System.out.print("发票文字提取结果==========>" + result);
         ZcInvoiceInf zcInvoiceInf = new ZcInvoiceInf();
         //校验返回结果是否成功
-        if (result != null && result.getJSONObject(WORDS_RESULT) != null) {
+        if (result != null && result.get(WORDS_RESULT) != null) {
             JSONObject wordsResult = result.getJSONObject(WORDS_RESULT);
             //时间格式化
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
@@ -109,7 +109,7 @@ public class OwnBillServiceImpl implements IOwnBillService {
             //发票类型
             String invoiceType = wordsResult.getString("InvoiceType");
             //发票类型编码
-            String type = RedisUtils.getDictValue("invoice_type", invoiceType);
+            String type = RedisUtils.getDictValue("zc_invoice_type", invoiceType);
             zcInvoiceInf.setZiiType(type);
             //校验码
             String checkCode = wordsResult.getString("CheckCode");
@@ -166,13 +166,20 @@ public class OwnBillServiceImpl implements IOwnBillService {
         String type = zcInvoiceInf.getZiiType();
         //不含税金额
         String amount = zcInvoiceInf.getZiiExcludedAmount();
+        System.out.println("发票验真参数==========>:{token:" + getToken() +
+                                                    ",no:" + no +
+                                                    ",number" + number +
+                                                    ",date:" + date +
+                                                    ",checkCode:" + checkCode +
+                                                    ",type:" + type +
+                                                    ",amount:" + amount +"}");
         //获取发票信息
         JSONObject result = OcrUtil.invoiceVerification(getToken(), no, number, date, checkCode, type, amount);
-        System.out.print("发票验真结果==========>" + result);
+        System.out.println("发票验真结果==========>" + result);
         //返回结果校验是否成功
         if (result != null
-                && result.getJSONObject(WORDS_RESULT) != null
-                && VERIFY_SUCCESS.equals(result.getJSONObject(WORDS_RESULT).getString(VERIFY_RESULT))
+                && result.get(WORDS_RESULT) != null
+                && VERIFY_SUCCESS.equals(result.getString(VERIFY_RESULT))
         ) {
             //校验成功
             zcInvoiceInf.setZiiCheckStt(CHECK_SUCCESS);

+ 38 - 0
sc-service/src/main/java/com/huyi/service/common/company/controller/companyController.java

@@ -1,10 +1,14 @@
 package com.huyi.service.common.company.controller;
 
+import com.huyi.service.base.entity.SysCompany;
+import com.huyi.service.base.service.ISysCompanyService;
 import com.huyi.service.common.company.service.CompanyService;
+import com.tianhu.common.core.domain.R;
 import com.tianhu.common.core.utils.CommonUtil;
 import com.tianhu.common.core.web.controller.BaseController;
 import com.tianhu.common.core.web.domain.AjaxResult;
 import com.tianhu.common.security.service.TokenService;
+import com.tianhu.system.api.model.LoginUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -26,6 +30,8 @@ public class companyController extends BaseController {
     private TokenService tokenService;
     @Autowired
     private CompanyService companyService;
+    @Autowired
+    private ISysCompanyService iSysCompanyService;
 
     /**
      * 根据类型获取公司
@@ -42,5 +48,37 @@ public class companyController extends BaseController {
         return AjaxResult.success(list);
     }
 
+    /**
+     * 获取自己企业
+     * @return
+     */
+    @GetMapping("/getOwnCompany")
+    public R getOwnCompany()
+    {
+        //获取当前操作员
+        LoginUser user = tokenService.getLoginUser();
+        String companyId = user.getSysUser().getCompanyId();
+        SysCompany sysCompany = iSysCompanyService.getById(companyId);
+        return R.ok(sysCompany);
+    }
 
+    /**
+     * 查询链属列表
+     * @param companyName   企业名称
+     * @return
+     */
+    @GetMapping("/companyRelList")
+    public R companyRelList(String companyName)
+    {
+        //获取当前操作员
+        LoginUser user = tokenService.getLoginUser();
+        String companyId = user.getSysUser().getCompanyId();
+        Map map = new HashMap();
+        map.put("companyId",companyId);
+        if(CommonUtil.isNotEmpty(companyName)) {
+            map.put("companyName", companyName);
+        }
+        List<Map> list = companyService.selectCompanyRelList(map);
+        return R.ok(list,companyId);
+    }
 }

+ 6 - 0
sc-service/src/main/java/com/huyi/service/common/company/mapper/CompanyMapper.java

@@ -18,4 +18,10 @@ public interface CompanyMapper {
      */
     public List<Map> selectCompanyList(@Param("paramMap") Map map);
 
+    /**
+     * 查询链属信息
+     * @param map
+     * @return
+     */
+    public List<Map> selectCompanyRelList(@Param("paramMap")Map map);
 }

+ 7 - 0
sc-service/src/main/java/com/huyi/service/common/company/service/CompanyService.java

@@ -15,4 +15,11 @@ public interface CompanyService {
      */
     public List<Map> selectCompanyList(Map map);
 
+    /**
+     * 查询链属信息
+     * @param map
+     * @return
+     */
+    public List<Map> selectCompanyRelList(Map map);
+
 }

+ 5 - 1
sc-service/src/main/java/com/huyi/service/common/company/service/impl/CompanyServiceImpl.java

@@ -2,6 +2,7 @@ package com.huyi.service.common.company.service.impl;
 
 import com.huyi.service.common.company.mapper.CompanyMapper;
 import com.huyi.service.common.company.service.CompanyService;
+import com.huyi.service.rel.mapper.OwnCompanyRelMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -19,5 +20,8 @@ public class CompanyServiceImpl implements CompanyService {
         return companyMapper.selectCompanyList(map);
     }
 
-
+    @Override
+    public List<Map> selectCompanyRelList(Map map) {
+        return companyMapper.selectCompanyRelList(map);
+    }
 }

+ 2 - 0
sc-service/src/main/resources/mapper/base/ZcBillInfMapper.xml

@@ -5,6 +5,7 @@
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="com.huyi.service.base.entity.ZcBillInf">
         <id column="zbi_id" property="zbiId" />
+        <result column="zbi_number" property="zbiNumber" />
         <result column="zbi_name" property="zbiName" />
         <result column="zbi_payer_id" property="zbiPayerId" />
         <result column="zbi_payee_id" property="zbiPayeeId" />
@@ -15,6 +16,7 @@
         <result column="zbi_service" property="zbiService" />
         <result column="zbi_order_no" property="zbiOrderNo" />
         <result column="zbi_distributor" property="zbiDistributor" />
+        <result column="zbi_status" property="zbiStatus" />
         <result column="zbi_remark" property="zbiRemark" />
         <result column="zbi_profit_spare1" property="zbiProfitSpare1" />
         <result column="zbi_profit_spare2" property="zbiProfitSpare2" />

+ 26 - 7
sc-service/src/main/resources/mapper/bill/OwnBillMapper.xml

@@ -7,27 +7,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectBillInfList" parameterType="map" resultType="map">
         SELECT
             b.zbi_id		        'zbiId',
+            b.zbi_number		    'zbiNumber',
             b.zbi_name		        'zbiName',
             b.zbi_contract_no	    'zbiContractNo',
             b.zbi_amount		    'zbiAmount',
             b.zbi_date		        'zbiDate',
             b.zbi_pay_date	        'zbiPayDate',
             r.scy_name		        'payerName',
-            e.scy_name		        'payeeName'
+            e.scy_name		        'payeeName',
+            f.zfi_number            'zfiNumber',
+            b.zbi_status            'zbiStatus',
+            (case when b.zbi_payer_id = #{paramMap.companyId} then '00' else '01' end) 'zbiType'
         FROM
             zc_bill_inf b
+        LEFT JOIN zc_finance_bill_rel rel
+            ON rel.zfbr_bill_id = b.zbi_id
+        LEFT JOIN zc_finance_inf f
+            ON rel.zfbr_finance_id = f.zfi_id
         LEFT JOIN sys_company r
             ON r.scy_id = b.zbi_payer_id
         LEFT JOIN sys_company e
             ON e.scy_id = b.zbi_payee_id
-        WHERE 1 = 1
-            and (b.zbi_payer_id = #{paramMap.contractNo} or b.zbi_payee_id = #{paramMap.contractNo})
-        <if test="paramMap.contractNo != null  and paramMap.contractNo != ''">
-            and b.zbi_contract_no = #{paramMap.contractNo}
+        WHERE b.zbi_status != '99'
+        <if test="paramMap.companyId != null  and paramMap.companyId != ''">
+            and (b.zbi_payer_id = #{paramMap.companyId} or b.zbi_payee_id = #{paramMap.companyId})
+        </if>
+        <if test="paramMap.payerId != null  and paramMap.payerId != ''">
+            and b.zbi_payer_id = #{paramMap.payerId}
+        </if>
+        <if test="paramMap.payeeId != null  and paramMap.payeeId != ''">
+            and b.zbi_payee_id = #{paramMap.payeeId}
+        </if>
+        <if test="paramMap.zbiNumber != null  and paramMap.zbiNumber != ''">
+            and b.zbi_number like concat('%', #{paramMap.zbiNumber}, '%')
         </if>
 
-        <if test="paramMap.name != null  and paramMap.name != ''">
-            and b.zbi_name like concat('%', #{paramMap.name}, '%')
+        <if test="paramMap.zbiName != null  and paramMap.zbiName != ''">
+            and b.zbi_name like concat('%', #{paramMap.zbiName}, '%')
         </if>
 
         <if test="paramMap.payerName != null  and paramMap.payerName != ''">
@@ -37,6 +53,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="paramMap.payeeName != null  and paramMap.payeeName != ''">
             and e.scy_name like concat('%', #{paramMap.payeeName}, '%')
         </if>
+        <if test="paramMap.zbiStatus != null  and paramMap.zbiStatus != ''">
+            and b.zbi_status = #{paramMap.zbiStatus}
+        </if>
         order by b.create_time desc
 
     </select>

+ 37 - 0
sc-service/src/main/resources/mapper/common/CompanyMapper.xml

@@ -21,4 +21,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </if>
         order by flag asc ,create_time desc
     </select>
+
+    <select id="selectCompanyRelList" parameterType="map" resultType="map">
+        SELECT
+        r.scr_id                'launchScrId',
+        r.scr_launch_company_id 'launchCompanyId',
+        r.scr_receive_company_id'launchReceiveScrCompanyId',
+        r.scr_status		    'launchScrStatus',
+        r.scr_contarct          'launchScrContarct',
+        r.scr_contarct_phone    'launchScrContarctPhone',
+        r.scr_contarct_email    'launchScrContarctEmail',
+        r.scr_launch_type       'launchScrLaunchType',
+        r.scr_receive_type      'launchScrReceiveType',
+        s.scy_id		        'launchScyId',
+        s.scy_social_code	    'launchScySocialCode',
+        s.scy_name		        'launchScyName',
+        s.scy_type		        'launchScyType',
+        s.scy_legal		        'launchScyLegal',
+        s.scy_phone		        'launchScyPhone',
+        p.scy_id		        'receiveScyId',
+        p.scy_social_code	    'receiveScySocialCode',
+        p.scy_name		        'receiveScyName',
+        p.scy_type		        'receiveScyType',
+        p.scy_legal		        'receiveScyLegal',
+        p.scy_phone		        'receiveScyPhone'
+        FROM sys_company_rel r
+        LEFT JOIN sys_company s ON r.scr_launch_company_id = s.scy_id
+        LEFT JOIN sys_company p ON r.scr_receive_company_id = p.scy_id
+        WHERE 1=1
+        <if test="paramMap.companyId != null and paramMap.companyId != '' ">
+            AND (r.scr_launch_company_id = #{paramMap.companyId} OR r.scr_receive_company_id = #{paramMap.companyId})
+        </if>
+        <if test="paramMap.companyName != null and paramMap.companyName != '' ">
+            AND (s.scy_name LIKE CONCAT('%', #{paramMap.companyName}, '%') OR p.scy_name LIKE CONCAT('%', #{paramMap.companyName}, '%'))
+        </if>
+        AND r.scr_status != '99'
+        ORDER BY r.create_time DESC
+    </select>
 </mapper>