package com.jsh.erp.service;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.utils.BaseResponseInfo;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public interface MaterialService {
    Material getMaterial(long id)throws Exception;

    List<Material> getMaterialListByIds(String ids)throws Exception;

    List<Material> getMaterial() throws Exception;

    List<MaterialVo4Unit> select(String materialParam, String standard, String model, String color, String brand, String mfrs,
                                 String materialOther, String weight, String expiryNum, String enableSerialNumber,
                                 String enableBatchNumber, String position, String enabled, String remark, String categoryId,
                                 String mpList)
            throws Exception;

    /**
     * 新增商品
     * @param obj
     */
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int insertMaterial(JSONObject obj, HttpServletRequest request)throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int updateMaterial(JSONObject obj, HttpServletRequest request) throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int deleteMaterial(Long id, HttpServletRequest request)throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int batchDeleteMaterial(String ids, HttpServletRequest request)throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int batchDeleteMaterialByIds(String ids) throws Exception;

    int checkIsNameExist(Long id, String name)throws Exception;

    int checkIsExist(Long id, String name, String model, String color, String standard, String mfrs,
                     String otherField1, String otherField2, String otherField3, String unit, Long unitId)throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int batchSetStatus(Boolean status, String ids)throws Exception;

    Unit findUnit(Long mId)throws Exception;

    List<MaterialVo4Unit> findById(Long id)throws Exception;

    List<MaterialVo4Unit> findByIdWithBarCode(Long meId)throws Exception;

    List<Long> getListByParentId(Long parentId);

    List<Long> getIdListByParentId(List<Long> idList, Long parentId);

    JSONArray getMaterialByParam(String materialParam);

    List<MaterialVo4Unit> findBySelectWithBarCode(Long categoryId, String q, String standardOrModel, String color,
                                                  String brand, String mfrs, String enableSerialNumber, String enableBatchNumber,
                                                  Integer offset, Integer rows, Long depotId) throws Exception;

    int findBySelectWithBarCodeCount(Long categoryId, String q, String standardOrModel, String color,
                                     String brand, String mfrs, String enableSerialNumber, String enableBatchNumber, Long depotId) throws Exception;

    void exportExcel(String categoryId, String materialParam, String color, String materialOther, String weight,
                     String expiryNum, String enabled, String enableSerialNumber, String enableBatchNumber,
                     String remark, HttpServletResponse response)throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    BaseResponseInfo importExcel(MultipartFile file, HttpServletRequest request) throws Exception;

    void batchCheckExistMaterialListByParam(List<MaterialWithInitStock> mList, String name, String standard,
                                            String model, String color, String unit, String sku);

    void batchCheckExistBarCodeByParam(List<MaterialWithInitStock> mList,
                                       String barCode, String manyBarCode) throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    void insertOrUpdateMaterialExtend(JSONObject materialExObj, String type, String defaultFlag, Long mId, User user) throws Exception;

    String getBasicBarCode(MaterialWithInitStock m);

    List<Material> getMaterialListByParam(String name, String standard, String model, String color, String unit, Long unitId, String basicBarCode) throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    void insertInitialStockByMaterialAndDepot(Long depotId, Long mId, BigDecimal stock, BigDecimal lowSafeStock, BigDecimal highSafeStock);

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    void insertCurrentStockByMaterialAndDepot(Long depotId, Long mId, BigDecimal stock);

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    void batchDeleteInitialStockByMaterialList(List<Long> mIdList);

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    void batchDeleteCurrentStockByMaterialList(List<Long> mIdList);

    List<MaterialVo4Unit> getMaterialEnableSerialNumberList(String q, Integer offset, Integer rows)throws Exception;

    Long getMaterialEnableSerialNumberCount(String q)throws Exception;

    BigDecimal parseBigDecimalEx(String str) throws Exception;

    BigDecimal parsePrice(String price, String ratio) throws Exception;

    BigDecimal getInitStockByMidAndDepotList(List<Long> depotList, Long materialId);

    BigDecimal getInitStock(Long materialId, Long depotId);

    BigDecimal getCurrentStockByMaterialIdAndDepotId(Long materialId, Long depotId);

    Map<Long,BigDecimal> getInitialStockMapByMaterialList(List<MaterialVo4Unit> list);

    Map<Long,BigDecimal> getCurrentStockMapByMaterialList(List<MaterialVo4Unit> list);

    MaterialInitialStock getSafeStock(Long materialId, Long depotId);

    List<MaterialVo4Unit> getMaterialByMeId(Long meId);

    String getMaxBarCode();

    List<String> getMaterialNameList();

    List<MaterialVo4Unit> getMaterialByBarCode(String barCode);

    List<MaterialVo4Unit> getMaterialByBarCodeAndWithOutMId(String barCode, Long mId);

    List<MaterialInitialStockWithMaterial> getInitialStockWithMaterial(List<Long> depotList);

    List<MaterialVo4Unit> getListWithStock(List<Long> depotList, List<Long> idList, String position, String materialParam,
                                           Boolean moveAvgPriceFlag, Integer zeroStock, String column, String order,
                                           Integer offset, Integer rows) throws Exception;

    int getListWithStockCount(List<Long> depotList, List<Long> idList, String position, String materialParam, Integer zeroStock);

    MaterialVo4Unit getTotalStockAndPrice(List<Long> depotList, List<Long> idList, String position, String materialParam);

    String getBigUnitStock(BigDecimal stock, Long unitId) throws Exception;

    String getMaterialOtherByParam(String[] mpArr, MaterialVo4Unit m);

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int batchSetMaterialCurrentStock(String ids) throws Exception;

    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    int batchSetMaterialCurrentUnitPrice(String ids) throws Exception;

    int batchUpdate(JSONObject jsonObject);

    MaterialExtend getMaterialExtendBySerialNumber(String serialNumber);

    List<MaterialVo4Unit> getMaterialByBatchNumber(String batchNumber);

    Material getMaterialById(Long id);

}
