Explorar el Código

供应商期初代码提交

hy hace 6 años
padre
commit
10dfabe2c1

+ 32 - 0
applications/document/document-dto/src/main/java/com.usoftchina.saas.document.dto/VendApamountDTO.java

@@ -0,0 +1,32 @@
+package com.usoftchina.saas.document.dto;
+
+import com.usoftchina.saas.base.dto.CommonBaseDTO;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class VendorDTO extends CommonBaseDTO implements Serializable{
+
+
+    private String ve_code;
+
+    private String ve_shortname;
+
+    private String ve_name;
+
+    private String ve_type;
+
+    private String ve_status;
+
+    private String ve_remark;
+
+    private Long ve_buyerid;
+
+    private String ve_buyercode;
+
+    private String ve_buyername;
+
+    private String ve_address;
+
+}

+ 122 - 0
applications/document/document-dto/src/main/java/com/usoftchina/saas/document/entities/VendApamount.java

@@ -0,0 +1,122 @@
+package com.usoftchina.saas.document.entities;
+
+import com.usoftchina.saas.base.entity.CommonBaseEntity;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 供应商资料
+ * @author chenwei
+ * @Date 2018/10/13
+ */
+@Data
+public class Vendor extends CommonBaseEntity implements Serializable{
+
+    /**
+     * 供应商编号
+     */
+    private String ve_code;
+
+    /**
+     * 供应商简称
+     */
+    private String ve_shortname;
+
+    /**
+     * 供应商名称
+     */
+    private String ve_name;
+    /**
+     * 供应商UU
+     */
+    private String ve_uu;
+    /**
+     * 供应商类型
+     */
+    private String ve_type;
+    /**
+     * 期初日期
+     */
+    private Date ve_begindate;
+    /**
+     * 期初应付
+     */
+    private Double ve_beginapamount;
+    /**
+     * 期初预付
+     */
+    private Double ve_beginprepayamount;
+    /**
+     * 承付天数
+     */
+    private Long ve_promisedays;
+    /**
+     * 税率
+     */
+    private Double ve_taxrate;
+    /**
+     * 纳税人识别号
+     */
+    private String ve_nsrzh;
+    /**
+     * 银行账号
+     */
+    private String ve_bankaccount;
+    /**
+     * 银行行号
+     */
+    private String ve_bankcode;
+    /**
+     * 状态   defualt "启用"
+     */
+    private String ve_status;
+    /**
+     * 状态码
+     */
+    private String ve_statuscode;
+    /**
+     * 自定义字段
+     */
+    private String ve_text1;
+    /**
+     * 自定义字段
+     */
+    private String ve_text2;
+    /**
+     * 自定义字段
+     */
+    private String ve_text3;
+    /**
+     * 自定义字段
+     */
+    private String ve_text4;
+    /**
+     * 自定义字段
+     */
+    private String ve_text5;
+
+    private Double ve_payamount;
+
+    private Double ve_leftamount;
+
+    private Integer ve_beginym;
+
+    private Double ve_preamount;
+
+    private String ve_remark;
+
+    private Long ve_buyerid;
+
+    private String ve_buyercode;
+
+    private String ve_buyername;
+
+    private String ve_address;
+
+    private String ve_currency;
+
+    private Double cr_rate;
+
+}

+ 141 - 0
applications/document/document-dto/src/main/java/com/usoftchina/saas/document/entities/VendApamountList.java

@@ -0,0 +1,141 @@
+package com.usoftchina.saas.document.entities;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class VendorList implements Serializable {
+
+    /* 主表字段 */
+    private Long id;
+    /**
+     * 供应商编号
+     */
+    private String ve_code;
+
+    /**
+     * 供应商简称
+     */
+    private String ve_shortname;
+    /**
+     * 供应商名称
+     */
+    private String ve_name;
+    /**
+     * 供应商UU
+     */
+    private String ve_uu;
+    /**
+     * 供应商类型
+     */
+    private String ve_type;
+    /**
+     * 期初日期
+     */
+    private Date ve_begindate;
+    /**
+     * 期初应付
+     */
+    private double ve_beginapamount;
+    /**
+     * 期初预付
+     */
+    private double ve_beginprepayamount;
+    /**
+     * 承付天数
+     */
+    private long ve_promisedays;
+    /**
+     * 税率
+     */
+    private double ve_taxrate;
+    /**
+     * 纳税人识别号
+     */
+    private String ve_nsrzh;
+    /**
+     * 银行账号
+     */
+    private String ve_bankaccount;
+    /**
+     * 银行行号
+     */
+    private String ve_bankcode;
+    /**
+     * 状态   defualt "启用"
+     */
+    private String ve_status;
+    /**
+     * 状态码
+     */
+    private String ve_statuscode;
+    /**
+     * 自定义字段
+     */
+    private String ve_text1;
+    /**
+     * 应付款金额
+     */
+    private double ve_leftamount;
+    /**
+     * 自定义字段
+     */
+    private String ve_text2;
+    /**
+     * 自定义字段
+     */
+    private String ve_text3;
+    /**
+     * 自定义字段
+     */
+    private String ve_text4;
+    /**
+     * 自定义字段
+     */
+    private String ve_text5;
+
+    private String ve_remark;
+
+    private Long ve_buyerid;
+
+    private String ve_buyercode;
+
+    private String ve_buyername;
+
+    private String ve_address;
+
+    private String ve_currency;
+
+    //currencys
+
+    private Double cr_rate;
+
+    /* 从表字段 */
+
+    private Integer vc_veid;
+
+    private Integer vc_detno;
+
+    private String vc_name;
+
+    private String vc_tel;
+
+    private String vc_qq;
+
+    private String vc_email;
+
+    private String vc_text1;
+
+    private String vc_text2;
+
+    private String vc_text3;
+
+    private String vc_text4;
+
+    private String vc_text5;
+
+    private String vc_default;
+
+}

+ 167 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/controller/VendApamountController.java

