Browse Source

Merge remote-tracking branch 'origin/master_liaozeyong'

13660505945 13 hours ago
parent
commit
9547104ef9

+ 33 - 19
src/main/java/com/jsh/erp/controller/pda/PdaController.java

@@ -1,15 +1,20 @@
 package com.jsh.erp.controller.pda;
 
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.jsh.erp.base.AjaxResult;
 import com.jsh.erp.base.BaseController;
 import com.jsh.erp.base.TableDataInfo;
-import com.jsh.erp.datasource.dto.DepotHeadDTO;
 import com.jsh.erp.datasource.entities.DepotHead;
 import com.jsh.erp.datasource.entities.DepotItem;
+import com.jsh.erp.datasource.entities.Supplier;
+import com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO;
+import com.jsh.erp.datasource.pda.vo.PDADepotHeadVO;
 import com.jsh.erp.query.LambdaQueryWrapperX;
 import com.jsh.erp.service.DepotHeadService;
 import com.jsh.erp.service.DepotItemService;
+import com.jsh.erp.service.SupplierService;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.*;
 
@@ -24,38 +29,40 @@ public class PdaController extends BaseController {
     @Resource
     private DepotHeadService depotHeadService;
 
+    @Resource
     private DepotItemService depotItemService;
 
+    @Resource
+    private SupplierService supplierService;
+
     /**
      * 采购入库
      * @return
      */
     @PostMapping ("/purchaseInventory")
     @ApiOperation(value = "采购入库")
-    public TableDataInfo purchaseInventory(@RequestBody DepotHeadDTO depotHeadDTO) {
+    public TableDataInfo purchaseInventory(@RequestBody PDADepotHeadDTO pdaDepotHeadDTO) {
+        pdaDepotHeadDTO.setSubType("采购订单");
         startPage();
-        List<DepotHead> list = depotHeadService.list(new LambdaQueryWrapperX<DepotHead>()
-                .eq(DepotHead::getSubType, "采购订单")
-                .eqIfPresent(DepotHead::getNumber, depotHeadDTO.getNumber())
-                .betweenIfPresent(DepotHead::getCreateTime, depotHeadDTO.getBeginTime(), depotHeadDTO.getEndTime())
-                .eqIfPresent(DepotHead::getStatus, depotHeadDTO.getStatus())
-//                .eq(DepotHead::getStatus, "1")
-        );
-        return getDataTable(list);
+        List<PDADepotHeadVO> pdaDepotHeadVOList = depotHeadService.pdaList(pdaDepotHeadDTO);
+        return getDataTable(pdaDepotHeadVOList);
     }
 
     @PostMapping("/saleOrder")
     @ApiOperation(value = "检货任务")
-    public TableDataInfo saleOrder(@RequestBody DepotHeadDTO depotHeadDTO) {
+    public TableDataInfo saleOrder(@RequestBody PDADepotHeadDTO pdaDepotHeadDTO) {
+        pdaDepotHeadDTO.setSubType("销售订单");
         startPage();
-        List<DepotHead> list = depotHeadService.list(new LambdaQueryWrapperX<DepotHead>()
-                .eq(DepotHead::getSubType, "销售订单")
-                .eqIfPresent(DepotHead::getNumber, depotHeadDTO.getNumber())
-                .betweenIfPresent(DepotHead::getCreateTime, depotHeadDTO.getBeginTime(), depotHeadDTO.getEndTime())
-                .eqIfPresent(DepotHead::getStatus, depotHeadDTO.getStatus())
-//                .eq(DepotHead::getStatus, "1")
-        );
-        return getDataTable(list);
+        List<PDADepotHeadVO> pdaDepotHeadVOList = depotHeadService.pdaList(pdaDepotHeadDTO);
+        return getDataTable(pdaDepotHeadVOList);
+    }
+
+    @ApiModelProperty(value = "订单详情")
+    @GetMapping("/orderInfo/{id}")
+    public AjaxResult orderInfo(@PathVariable("id") Long id){
+        DepotHead depotHead = depotHeadService.getOne(new LambdaQueryWrapperX<DepotHead>().eq(DepotHead::getId, id));
+        depotHead.setSupplierName(supplierService.getOne(new LambdaQueryWrapperX<Supplier>().eq(Supplier::getId, depotHead.getOrganId())).getSupplier());
+        return AjaxResult.success(depotHead);
     }
 
     @GetMapping("/orderDetail/{id}")
@@ -66,6 +73,13 @@ public class PdaController extends BaseController {
         return getDataTable(list);
     }
 
+    @ApiModelProperty("订单开始处理")
+    @GetMapping("/orderStartHandle/{id}")
+    public AjaxResult orderStartHandle(@PathVariable("id") Long id) {
+        depotHeadService.update(new UpdateWrapper<DepotHead>().set("status", "4").eq("id", id));
+        return AjaxResult.success();
+    }
+
 
 
 }

+ 5 - 0
src/main/java/com/jsh/erp/datasource/entities/DepotHead.java

@@ -1,5 +1,6 @@
 package com.jsh.erp.datasource.entities;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -122,6 +123,10 @@ public class DepotHead {
     @ApiModelProperty("商品总类数量")
     private int goodsTypeCount;
 
+    @TableField(exist = false)
+    @ApiModelProperty("供应商名称")
+    private String supplierName;
+
     public Long getId() {
         return id;
     }

+ 9 - 0
src/main/java/com/jsh/erp/datasource/mappers/DepotHeadMapper.java

@@ -4,10 +4,19 @@ import com.jsh.erp.datasource.entities.DepotHead;
 import com.jsh.erp.datasource.entities.DepotHeadExample;
 import java.util.List;
 
+import com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO;
+import com.jsh.erp.datasource.pda.vo.PDADepotHeadVO;
 import org.apache.ibatis.annotations.Param;
 
 public interface DepotHeadMapper extends BaseMapperX<DepotHead> {
 
+    /**
+     * PDA查询订单
+     * @param pdaDepotHeadDTO 筛选条件
+     * @return
+     */
+    List<PDADepotHeadVO> pdaList(PDADepotHeadDTO pdaDepotHeadDTO);
+
     long countByExample(DepotHeadExample example);
 
     int deleteByExample(DepotHeadExample example);

+ 1 - 1
src/main/java/com/jsh/erp/datasource/mappers/SupplierMapper.java

@@ -5,7 +5,7 @@ import com.jsh.erp.datasource.entities.SupplierExample;
 import java.util.List;
 import org.apache.ibatis.annotations.Param;
 
-public interface SupplierMapper {
+public interface SupplierMapper extends BaseMapperX<Supplier> {
     long countByExample(SupplierExample example);
 
     int deleteByExample(SupplierExample example);

+ 6 - 3
src/main/java/com/jsh/erp/datasource/dto/DepotHeadDTO.java → src/main/java/com/jsh/erp/datasource/pda/dto/PDADepotHeadDTO.java

@@ -1,10 +1,10 @@
-package com.jsh.erp.datasource.dto;
+package com.jsh.erp.datasource.pda.dto;
 
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 @Data
-public class DepotHeadDTO {
+public class PDADepotHeadDTO {
 
     @ApiModelProperty("开始时间")
     private String beginTime;
@@ -15,6 +15,9 @@ public class DepotHeadDTO {
     @ApiModelProperty("单据编号")
     private String number;
 
-    @ApiModelProperty("状态")
+    @ApiModelProperty("状态 0.未审核,1.已审核,2.已完成,3.部分完成,4.进行中,9.审核中")
     private String status;
+
+    @ApiModelProperty("单据类型")
+    private String subType;
 }

+ 32 - 0
src/main/java/com/jsh/erp/datasource/pda/vo/PDADepotHeadVO.java

@@ -0,0 +1,32 @@
+package com.jsh.erp.datasource.pda.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class PDADepotHeadVO {
+
+    @ApiModelProperty("主键ID")
+    private Long id;
+
+    @ApiModelProperty("单据编号")
+    private String number;
+
+    @ApiModelProperty("供应商名称")
+    private String supplierName;
+
+    @ApiModelProperty("订单创建时间")
+    private Date createTime;
+
+    @ApiModelProperty("商品总数量")
+    private int goodsQuantity;
+
+    @ApiModelProperty("商品总类")
+    private String goodsTypeCount;
+
+    @ApiModelProperty("订单状态")
+    private String status;
+
+}

+ 10 - 0
src/main/java/com/jsh/erp/service/DepotHeadService.java

@@ -3,6 +3,8 @@ package com.jsh.erp.service;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.jsh.erp.datasource.entities.DepotHead;
+import com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO;
+import com.jsh.erp.datasource.pda.vo.PDADepotHeadVO;
 import com.jsh.erp.datasource.vo.DepotHeadVo4InDetail;
 import com.jsh.erp.datasource.vo.DepotHeadVo4InOutMCount;
 import com.jsh.erp.datasource.vo.DepotHeadVo4List;
@@ -16,6 +18,14 @@ import java.util.List;
 import java.util.Map;
 
 public interface DepotHeadService extends IService<DepotHead> {
+
+    /**
+     * PDA查询订单
+     * @param pdaDepotHeadDTO 筛选条件
+     * @return
+     */
+    List<PDADepotHeadVO> pdaList(PDADepotHeadDTO pdaDepotHeadDTO);
+
     DepotHead getDepotHead(long id)throws Exception;
 
     List<DepotHead> getDepotHead()throws Exception;

+ 59 - 684
src/main/java/com/jsh/erp/service/SupplierService.java

@@ -1,717 +1,92 @@
 package com.jsh.erp.service;
 
 import com.alibaba.fastjson.JSONObject;
-import com.jsh.erp.constants.BusinessConstants;
-import com.jsh.erp.constants.ExceptionConstants;
-import com.jsh.erp.datasource.entities.*;
-import com.jsh.erp.datasource.mappers.*;
-import com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount;
-import com.jsh.erp.exception.BusinessRunTimeException;
-import com.jsh.erp.exception.JshException;
-import com.jsh.erp.utils.*;
-import jxl.Sheet;
-import jxl.Workbook;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.jsh.erp.datasource.entities.Supplier;
+import com.jsh.erp.utils.BaseResponseInfo;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.io.File;
 import java.math.BigDecimal;
-import java.util.*;
-
-
-@Service
-public class SupplierService {
-    private Logger logger = LoggerFactory.getLogger(SupplierService.class);
-
-    @Resource
-    private SupplierMapper supplierMapper;
-
-    @Resource
-    private SupplierMapperEx supplierMapperEx;
-    @Resource
-    private LogService logService;
-    @Resource
-    private UserService userService;
-    @Resource
-    private AccountHeadMapperEx accountHeadMapperEx;
-    @Resource
-    private DepotHeadMapperEx depotHeadMapperEx;
-    @Resource
-    private AccountItemMapperEx accountItemMapperEx;
-    @Resource
-    private DepotHeadService depotHeadService;
-    @Resource
-    private UserBusinessService userBusinessService;
-    @Resource
-    private UserBusinessMapper userBusinessMapper;
-
-    public Supplier getSupplier(long id)throws Exception {
-        Supplier result=null;
-        try{
-            result=supplierMapper.selectByPrimaryKey(id);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return result;
-    }
-
-    public List<Supplier> getSupplierListByIds(String ids)throws Exception {
-        List<Long> idList = StringUtil.strToLongList(ids);
-        List<Supplier> list = new ArrayList<>();
-        try{
-            SupplierExample example = new SupplierExample();
-            example.createCriteria().andIdIn(idList);
-            list = supplierMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
-
-    public List<Supplier> getSupplier()throws Exception {
-        SupplierExample example = new SupplierExample();
-        example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        List<Supplier> list=null;
-        try{
-            list=supplierMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
-
-    public List<Supplier> select(String supplier, String type, String phonenum, String telephone) throws Exception{
-        List<Supplier> list = new ArrayList<>();
-        try{
-            String [] creatorArray = depotHeadService.getCreatorArray();
-            PageUtils.startPage();
-            list = supplierMapperEx.selectByConditionSupplier(supplier, type, phonenum, telephone, creatorArray);
-            for(Supplier s : list) {
-                Integer supplierId = s.getId().intValue();
-                String beginTime = Tools.getYearBegin();
-                String endTime = Tools.getCenternTime(new Date());
-                BigDecimal sum = BigDecimal.ZERO;
-                String supplierType = type;
-                String inOutType = "";
-                String subType = "";
-                String typeBack = "";
-                String subTypeBack = "";
-                String billType = "";
-                if (("供应商").equals(supplierType)) {
-                    inOutType = "入库";
-                    subType = "采购";
-                    typeBack = "出库";
-                    subTypeBack = "采购退货";
-                    billType = "付款";
-                } else if (("客户").equals(supplierType)) {
-                    inOutType = "出库";
-                    subType = "销售";
-                    typeBack = "入库";
-                    subTypeBack = "销售退货";
-                    billType = "收款";
-                }
-                List<DepotHeadVo4StatementAccount> saList = depotHeadService.getStatementAccount(beginTime, endTime, supplierId, null,
-                        1, supplierType, inOutType, subType, typeBack, subTypeBack, billType, null, null);
-                if(saList.size()>0) {
-                    DepotHeadVo4StatementAccount item = saList.get(0);
-                    //期初 = 起始期初金额+上期欠款金额-上期退货的欠款金额-上期收付款
-                    BigDecimal preNeed = item.getBeginNeed().add(item.getPreDebtMoney()).subtract(item.getPreReturnDebtMoney()).subtract(item.getPreBackMoney());
-                    item.setPreNeed(preNeed);
-                    //实际欠款 = 本期欠款-本期退货的欠款金额
-                    BigDecimal realDebtMoney = item.getDebtMoney().subtract(item.getReturnDebtMoney());
-                    item.setDebtMoney(realDebtMoney);
-                    //期末 = 期初+实际欠款-本期收款
-                    BigDecimal allNeedGet = preNeed.add(realDebtMoney).subtract(item.getBackMoney());
-                    sum = sum.add(allNeedGet);
-                }
-                if(("客户").equals(s.getType())) {
-                    s.setAllNeedGet(sum);
-                } else if(("供应商").equals(s.getType())) {
-                    s.setAllNeedPay(sum);
-                }
-            }
-        } catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
+import java.util.List;
+import java.util.Map;
+
+public interface SupplierService extends IService<Supplier> {
+    Supplier getSupplier(long id)throws Exception;
+
+    List<Supplier> getSupplierListByIds(String ids)throws Exception;
+
+    List<Supplier> getSupplier()throws Exception;
+
+    List<Supplier> select(String supplier, String type, String phonenum, String telephone) throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int insertSupplier(JSONObject obj, HttpServletRequest request)throws Exception {
-        Supplier supplier = JSONObject.parseObject(obj.toJSONString(), Supplier.class);
-        int result=0;
-        try{
-            supplier.setEnabled(true);
-            User userInfo=userService.getCurrentUser();
-            supplier.setCreator(userInfo==null?null:userInfo.getId());
-            result=supplierMapper.insertSelective(supplier);
-            //新增客户时给当前用户自动授权
-            setUserCustomerPermission(request, supplier);
-            logService.insertLog("商家",
-                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(supplier.getSupplier()).toString(),request);
-        }catch(Exception e){
-            JshException.writeFail(logger, e);
-        }
-        return result;
-    }
+    int insertSupplier(JSONObject obj, HttpServletRequest request)throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int updateSupplier(JSONObject obj, HttpServletRequest request)throws Exception {
-        Supplier supplier = JSONObject.parseObject(obj.toJSONString(), Supplier.class);
-        if(supplier.getBeginNeedPay() == null) {
-            supplier.setBeginNeedPay(BigDecimal.ZERO);
-        }
-        if(supplier.getBeginNeedGet() == null) {
-            supplier.setBeginNeedGet(BigDecimal.ZERO);
-        }
-        int result=0;
-        try{
-            result=supplierMapper.updateByPrimaryKeySelective(supplier);
-            logService.insertLog("商家",
-                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(supplier.getSupplier()).toString(), request);
-        }catch(Exception e){
-            JshException.writeFail(logger, e);
-        }
-        return result;
-    }
+    int updateSupplier(JSONObject obj, HttpServletRequest request)throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int deleteSupplier(Long id, HttpServletRequest request)throws Exception {
-        return batchDeleteSupplierByIds(id.toString());
-    }
+    int deleteSupplier(Long id, HttpServletRequest request)throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int batchDeleteSupplier(String ids, HttpServletRequest request) throws Exception{
-        return batchDeleteSupplierByIds(ids);
-    }
+    int batchDeleteSupplier(String ids, HttpServletRequest request) throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int batchDeleteSupplierByIds(String ids)throws Exception {
-        int result=0;
-        String [] idArray=ids.split(",");
-        //校验财务主表	jsh_accounthead
-        List<AccountHead> accountHeadList=null;
-        try{
-            accountHeadList = accountHeadMapperEx.getAccountHeadListByOrganIds(idArray);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        if(accountHeadList!=null&&accountHeadList.size()>0){
-            logger.error("异常码[{}],异常提示[{}],参数,OrganIds[{}]",
-                    ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
-            throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
-                    ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
-        }
-        //校验单据主表	jsh_depot_head
-        List<DepotHead> depotHeadList=null;
-        try{
-            depotHeadList = depotHeadMapperEx.getDepotHeadListByOrganIds(idArray);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        if(depotHeadList!=null&&depotHeadList.size()>0){
-            logger.error("异常码[{}],异常提示[{}],参数,OrganIds[{}]",
-                    ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
-            throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
-                    ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
-        }
-        //记录日志
-        StringBuffer sb = new StringBuffer();
-        sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
-        List<Supplier> list = getSupplierListByIds(ids);
-        for(Supplier supplier: list){
-            sb.append("[").append(supplier.getSupplier()).append("]");
-        }
-        logService.insertLog("商家", sb.toString(),
-                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
-        User userInfo=userService.getCurrentUser();
-        //校验通过执行删除操作
-        try{
-            result = supplierMapperEx.batchDeleteSupplierByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
-        }catch(Exception e){
-            JshException.writeFail(logger, e);
-        }
-        return result;
-    }
-
-    public int checkIsNameExist(Long id, String name)throws Exception {
-        SupplierExample example = new SupplierExample();
-        example.createCriteria().andIdNotEqualTo(id).andSupplierEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        List<Supplier> list=null;
-        try{
-            list= supplierMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list==null?0:list.size();
-    }
-
-    public int checkIsNameAndTypeExist(Long id, String name, String type)throws Exception {
-        name = name == null? "": name;
-        SupplierExample example = new SupplierExample();
-        example.createCriteria().andIdNotEqualTo(id).andSupplierEqualTo(name).andTypeEqualTo(type)
-                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        List<Supplier> list=null;
-        try{
-            list= supplierMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list==null?0:list.size();
-    }
-
-    /**
-     * 更新会员的预付款
-     * @param supplierId
-     */
+    int batchDeleteSupplierByIds(String ids)throws Exception;
+
+    int checkIsNameExist(Long id, String name)throws Exception;
+
+    int checkIsNameAndTypeExist(Long id, String name, String type)throws Exception;
+
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public void updateAdvanceIn(Long supplierId) {
-        try{
-            //查询会员在收预付款单据的总金额
-            BigDecimal financialAllPrice = accountHeadMapperEx.getFinancialAllPriceByOrganId(supplierId);
-            //查询会员在零售出库单据的总金额
-            BigDecimal billAllPrice = depotHeadMapperEx.getBillAllPriceByOrganId(supplierId);
-            Supplier supplier = new Supplier();
-            supplier.setId(supplierId);
-            supplier.setAdvanceIn(financialAllPrice.subtract(billAllPrice));
-            supplierMapper.updateByPrimaryKeySelective(supplier);
-        } catch (Exception e){
-            JshException.writeFail(logger, e);
-        }
-    }
-
-    public List<Supplier> findBySelectCus()throws Exception {
-        SupplierExample example = new SupplierExample();
-        example.createCriteria().andTypeLike("客户").andEnabledEqualTo(true).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        example.setOrderByClause("sort asc, id desc");
-        List<Supplier> list=null;
-        try{
-            list = supplierMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
-
-    public List<Supplier> findBySelectSup()throws Exception {
-        SupplierExample example = new SupplierExample();
-        example.createCriteria().andTypeLike("供应商").andEnabledEqualTo(true)
-                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        example.setOrderByClause("sort asc, id desc");
-        List<Supplier> list=null;
-        try{
-            list = supplierMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
-
-    public List<Supplier> findBySelectRetail()throws Exception {
-        SupplierExample example = new SupplierExample();
-        example.createCriteria().andTypeLike("会员").andEnabledEqualTo(true)
-                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        example.setOrderByClause("sort asc, id desc");
-        List<Supplier> list=null;
-        try{
-            list = supplierMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
-
-    public List<Supplier> findById(Long supplierId)throws Exception {
-        SupplierExample example = new SupplierExample();
-        example.createCriteria().andIdEqualTo(supplierId)
-                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        example.setOrderByClause("sort asc, id desc");
-        List<Supplier> list=null;
-        try{
-            list = supplierMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
+    void updateAdvanceIn(Long supplierId);
+
+    List<Supplier> findBySelectCus()throws Exception;
+
+    List<Supplier> findBySelectSup()throws Exception;
+
+    List<Supplier> findBySelectRetail()throws Exception;
+
+    List<Supplier> findById(Long supplierId)throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int batchSetStatus(Boolean status, String ids)throws Exception {
-        logService.insertLog("商家",
-                new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ENABLED).toString(),
-                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
-        List<Long> supplierIds = StringUtil.strToLongList(ids);
-        Supplier supplier = new Supplier();
-        supplier.setEnabled(status);
-        SupplierExample example = new SupplierExample();
-        example.createCriteria().andIdIn(supplierIds);
-        int result=0;
-        try{
-            result = supplierMapper.updateByExampleSelective(supplier, example);
-        }catch(Exception e){
-            JshException.writeFail(logger, e);
-        }
-        return result;
-    }
-
-    public List<Supplier> findUserCustomer()throws Exception{
-        SupplierExample example = new SupplierExample();
-        example.createCriteria().andTypeEqualTo("客户")
-                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        example.setOrderByClause("sort asc, id desc");
-        List<Supplier> list=null;
-        try{
-            list = supplierMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
-
-    public List<Supplier> findByAll(String supplier, String type, String phonenum, String telephone) throws Exception{
-        List<Supplier> list=null;
-        try{
-            list = supplierMapperEx.findByAll(supplier, type, phonenum, telephone);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
-
-    public Map<String, Object> getBeginNeedByOrganId(Long organId) throws Exception {
-        Supplier supplier = getSupplier(organId);
-        Map<String, Object> map = new HashMap<>();
-        BigDecimal needDebt = BigDecimal.ZERO;
-        if("供应商".equals(supplier.getType())) {
-            needDebt = supplier.getBeginNeedPay();
-        } else if("客户".equals(supplier.getType())) {
-            needDebt = supplier.getBeginNeedGet();
-        }
-        BigDecimal finishDebt = accountItemMapperEx.getFinishDebtByOrganId(organId).abs();
-        BigDecimal eachAmount = BigDecimal.ZERO;
-        if(needDebt != null) {
-            eachAmount = needDebt.subtract(finishDebt);
-        }
-        //应收欠款
-        map.put("needDebt", needDebt);
-        //已收欠款
-        map.put("finishDebt", finishDebt);
-        //本次收款
-        map.put("eachAmount", eachAmount);
-        return map;
-    }
+    int batchSetStatus(Boolean status, String ids)throws Exception;
+
+    List<Supplier> findUserCustomer()throws Exception;
+
+    List<Supplier> findByAll(String supplier, String type, String phonenum, String telephone) throws Exception;
+
+    Map<String, Object> getBeginNeedByOrganId(Long organId) throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public void importVendor(MultipartFile file, HttpServletRequest request) throws Exception{
-        String type = "供应商";
-        User userInfo = userService.getCurrentUser();
-        Workbook workbook = Workbook.getWorkbook(file.getInputStream());
-        Sheet src = workbook.getSheet(0);
-        //'名称', '联系人', '手机号码', '联系电话', '电子邮箱', '纳税人识别号', '开具发票情况','税率(%)', '开户行', '账号', '地址', '供应商分级', '结算方式',	'账单周期', '采购对接人', '到货天数', '备注', '排序', '状态'
-        List<Supplier> sList = new ArrayList<>();
-        for (int i = 2; i < src.getRows(); i++) {
-            String supplierName = ExcelUtils.getContent(src, i, 0);
-            String enabled = ExcelUtils.getContent(src, i, 18);
-            if(StringUtil.isNotEmpty(supplierName) && StringUtil.isNotEmpty(enabled)) {
-                Supplier s = new Supplier();
-                s.setType(type);
-                s.setSupplier(supplierName);
-                s.setContacts(ExcelUtils.getContent(src, i, 1));
-                s.setTelephone(ExcelUtils.getContent(src, i, 2));
-                s.setPhoneNum(ExcelUtils.getContent(src, i, 3));
-                s.setEmail(ExcelUtils.getContent(src, i, 4));
-                s.setTaxNum(ExcelUtils.getContent(src, i, 5));
-                s.setInvoiceType(ExcelUtils.getContent(src, i, 6));
-                s.setTaxRate(parseBigDecimalEx(ExcelUtils.getContent(src, i, 7)));
-                s.setBankName(ExcelUtils.getContent(src, i, 8));
-                s.setAccountNumber(ExcelUtils.getContent(src, i, 9));
-                s.setAddress(ExcelUtils.getContent(src, i, 10));
-                s.setSupplierLevel(ExcelUtils.getContent(src, i, 11));
-                s.setSettlementMethod(ExcelUtils.getContent(src, i, 12));
-                s.setBillingCycleDays(parseIntegerFromExcel(ExcelUtils.getContent(src, i, 13)));
-                s.setProcurementContact(ExcelUtils.getContent(src, i, 14));
-                s.setDeliverydays(parseIntegerFromExcel(ExcelUtils.getContent(src, i, 15)));
-                s.setDescription(ExcelUtils.getContent(src, i, 16));
-                s.setSort(ExcelUtils.getContent(src, i, 17));
-                s.setCreator(userInfo==null?null:userInfo.getId());
-                s.setEnabled("1".equals(enabled));
-                sList.add(s);
-            }
-        }
-        importExcel(sList, type, request);
-    }
-
-    private Integer parseIntegerFromExcel(String content) {
-        if (content != null && !content.isEmpty()) {
-            try {
-                return Integer.valueOf(content);
-            } catch (NumberFormatException e) {
-                logger.error("无法解析整数值: {}", content, e);
-                return null;
-            }
-        }
-        return null;
-    }
+    void importVendor(MultipartFile file, HttpServletRequest request) throws Exception;
+
+    Integer parseIntegerFromExcel(String content);
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public void importCustomer(MultipartFile file, HttpServletRequest request) throws Exception{
-        String type = "客户";
-        User userInfo = userService.getCurrentUser();
-        Workbook workbook = Workbook.getWorkbook(file.getInputStream());
-        Sheet src = workbook.getSheet(0);
-        //'名称', '联系人', '手机号码', '联系电话', '电子邮箱', '传真', '期初应收', '纳税人识别号', '税率(%)', '开户行', '账号', '地址', '备注', '排序', '状态'
-        List<Supplier> sList = new ArrayList<>();
-        for (int i = 2; i < src.getRows(); i++) {
-            String supplierName = ExcelUtils.getContent(src, i, 0);
-            String enabled = ExcelUtils.getContent(src, i, 14);
-            if(StringUtil.isNotEmpty(supplierName) && StringUtil.isNotEmpty(enabled)) {
-                Supplier s = new Supplier();
-                s.setType(type);
-                s.setSupplier(supplierName);
-                s.setContacts(ExcelUtils.getContent(src, i, 1));
-                s.setTelephone(ExcelUtils.getContent(src, i, 2));
-                s.setPhoneNum(ExcelUtils.getContent(src, i, 3));
-                s.setEmail(ExcelUtils.getContent(src, i, 4));
-                s.setFax(ExcelUtils.getContent(src, i, 5));
-                s.setBeginNeedGet(parseBigDecimalEx(ExcelUtils.getContent(src, i, 6)));
-                s.setTaxNum(ExcelUtils.getContent(src, i, 7));
-                s.setTaxRate(parseBigDecimalEx(ExcelUtils.getContent(src, i, 8)));
-                s.setBankName(ExcelUtils.getContent(src, i, 9));
-                s.setAccountNumber(ExcelUtils.getContent(src, i, 10));
-                s.setAddress(ExcelUtils.getContent(src, i, 11));
-                s.setDescription(ExcelUtils.getContent(src, i, 12));
-                s.setSort(ExcelUtils.getContent(src, i, 13));
-                s.setCreator(userInfo==null?null:userInfo.getId());
-                s.setEnabled("1".equals(enabled));
-                sList.add(s);
-            }
-        }
-        importExcel(sList, type, request);
-    }
+    void importCustomer(MultipartFile file, HttpServletRequest request) throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public void importMember(MultipartFile file, HttpServletRequest request) throws Exception{
-        String type = "会员";
-        User userInfo = userService.getCurrentUser();
-        Workbook workbook = Workbook.getWorkbook(file.getInputStream());
-        Sheet src = workbook.getSheet(0);
-        //'名称', '联系人', '手机号码', '联系电话', '电子邮箱', '备注', '排序', '状态'
-        List<Supplier> sList = new ArrayList<>();
-        for (int i = 2; i < src.getRows(); i++) {
-            String supplierName = ExcelUtils.getContent(src, i, 0);
-            String enabled = ExcelUtils.getContent(src, i, 7);
-            if(StringUtil.isNotEmpty(supplierName) && StringUtil.isNotEmpty(enabled)) {
-                Supplier s = new Supplier();
-                s.setType(type);
-                s.setSupplier(supplierName);
-                s.setContacts(ExcelUtils.getContent(src, i, 1));
-                s.setTelephone(ExcelUtils.getContent(src, i, 2));
-                s.setPhoneNum(ExcelUtils.getContent(src, i, 3));
-                s.setEmail(ExcelUtils.getContent(src, i, 4));
-                s.setDescription(ExcelUtils.getContent(src, i, 5));
-                s.setSort(ExcelUtils.getContent(src, i, 6));
-                s.setCreator(userInfo==null?null:userInfo.getId());
-                s.setEnabled("1".equals(enabled));
-                sList.add(s);
-            }
-        }
-        importExcel(sList, type, request);
-    }
+    void importMember(MultipartFile file, HttpServletRequest request) throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public BaseResponseInfo importExcel(List<Supplier> mList, String type, HttpServletRequest request) throws Exception {
-        logService.insertLog(type,
-                new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(),
-                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
-        BaseResponseInfo info = new BaseResponseInfo();
-        Map<String, Object> data = new HashMap<>();
-        try {
-            for(Supplier supplier: mList) {
-                SupplierExample example = new SupplierExample();
-                example.createCriteria().andSupplierEqualTo(supplier.getSupplier()).andTypeEqualTo(type).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-                List<Supplier> list= supplierMapper.selectByExample(example);
-                if(list.size() <= 0) {
-                    supplierMapper.insertSelective(supplier);
-                    //新增客户时给当前用户自动授权
-                    setUserCustomerPermission(request, supplier);
-                } else {
-                    Long id = list.get(0).getId();
-                    supplier.setId(id);
-                    supplierMapper.updateByPrimaryKeySelective(supplier);
-                }
-            }
-            info.code = 200;
-            data.put("message", "成功");
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-            info.code = 500;
-            data.put("message", e.getMessage());
-        }
-        info.data = data;
-        return info;
-    }
-
-    public BigDecimal parseBigDecimalEx(String str)throws Exception{
-        if(!StringUtil.isEmpty(str)) {
-            return new BigDecimal(str);
-        } else {
-            return null;
-        }
-    }
-
-    public File exportExcel(List<Supplier> dataList, String type) throws Exception {
-        if("供应商".equals(type)) {
-            return exportExcelVendorOrCustomer(dataList, type);
-        } else if("客户".equals(type)) {
-            return exportExcelVendorOrCustomer(dataList, type);
-        } else {
-            //会员
-            String[] names = {"会员卡号*", "联系人", "手机号码", "联系电话", "电子邮箱", "备注", "排序", "状态*"};
-            String title = "信息内容";
-            List<String[]> objects = new ArrayList<String[]>();
-            if (null != dataList) {
-                for (Supplier s : dataList) {
-                    String[] objs = new String[names.length];
-                    objs[0] = s.getSupplier();
-                    objs[1] = s.getContacts();
-                    objs[2] = s.getTelephone();
-                    objs[3] = s.getPhoneNum();
-                    objs[4] = s.getEmail();
-                    objs[5] = s.getDescription();
-                    objs[6] = s.getSort();
-                    objs[7] = s.getEnabled() ? "1" : "0";
-                    objects.add(objs);
-                }
-            }
-            return ExcelUtils.exportObjectsOneSheet(title, "*导入时本行内容请勿删除,切记!", names, title, objects);
-        }
-    }
-
-    private File exportExcelVendorOrCustomer(List<Supplier> dataList, String type) throws Exception {
-        /*String beginNeedStr = "";
-        if("供应商".equals(type)) {
-            beginNeedStr = "期初应付";
-        } else if("客户".equals(type)) {
-            beginNeedStr = "期初应收";
-        }*/
-        String[] names = {"名称*", "联系人", "手机号码", "联系电话", "电子邮箱",
-                "纳税人识别号", "发票类型","税率(%)", "开户行", "账号", "地址","供应商分级",
-                "结算方式", "账单周期", "采购对接人", "到货天数", "备注", "排序", "状态*"};
-        String title = "信息内容";
-        List<String[]> objects = new ArrayList<String[]>();
-        if (null != dataList) {
-            for (Supplier s : dataList) {
-                String[] objs = new String[names.length];
-                objs[0] = s.getSupplier();
-                objs[1] = s.getContacts();
-                objs[2] = s.getTelephone();
-                objs[3] = s.getPhoneNum();
-                objs[4] = s.getEmail();
-                /*if(("客户").equals(s.getType())) {
-                    objs[6] = s.getBeginNeedGet() == null? "" : s.getBeginNeedGet().setScale(2,BigDecimal.ROUND_HALF_UP).toString();
-                } else if(("供应商").equals(s.getType())) {
-                    objs[6] = s.getBeginNeedPay() == null? "" : s.getBeginNeedPay().setScale(2,BigDecimal.ROUND_HALF_UP).toString();
-                }*/
-                objs[5] = s.getTaxNum();
-                // 发票类型
-                objs[6] = mapInvoiceType(s.getInvoiceType());
-                // 税率
-                objs[7] = s.getTaxRate() == null? "" : s.getTaxRate().setScale(2,BigDecimal.ROUND_HALF_UP).toString();
-
-                // 银行信息
-                objs[8] = s.getBankName();
-                objs[9] = s.getAccountNumber();
-                objs[10] = s.getAddress();
-
-                // 供应商分级
-                objs[11] = s.getSupplierLevel();
-
-                // 结算方式
-                objs[12] = mapSettlementMethod(s.getSettlementMethod());
-                // 账单周期
-                objs[13] = s.getBillingCycleDays() == null? "" : s.getBillingCycleDays().toString();
-                // 采购对接人
-                objs[14] = s.getProcurementContact();
-                // 到货天数
-                objs[15] = s.getDeliverydays() == null? "" : s.getDeliverydays().toString();
-                objs[16] = s.getDescription();
-                objs[17] = s.getSort();
-                objs[18] = s.getEnabled() ? "1" : "0";
-                objects.add(objs);
-            }
-        }
-        return ExcelUtils.exportObjectsOneSheet(title, "*导入时本行内容请勿删除,切记!", names, title, objects);
-    }
-
-    private String mapInvoiceType(String invoiceType) {
-        if ("0".equals(invoiceType)) {
-            return "普通发票";
-        } else if ("1".equals(invoiceType)) {
-            return "增值税专用发票";
-        }
-        return "";
-    }
-
-    private String mapSettlementMethod(String settlementMethod) {
-        if ("0".equals(settlementMethod)) {
-            return "周结";
-        } else if ("1".equals(settlementMethod)) {
-            return "现结/按单";
-        } else if ("2".equals(settlementMethod)) {
-            return "预付款";
-        } else if ("3".equals(settlementMethod)) {
-            return "月结";
-        }
-        return "";
-    }
-
-    /**
-     * 新增客户时给当前用户自动授权
-     * @param request
-     * @param supplier
-     * @throws Exception
-     */
-    private void setUserCustomerPermission(HttpServletRequest request, Supplier supplier) throws Exception {
-        if("客户".equals(supplier.getType())) {
-            Long userId = userService.getUserId(request);
-            Supplier sInfo = supplierMapperEx.getSupplierByNameAndType(supplier.getSupplier(), supplier.getType());
-            String ubKey = "[" + sInfo.getId() + "]";
-            List<UserBusiness> ubList = userBusinessService.getBasicData(userId.toString(), "UserCustomer");
-            if(ubList ==null || ubList.size() == 0) {
-                JSONObject ubObj = new JSONObject();
-                ubObj.put("type", "UserCustomer");
-                ubObj.put("keyId", userId);
-                ubObj.put("value", ubKey);
-                UserBusiness userBusiness = JSONObject.parseObject(ubObj.toJSONString(), UserBusiness.class);
-                userBusinessMapper.insertSelective(userBusiness);
-            } else {
-                UserBusiness ubInfo = ubList.get(0);
-                JSONObject ubObj = new JSONObject();
-                ubObj.put("id", ubInfo.getId());
-                ubObj.put("type", ubInfo.getType());
-                ubObj.put("keyId", ubInfo.getKeyId());
-                ubObj.put("value", ubInfo.getValue() + ubKey);
-                UserBusiness userBusiness = JSONObject.parseObject(ubObj.toJSONString(), UserBusiness.class);
-                userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
-            }
-        }
-    }
+    BaseResponseInfo importExcel(List<Supplier> mList, String type, HttpServletRequest request) throws Exception;
+
+    BigDecimal parseBigDecimalEx(String str)throws Exception;
+
+    File exportExcel(List<Supplier> dataList, String type) throws Exception;
+
+    File exportExcelVendorOrCustomer(List<Supplier> dataList, String type) throws Exception;
+
+    String mapInvoiceType(String invoiceType);
+
+    String mapSettlementMethod(String settlementMethod);
+
+    void setUserCustomerPermission(HttpServletRequest request, Supplier supplier) throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int batchSetAdvanceIn(String ids) throws Exception {
-        int res = 0;
-        List<Long> idList = StringUtil.strToLongList(ids);
-        for(Long sId: idList) {
-            updateAdvanceIn(sId);
-            res = 1;
-        }
-        return res;
-    }
+    int batchSetAdvanceIn(String ids) throws Exception;
 }

+ 12 - 1
src/main/java/com/jsh/erp/service/impl/DepotHeadServiceImpl.java

@@ -2,7 +2,6 @@ package com.jsh.erp.service.impl;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jsh.erp.constants.BusinessConstants;
 import com.jsh.erp.constants.ExceptionConstants;
@@ -10,6 +9,8 @@ import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.mappers.DepotHeadMapper;
 import com.jsh.erp.datasource.mappers.DepotHeadMapperEx;
 import com.jsh.erp.datasource.mappers.DepotItemMapperEx;
+import com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO;
+import com.jsh.erp.datasource.pda.vo.PDADepotHeadVO;
 import com.jsh.erp.datasource.vo.*;
 import com.jsh.erp.exception.BusinessRunTimeException;
 import com.jsh.erp.exception.JshException;
@@ -83,6 +84,16 @@ public class DepotHeadServiceImpl extends ServiceImpl<DepotHeadMapper, DepotHead
     @Resource
     private QRCodeGenerator qrCodeGenerator;
 
+    /**
+     * PDA查询订单
+     * @param pdaDepotHeadDTO 筛选条件
+     * @return
+     */
+    @Override
+    public List<PDADepotHeadVO> pdaList(PDADepotHeadDTO pdaDepotHeadDTO) {
+        return depotHeadMapper.pdaList(pdaDepotHeadDTO);
+    }
+
     @Override
     public DepotHead getDepotHead(long id)throws Exception {
         DepotHead result=null;

+ 751 - 0
src/main/java/com/jsh/erp/service/impl/SupplierServiceImpl.java

@@ -0,0 +1,751 @@
+package com.jsh.erp.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.jsh.erp.constants.BusinessConstants;
+import com.jsh.erp.constants.ExceptionConstants;
+import com.jsh.erp.datasource.entities.*;
+import com.jsh.erp.datasource.mappers.*;
+import com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount;
+import com.jsh.erp.exception.BusinessRunTimeException;
+import com.jsh.erp.exception.JshException;
+import com.jsh.erp.service.*;
+import com.jsh.erp.utils.*;
+import jxl.Sheet;
+import jxl.Workbook;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.math.BigDecimal;
+import java.util.*;
+
+
+@Service
+public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {
+    private Logger logger = LoggerFactory.getLogger(SupplierService.class);
+
+    @Resource
+    private SupplierMapper supplierMapper;
+
+    @Resource
+    private SupplierMapperEx supplierMapperEx;
+    @Resource
+    private LogService logService;
+    @Resource
+    private UserService userService;
+    @Resource
+    private AccountHeadMapperEx accountHeadMapperEx;
+    @Resource
+    private DepotHeadMapperEx depotHeadMapperEx;
+    @Resource
+    private AccountItemMapperEx accountItemMapperEx;
+    @Resource
+    private DepotHeadService depotHeadService;
+    @Resource
+    private UserBusinessService userBusinessService;
+    @Resource
+    private UserBusinessMapper userBusinessMapper;
+
+    @Override
+    public Supplier getSupplier(long id)throws Exception {
+        Supplier result=null;
+        try{
+            result=supplierMapper.selectByPrimaryKey(id);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return result;
+    }
+
+    @Override
+    public List<Supplier> getSupplierListByIds(String ids)throws Exception {
+        List<Long> idList = StringUtil.strToLongList(ids);
+        List<Supplier> list = new ArrayList<>();
+        try{
+            SupplierExample example = new SupplierExample();
+            example.createCriteria().andIdIn(idList);
+            list = supplierMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    public List<Supplier> getSupplier()throws Exception {
+        SupplierExample example = new SupplierExample();
+        example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        List<Supplier> list=null;
+        try{
+            list=supplierMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    public List<Supplier> select(String supplier, String type, String phonenum, String telephone) throws Exception{
+        List<Supplier> list = new ArrayList<>();
+        try{
+            String [] creatorArray = depotHeadService.getCreatorArray();
+            PageUtils.startPage();
+            list = supplierMapperEx.selectByConditionSupplier(supplier, type, phonenum, telephone, creatorArray);
+            for(Supplier s : list) {
+                Integer supplierId = s.getId().intValue();
+                String beginTime = Tools.getYearBegin();
+                String endTime = Tools.getCenternTime(new Date());
+                BigDecimal sum = BigDecimal.ZERO;
+                String supplierType = type;
+                String inOutType = "";
+                String subType = "";
+                String typeBack = "";
+                String subTypeBack = "";
+                String billType = "";
+                if (("供应商").equals(supplierType)) {
+                    inOutType = "入库";
+                    subType = "采购";
+                    typeBack = "出库";
+                    subTypeBack = "采购退货";
+                    billType = "付款";
+                } else if (("客户").equals(supplierType)) {
+                    inOutType = "出库";
+                    subType = "销售";
+                    typeBack = "入库";
+                    subTypeBack = "销售退货";
+                    billType = "收款";
+                }
+                List<DepotHeadVo4StatementAccount> saList = depotHeadService.getStatementAccount(beginTime, endTime, supplierId, null,
+                        1, supplierType, inOutType, subType, typeBack, subTypeBack, billType, null, null);
+                if(saList.size()>0) {
+                    DepotHeadVo4StatementAccount item = saList.get(0);
+                    //期初 = 起始期初金额+上期欠款金额-上期退货的欠款金额-上期收付款
+                    BigDecimal preNeed = item.getBeginNeed().add(item.getPreDebtMoney()).subtract(item.getPreReturnDebtMoney()).subtract(item.getPreBackMoney());
+                    item.setPreNeed(preNeed);
+                    //实际欠款 = 本期欠款-本期退货的欠款金额
+                    BigDecimal realDebtMoney = item.getDebtMoney().subtract(item.getReturnDebtMoney());
+                    item.setDebtMoney(realDebtMoney);
+                    //期末 = 期初+实际欠款-本期收款
+                    BigDecimal allNeedGet = preNeed.add(realDebtMoney).subtract(item.getBackMoney());
+                    sum = sum.add(allNeedGet);
+                }
+                if(("客户").equals(s.getType())) {
+                    s.setAllNeedGet(sum);
+                } else if(("供应商").equals(s.getType())) {
+                    s.setAllNeedPay(sum);
+                }
+            }
+        } catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int insertSupplier(JSONObject obj, HttpServletRequest request)throws Exception {
+        Supplier supplier = JSONObject.parseObject(obj.toJSONString(), Supplier.class);
+        int result=0;
+        try{
+            supplier.setEnabled(true);
+            User userInfo=userService.getCurrentUser();
+            supplier.setCreator(userInfo==null?null:userInfo.getId());
+            result=supplierMapper.insertSelective(supplier);
+            //新增客户时给当前用户自动授权
+            setUserCustomerPermission(request, supplier);
+            logService.insertLog("商家",
+                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(supplier.getSupplier()).toString(),request);
+        }catch(Exception e){
+            JshException.writeFail(logger, e);
+        }
+        return result;
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int updateSupplier(JSONObject obj, HttpServletRequest request)throws Exception {
+        Supplier supplier = JSONObject.parseObject(obj.toJSONString(), Supplier.class);
+        if(supplier.getBeginNeedPay() == null) {
+            supplier.setBeginNeedPay(BigDecimal.ZERO);
+        }
+        if(supplier.getBeginNeedGet() == null) {
+            supplier.setBeginNeedGet(BigDecimal.ZERO);
+        }
+        int result=0;
+        try{
+            result=supplierMapper.updateByPrimaryKeySelective(supplier);
+            logService.insertLog("商家",
+                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(supplier.getSupplier()).toString(), request);
+        }catch(Exception e){
+            JshException.writeFail(logger, e);
+        }
+        return result;
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int deleteSupplier(Long id, HttpServletRequest request)throws Exception {
+        return batchDeleteSupplierByIds(id.toString());
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int batchDeleteSupplier(String ids, HttpServletRequest request) throws Exception{
+        return batchDeleteSupplierByIds(ids);
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int batchDeleteSupplierByIds(String ids)throws Exception {
+        int result=0;
+        String [] idArray=ids.split(",");
+        //校验财务主表	jsh_accounthead
+        List<AccountHead> accountHeadList=null;
+        try{
+            accountHeadList = accountHeadMapperEx.getAccountHeadListByOrganIds(idArray);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        if(accountHeadList!=null&&accountHeadList.size()>0){
+            logger.error("异常码[{}],异常提示[{}],参数,OrganIds[{}]",
+                    ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
+            throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
+                    ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
+        }
+        //校验单据主表	jsh_depot_head
+        List<DepotHead> depotHeadList=null;
+        try{
+            depotHeadList = depotHeadMapperEx.getDepotHeadListByOrganIds(idArray);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        if(depotHeadList!=null&&depotHeadList.size()>0){
+            logger.error("异常码[{}],异常提示[{}],参数,OrganIds[{}]",
+                    ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
+            throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
+                    ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
+        }
+        //记录日志
+        StringBuffer sb = new StringBuffer();
+        sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
+        List<Supplier> list = getSupplierListByIds(ids);
+        for(Supplier supplier: list){
+            sb.append("[").append(supplier.getSupplier()).append("]");
+        }
+        logService.insertLog("商家", sb.toString(),
+                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
+        User userInfo=userService.getCurrentUser();
+        //校验通过执行删除操作
+        try{
+            result = supplierMapperEx.batchDeleteSupplierByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
+        }catch(Exception e){
+            JshException.writeFail(logger, e);
+        }
+        return result;
+    }
+
+    @Override
+    public int checkIsNameExist(Long id, String name)throws Exception {
+        SupplierExample example = new SupplierExample();
+        example.createCriteria().andIdNotEqualTo(id).andSupplierEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        List<Supplier> list=null;
+        try{
+            list= supplierMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list==null?0:list.size();
+    }
+
+    @Override
+    public int checkIsNameAndTypeExist(Long id, String name, String type)throws Exception {
+        name = name == null? "": name;
+        SupplierExample example = new SupplierExample();
+        example.createCriteria().andIdNotEqualTo(id).andSupplierEqualTo(name).andTypeEqualTo(type)
+                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        List<Supplier> list=null;
+        try{
+            list= supplierMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list==null?0:list.size();
+    }
+
+    /**
+     * 更新会员的预付款
+     * @param supplierId
+     */
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public void updateAdvanceIn(Long supplierId) {
+        try{
+            //查询会员在收预付款单据的总金额
+            BigDecimal financialAllPrice = accountHeadMapperEx.getFinancialAllPriceByOrganId(supplierId);
+            //查询会员在零售出库单据的总金额
+            BigDecimal billAllPrice = depotHeadMapperEx.getBillAllPriceByOrganId(supplierId);
+            Supplier supplier = new Supplier();
+            supplier.setId(supplierId);
+            supplier.setAdvanceIn(financialAllPrice.subtract(billAllPrice));
+            supplierMapper.updateByPrimaryKeySelective(supplier);
+        } catch (Exception e){
+            JshException.writeFail(logger, e);
+        }
+    }
+
+    @Override
+    public List<Supplier> findBySelectCus()throws Exception {
+        SupplierExample example = new SupplierExample();
+        example.createCriteria().andTypeLike("客户").andEnabledEqualTo(true).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        example.setOrderByClause("sort asc, id desc");
+        List<Supplier> list=null;
+        try{
+            list = supplierMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    public List<Supplier> findBySelectSup()throws Exception {
+        SupplierExample example = new SupplierExample();
+        example.createCriteria().andTypeLike("供应商").andEnabledEqualTo(true)
+                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        example.setOrderByClause("sort asc, id desc");
+        List<Supplier> list=null;
+        try{
+            list = supplierMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    public List<Supplier> findBySelectRetail()throws Exception {
+        SupplierExample example = new SupplierExample();
+        example.createCriteria().andTypeLike("会员").andEnabledEqualTo(true)
+                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        example.setOrderByClause("sort asc, id desc");
+        List<Supplier> list=null;
+        try{
+            list = supplierMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    public List<Supplier> findById(Long supplierId)throws Exception {
+        SupplierExample example = new SupplierExample();
+        example.createCriteria().andIdEqualTo(supplierId)
+                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        example.setOrderByClause("sort asc, id desc");
+        List<Supplier> list=null;
+        try{
+            list = supplierMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int batchSetStatus(Boolean status, String ids)throws Exception {
+        logService.insertLog("商家",
+                new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ENABLED).toString(),
+                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
+        List<Long> supplierIds = StringUtil.strToLongList(ids);
+        Supplier supplier = new Supplier();
+        supplier.setEnabled(status);
+        SupplierExample example = new SupplierExample();
+        example.createCriteria().andIdIn(supplierIds);
+        int result=0;
+        try{
+            result = supplierMapper.updateByExampleSelective(supplier, example);
+        }catch(Exception e){
+            JshException.writeFail(logger, e);
+        }
+        return result;
+    }
+
+    @Override
+    public List<Supplier> findUserCustomer()throws Exception{
+        SupplierExample example = new SupplierExample();
+        example.createCriteria().andTypeEqualTo("客户")
+                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        example.setOrderByClause("sort asc, id desc");
+        List<Supplier> list=null;
+        try{
+            list = supplierMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    public List<Supplier> findByAll(String supplier, String type, String phonenum, String telephone) throws Exception{
+        List<Supplier> list=null;
+        try{
+            list = supplierMapperEx.findByAll(supplier, type, phonenum, telephone);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    public Map<String, Object> getBeginNeedByOrganId(Long organId) throws Exception {
+        Supplier supplier = getSupplier(organId);
+        Map<String, Object> map = new HashMap<>();
+        BigDecimal needDebt = BigDecimal.ZERO;
+        if("供应商".equals(supplier.getType())) {
+            needDebt = supplier.getBeginNeedPay();
+        } else if("客户".equals(supplier.getType())) {
+            needDebt = supplier.getBeginNeedGet();
+        }
+        BigDecimal finishDebt = accountItemMapperEx.getFinishDebtByOrganId(organId).abs();
+        BigDecimal eachAmount = BigDecimal.ZERO;
+        if(needDebt != null) {
+            eachAmount = needDebt.subtract(finishDebt);
+        }
+        //应收欠款
+        map.put("needDebt", needDebt);
+        //已收欠款
+        map.put("finishDebt", finishDebt);
+        //本次收款
+        map.put("eachAmount", eachAmount);
+        return map;
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public void importVendor(MultipartFile file, HttpServletRequest request) throws Exception{
+        String type = "供应商";
+        User userInfo = userService.getCurrentUser();
+        Workbook workbook = Workbook.getWorkbook(file.getInputStream());
+        Sheet src = workbook.getSheet(0);
+        //'名称', '联系人', '手机号码', '联系电话', '电子邮箱', '纳税人识别号', '开具发票情况','税率(%)', '开户行', '账号', '地址', '供应商分级', '结算方式',	'账单周期', '采购对接人', '到货天数', '备注', '排序', '状态'
+        List<Supplier> sList = new ArrayList<>();
+        for (int i = 2; i < src.getRows(); i++) {
+            String supplierName = ExcelUtils.getContent(src, i, 0);
+            String enabled = ExcelUtils.getContent(src, i, 18);
+            if(StringUtil.isNotEmpty(supplierName) && StringUtil.isNotEmpty(enabled)) {
+                Supplier s = new Supplier();
+                s.setType(type);
+                s.setSupplier(supplierName);
+                s.setContacts(ExcelUtils.getContent(src, i, 1));
+                s.setTelephone(ExcelUtils.getContent(src, i, 2));
+                s.setPhoneNum(ExcelUtils.getContent(src, i, 3));
+                s.setEmail(ExcelUtils.getContent(src, i, 4));
+                s.setTaxNum(ExcelUtils.getContent(src, i, 5));
+                s.setInvoiceType(ExcelUtils.getContent(src, i, 6));
+                s.setTaxRate(parseBigDecimalEx(ExcelUtils.getContent(src, i, 7)));
+                s.setBankName(ExcelUtils.getContent(src, i, 8));
+                s.setAccountNumber(ExcelUtils.getContent(src, i, 9));
+                s.setAddress(ExcelUtils.getContent(src, i, 10));
+                s.setSupplierLevel(ExcelUtils.getContent(src, i, 11));
+                s.setSettlementMethod(ExcelUtils.getContent(src, i, 12));
+                s.setBillingCycleDays(parseIntegerFromExcel(ExcelUtils.getContent(src, i, 13)));
+                s.setProcurementContact(ExcelUtils.getContent(src, i, 14));
+                s.setDeliverydays(parseIntegerFromExcel(ExcelUtils.getContent(src, i, 15)));
+                s.setDescription(ExcelUtils.getContent(src, i, 16));
+                s.setSort(ExcelUtils.getContent(src, i, 17));
+                s.setCreator(userInfo==null?null:userInfo.getId());
+                s.setEnabled("1".equals(enabled));
+                sList.add(s);
+            }
+        }
+        importExcel(sList, type, request);
+    }
+
+    @Override
+    public Integer parseIntegerFromExcel(String content) {
+        if (content != null && !content.isEmpty()) {
+            try {
+                return Integer.valueOf(content);
+            } catch (NumberFormatException e) {
+                logger.error("无法解析整数值: {}", content, e);
+                return null;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public void importCustomer(MultipartFile file, HttpServletRequest request) throws Exception{
+        String type = "客户";
+        User userInfo = userService.getCurrentUser();
+        Workbook workbook = Workbook.getWorkbook(file.getInputStream());
+        Sheet src = workbook.getSheet(0);
+        //'名称', '联系人', '手机号码', '联系电话', '电子邮箱', '传真', '期初应收', '纳税人识别号', '税率(%)', '开户行', '账号', '地址', '备注', '排序', '状态'
+        List<Supplier> sList = new ArrayList<>();
+        for (int i = 2; i < src.getRows(); i++) {
+            String supplierName = ExcelUtils.getContent(src, i, 0);
+            String enabled = ExcelUtils.getContent(src, i, 14);
+            if(StringUtil.isNotEmpty(supplierName) && StringUtil.isNotEmpty(enabled)) {
+                Supplier s = new Supplier();
+                s.setType(type);
+                s.setSupplier(supplierName);
+                s.setContacts(ExcelUtils.getContent(src, i, 1));
+                s.setTelephone(ExcelUtils.getContent(src, i, 2));
+                s.setPhoneNum(ExcelUtils.getContent(src, i, 3));
+                s.setEmail(ExcelUtils.getContent(src, i, 4));
+                s.setFax(ExcelUtils.getContent(src, i, 5));
+                s.setBeginNeedGet(parseBigDecimalEx(ExcelUtils.getContent(src, i, 6)));
+                s.setTaxNum(ExcelUtils.getContent(src, i, 7));
+                s.setTaxRate(parseBigDecimalEx(ExcelUtils.getContent(src, i, 8)));
+                s.setBankName(ExcelUtils.getContent(src, i, 9));
+                s.setAccountNumber(ExcelUtils.getContent(src, i, 10));
+                s.setAddress(ExcelUtils.getContent(src, i, 11));
+                s.setDescription(ExcelUtils.getContent(src, i, 12));
+                s.setSort(ExcelUtils.getContent(src, i, 13));
+                s.setCreator(userInfo==null?null:userInfo.getId());
+                s.setEnabled("1".equals(enabled));
+                sList.add(s);
+            }
+        }
+        importExcel(sList, type, request);
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public void importMember(MultipartFile file, HttpServletRequest request) throws Exception{
+        String type = "会员";
+        User userInfo = userService.getCurrentUser();
+        Workbook workbook = Workbook.getWorkbook(file.getInputStream());
+        Sheet src = workbook.getSheet(0);
+        //'名称', '联系人', '手机号码', '联系电话', '电子邮箱', '备注', '排序', '状态'
+        List<Supplier> sList = new ArrayList<>();
+        for (int i = 2; i < src.getRows(); i++) {
+            String supplierName = ExcelUtils.getContent(src, i, 0);
+            String enabled = ExcelUtils.getContent(src, i, 7);
+            if(StringUtil.isNotEmpty(supplierName) && StringUtil.isNotEmpty(enabled)) {
+                Supplier s = new Supplier();
+                s.setType(type);
+                s.setSupplier(supplierName);
+                s.setContacts(ExcelUtils.getContent(src, i, 1));
+                s.setTelephone(ExcelUtils.getContent(src, i, 2));
+                s.setPhoneNum(ExcelUtils.getContent(src, i, 3));
+                s.setEmail(ExcelUtils.getContent(src, i, 4));
+                s.setDescription(ExcelUtils.getContent(src, i, 5));
+                s.setSort(ExcelUtils.getContent(src, i, 6));
+                s.setCreator(userInfo==null?null:userInfo.getId());
+                s.setEnabled("1".equals(enabled));
+                sList.add(s);
+            }
+        }
+        importExcel(sList, type, request);
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public BaseResponseInfo importExcel(List<Supplier> mList, String type, HttpServletRequest request) throws Exception {
+        logService.insertLog(type,
+                new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(),
+                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
+        BaseResponseInfo info = new BaseResponseInfo();
+        Map<String, Object> data = new HashMap<>();
+        try {
+            for(Supplier supplier: mList) {
+                SupplierExample example = new SupplierExample();
+                example.createCriteria().andSupplierEqualTo(supplier.getSupplier()).andTypeEqualTo(type).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+                List<Supplier> list= supplierMapper.selectByExample(example);
+                if(list.size() <= 0) {
+                    supplierMapper.insertSelective(supplier);
+                    //新增客户时给当前用户自动授权
+                    setUserCustomerPermission(request, supplier);
+                } else {
+                    Long id = list.get(0).getId();
+                    supplier.setId(id);
+                    supplierMapper.updateByPrimaryKeySelective(supplier);
+                }
+            }
+            info.code = 200;
+            data.put("message", "成功");
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            info.code = 500;
+            data.put("message", e.getMessage());
+        }
+        info.data = data;
+        return info;
+    }
+
+    @Override
+    public BigDecimal parseBigDecimalEx(String str)throws Exception{
+        if(!StringUtil.isEmpty(str)) {
+            return new BigDecimal(str);
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public File exportExcel(List<Supplier> dataList, String type) throws Exception {
+        if("供应商".equals(type)) {
+            return exportExcelVendorOrCustomer(dataList, type);
+        } else if("客户".equals(type)) {
+            return exportExcelVendorOrCustomer(dataList, type);
+        } else {
+            //会员
+            String[] names = {"会员卡号*", "联系人", "手机号码", "联系电话", "电子邮箱", "备注", "排序", "状态*"};
+            String title = "信息内容";
+            List<String[]> objects = new ArrayList<String[]>();
+            if (null != dataList) {
+                for (Supplier s : dataList) {
+                    String[] objs = new String[names.length];
+                    objs[0] = s.getSupplier();
+                    objs[1] = s.getContacts();
+                    objs[2] = s.getTelephone();
+                    objs[3] = s.getPhoneNum();
+                    objs[4] = s.getEmail();
+                    objs[5] = s.getDescription();
+                    objs[6] = s.getSort();
+                    objs[7] = s.getEnabled() ? "1" : "0";
+                    objects.add(objs);
+                }
+            }
+            return ExcelUtils.exportObjectsOneSheet(title, "*导入时本行内容请勿删除,切记!", names, title, objects);
+        }
+    }
+
+    @Override
+    public File exportExcelVendorOrCustomer(List<Supplier> dataList, String type) throws Exception {
+        /*String beginNeedStr = "";
+        if("供应商".equals(type)) {
+            beginNeedStr = "期初应付";
+        } else if("客户".equals(type)) {
+            beginNeedStr = "期初应收";
+        }*/
+        String[] names = {"名称*", "联系人", "手机号码", "联系电话", "电子邮箱",
+                "纳税人识别号", "发票类型","税率(%)", "开户行", "账号", "地址","供应商分级",
+                "结算方式", "账单周期", "采购对接人", "到货天数", "备注", "排序", "状态*"};
+        String title = "信息内容";
+        List<String[]> objects = new ArrayList<String[]>();
+        if (null != dataList) {
+            for (Supplier s : dataList) {
+                String[] objs = new String[names.length];
+                objs[0] = s.getSupplier();
+                objs[1] = s.getContacts();
+                objs[2] = s.getTelephone();
+                objs[3] = s.getPhoneNum();
+                objs[4] = s.getEmail();
+                /*if(("客户").equals(s.getType())) {
+                    objs[6] = s.getBeginNeedGet() == null? "" : s.getBeginNeedGet().setScale(2,BigDecimal.ROUND_HALF_UP).toString();
+                } else if(("供应商").equals(s.getType())) {
+                    objs[6] = s.getBeginNeedPay() == null? "" : s.getBeginNeedPay().setScale(2,BigDecimal.ROUND_HALF_UP).toString();
+                }*/
+                objs[5] = s.getTaxNum();
+                // 发票类型
+                objs[6] = mapInvoiceType(s.getInvoiceType());
+                // 税率
+                objs[7] = s.getTaxRate() == null? "" : s.getTaxRate().setScale(2,BigDecimal.ROUND_HALF_UP).toString();
+
+                // 银行信息
+                objs[8] = s.getBankName();
+                objs[9] = s.getAccountNumber();
+                objs[10] = s.getAddress();
+
+                // 供应商分级
+                objs[11] = s.getSupplierLevel();
+
+                // 结算方式
+                objs[12] = mapSettlementMethod(s.getSettlementMethod());
+                // 账单周期
+                objs[13] = s.getBillingCycleDays() == null? "" : s.getBillingCycleDays().toString();
+                // 采购对接人
+                objs[14] = s.getProcurementContact();
+                // 到货天数
+                objs[15] = s.getDeliverydays() == null? "" : s.getDeliverydays().toString();
+                objs[16] = s.getDescription();
+                objs[17] = s.getSort();
+                objs[18] = s.getEnabled() ? "1" : "0";
+                objects.add(objs);
+            }
+        }
+        return ExcelUtils.exportObjectsOneSheet(title, "*导入时本行内容请勿删除,切记!", names, title, objects);
+    }
+
+    @Override
+    public String mapInvoiceType(String invoiceType) {
+        if ("0".equals(invoiceType)) {
+            return "普通发票";
+        } else if ("1".equals(invoiceType)) {
+            return "增值税专用发票";
+        }
+        return "";
+    }
+
+    @Override
+    public String mapSettlementMethod(String settlementMethod) {
+        if ("0".equals(settlementMethod)) {
+            return "周结";
+        } else if ("1".equals(settlementMethod)) {
+            return "现结/按单";
+        } else if ("2".equals(settlementMethod)) {
+            return "预付款";
+        } else if ("3".equals(settlementMethod)) {
+            return "月结";
+        }
+        return "";
+    }
+
+    /**
+     * 新增客户时给当前用户自动授权
+     * @param request
+     * @param supplier
+     * @throws Exception
+     */
+    @Override
+    public void setUserCustomerPermission(HttpServletRequest request, Supplier supplier) throws Exception {
+        if("客户".equals(supplier.getType())) {
+            Long userId = userService.getUserId(request);
+            Supplier sInfo = supplierMapperEx.getSupplierByNameAndType(supplier.getSupplier(), supplier.getType());
+            String ubKey = "[" + sInfo.getId() + "]";
+            List<UserBusiness> ubList = userBusinessService.getBasicData(userId.toString(), "UserCustomer");
+            if(ubList ==null || ubList.size() == 0) {
+                JSONObject ubObj = new JSONObject();
+                ubObj.put("type", "UserCustomer");
+                ubObj.put("keyId", userId);
+                ubObj.put("value", ubKey);
+                UserBusiness userBusiness = JSONObject.parseObject(ubObj.toJSONString(), UserBusiness.class);
+                userBusinessMapper.insertSelective(userBusiness);
+            } else {
+                UserBusiness ubInfo = ubList.get(0);
+                JSONObject ubObj = new JSONObject();
+                ubObj.put("id", ubInfo.getId());
+                ubObj.put("type", ubInfo.getType());
+                ubObj.put("keyId", ubInfo.getKeyId());
+                ubObj.put("value", ubInfo.getValue() + ubKey);
+                UserBusiness userBusiness = JSONObject.parseObject(ubObj.toJSONString(), UserBusiness.class);
+                userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
+            }
+        }
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int batchSetAdvanceIn(String ids) throws Exception {
+        int res = 0;
+        List<Long> idList = StringUtil.strToLongList(ids);
+        for(Long sId: idList) {
+            updateAdvanceIn(sId);
+            res = 1;
+        }
+        return res;
+    }
+}

+ 28 - 0
src/main/resources/mapper_xml/DepotHeadMapper.xml

@@ -674,4 +674,32 @@
       delete_flag = #{deleteFlag,jdbcType=VARCHAR}
     where id = #{id,jdbcType=BIGINT}
   </update>
+
+  <select id="pdaList" parameterType="com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO" resultType="com.jsh.erp.datasource.pda.vo.PDADepotHeadVO">
+    SELECT
+      dh.id,
+      dh.number,
+      dh.create_time,
+      dh.goods_quantity,
+      dh.goods_type_count,
+      s.supplier AS supplier_name,
+      dh.status
+    FROM
+      jsh_depot_head dh
+        LEFT JOIN jsh_supplier s ON dh.organ_id = s.id
+    <where>
+      dh.sub_type = #{subType}
+      AND dh.delete_flag = '0'
+      <if test="number != null and number != ''">
+        AND dh.number = #{number}
+      </if>
+      <if test="status != null and status != ''">
+        AND dh.status = #{status}
+      </if>
+      <if test="beginTime != null and beginTime != ''">
+        AND dh.create_time between #{beginTime} and #{endTime}
+      </if>
+    </where>
+      GROUP BY dh.id
+  </select>
 </mapper>