@@ -0,0 +1,167 @@
+package com.usoftchina.saas.document.controller;
+
+import com.github.pagehelper.PageInfo;
+import com.usoftchina.saas.base.Result;
+
+import com.usoftchina.saas.commons.dto.BatchDealBaseDTO;
+import com.usoftchina.saas.commons.dto.DocBaseDTO;
+import com.usoftchina.saas.commons.dto.ListReqDTO;
+import com.usoftchina.saas.document.dto.VendorDTO;
+import com.usoftchina.saas.document.dto.VendorListDTO;
+import com.usoftchina.saas.document.entities.VendorList;
+import com.usoftchina.saas.document.service.VendorService;
+import com.usoftchina.saas.inquiry.api.SearchUUApi;
+import com.usoftchina.saas.page.PageRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/vendor")
+public class VendorController {
+
+    @Autowired
+    private VendorService vendorService;
+    @Autowired
+    private SearchUUApi searchUUApi;
+
+    /**
+     * 获取供应商信息
+     * @param page
+     * @param listReqDTO
+     * @return
+     */
+    @GetMapping("/getVendorsByCondition")
+    public Result<List<VendorDTO>> getVendorsByCondition(PageRequest page, ListReqDTO listReqDTO){
+        PageInfo<VendorDTO> vendorList = vendorService.getVendorsByCondition(page, listReqDTO);
+        return Result.success(vendorList);
+    }
+
+    /**
+     * 通过供应商ID查找  供应商主从表数据
+     * @param id
+     * @return
+     */
+    @GetMapping("/read/{id}")
+    public Result<VendorListDTO> getDataById(@PathVariable("id") Long id){
+        VendorListDTO vendorListDTO = vendorService.getListById(id);
+        return Result.success(vendorListDTO);
+    }
+
+    @GetMapping(value = "/read", params = "uu")
+    public Result<VendorDTO> findByUU(@RequestParam("uu") Long uu){
+        return Result.success(vendorService.findByUU(uu));
+    }
+
+    @GetMapping(value = "/read", params = "name")
+    public Result<VendorDTO> findByName(@RequestParam("name") String name){
+        return Result.success(vendorService.findByName(name));
+    }
+
+    /**
+     * 获取 供应商列表数据,包含供应商主表、从表数据
+     * @param listReqDTO
+     * @return
+     */
+    @GetMapping("/list")
+    public Result<PageInfo<VendorList>> getListDataByCondition(PageRequest page, ListReqDTO listReqDTO){
+        return Result.success(vendorService.getListDataByCondition(page, listReqDTO));
+    }
+
+    /**
+     * 保存供应商资料, 主从表数据
+     * @param vendorListDTO
+     * @return
+     */
+    @PostMapping("/save")
+    public Result<DocBaseDTO> saveFormData(@RequestBody VendorListDTO vendorListDTO){
+        DocBaseDTO docBaseDTO = vendorService.saveFormData(vendorListDTO);
+        return Result.success(docBaseDTO);
+    }
+
+    /**
+     * 删除
+     * @param id
+     * @return
+     */
+    @PostMapping("/delete/{id}")
+    public Result delete(@PathVariable("id") Long id){
+        vendorService.deleteById(id);
+        return Result.success();
+    }
+
+    /**
+     * 关闭
+     * @param id
+     * @return
+     */
+    @PostMapping("/close/{id}")
+    public Result close(@PathVariable("id") Long id){
+        DocBaseDTO docBaseDTO = vendorService.close(id);
+        return Result.success(docBaseDTO);
+    }
+
+    /**
+     * 开启
+     * @param id
+     * @return
+     */
+    @PostMapping("/open/{id}")
+    public Result open(@PathVariable("id") Long id){
+        DocBaseDTO docBaseDTO = vendorService.open(id);
+        return Result.success(docBaseDTO);
+    }
+
+    /**
+     * 批量关闭
+     * @param baseDTOs
+     * @return
+     */
+    @PostMapping("/batchClose")
+    public Result batchClose(@RequestBody BatchDealBaseDTO baseDTOs){
+        String msg = vendorService.batchClose(baseDTOs);
+        return Result.success(msg);
+    }
+
+    /**
+     * 批量开启
+     * @param baseDTOs
+     * @return
+     */
+    @PostMapping("/batchOpen")
+    public Result batchOpen(@RequestBody BatchDealBaseDTO baseDTOs){
+        String msg = vendorService.batchOpen(baseDTOs);
+        return Result.success(msg);
+    }
+
+    @PostMapping("/deleteContact/{id}")
+    public Result deleteContact(@PathVariable("id") Long id){
+        vendorService.deleteContact(id);
+        return Result.success();
+    }
+
+    @PostMapping("/batchDelete")
+    public Result batchDelete(@RequestBody BatchDealBaseDTO baseDTOs){
+        vendorService.batchDelete(baseDTOs);
+        return Result.success();
+    }
+
+    //导入保存至列表
+    @RequestMapping("/saveToFormal")
+    public Result saveToFormal(Integer id, boolean update) {
+        vendorService.saveToFormal(id, update);
+        return Result.success();
+    }
+
+    /**
+     * 获取供应商UU
+     * @param name
+     * @return
+     */
+    @GetMapping("/getVendorUU")
+    public Result getVendorUU(@RequestParam("name") String name){
+        return Result.success(searchUUApi.queryEnterprises(name));
+    }
+
+}

+ 40 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/VendApamountMapper.java

@@ -0,0 +1,40 @@
+package com.usoftchina.saas.document.mapper;
+
+import com.usoftchina.saas.base.mapper.CommonBaseMapper;
+
+
+import com.usoftchina.saas.document.dto.VendorDTO;
+import com.usoftchina.saas.document.dto.VendorListDTO;
+import com.usoftchina.saas.document.entities.Vendor;
+import com.usoftchina.saas.document.entities.VendorList;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Map;
+
+public interface VendorMapper extends CommonBaseMapper<Vendor> {
+
+    List<VendorDTO> getVendorsByCondition(@Param("condition") String condition, @Param("companyId") Long companyId);
+
+    List<VendorList> getListDataByCondition(@Param("condition") String condition, @Param("companyId") Long companyId);
+
+    int validateCodeWhenInsert(@Param("code") String code, @Param("companyId") Long companyId);
+
+    int validateCodeWhenUpdate(@Param("code") String code, @Param("id") Long id, @Param("companyId") Long company);
+
+    String getCodeById(@Param("id") Long id, @Param("companyId") Long companyId);
+
+    int getCountByCode(@Param("code") String code, @Param("companyId") Long companyId);
+
+    int getCountByName(@Param("name") String name, @Param("companyId") Long companyId);
+
+    int validFinish(@Param("id") Long id,@Param("companyId") Long companyId);
+
+    void check(Map<String, Object> map);
+
+    Long selectIdByCode(@Param("code") String code, @Param("companyId") Long companyId);
+
+    VendorDTO selectByUU(@Param("uu") Long uu, @Param("companyId") Long companyId);
+
+    VendorDTO selectByName(@Param("name") String name, @Param("companyId") Long companyId);
+}

+ 114 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/VendApamountService.java

@@ -0,0 +1,114 @@
+package com.usoftchina.saas.document.service;
+
+import com.github.pagehelper.PageInfo;
+import com.usoftchina.saas.base.service.CommonBaseService;
+
+import com.usoftchina.saas.commons.dto.BatchDealBaseDTO;
+import com.usoftchina.saas.commons.dto.DocBaseDTO;
+import com.usoftchina.saas.commons.dto.ListReqDTO;
+import com.usoftchina.saas.document.dto.VendorDTO;
+import com.usoftchina.saas.document.dto.VendorListDTO;
+import com.usoftchina.saas.document.entities.Vendor;
+import com.usoftchina.saas.document.entities.VendorList;
+import com.usoftchina.saas.document.mapper.VendorMapper;
+
+import com.usoftchina.saas.page.PageRequest;
+
+import java.util.List;
+
+
+public interface VendorService extends CommonBaseService<VendorMapper, Vendor>{
+
+    /**
+     * 获取主表数据
+     * @param page      分页对象
+     * @param listReqDTO    条件对象
+     * @return  PageInfo<VendorDTO>
+     */
+    PageInfo<VendorDTO> getVendorsByCondition(PageRequest page, ListReqDTO listReqDTO);
+
+    /**
+     * 通过ID 获取主从表数据
+     * @param id
+     * @return VendorListDTO
+     */
+    VendorListDTO getListById(Long id);
+
+    /**
+     * 获取供应商资料列表
+     * @param listReqDTO  条件对象
+     * @return List<VendorList>
+     */
+    PageInfo<VendorList> getListDataByCondition(PageRequest page, ListReqDTO listReqDTO);
+
+    /**
+     * 保存主从表数据
+     * @param vendorListDTO
+     * @return  DocBaseDTO
+     */
+    DocBaseDTO saveFormData(VendorListDTO vendorListDTO);
+
+    /**
+     * 通过主表ID  删除主从表数据
+     * @param id
+     */
+    void deleteById(Long id);
+
+    /**
+     * 关闭
+     * @param id
+     * @return  boolean
+     */
+    DocBaseDTO close(Long id);
+
+    /**
+     * 开启
+     * @param id
+     * @return  boolean
+     */
+    DocBaseDTO open(Long id);
+
+    /**
+     * 批量关闭
+     * @param baseDTOs
+     * @return
+     */
+    String batchClose(BatchDealBaseDTO baseDTOs);
+
+    /**
+     * 批量开启
+     * @param baseDTOs
+     * @return
+     */
+    String batchOpen(BatchDealBaseDTO baseDTOs);
+
+    /**
+     * 删除明细
+     * @param id
+     * @return
+     */
+    boolean deleteContact(Long id);
+
+    /**
+     * 批量删除
+     * @param baseDTOs
+     * @return
+     */
+    boolean batchDelete(BatchDealBaseDTO baseDTOs);
+
+    void saveToFormal(Integer id, boolean update);
+
+    /**
+     * 通过供应商UU号查找供应商信息
+     * @param uu
+     * @return
+     */
+    VendorDTO findByUU(Long uu);
+
+    /**
+     * 通过供应商名称查找供应商信息
+     * @param name
+     * @return
+     */
+    VendorDTO findByName(String name);
+}

+ 661 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/VendApamountServiceImpl.java

@@ -0,0 +1,661 @@
+package com.usoftchina.saas.document.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.usoftchina.saas.account.api.CompanyApi;
+import com.usoftchina.saas.account.dto.CompanyDTO;
+import com.usoftchina.saas.base.Result;
+import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
+import com.usoftchina.saas.commons.api.MaxnumberService;
+import com.usoftchina.saas.commons.api.MessageLogService;
+import com.usoftchina.saas.commons.dto.BatchDealBaseDTO;
+import com.usoftchina.saas.commons.dto.DocBaseDTO;
+import com.usoftchina.saas.commons.dto.ListReqDTO;
+import com.usoftchina.saas.commons.exception.BizExceptionCode;
+import com.usoftchina.saas.commons.po.BillCodeSeq;
+import com.usoftchina.saas.commons.po.DataImportDetail;
+import com.usoftchina.saas.commons.po.Operation;
+import com.usoftchina.saas.commons.po.Status;
+import com.usoftchina.saas.context.BaseContextHolder;
+import com.usoftchina.saas.document.dto.VendorDTO;
+import com.usoftchina.saas.document.dto.VendorListDTO;
+import com.usoftchina.saas.document.entities.*;
+import com.usoftchina.saas.document.mapper.DataImportMapper;
+import com.usoftchina.saas.document.mapper.SubledgerMapper;
+import com.usoftchina.saas.document.mapper.VendorMapper;
+import com.usoftchina.saas.document.mapper.VendorcontactMapper;
+import com.usoftchina.saas.document.service.VendorService;
+import com.usoftchina.saas.document.service.VendorkindService;
+import com.usoftchina.saas.exception.BizException;
+import com.usoftchina.saas.page.PageRequest;
+import com.usoftchina.saas.utils.CollectionUtils;
+import com.usoftchina.saas.utils.DateUtils;
+import com.usoftchina.saas.utils.JsonUtils;
+import com.usoftchina.saas.utils.RegexpUtils;
+import com.usoftchina.saas.utils.http.HttpUtil;
+import com.usoftchina.saas.utils.http.HttpUtil.Response;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * @author chenwei
+ * @Date 2018/10/13
+ */
+@Service
+public class VendorServiceImpl extends CommonBaseServiceImpl<VendorMapper, Vendor> implements VendorService {
+
+    @Autowired
+    private VendorcontactMapper vendorcontactMapper;
+    @Autowired
+    private MessageLogService messageLogService;
+    @Autowired
+    private MaxnumberService maxnumberService;
+    @Autowired
+    private SubledgerMapper subledgerMapper;
+    @Autowired
+    private VendorMapper vendorMapper;
+    @Autowired
+    private DataImportMapper dataImportMapper;
+    @Autowired
+    private VendorkindService vendorkindService;
+    @Autowired
+    private CompanyApi companyApi;
+    @Value("${b2b.baseUrl.common}")
+    private String b2bUrl;
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(VendorServiceImpl.class);
+
+    @Override
+    public PageInfo<VendorDTO> getVendorsByCondition(PageRequest page, ListReqDTO listReqDTO) {
+        //设置分页
+        if (null == page || page.getSize() == 0 || page.getNumber() == 0) {
+            page = new PageRequest();
+            page.setNumber(1);
+            page.setSize(10);
+        }
+        PageHelper.startPage(page.getNumber(), page.getSize());
+        List<VendorDTO> vendorList = getList(listReqDTO);
+        //取分页信息
+        PageInfo<VendorDTO> pageInfo = new PageInfo<VendorDTO>(vendorList);
+        return pageInfo;
+    }
+
+    /**
+     * 通过ID查找主从表数据
+     * @param id
+     * @return
+     */
+    @Override
+    public VendorListDTO getListById(Long id) {
+        VendorListDTO vendorListDTO = new VendorListDTO();
+        Vendor vendor = getMapper().selectByPrimaryKey(id);
+        List<Vendorcontact> vendorcontactList = vendorcontactMapper.selectByFK(id);
+        //设置主从表信息
+        vendorListDTO.setMain(vendor);
+        vendorListDTO.setItems(vendorcontactList);
+        return vendorListDTO;
+    }
+
+    @Override
+    public VendorDTO findByUU(Long uu){
+        VendorDTO vendorDTO = getMapper().selectByUU(uu, BaseContextHolder.getCompanyId());
+        return vendorDTO;
+    }
+
+    @Override
+    public VendorDTO findByName(String name){
+        VendorDTO vendorDTO = getMapper().selectByName(name, BaseContextHolder.getCompanyId());
+        return vendorDTO;
+    }
+
+    /**
+     * 返回列表数据
+     * @return
+     */
+    public PageInfo<VendorList> getListDataByCondition(PageRequest page, ListReqDTO listReqDTO){
+        //设置分页
+        if (null == page || page.getSize() == 0 || page.getNumber() == 0) {
+            page = new PageRequest();
+            page.setNumber(1);
+            page.setSize(10);
+        }
+        PageHelper.startPage(page.getNumber(), page.getSize());
+        //取分页信息
+        String condition = listReqDTO.getFinalCondition();
+        List<VendorList> list = getMapper().getListDataByCondition(condition, BaseContextHolder.getCompanyId());
+        PageInfo<VendorList> pageInfo = new PageInfo<VendorList>(list);
+        return pageInfo;
+    }
+
+    /**
+     * 保存主从表数据
+     * @param vendorListDTO
+     */
+    @Override
+    @Transactional
+    public DocBaseDTO saveFormData(VendorListDTO vendorListDTO) {
+        Long companyId = BaseContextHolder.getCompanyId();
+        String userName= BaseContextHolder.getUserName();
+        Long userId = BaseContextHolder.getUserId();
+        if (null == vendorListDTO || null == vendorListDTO.getMain()){
+            throw new BizException(BizExceptionCode.EMPTY_DATA);
+        }
+        Vendor main = vendorListDTO.getMain();
+        main.setCompanyId(BaseContextHolder.getCompanyId());
+        List<Vendorcontact> items = vendorListDTO.getItems();
+        String ve_code = main.getVe_code().trim().toUpperCase();
+
+        //获取已结账的期间
+        String YM = subledgerMapper.selectUnPeriod(companyId);
+        if(YM==null || YM.equals("")){
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM");
+            YM = simpleDateFormat.format(main.getVe_begindate());
+        }else{
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM");
+            String beginDate = simpleDateFormat.format(main.getVe_begindate());
+            if(Integer.valueOf(YM)>Integer.valueOf(beginDate)){
+                int code = BizExceptionCode.LIMIT_PERIOD_VENDOR.getCode();
+                String mes = String.format(BizExceptionCode.LIMIT_PERIOD_VENDOR.getMessage(),YM);
+                throw new BizException(code , mes);
+            }
+            YM = beginDate;
+        }
+        ve_code = RegexpUtils.replaceSpecCharacter(ve_code);
+        if (vendorListDTO.isCodeModified()) {
+            ve_code = pushMaxnubmer(ve_code, main.getId());
+        }
+        //String code = pushMaxnubmer(ve_code, main.getId());
+        if(main.getId() == 0){
+            int count = getMapper().getCountByCode(ve_code, companyId);
+            if(count > 0){
+                throw new BizException(BizExceptionCode.REPEAT_CODE);
+            }
+            count = getMapper().getCountByName(main.getVe_name(), companyId);
+            if (count > 0){
+                throw new BizException(BizExceptionCode.REPEAT_NAME);
+            }
+            //保存主表信息
+            main.setVe_code(ve_code);
+            //更新应付款余额
+            Double beginapamount = main.getVe_beginapamount()==null ? new Double(0):main.getVe_beginapamount();
+            Double beginprepayamount = main.getVe_beginprepayamount()==null ? new Double(0):main.getVe_beginprepayamount();
+            Double payamount = main.getVe_payamount()==null? new Double(0):main.getVe_payamount();
+            Double preamount = main.getVe_preamount()==null? new Double(0):main.getVe_preamount();
+            main.setVe_leftamount(beginapamount-beginprepayamount+payamount-preamount);
+            //更新录入人录入时间ID
+            main.setCreatorId(BaseContextHolder.getUserId());
+            getMapper().insertSelective(main);
+            Long mainId = main.getId();
+            //更新明细表vc_veid
+            for(Vendorcontact item : items){
+                item.setVc_veid(mainId);
+                item.setCompanyId(BaseContextHolder.getCompanyId());
+                item.setCreatorId(BaseContextHolder.getUserId());
+                item.setCreateTime(new Date());
+
+            }
+            //保存明细表信息
+            if (items.size() > 0){
+                vendorcontactMapper.batchInsert(items);
+            }
+            //记录LOG
+            messageLogService.save(generateMsgObj(mainId, ve_code));
+        }else{
+            main.setVe_code(ve_code);
+            Long mainId = main.getId();
+            Vendor oldVendor = getMapper().selectByPrimaryKey(main.getId());
+
+            int count = getMapper().getCountByCode(ve_code, companyId);
+            if (!ve_code.equals(oldVendor.getVe_code())){
+                if (count > 0){
+                    throw new BizException(BizExceptionCode.REPEAT_CODE);
+                }
+            }
+            if (!main.getVe_name().equals(oldVendor.getVe_name())){
+                count = getMapper().getCountByName(main.getVe_name(), companyId);
+                if (count > 0){
+                    throw new BizException(BizExceptionCode.REPEAT_NAME);
+                }
+            }
+
+            //有关联时不可修改名称编号
+            Map<String, Object> map = new HashMap<String, Object>();
+            map.put("v_id",main.getId());
+            map.put("v_code", ve_code);
+            map.put("v_type","vend");
+            map.put("v_companyid",BaseContextHolder.getCompanyId());
+            map.put("v_res","");
+            vendorMapper.check(map);
+            Object result =  map.get("v_res");
+            if(!StringUtils.isEmpty(result)){
+                //限制关联单据不可修改金额
+                Vendor vendor = getMapper().selectByPrimaryKey(main.getId());
+                if (vendor.getVe_beginapamount().doubleValue() != main.getVe_beginapamount().doubleValue() ||
+                        vendor.getVe_beginprepayamount().doubleValue() != main.getVe_beginprepayamount().doubleValue() ||
+                        vendor.getVe_begindate().compareTo(main.getVe_begindate()) != 0){
+                    throw new BizException(BizExceptionCode.BIZ_RELUPDATE_AMOUNT);
+                }
+            }
+
+            //检查期初日期是否已结转
+            count = getMapper().validFinish(mainId,companyId);
+            if (count>0) {
+                Vendor vendortpl = getMapper().selectByPrimaryKey(mainId);
+                //期初应收
+                main.setVe_beginapamount(vendortpl.getVe_beginapamount());
+                //期初预收
+                main.setVe_beginprepayamount(vendortpl.getVe_beginprepayamount());
+            }
+
+            //启用B2B对账
+            if (StringUtils.isEmpty(oldVendor.getVe_uu()) && !StringUtils.isEmpty(main.getVe_uu())){
+                try {
+                    enableApCheck(main.getVe_uu());
+                } catch (Exception e) {
+                    LOGGER.info("请求B2B对账启用接口失败!, time={}", DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
+                }
+            }
+
+            getMapper().updateByPrimaryKeySelective(main);
+            if (items.size() > 0) {
+                List<Vendorcontact> updateItems = new ArrayList<Vendorcontact>();
+                List<Vendorcontact> insertItems = new ArrayList<Vendorcontact>();
+                //获取执行更新、插入的明细数据
+                for(Vendorcontact vendorcontact : items){
+                    if(vendorcontact.getId() == 0){
+                        vendorcontact.setCompanyId(BaseContextHolder.getCompanyId());
+                        vendorcontact.setCreateTime(new Date());
+                        vendorcontact.setCreatorId(BaseContextHolder.getUserId());
+                        vendorcontact.setVc_veid(main.getId());
+                        insertItems.add(vendorcontact);
+                    }else{
+                        vendorcontact.setUpdaterId(BaseContextHolder.getUserId());
+                        vendorcontact.setUpdateTime(new Date());
+                        updateItems.add(vendorcontact);
+                    }
+                }
+                if (insertItems.size() > 0){
+                    vendorcontactMapper.batchInsert(insertItems);
+                }
+                if (updateItems.size() > 0){
+                    vendorcontactMapper.batchUpdate(items);
+                }
+            }
+            //记录LOG
+            messageLogService.update(generateMsgObj(main.getId(), ve_code));
+        }
+
+        //更新应收款余额
+        Double ve_leftamount = (main.getVe_beginapamount() == null ? new Double(0) : main.getVe_beginapamount())
+                - (main.getVe_beginprepayamount() == null ? new Double(0) : main.getVe_beginprepayamount())
+                + (main.getVe_payamount() == null ? new Double(0) : main.getVe_payamount())
+                - (main.getVe_preamount() == null ? new Double(0) : main.getVe_preamount());
+        main.setVe_leftamount(ve_leftamount);
+        getMapper().updateByPrimaryKeySelective(main);
+
+        //插入中间表
+        Double amount = (main.getVe_beginapamount() == null ? new Double(0) : main.getVe_beginapamount())
+                - (main.getVe_beginprepayamount() == null ? new Double(0) : main.getVe_beginprepayamount());
+        Subledger subledger = new Subledger();
+        subledger.setSl_code("期初余额");
+        subledger.setSl_kind("期初余额");
+        subledger.setSl_vendid(Math.toIntExact(main.getId()));
+        subledger.setSl_custid(0);
+        subledger.setCompanyId(BaseContextHolder.getCompanyId());
+        subledger.setSl_date(DateUtils.getFirstDay(main.getVe_begindate()));
+        subledger.setSl_ym(DateUtils.getYm(main.getVe_begindate()));
+        subledger.setSl_currency(main.getVe_currency());
+        if (amount > new Double(0)){
+            subledger.setSl_preamount(new Double(0));
+            subledger.setSl_amount(Math.abs(amount));
+        }else {
+            subledger.setSl_amount(new Double(0));
+            subledger.setSl_preamount(Math.abs(amount));
+        }
+        subledger.setSl_orderamount(Math.abs(amount));
+        subledger.setSl_namount((subledger.getSl_orderamount() == null ? new Double(0) : subledger.getSl_orderamount()) +
+                (subledger.getSl_discount() == null ? new Double(0) : subledger.getSl_discount()) -
+                (subledger.getSl_yamount() == null ? new Double(0) : subledger.getSl_yamount()));
+        subledger.setCreateTime(new Date());
+        subledger.setCreatorId(BaseContextHolder.getUserId());
+        subledger.setCreatorName(BaseContextHolder.getUserName());
+        Long sl_id = subledgerMapper.selectByKindCodeVendid("期初余额","期初余额",
+                Math.toIntExact(main.getId()),BaseContextHolder.getCompanyId(),YM);
+
+        subledger.setId(sl_id);
+        if ( sl_id!=null && sl_id > 0 ) {
+            subledgerMapper.updateByPrimaryKeySelective(subledger);
+        }else {
+            subledgerMapper.insertSelective(subledger);
+        }
+
+        return generateMsgObj(main.getId(), ve_code);
+    }
+
+    /**
+     * 启用B2B对账
+     * @param ve_uu
+     * @throws Exception
+     */
+    private void enableApCheck(String ve_uu) throws Exception {
+        CompanyDTO companyDTO = companyApi.getCompanyById(BaseContextHolder.getCompanyId()).getData();
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("venduu", ve_uu);
+        map.put("custuu", companyDTO.getUu());
+        map.put("apcheck", 1);
+        Map<String, String> params = new HashMap<String, String>();
+        List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
+        data.add(map);
+        params.put("data", JsonUtils.toJsonString(data));
+        Response response = HttpUtil.sendPostRequest(b2bUrl + "/erp/vendor/apcheck?access_id=" + companyDTO.getUu(), params, true, companyDTO.getAccessKey());
+        if (response.getStatusCode() == 200){
+            LOGGER.info("供应商UU={},启用B2B对账成功!", ve_uu);
+        }else {
+            LOGGER.info("供应商UU={},启用B2B对账失败!,原因={}", ve_uu, response.getResponseText());
+        }
+    }
+
+    /**
+     * 删除主从表数据
+     * @param id
+     */
+    @Override
+    @Transactional
+    public void deleteById(Long id) {
+        if(id != null && id > 0){
+            String code = getMapper().getCodeById(id, BaseContextHolder.getCompanyId());
+            Map<String, Object> map = new HashMap<String, Object>();
+            map.put("v_id",id);
+            map.put("v_code", code);
+            map.put("v_type","vend");
+            map.put("v_companyid",BaseContextHolder.getCompanyId());
+            map.put("v_res","");
+            vendorMapper.check(map);
+            Object result =  map.get("v_res");
+            if(!StringUtils.isEmpty(result)){
+                throw new BizException(BizExceptionCode.USING_EXISTS.getCode(),result.toString());
+            }else{
+                vendorcontactMapper.deleteByFK(id);
+                getMapper().deleteByPrimaryKey(id);
+                //删除中间表
+                subledgerMapper.deleteVendor("期初余额", "期初余额", Math.toIntExact(id));
+                //记录LOG
+                messageLogService.delete(generateMsgObj(id, code));
+            }
+        }
+    }
+
+    /**
+     * 关闭
+     * @param id
+     * @return
+     */
+    @Override
+    public DocBaseDTO close(Long id){
+        if(id != null && id > 0){
+            Vendor vendor = new Vendor();
+            vendor.setId(id);
+            vendor.setVe_status(Status.BANNED.getDisplay());
+            vendor.setVe_statuscode(Status.BANNED.name());
+            vendor.setUpdaterId(BaseContextHolder.getUserId());
+            vendor.setUpdateTime(new Date());
+
+            String code = getMapper().getCodeById(id, BaseContextHolder.getCompanyId());
+            getMapper().updateByPrimaryKeySelective(vendor);
+            //记录LOG
+            DocBaseDTO docBaseDTO = generateMsgObj(id, code);
+            messageLogService.customizeLog(docBaseDTO, Operation.BANNED);
+            return docBaseDTO;
+        }else{
+            throw new BizException(BizExceptionCode.ILLEGAL_ID);
+        }
+    }
+
+    /**
+     * 开启
+     * @param id
+     * @return
+     */
+    @Override
+    public DocBaseDTO open(Long id){
+        if (id != null && id > 0){
+            Vendor vendor = getMapper().selectByPrimaryKey(id);
+            if(vendor == null){
+                throw new BizException(BizExceptionCode.NO_DATA);
+            }
+            if (Status.BANNED.name().equals(vendor.getVe_statuscode())){
+                String code = vendor.getVe_code();
+                vendor = new Vendor();
+                vendor.setId(id);
+                vendor.setVe_statuscode(Status.ENABLE.name());
+                vendor.setVe_status(Status.ENABLE.getDisplay());
+                getMapper().updateByPrimaryKeySelective(vendor);
+                //记录LOG
+                DocBaseDTO docBaseDTO = generateMsgObj(id, code);
+                messageLogService.customizeLog(docBaseDTO, Operation.ENABLE);
+                return docBaseDTO;
+            }else {
+                throw new BizException(BizExceptionCode.BIZ_ENABLE);
+            }
+        }else {
+            throw new BizException(BizExceptionCode.ILLEGAL_ID);
+        }
+    }
+
+    @Override
+    public String batchClose(BatchDealBaseDTO baseDTOs) {
+        StringBuilder errorMsg = new StringBuilder();
+        for (DocBaseDTO docBaseDTO : baseDTOs.getBaseDTOs()){
+            try{
+                close(docBaseDTO.getId());
+            }catch (Exception e){
+                String msg = BizExceptionCode.DEAL_FAILED.getMessage();
+                errorMsg.append(String.format(msg, docBaseDTO.getCode(), e.getMessage()));
+            }
+        }
+        return errorMsg.toString();
+    }
+
+    @Override
+    public String batchOpen(BatchDealBaseDTO baseDTOs) {
+        StringBuilder errorMsg = new StringBuilder();
+        for (DocBaseDTO docBaseDTO : baseDTOs.getBaseDTOs()){
+            try{
+                open(docBaseDTO.getId());
+            }catch (Exception e){
+                String msg = BizExceptionCode.DEAL_FAILED.getMessage();
+                errorMsg.append(String.format(msg, docBaseDTO.getCode(), e.getMessage()));
+            }
+        }
+        return errorMsg.toString();
+    }
+
+    @Override
+    public boolean deleteContact(Long id) {
+        Long ve_id = vendorcontactMapper.selectByPrimaryKey(id).getVc_veid();
+        String code = getMapper().getCodeById(ve_id, BaseContextHolder.getCompanyId());
+        vendorcontactMapper.deleteByPrimaryKey(id);
+        //记录LOG
+        messageLogService.deleteDetail(generateMsgObj(id, code));
+        return true;
+    }
+
+    @Override
+    public boolean batchDelete(BatchDealBaseDTO baseDTOs) {
+        if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
+                baseDTOs.getBaseDTOs().size() == 0) {
+            return false;
+        }
+        for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
+            deleteById(base.getId());
+        }
+        return true;
+    }
+
+    @Override
+    public void saveToFormal(Integer id, boolean update) {
+        if (null == id || "0".equals(id)) {
+            return;
+        }
+        Long companyId = BaseContextHolder.getCompanyId();
+        StringBuilder err = new StringBuilder();
+        List<VendorListDTO> list = new ArrayList<>();
+        VendorListDTO listDTO = null;
+        List<DataImportDetail> details = dataImportMapper.selectDataById(id);
+        if (!CollectionUtils.isEmpty(details)) {
+            Map<String, List<DataImportDetail>> datas = CollectionUtils.groupBy(details, DataImportDetail::getDd_codevalue);
+            Integer detno = null;
+            for (String code : datas.keySet()) {
+                listDTO = new VendorListDTO();
+                List<Vendorcontact> details_ = new ArrayList<>();
+                int i = getMapper().validateCodeWhenInsert(code, companyId);
+                List<DataImportDetail> data = datas.get(code);
+                DataImportDetail main = dataImportMapper.selectMainBycode(code, id, companyId);
+                if (StringUtils.isEmpty(main)) {
+                    throw new BizException(BizExceptionCode.BIZ_REPORT_NOTCORRECT);
+                }
+                Vendor vendor = JSONObject.parseObject(main.getDd_maindata(), Vendor.class);
+                vendor.setVe_status(Status.ENABLE.getDisplay());
+                vendor.setVe_statuscode(Status.ENABLE.name());
+                if (!StringUtils.isEmpty(vendor.getVe_type())) {
+                    Vendorkind type = vendorkindService.getTypeByname(vendor.getVe_type());
+                    if (null == type) {
+                        throw new BizException(70110581,"供应商: " + vendor.getVe_name() + " 类型: " + vendor.getVe_type() + " 在系统中不存在");
+                    }
+                }
+                //编号不存在
+                if (i == 0) {
+                    vendor.setId(0l);
+                    //编号存在、需要更新
+                } else if (update){
+                    Long pr_id = getMapper().selectIdByCode(code, companyId);
+                    vendor.setId(pr_id);
+                    //编号存在、不需要处理
+                } else {
+                    continue;
+                }
+                //添加从表
+                if (data.size() > 0) {
+                    detno = 1;
+                    int count = 0;
+                    for (DataImportDetail productDetail : data) {
+                        Vendorcontact detail = JSONObject.parseObject(productDetail.getDd_detaildata(), Vendorcontact.class);
+                        if (null != detail) {
+                            detail.setVc_veid(vendor.getId());
+                            detail.setVc_detno(detno);
+                            detno++;
+                            if ("是".equals(detail.getVc_default())) {
+                                detail.setVc_default("1");
+                                count++;
+                            } else {
+                                detail.setVc_default("0");
+                            }
+                            details_.add(detail);
+                        }
+                    }
+                    if (count > 1) {
+                        throw new BizException(70110582,"供应商: " + vendor.getVe_name() + " 存在多个默认联系人");
+                    }
+                }
+                listDTO.setMain(vendor);
+                listDTO.setItems(details_);
+                list.add(listDTO);
+            }
+            if (err.length() > 0) {
+                dataImportMapper.updateDataImportError(err.toString(), id);
+                throw new BizException(12345, err.toString());
+            }
+            for (VendorListDTO  dto : list) {
+                saveFormData(dto);
+            }
+            dataImportMapper.updateDataImport(id);
+        }
+    }
+
+    private List<VendorDTO> getList(ListReqDTO listReqDTO){
+        Long companyId = BaseContextHolder.getCompanyId();
+        String condition = listReqDTO.getFinalCondition();
+        if(condition == null){
+            condition = "1=1";
+        }
+        List<VendorDTO> vendorDTOList = getMapper().getVendorsByCondition(condition, companyId);
+        return vendorDTOList;
+    }
+
+    /**
+     * 构造日记记录对象
+     * @param id
+     * @return
+     */
+    private DocBaseDTO generateMsgObj(Long id, String code){
+        return new DocBaseDTO(id, code, "Vendor");
+    }
+
+    /**
+     * @Description: 检验获取并更新单号
+     * @Param: [code, id]
+     * @return: java.lang.String
+     * @Author: chenwei
+     * @Date: 2018/10/26
+     */
+    private String pushMaxnubmer(String code, Long id) {
+        if (null == code) {
+            throw new BizException(BizExceptionCode.NULL_CODE);
+        }
+        Long companyId = BaseContextHolder.getCompanyId();
+        String billcode = null;
+        synchronized (VendorServiceImpl.class) {
+            Integer count = "0".equals(String.valueOf(id)) ? getMapper().validateCodeWhenInsert(code, companyId) :
+                    getMapper().validateCodeWhenUpdate(code, id, companyId);
+            Result<String> res = maxnumberService.pushMaxnubmer(count, code, BillCodeSeq.VENDOR.getCaller());
+            if (res.isSuccess()) {
+                billcode = res.getData();
+            } else {
+                throw new BizException(123456, res.getMessage());
+            }
+           //billcode = maxnumberService.pushMaxnubmer(count, code, BillCodeSeq.VENDOR.getCaller()).getData();
+        }
+        return billcode;
+    }
+
+    /**
+     * String转Date类型
+     *
+     * @param dateStr
+     *            时间字符串
+     * @return Date类型时间
+     * @throws Exception
+     *             异常
+     */
+    public static Date string2Date(String dateStr, String format) throws Exception {
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        if (dateStr != null) {
+            return sdf.parse(dateStr);
+        }
+        return null;
+    }
+
+    /**
+     * Date转String
+     *
+     * @param date
+     *            Date类型时间
+     * @return 时间字符串
+     */
+    public static String date2String(Date date, String format) {
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        if (date != null) {
+            return sdf.format(date);
+        }
+        return null;
+    }
+}

+ 509 - 0
applications/document/document-server/src/main/resources/mapper/VendApamountMapper.xml

@@ -0,0 +1,509 @@
+<?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.usoftchina.saas.document.mapper.VendorMapper">
+    <resultMap id="VendorResultMapper" type="com.usoftchina.saas.document.entities.Vendor">
+        <id column="ve_id" property="id" jdbcType="INTEGER" />
+        <result column="ve_code" property="ve_code" jdbcType="VARCHAR" />
+        <result column="ve_shortname" property="ve_shortname" jdbcType="VARCHAR"/>
+        <result column="ve_uu" property="ve_uu" jdbcType="VARCHAR" />
+        <result column="ve_name" property="ve_name" jdbcType="VARCHAR" />
+        <result column="ve_type" property="ve_type" jdbcType="VARCHAR" />
+        <result column="ve_begindate" property="ve_begindate" jdbcType="TIMESTAMP" />
+        <result column="ve_beginapamount" property="ve_beginapamount" jdbcType="DOUBLE" />
+        <result column="ve_beginprepayamount" property="ve_beginprepayamount" jdbcType="DOUBLE" />
+        <result column="ve_promisedays" property="ve_promisedays" jdbcType="INTEGER" />
+        <result column="ve_taxrate" property="ve_taxrate" jdbcType="DOUBLE" />
+        <result column="ve_nsrzh" property="ve_nsrzh" jdbcType="VARCHAR" />
+        <result column="ve_bankaccount" property="ve_bankaccount" jdbcType="VARCHAR" />
+        <result column="ve_bankcode" property="ve_bankcode" jdbcType="VARCHAR" />
+        <result column="ve_status" property="ve_status" jdbcType="VARCHAR" />
+        <result column="ve_statuscode" property="ve_statuscode" jdbcType="VARCHAR" />
+        <result column="companyId" property="companyId" jdbcType="INTEGER" />
+        <result column="updaterId" property="updaterId" jdbcType="INTEGER" />
+        <result column="updateTime" property="updateTime" jdbcType="TIMESTAMP" />
+        <result column="ve_text1" property="ve_text1" jdbcType="VARCHAR" />
+        <result column="ve_text2" property="ve_text2" jdbcType="VARCHAR" />
+        <result column="ve_text3" property="ve_text3" jdbcType="VARCHAR" />
+        <result column="ve_text4" property="ve_text4" jdbcType="VARCHAR" />
+        <result column="ve_text5" property="ve_text5" jdbcType="VARCHAR" />
+        <result column="ve_payamount" property="ve_payamount" jdbcType="DOUBLE" />
+        <result column="ve_leftamount" property="ve_leftamount" jdbcType="DOUBLE" />
+        <result column="ve_beginym" property="ve_beginym" jdbcType="INTEGER" />
+        <result column="ve_preamount" property="ve_preamount" jdbcType="DOUBLE" />
+        <result column="ve_remark" property="ve_remark" jdbcType="VARCHAR" />
+        <result column="ve_address" property="ve_address" jdbcType="VARCHAR" />
+        <result column="ve_currency" property="ve_currency" jdbcType="VARCHAR" />
+    </resultMap>
+    <resultMap id="VendorDTOResultMapper" type="com.usoftchina.saas.document.dto.VendorDTO">
+        <id column="ve_id" property="id" jdbcType="INTEGER" />
+        <result column="ve_code" property="ve_code" jdbcType="VARCHAR" />
+        <result column="ve_shortname" property="ve_shortname" jdbcType="VARCHAR"/>
+        <result column="ve_name" property="ve_name" jdbcType="VARCHAR" />
+        <result column="ve_type" property="ve_type" jdbcType="VARCHAR" />
+        <result column="ve_status" property="ve_status" jdbcType="VARCHAR" />
+        <result column="ve_remark" property="ve_remark" jdbcType="VARCHAR" />
+        <result column="ve_address" property="ve_address" jdbcType="VARCHAR" />
+    </resultMap>
+
+    <select id="getVendorsByCondition" resultMap="VendorDTOResultMapper">
+        SELECT * FROM VENDOR
+        <where>
+            <if test="condition!=null">
+                ${condition}
+            </if>
+            <if test="companyId!=null">
+                AND companyId = #{companyId}
+            </if>
+        </where>
+        ORDER BY VE_ID DESC
+    </select>
+
+    <resultMap id="VendorListResultMapper" type="com.usoftchina.saas.document.entities.VendorList">
+        <id column="ve_id" property="id" jdbcType="INTEGER" />
+        <result column="ve_code" property="ve_code" jdbcType="VARCHAR" />
+        <result column="ve_uu" property="ve_uu" jdbcType="VARCHAR" />
+        <result column="ve_shortname" property="ve_shortname" jdbcType="VARCHAR"/>
+        <result column="ve_name" property="ve_name" jdbcType="VARCHAR" />
+        <result column="ve_type" property="ve_type" jdbcType="VARCHAR" />
+        <result column="ve_begindate" property="ve_begindate" jdbcType="TIMESTAMP" />
+        <result column="ve_beginapamount" property="ve_beginapamount" jdbcType="DOUBLE" />
+        <result column="ve_beginprepayamount" property="ve_beginprepayamount" jdbcType="DOUBLE" />
+        <result column="ve_promisedays" property="ve_promisedays" jdbcType="INTEGER" />
+        <result column="ve_taxrate" property="ve_taxrate" jdbcType="DOUBLE" />
+        <result column="ve_nsrzh" property="ve_nsrzh" jdbcType="VARCHAR" />
+        <result column="ve_bankaccount" property="ve_bankaccount" jdbcType="VARCHAR" />
+        <result column="ve_bankcode" property="ve_bankcode" jdbcType="VARCHAR" />
+        <result column="ve_status" property="ve_status" jdbcType="VARCHAR" />
+        <result column="ve_statuscode" property="ve_statuscode" jdbcType="VARCHAR" />
+        <result column="ve_leftamount" property="ve_leftamount" jdbcType="INTEGER" />
+        <result column="ve_address" property="ve_address" jdbcType="VARCHAR" />
+        <result column="ve_text1" property="ve_text1" jdbcType="VARCHAR" />
+        <result column="ve_text2" property="ve_text2" jdbcType="VARCHAR" />
+        <result column="ve_text3" property="ve_text3" jdbcType="VARCHAR" />
+        <result column="ve_text4" property="ve_text4" jdbcType="VARCHAR" />
+        <result column="ve_text5" property="ve_text5" jdbcType="VARCHAR" />
+        <result column="ve_remark" property="ve_remark" jdbcType="VARCHAR" />
+        <result column="ve_buyerid" property="ve_buyerid" jdbcType="INTEGER" />
+        <result column="ve_buyercode" property="ve_buyercode" jdbcType="VARCHAR" />
+        <result column="ve_buyername" property="ve_buyername" jdbcType="VARCHAR" />
+        <result column="vc_veid" property="vc_veid" jdbcType="INTEGER" />
+        <result column="vc_detno" property="vc_detno" jdbcType="INTEGER" />
+        <result column="vc_name" property="vc_name" jdbcType="VARCHAR" />
+        <result column="vc_tel" property="vc_tel" jdbcType="VARCHAR" />
+        <result column="vc_qq" property="vc_qq" jdbcType="VARCHAR" />
+        <result column="vc_email" property="vc_email" jdbcType="VARCHAR" />
+        <result column="vc_text1" property="vc_text1" jdbcType="VARCHAR" />
+        <result column="vc_text2" property="vc_text2" jdbcType="VARCHAR" />
+        <result column="vc_text3" property="vc_text3" jdbcType="VARCHAR" />
+        <result column="vc_text4" property="vc_text4" jdbcType="VARCHAR" />
+        <result column="vc_text5" property="vc_text5" jdbcType="VARCHAR" />
+        <result column="vc_default" property="vc_default" jdbcType="VARCHAR" />
+        <result column="ve_currency" property="ve_currency" jdbcType="VARCHAR" />
+        <result column="cr_rate" property="cr_rate" jdbcType="DOUBLE" />
+    </resultMap>
+
+    <select id="getListDataByCondition" resultMap="VendorListResultMapper">
+        SELECT * FROM VENDOR
+        LEFT JOIN VENDORCONTACT ON VE_ID = VC_VEID and vc_default = 1
+        left join currencys on cr_name = ve_currency and currencys.companyid = VENDOR.companyid
+        <where>
+            <if test="condition!=null">
+                ${condition}
+            </if>
+            AND VENDOR.COMPANYID = #{companyId}
+        </where>
+        order by VE_ID DESC
+    </select>
+
+    <sql id="Base_Column_List" >
+        ve_id, ve_code, ve_shortname,ve_name, ve_uu, ve_type, ve_begindate, ve_beginapamount, ve_beginprepayamount,
+        ve_promisedays, ve_taxrate, ve_nsrzh, ve_bankaccount, ve_bankcode, ve_status, ve_statuscode,
+        vendor.companyId companyId, vendor.updaterId updaterId, vendor.updateTime updateTime, ve_text1,
+        ve_text2, ve_text3, ve_text4, ve_text5, ve_payamount, ve_leftamount, ve_beginym, ve_preamount,ve_remark,
+        ve_buyerid,ve_buyercode,ve_buyername,ve_address,ve_currency,cr_rate
+    </sql>
+    <select id="selectByPrimaryKey" resultMap="VendorResultMapper" parameterType="java.lang.Long" >
+        select
+        <include refid="Base_Column_List" />
+        from vendor left join currencys on cr_name = ve_currency and vendor.companyId = currencys.companyId
+        where ve_id = #{id}
+    </select>
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
+        delete from vendor
+        where ve_id = #{id}
+    </delete>
+    <insert id="insertSelective" parameterType="com.usoftchina.saas.document.entities.Vendor" >
+        <selectKey resultType="java.lang.Long" keyProperty="id">
+            SELECT LAST_INSERT_ID() AS ID
+        </selectKey>
+        insert into vendor
+        <trim prefix="(" suffix=")" suffixOverrides="," >
+            <if test="ve_code != null" >
+                ve_code,
+            </if>
+            <if test="ve_shortname !=null">
+                ve_shortname,
+            </if>
+            <if test="ve_name != null" >
+                ve_name,
+            </if>
+            <if test="ve_uu != null" >
+                ve_uu,
+            </if>
+            <if test="ve_type != null" >
+                ve_type,
+            </if>
+            <if test="ve_begindate != null" >
+                ve_begindate,
+            </if>
+            <if test="ve_beginapamount != null" >
+                ve_beginapamount,
+            </if>
+            <if test="ve_beginprepayamount != null" >
+                ve_beginprepayamount,
+            </if>
+            <if test="ve_promisedays != null" >
+                ve_promisedays,
+            </if>
+            <if test="ve_taxrate != null" >
+                ve_taxrate,
+            </if>
+            <if test="ve_nsrzh != null" >
+                ve_nsrzh,
+            </if>
+            <if test="ve_bankaccount != null" >
+                ve_bankaccount,
+            </if>
+            <if test="ve_bankcode != null" >
+                ve_bankcode,
+            </if>
+            <if test="ve_status != null" >
+                ve_status,
+            </if>
+            <if test="ve_statuscode != null" >
+                ve_statuscode,
+            </if>
+            <if test="companyId != null" >
+                companyId,
+            </if>
+            <if test="updaterId != null" >
+                updaterId,
+            </if>
+            <if test="updateTime != null" >
+                updateTime,
+            </if>
+            <if test="ve_text1 != null" >
+                ve_text1,
+            </if>
+            <if test="ve_text2 != null" >
+                ve_text2,
+            </if>
+            <if test="ve_text3 != null" >
+                ve_text3,
+            </if>
+            <if test="ve_text4 != null" >
+                ve_text4,
+            </if>
+            <if test="ve_text5 != null" >
+                ve_text5,
+            </if>
+            <if test="ve_payamount != null" >
+                ve_payamount,
+            </if>
+            <if test="ve_leftamount != null" >
+                ve_leftamount,
+            </if>
+            <if test="ve_beginym != null" >
+                ve_beginym,
+            </if>
+            <if test="ve_preamount !=null" >
+                ve_preamount,
+            </if>
+            <if test="creatorId != null" >
+                creatorId,
+            </if>
+            <if test="createTime != null" >
+                createTime,
+            </if>
+            <if test="creatorName != null" >
+                creatorName,
+            </if>
+            <if test="ve_remark!=null">
+                ve_remark,
+            </if>
+            <if test="ve_buyerid!=null">
+                ve_buyerid,
+            </if>
+            <if test="ve_buyercode!=null">
+                ve_buyercode,
+            </if>
+            <if test="ve_buyername!=null">
+                ve_buyername,
+            </if>
+            <if test="ve_address!=null">
+                ve_address,
+            </if>
+            <if test="ve_currency!=null">
+              ve_currency,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides="," >
+            <if test="ve_code != null" >
+                #{ve_code,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_shortname !=null">
+                #{ve_shortname,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_name != null" >
+                #{ve_name,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_uu != null" >
+                #{ve_uu,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_type != null" >
+                #{ve_type,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_begindate != null" >
+                #{ve_begindate,jdbcType=TIMESTAMP},
+            </if>
+            <if test="ve_beginapamount != null" >
+                #{ve_beginapamount,jdbcType=DOUBLE},
+            </if>
+            <if test="ve_beginprepayamount != null" >
+                #{ve_beginprepayamount,jdbcType=DOUBLE},
+            </if>
+            <if test="ve_promisedays != null" >
+                #{ve_promisedays,jdbcType=DECIMAL},
+            </if>
+            <if test="ve_taxrate != null" >
+                #{ve_taxrate,jdbcType=DOUBLE},
+            </if>
+            <if test="ve_nsrzh != null" >
+                #{ve_nsrzh,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_bankaccount != null" >
+                #{ve_bankaccount,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_bankcode != null" >
+                #{ve_bankcode,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_status != null" >
+                #{ve_status,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_statuscode != null" >
+                #{ve_statuscode,jdbcType=VARCHAR},
+            </if>
+            <if test="companyId != null" >
+                #{companyId,jdbcType=DECIMAL},
+            </if>
+            <if test="updaterId != null" >
+                #{updaterId,jdbcType=DECIMAL},
+            </if>
+            <if test="updateTime != null" >
+                #{updateTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="ve_text1 != null" >
+                #{ve_text1,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_text2 != null" >
+                #{ve_text2,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_text3 != null" >
+                #{ve_text3,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_text4 != null" >
+                #{ve_text4,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_text5 != null" >
+                #{ve_text5,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_payamount != null" >
+                #{ve_payamount,jdbcType=DOUBLE},
+            </if>
+            <if test="ve_leftamount != null" >
+                #{ve_leftamount,jdbcType=DOUBLE},
+            </if>
+            <if test="ve_beginym != null" >
+                #{ve_beginym,jdbcType=INTEGER},
+            </if>
+            <if test="ve_preamount !=null" >
+                #{ve_preamount,jdbcType=DOUBLE},
+            </if>
+            <if test="creatorId != null" >
+                #{creatorId,jdbcType=INTEGER},
+            </if>
+            <if test="createTime != null" >
+                #{createTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="creatorName != null" >
+                #{creatorName,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_remark != null">
+                #{ve_remark,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_buyerid != null">
+                #{ve_buyerid,jdbcType=INTEGER},
+            </if>
+            <if test="ve_buyercode != null">
+                #{ve_buyercode,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_buyername != null">
+                #{ve_buyername,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_address != null">
+                #{ve_address,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_currency != null">
+              #{ve_currency,jdbcType=VARCHAR},
+            </if>
+        </trim>
+    </insert>
+    <update id="updateByPrimaryKeySelective" parameterType="com.usoftchina.saas.document.entities.Vendor" >
+        update vendor
+        <set >
+            <if test="ve_code != null" >
+                ve_code = #{ve_code,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_shortname !=null">
+                ve_shortname = #{ve_shortname,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_name != null" >
+                ve_name = #{ve_name,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_uu != null" >
+                ve_uu = #{ve_uu,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_type != null" >
+                ve_type = #{ve_type,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_begindate != null" >
+                ve_begindate = #{ve_begindate,jdbcType=TIMESTAMP},
+            </if>
+            <if test="ve_beginapamount != null" >
+                ve_beginapamount = #{ve_beginapamount,jdbcType=DOUBLE},
+            </if>
+            <if test="ve_beginprepayamount != null" >
+                ve_beginprepayamount = #{ve_beginprepayamount,jdbcType=DOUBLE},
+            </if>
+            <if test="ve_promisedays != null" >
+                ve_promisedays = #{ve_promisedays,jdbcType=DECIMAL},
+            </if>
+            <if test="ve_taxrate != null" >
+                ve_taxrate = #{ve_taxrate,jdbcType=DOUBLE},
+            </if>
+            <if test="ve_nsrzh != null" >
+                ve_nsrzh = #{ve_nsrzh,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_bankaccount != null" >
+                ve_bankaccount = #{ve_bankaccount,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_bankcode != null" >
+                ve_bankcode = #{ve_bankcode,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_status != null" >
+                ve_status = #{ve_status,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_statuscode != null" >
+                ve_statuscode = #{ve_statuscode,jdbcType=VARCHAR},
+            </if>
+            <if test="companyId != null" >
+                companyId = #{companyId,jdbcType=DECIMAL},
+            </if>
+            <if test="updaterId != null" >
+                updaterId = #{updaterId,jdbcType=DECIMAL},
+            </if>
+            <if test="updateTime != null" >
+                updateTime = #{updateTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="ve_text1 != null" >
+                ve_text1 = #{ve_text1,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_text2 != null" >
+                ve_text2 = #{ve_text2,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_text3 != null" >
+                ve_text3 = #{ve_text3,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_text4 != null" >
+                ve_text4 = #{ve_text4,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_text5 != null" >
+                ve_text5 = #{ve_text5,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_payamount != null" >
+                ve_payamount = #{ve_payamount,jdbcType=DOUBLE},
+            </if>
+            <if test="ve_leftamount != null" >
+                ve_leftamount = #{ve_leftamount,jdbcType=DOUBLE},
+            </if>
+            <if test="ve_beginym != null" >
+                ve_beginym = #{ve_beginym,jdbcType=INTEGER},
+            </if>
+            <if test="ve_preamount !=null" >
+                #{ve_preamount,jdbcType=DOUBLE},
+            </if>
+            <if test="ve_remark != null" >
+                ve_remark = #{ve_remark,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_buyerid != null" >
+                ve_buyerid = #{ve_buyerid,jdbcType=INTEGER},
+            </if>
+            <if test="ve_buyercode != null" >
+                ve_buyercode = #{ve_buyercode,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_buyername != null" >
+                ve_buyername = #{ve_buyername,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_address != null">
+                ve_address = #{ve_address,jdbcType=VARCHAR},
+            </if>
+            <if test="ve_currency != null">
+              ve_currency = #{ve_currency,jdbcType=VARCHAR},
+            </if>
+        </set>
+        where ve_id = #{id}
+    </update>
+    <select id="validateCodeWhenInsert" resultType="int">
+        select count(*) from VENDOR where VE_CODE = #{code} and companyId =#{companyId}
+    </select>
+    <select id="validateCodeWhenUpdate" resultType="int" >
+        select count(*) from VENDOR where VE_CODE = #{code} and VE_ID != #{id} and companyId =#{companyId}
+    </select>
+    <select id="getCodeById" resultType="string">
+        SELECT VE_CODE FROM VENDOR WHERE VE_ID = #{id} and COMPANYID = #{companyId}
+    </select>
+    <select id="getCountByCode" resultType="int">
+        SELECT COUNT(*) FROM VENDOR WHERE COMPANYID = #{companyId} AND VE_CODE=#{code}
+    </select>
+    <select id="getCountByName" resultType="int">
+        SELECT COUNT(*) FROM VENDOR WHERE COMPANYID = #{companyId} AND VE_NAME=#{name}
+    </select>
+
+    <select id="validFinish" parameterType="long" resultType="int">
+        select count(1) from periodsdetail where pd_status=99 and pd_detno=(select DATE_FORMAT(ve_begindate,'%Y%m') from vendor where ve_id =#{id})
+        and companyId =#{companyId};
+    </select>
+
+    <select id="check" parameterMap="checkParamMap" statementType="CALLABLE">
+        CALL SP_LIMITBASE(?, ?, ?, ?,?)
+    </select>
+    <parameterMap id="checkParamMap" type="java.util.Map">
+        <parameter property="v_type" jdbcType="VARCHAR" mode="IN" />
+        <parameter property="v_id" jdbcType="INTEGER" mode="IN" />
+        <parameter property="v_code" jdbcType="VARCHAR" mode="IN" />
+        <parameter property="v_companyid" jdbcType="INTEGER" mode="IN" />
+        <parameter property="v_res" jdbcType="VARCHAR" mode="OUT" />
+    </parameterMap>
+
+    <select id="selectIdByCode" resultType="long">
+        select ve_id from VENDOR where ve_code=#{code} and companyId=#{companyId}
+    </select>
+    <select id="selectByUU" resultMap="VendorDTOResultMapper">
+        select * from vendor where ve_uu = #{uu} and companyId = #{companyId}
+    </select>
+
+    <select id="selectByName" resultMap="VendorDTOResultMapper">
+      select * from vendor where ve_name = #{name} and companyId = #{companyId}
+    </select>
+</mapper>
+