Browse Source

bom求购

liusw 8 years ago
parent
commit
6c86c38ccd

+ 184 - 0
src/main/java/com/uas/platform/b2c/trade/seek/controller/SeekPurchaseBomController.java

@@ -0,0 +1,184 @@
+package com.uas.platform.b2c.trade.seek.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.uas.platform.b2c.common.account.model.User;
+import com.uas.platform.b2c.common.base.model.FileUpload;
+import com.uas.platform.b2c.core.support.SystemSession;
+import com.uas.platform.b2c.core.support.log.UsageBufferedLogger;
+import com.uas.platform.b2c.core.support.view.JxlsExcelView;
+import com.uas.platform.b2c.core.utils.FastjsonUtils;
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseBom;
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseBomList;
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseByBatch;
+import com.uas.platform.b2c.trade.seek.service.SeekPurchaseBomService;
+import com.uas.platform.b2c.trade.support.CodeType;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import com.uas.platform.core.logging.BufferedLoggerManager;
+import com.uas.platform.core.model.PageInfo;
+import com.uas.platform.core.model.PageParams;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.servlet.ModelAndView;
+
+/**
+ * @author liusw
+ * @version 2018/1/19 14:33
+ */
+@RestController
+@RequestMapping("/seek")
+public class SeekPurchaseBomController {
+    /**
+     * 求购业务api
+     */
+    @Autowired
+    private SeekPurchaseBomService seekPurchaseBomService;
+
+    /**
+     * 日志
+     */
+    private static final UsageBufferedLogger logger = BufferedLoggerManager
+            .getLogger(UsageBufferedLogger.class);
+
+
+    /**
+     * 导入bom
+     * @param uploadItem
+     * @return
+     */
+    @RequestMapping(value = "/importBom", method = RequestMethod.POST)
+    public ResultMap importBom(FileUpload uploadItem) {
+        String fileName = uploadItem.getFile().getOriginalFilename();
+        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
+        String bomName = fileName.substring(0, fileName.lastIndexOf("."));
+        InputStream is = null;
+        Workbook workbook = null;
+        try {
+            is = uploadItem.getFile().getInputStream();
+            if ("xls".equals(suffix)) {
+                workbook = new HSSFWorkbook(is);
+            } else if ("xlsx".equals(suffix)) {
+                workbook = new XSSFWorkbook(is);
+            } else {
+                return new ResultMap(CodeType.PARAMETER_ERROR, "文件格式不正确!请上传.xls或.xlsx格式的文件");
+            }
+            User user = SystemSession.getUser();
+            logger.log("求购", "导入新的bom求购,uu:" + user.getUserUU());
+            return seekPurchaseBomService.importBom(workbook, bomName, user);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 分页获取求购临时数据
+     * @param params
+     * @param bomId
+     * @return
+     */
+    @RequestMapping(value = "/getSeekPurchaseByBatchPageInfo", method = RequestMethod.GET)
+    public Page<SeekPurchaseByBatch> getSeekPurchaseByBatchPageInfo(PageParams params, Long bomId) {
+        PageInfo pageInfo = new PageInfo(params);
+        logger.log("求购", "分页获取求购临时数据,bomId:" + bomId);
+        return seekPurchaseBomService.getSeekPurchaseByBatchPageInfo(pageInfo, bomId);
+    }
+
+    /**
+     * 确认发布
+     * @return
+     */
+    @RequestMapping(value = "/confirmBom", method = RequestMethod.POST)
+    @ResponseBody
+    public ResultMap confirmBom(@RequestBody String json) {
+        JSONObject object = FastjsonUtils.parseObject(json);
+        logger.log("求购", "确认发布bom求购,bomId:" + object.get("bomId"));
+        return seekPurchaseBomService.confirmBom(Long.valueOf(object.get("bomId").toString()), object.get("spIds") == null ? null : object.get("spIds").toString());
+    }
+
+    /**
+     * 获取bom求购列表
+     * @param params
+     * @return
+     */
+    @RequestMapping(value = "/getSeekPurchaseBomListPage", method = RequestMethod.GET)
+    public Page<SeekPurchaseBomList> getSeekPurchaseBomListPage(PageParams params, String minReleaseDate, String maxReleaseDate, String name) {
+        User user = SystemSession.getUser();
+        PageInfo pageInfo = new PageInfo(params);
+        logger.log("求购", "获取bom求购列表,uu:" + user.getUserUU());
+        return seekPurchaseBomService.getSeekPurchaseBomListPage(pageInfo, user, minReleaseDate, maxReleaseDate, name);
+    }
+
+    /**
+     * 根据bomId获取当前bom单的情况
+     * @param bomId
+     * @return
+     */
+    @RequestMapping(value = "/getImportBomInfo", method = RequestMethod.GET)
+    public Map<String, Object> getImportBomInfo(Long bomId) {
+        return seekPurchaseBomService.getImportBomInfo(bomId);
+    }
+
+    /**
+     * 修改临时表数据
+     * @param seekPurchaseByBatch
+     * @return
+     */
+    @RequestMapping(value = "/updateSeekPurchaseByBatch", method = RequestMethod.PUT)
+    public ResultMap updateSeekPurchaseByBatch(@RequestBody SeekPurchaseByBatch seekPurchaseByBatch) {
+        return seekPurchaseBomService.updateSeekPurchaseByBatch(seekPurchaseByBatch);
+    }
+
+    /**
+     * 删除临时表数据
+     * @param json
+     * @return
+     */
+    @RequestMapping(value = "/deleteSeekPurchaseByBatch", method = RequestMethod.PUT)
+    public ResultMap deleteSeekPurchaseByBatch(@RequestBody String json) {
+        JSONObject object = FastjsonUtils.parseObject(json);
+        return seekPurchaseBomService.deleteSeekPurchaseByBatch(object.get("spIds").toString());
+    }
+
+    /**
+     * 获取单个bom的信息
+     * @param bomId
+     * @return
+     */
+    @RequestMapping(value = "/findOneBom", method = RequestMethod.GET)
+    public SeekPurchaseBomList findOneBom(Long bomId) {
+        return seekPurchaseBomService.findOneBom(bomId);
+    }
+
+    /**
+     * 修改bom信息
+     * @param seekPurchaseBom
+     * @return
+     */
+    @RequestMapping(value = "/updateSeekPurchaseBom", method = RequestMethod.PUT)
+    public ResultMap updateSeekPurchaseBom(@RequestBody SeekPurchaseBom seekPurchaseBom){
+        return seekPurchaseBomService.updateSeekPurchaseBom(seekPurchaseBom);
+    }
+
+    /**
+     * bom求购模板下载
+     * @return
+     */
+    @RequestMapping(value = "/release/template", method = RequestMethod.GET)
+    public ModelAndView exportSeekPurchaseByBatch() {
+        ModelAndView modelAndView = new ModelAndView();
+        modelAndView.setView(new JxlsExcelView("classpath:jxls-tpl/trade/seekPurchaseByBatch", "bom求购模板-优软商城"));
+        logger.log("求购", "下载bom求购的Excel模板");
+        return modelAndView;
+    }
+}

+ 0 - 134
src/main/java/com/uas/platform/b2c/trade/seek/controller/SeekPurchaseController.java

@@ -141,138 +141,4 @@ public class SeekPurchaseController {
         logger.log("求购", "获取商城现货,spId:" + spId);
         return seekPurchaseService.getMallGoodsList(spId);
     }
-
-    /**
-     * 导入bom
-     * @param uploadItem
-     * @return
-     */
-    @RequestMapping(value = "/importBom", method = RequestMethod.POST)
-    public ResultMap importBom(FileUpload uploadItem) {
-        String fileName = uploadItem.getFile().getOriginalFilename();
-        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
-        String bomName = fileName.substring(0, fileName.lastIndexOf("."));
-        InputStream is = null;
-        Workbook workbook = null;
-        try {
-            is = uploadItem.getFile().getInputStream();
-            if ("xls".equals(suffix)) {
-                workbook = new HSSFWorkbook(is);
-            } else if ("xlsx".equals(suffix)) {
-                workbook = new XSSFWorkbook(is);
-            } else {
-                return new ResultMap(CodeType.PARAMETER_ERROR, "文件格式不正确!请上传.xls或.xlsx格式的文件");
-            }
-            User user = SystemSession.getUser();
-            logger.log("求购", "导入新的bom求购,uu:" + user.getUserUU());
-            return seekPurchaseService.importBom(workbook, bomName, user);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    /**
-     * 分页获取求购临时数据
-     * @param params
-     * @param bomId
-     * @return
-     */
-    @RequestMapping(value = "/getSeekPurchaseByBatchPageInfo", method = RequestMethod.GET)
-    public Page<SeekPurchaseByBatch> getSeekPurchaseByBatchPageInfo(PageParams params, Long bomId) {
-        PageInfo pageInfo = new PageInfo(params);
-        logger.log("求购", "分页获取求购临时数据,bomId:" + bomId);
-        return seekPurchaseService.getSeekPurchaseByBatchPageInfo(pageInfo, bomId);
-    }
-
-    /**
-     * 确认发布
-     * @param bomId
-     * @param spIds
-     * @return
-     */
-    @RequestMapping(value = "/confirmBom", method = RequestMethod.POST)
-    @ResponseBody
-    public ResultMap confirmBom(@RequestBody String json) {
-        JSONObject object = FastjsonUtils.parseObject(json);
-        logger.log("求购", "确认发布bom求购,bomId:" + object.get("bomId"));
-        return seekPurchaseService.confirmBom(Long.valueOf(object.get("bomId").toString()), object.get("spIds") == null ? null : object.get("spIds").toString());
-    }
-
-    /**
-     * 获取bom求购列表
-     * @param params
-     * @return
-     */
-    @RequestMapping(value = "/getSeekPurchaseBomListPage", method = RequestMethod.GET)
-    public Page<SeekPurchaseBomList> getSeekPurchaseBomListPage(PageParams params, String minReleaseDate, String maxReleaseDate, String name) {
-        User user = SystemSession.getUser();
-        PageInfo pageInfo = new PageInfo(params);
-        logger.log("求购", "获取bom求购列表,uu:" + user.getUserUU());
-        return seekPurchaseService.getSeekPurchaseBomListPage(pageInfo, user, minReleaseDate, maxReleaseDate, name);
-    }
-
-    /**
-     * 根据bomId获取当前bom单的情况
-     * @param bomId
-     * @return
-     */
-    @RequestMapping(value = "/getImportBomInfo", method = RequestMethod.GET)
-    public Map<String, Object> getImportBomInfo(Long bomId) {
-        return seekPurchaseService.getImportBomInfo(bomId);
-    }
-
-    /**
-     * 修改临时表数据
-     * @param seekPurchaseByBatch
-     * @return
-     */
-    @RequestMapping(value = "/updateSeekPurchaseByBatch", method = RequestMethod.PUT)
-    public ResultMap updateSeekPurchaseByBatch(@RequestBody SeekPurchaseByBatch seekPurchaseByBatch) {
-        return seekPurchaseService.updateSeekPurchaseByBatch(seekPurchaseByBatch);
-    }
-
-    /**
-     * 删除临时表数据
-     * @param json
-     * @return
-     */
-    @RequestMapping(value = "/deleteSeekPurchaseByBatch", method = RequestMethod.PUT)
-    public ResultMap deleteSeekPurchaseByBatch(@RequestBody String json) {
-        JSONObject object = FastjsonUtils.parseObject(json);
-        return seekPurchaseService.deleteSeekPurchaseByBatch(object.get("spIds").toString());
-    }
-
-    /**
-     * 获取单个bom的信息
-     * @param bomId
-     * @return
-     */
-    @RequestMapping(value = "/findOneBom", method = RequestMethod.GET)
-    public SeekPurchaseBomList findOneBom(Long bomId) {
-        return seekPurchaseService.findOneBom(bomId);
-    }
-
-    /**
-     * 修改bom信息
-     * @param seekPurchaseBom
-     * @return
-     */
-    @RequestMapping(value = "/updateSeekPurchaseBom", method = RequestMethod.PUT)
-    public ResultMap updateSeekPurchaseBom(@RequestBody SeekPurchaseBom seekPurchaseBom){
-        return seekPurchaseService.updateSeekPurchaseBom(seekPurchaseBom);
-    }
-
-    /**
-     * bom求购模板下载
-     * @param currency
-     * @return
-     */
-    @RequestMapping(value = "/release/template", method = RequestMethod.GET)
-    public ModelAndView exportSeekPurchaseByBatch() {
-        ModelAndView modelAndView = new ModelAndView();
-        modelAndView.setView(new JxlsExcelView("classpath:jxls-tpl/trade/seekPurchaseByBatch", "bom求购模板-优软商城"));
-        logger.log("求购", "下载bom求购的Excel模板");
-        return modelAndView;
-    }
 }

+ 86 - 0
src/main/java/com/uas/platform/b2c/trade/seek/service/SeekPurchaseBomService.java

@@ -0,0 +1,86 @@
+package com.uas.platform.b2c.trade.seek.service;
+
+import com.uas.platform.b2c.common.account.model.User;
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseBom;
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseBomList;
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseByBatch;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import com.uas.platform.core.model.PageInfo;
+import java.util.Map;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.springframework.data.domain.Page;
+
+/**
+ * @author liusw
+ * @version 2018/1/19 14:54
+ */
+public interface SeekPurchaseBomService {
+    /**
+     * 导入bom
+     * @param workbook
+     * @param bomName
+     * @param user
+     * @return
+     */
+    ResultMap importBom(Workbook workbook, String bomName, User user);
+
+    /**
+     * 根据bomId分页获取求购临时数据
+     * @param pageInfo
+     * @param bomId
+     * @return
+     */
+    Page<SeekPurchaseByBatch> getSeekPurchaseByBatchPageInfo(PageInfo pageInfo, Long bomId);
+
+    /**
+     * 确认发布
+     *
+     * @param bomId
+     * @param spIds
+     * @return
+     */
+    ResultMap confirmBom(Long bomId, String spIds);
+
+    /**
+     * 分页获取bom求购列表
+     * @param pageInfo
+     * @param user
+     * @return
+     */
+    Page<SeekPurchaseBomList> getSeekPurchaseBomListPage(PageInfo pageInfo, User user, String minReleaseDate, String maxReleaseDate, String name);
+
+    /**
+     * 根据bomId获取当前bom单的情况
+     * @param bomId
+     * @return
+     */
+    Map<String, Object> getImportBomInfo(Long bomId);
+
+    /**
+     * 修改临时表数据
+     * @param seekPurchaseByBatch
+     * @return
+     */
+    ResultMap updateSeekPurchaseByBatch(SeekPurchaseByBatch seekPurchaseByBatch);
+
+    /**
+     * 删除临时表数据
+     * @param spIds
+     * @return
+     */
+    ResultMap deleteSeekPurchaseByBatch(String spIds);
+
+    /**
+     * 修改Bom信息
+     * @param seekPurchaseBom
+     * @return
+     */
+    ResultMap updateSeekPurchaseBom(SeekPurchaseBom seekPurchaseBom);
+
+    /**
+     * 获取单个bom信息
+     * @param bomId
+     * @return
+     */
+    SeekPurchaseBomList findOneBom(Long bomId);
+}

+ 0 - 68
src/main/java/com/uas/platform/b2c/trade/seek/service/SeekPurchaseService.java

@@ -83,72 +83,4 @@ public interface SeekPurchaseService {
      * @return     */
     SeekPurchase confirmSeekPurchase(Long spId, Double purchaseQuantity);
 
-    /**
-     * 导入bom
-     * @param workbook
-     * @param bomName
-     * @param user
-     * @return
-     */
-    ResultMap importBom(Workbook workbook, String bomName, User user);
-
-    /**
-     * 根据bomId分页获取求购临时数据
-     * @param pageInfo
-     * @param bomId
-     * @return
-     */
-    Page<SeekPurchaseByBatch> getSeekPurchaseByBatchPageInfo(PageInfo pageInfo, Long bomId);
-
-    /**
-     * 确认发布
-     *
-     * @param bomId
-     * @param spIds
-     * @return
-     */
-    ResultMap confirmBom(Long bomId, String spIds);
-
-    /**
-     * 分页获取bom求购列表
-     * @param pageInfo
-     * @param user
-     * @return
-     */
-    Page<SeekPurchaseBomList> getSeekPurchaseBomListPage(PageInfo pageInfo, User user, String minReleaseDate, String maxReleaseDate, String name);
-
-    /**
-     * 根据bomId获取当前bom单的情况
-     * @param bomId
-     * @return
-     */
-    Map<String, Object> getImportBomInfo(Long bomId);
-
-    /**
-     * 修改临时表数据
-     * @param seekPurchaseByBatch
-     * @return
-     */
-    ResultMap updateSeekPurchaseByBatch(SeekPurchaseByBatch seekPurchaseByBatch);
-
-    /**
-     * 删除临时表数据
-     * @param spIds
-     * @return
-     */
-    ResultMap deleteSeekPurchaseByBatch(String spIds);
-
-    /**
-     * 修改Bom信息
-     * @param seekPurchaseBom
-     * @return
-     */
-    ResultMap updateSeekPurchaseBom(SeekPurchaseBom seekPurchaseBom);
-
-    /**
-     * 获取单个bom信息
-     * @param bomId
-     * @return
-     */
-    SeekPurchaseBomList findOneBom(Long bomId);
 }

+ 511 - 0
src/main/java/com/uas/platform/b2c/trade/seek/service/impl/SeekPurchaseBomServiceImpl.java

@@ -0,0 +1,511 @@
+package com.uas.platform.b2c.trade.seek.service.impl;
+
+import com.uas.platform.b2c.common.account.model.User;
+import com.uas.platform.b2c.common.search.service.SearcherService;
+import com.uas.platform.b2c.core.utils.StringUtilB2C;
+import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
+import com.uas.platform.b2c.prod.commodity.model.Goods;
+import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
+import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseBomDao;
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseBomListDao;
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseByBatchDao;
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseDao;
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseGoodsDao;
+import com.uas.platform.b2c.trade.seek.dao.SeekPurchaseOfferDao;
+import com.uas.platform.b2c.trade.seek.model.SeekPurchase;
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseBom;
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseBomList;
+import com.uas.platform.b2c.trade.seek.model.SeekPurchaseByBatch;
+import com.uas.platform.b2c.trade.seek.service.SeekPurchaseBomService;
+import com.uas.platform.b2c.trade.seek.status.Status;
+import com.uas.platform.b2c.trade.seek.utils.DateUtils;
+import com.uas.platform.b2c.trade.support.CodeType;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import com.uas.platform.core.exception.IllegalOperatorException;
+import com.uas.platform.core.model.PageInfo;
+import com.uas.platform.core.persistence.criteria.PredicateUtils;
+import java.math.BigDecimal;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataAccessException;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.Sort.Direction;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+/**
+ * @author liusw
+ * @version 2018/1/19 15:06
+ */
+@Service
+public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService{
+
+    @Autowired
+    private SeekPurchaseDao seekPurchasedao;
+
+    @Autowired
+    private BrandDao brandDao;
+
+    @Autowired
+    private ComponentDao componentDao;
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    @Autowired
+    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
+
+    @Autowired
+    private GoodsDao goodsDao;
+
+    @Autowired
+    private SeekPurchaseOfferDao seekPurchaseOfferDao;
+
+    @Autowired
+    private SeekPurchaseGoodsDao seekPurchaseGoodsDao;
+
+    @Autowired
+    private SeekPurchaseBomDao seekPurchaseBomDao;
+
+    @Autowired
+    private SeekPurchaseByBatchDao seekPurchaseByBatchDao;
+
+    @Autowired
+    private SeekPurchaseBomListDao seekPurchaseBomListDao;
+
+    @Autowired
+    private SearcherService searcherService;
+
+    private static Long deadlineTime = Long.valueOf(90 * 24 * 60 * 60 * 1000);
+
+    /**
+     * 导入bom
+     * @param workbook
+     * @param bomName
+     * @param user
+     * @return
+     */
+    @Override
+    public ResultMap importBom(Workbook workbook, String bomName, User user) {
+        // 获取第一个工作表
+        Sheet sheet = workbook.getSheetAt(0);
+        int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
+        if (colNum != 8) {
+            return new ResultMap(CodeType.PARAMETER_ERROR, "表格模板不正确!请重新下载最新模板");
+        }
+        int rowNum = sheet.getLastRowNum();
+        if (rowNum > 500) {
+            return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息超过500条,请拆分成2000以再在上传");
+        }
+        // 插入Bom求购中
+        SeekPurchaseBom seekPurchaseBom = new SeekPurchaseBom();
+        seekPurchaseBom.setReleaseDate(new Date(System.currentTimeMillis()));
+        seekPurchaseBom.setEnuu(user.getEnterprise().getUu());
+        seekPurchaseBom.setUu(user.getUserUU());
+        seekPurchaseBom.setName(bomName);
+        seekPurchaseBom.setStatus(0);
+        seekPurchaseBom = seekPurchaseBomDao.save(seekPurchaseBom);
+        // 获取第一行的信息
+        Row headerRow = sheet.getRow(0);
+        int total = 0;
+        int blankNum = 0;
+        if (headerRow != null) {
+            // 验证是否为商城模板
+            if (!vaildTemplete(headerRow)) {
+                return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息列信息不正确,请与模板的列做比较");
+            }
+            List<SeekPurchaseByBatch> seekPurchaseByBatchList = new ArrayList<>();
+            for (int r = 3; r <= rowNum; r++) {
+                Row row = sheet.getRow(r);
+                if (row != null) {
+                    SeekPurchaseByBatch seekPurchaseByBatch = new SeekPurchaseByBatch();
+                    blankNum = convertValueToSeekPurchaseByBatch(row, seekPurchaseByBatch, r);
+                    seekPurchaseByBatch.setBomId(seekPurchaseBom.getId());
+                    seekPurchaseByBatch.setReleaseDate(new Date(System.currentTimeMillis()));
+                    seekPurchaseByBatchList.add(seekPurchaseByBatch);
+                }
+            }
+            seekPurchaseByBatchDao.save(seekPurchaseByBatchList);
+        }
+        return ResultMap.success(seekPurchaseBom.getId());
+    }
+
+    /**
+     * 验证是否为商城模板
+     * @param headerRow
+     * @return
+     */
+    private boolean vaildTemplete(Row headerRow){
+        Object codeCellObj = readWorkBookCell(headerRow.getCell(0), Cell.CELL_TYPE_STRING,
+                0, 0);
+        if (!"产品型号".equals(StringUtilB2C.getStr(codeCellObj))) {
+            return false;
+        }
+        Object brandCellObj = readWorkBookCell(headerRow.getCell(1), Cell.CELL_TYPE_STRING,
+                0, 1);
+        if (!"品牌名称".equals(StringUtilB2C.getStr(brandCellObj))) {
+            return false;
+        }
+        Object deadlineCellObj = readWorkBookCell(headerRow.getCell(2), Cell.CELL_TYPE_STRING,
+                0, 2);
+        if (!"截止时间".equals(StringUtilB2C.getStr(deadlineCellObj))) {
+            return false;
+        }
+        Object produceDateCellObj = readWorkBookCell(headerRow.getCell(7), Cell.CELL_TYPE_STRING,
+                0, 7);
+        if (!"生产日期".equals(StringUtilB2C.getStr(produceDateCellObj))) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * 将列信息注入到求购临时实体中
+     * @param row
+     * @param seekPurchaseByBatch
+     * @param rowNum
+     * @return
+     */
+    private int convertValueToSeekPurchaseByBatch(Row row, SeekPurchaseByBatch seekPurchaseByBatch, int rowNum) {
+        // 统计为空的个数
+        int result = 0;
+        // 型号
+        Object codeValue = readWorkBookCell(row.getCell(0), Cell.CELL_TYPE_STRING,
+                rowNum, 0);
+        if (StringUtils.isEmpty(codeValue)) {
+            result += 1;
+        } else {
+            seekPurchaseByBatch.setCode(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(codeValue)));
+        }
+
+        // 品牌
+        Object brandValue = readWorkBookCell(row.getCell(1), Cell.CELL_TYPE_STRING,
+                rowNum, 1);
+        if (StringUtils.isEmpty(brandValue)) {
+            result += 1;
+        } else {
+            seekPurchaseByBatch.setBrand(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(brandValue)));
+        }
+
+        // 截止日期
+        Object deadlineValue = readWorkBookCell(row.getCell(2), Cell.CELL_TYPE_STRING,
+                rowNum, 2);
+        if (StringUtils.isEmpty(deadlineValue)) {
+            result += 1;
+        } else {
+            String deadline = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(deadlineValue));
+            try {
+                deadline = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(deadline, 10);
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                Date deadlineDate = sdf.parse(deadline);
+                if (deadlineDate.getTime() < System.currentTimeMillis()) {
+                    seekPurchaseByBatch.setDeadline(DateUtils.addTime(new Date(), 1, 23, 59,59));
+                } else {
+                    seekPurchaseByBatch.setDeadline(DateUtils.addTime(deadlineDate));
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                seekPurchaseByBatch.setDeadline(DateUtils.addTime(new Date(System.currentTimeMillis())));
+            }
+        }
+
+        // 求购数量
+        Object amountValue = readWorkBookCell(row.getCell(3), Cell.CELL_TYPE_STRING,
+                rowNum, 3);
+        if (!StringUtils.isEmpty(amountValue)) {
+            try {
+                Integer amount = Integer.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(amountValue)));
+                seekPurchaseByBatch.setAmount(amount);
+            } catch (NumberFormatException e) {
+                seekPurchaseByBatch.setAmount(null);
+            }
+        }
+
+        // 币别
+        Object currencyValue = readWorkBookCell(row.getCell(4), Cell.CELL_TYPE_STRING,
+                rowNum, 4);
+        if (!StringUtils.isEmpty(currencyValue)) {
+            try {
+                String currency = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(currencyValue));
+                seekPurchaseByBatch.setCurrency(currency);
+            } catch (Exception e) {
+                seekPurchaseByBatch.setCurrency("RMB");
+            }
+        }
+
+        // 单价
+        Object unitPriceValue = readWorkBookCell(row.getCell(5), Cell.CELL_TYPE_STRING,
+                rowNum, 5);
+        if (!StringUtils.isEmpty(unitPriceValue)) {
+            try {
+                Double unitPrice = Double.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(unitPriceValue)));
+                seekPurchaseByBatch.setUnitPrice(unitPrice);
+            } catch (NumberFormatException e) {
+                seekPurchaseByBatch.setUnitPrice(null);
+            }
+        }
+        // 如果填了单价又不选币种,导入的时候系统就默认人民币吧
+        if (!StringUtils.isEmpty(unitPriceValue) && StringUtils.isEmpty(currencyValue)) {
+            seekPurchaseByBatch.setCurrency("RMB");
+        }
+
+        // 封装
+        Object encapsulationValue = readWorkBookCell(row.getCell(6), Cell.CELL_TYPE_STRING,
+                rowNum, 6);
+        if (!StringUtils.isEmpty(encapsulationValue)) {
+            try {
+                String encapsulation = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(encapsulationValue));
+                seekPurchaseByBatch.setEncapsulation(encapsulation);
+            } catch (Exception e) {
+                seekPurchaseByBatch.setEncapsulation(null);
+            }
+        }
+
+
+        // 生产日期
+        Object produceDateValue = readWorkBookCell(row.getCell(7), Cell.CELL_TYPE_STRING,
+                rowNum, 7);
+        if (!StringUtils.isEmpty(produceDateValue)) {
+            try {
+                String produceDate = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(produceDateValue));
+                seekPurchaseByBatch.setProduceDate(produceDate);
+            } catch (Exception e) {
+                seekPurchaseByBatch.setProduceDate(null);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 读取excel
+     * @param cell
+     * @param cellType
+     * @param r
+     * @param n
+     * @return
+     */
+    private Object readWorkBookCell(Cell cell, int cellType, int r, int n) {
+        Object obj = null;
+        try {
+            if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
+                switch (cellType) {
+                    case Cell.CELL_TYPE_STRING :
+                        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
+                        String str = cell.getStringCellValue().trim();
+                        if (str.indexOf("\u00A0") > 0) {
+                            str= str.replaceAll("\u00A0", "");
+                        }
+                        str = StringUtilB2C.replaceTabAndLineBreak(str);
+                        obj = str.trim();
+                        break;
+                    case Cell.CELL_TYPE_NUMERIC :
+                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+                        obj = cell.getNumericCellValue();
+                        if (obj != null) {
+                            if (obj.toString().indexOf("E") > 0) {
+                                BigDecimal b = new BigDecimal(obj.toString());
+                                obj = b.toPlainString();
+                            }
+                        }
+                        break;
+                    default :
+                        if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
+                            String productTime = cell.getStringCellValue();
+                            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
+                            Matcher m = p.matcher(productTime);
+                            String time = m.replaceAll("");
+                            if (time.indexOf("\u00A0") > 0){
+                                time= time.replaceAll("\u00A0", "");
+                            }
+                            DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd");
+                            obj = format1.parse(time);
+                        } else if (HSSFDateUtil.isCellDateFormatted(cell)) {
+                            obj = cell.getDateCellValue();
+                        }
+                        break;
+                }
+            }
+        } catch (Exception e) {
+            throw new IllegalOperatorException("读取表格中" + r + "行" + (n + 1) + "列的内容错误,有可能是该单元格的格式不正确");
+        }
+        return obj;
+    }
+
+    @Override
+    public Page<SeekPurchaseByBatch> getSeekPurchaseByBatchPageInfo(final PageInfo pageInfo, Long bomId) {
+        if (bomId != null) {
+            pageInfo.filter("bomId", bomId);
+        }
+        Page<SeekPurchaseByBatch> pageSeeks = seekPurchaseByBatchDao.findAll(new Specification<SeekPurchaseByBatch>() {
+            public Predicate toPredicate(Root<SeekPurchaseByBatch> root, CriteriaQuery<?> query,
+                    CriteriaBuilder builder) {
+                query.where(pageInfo.getPredicates(root, query, builder));
+                return null;
+            }
+        }, pageInfo);
+        List<SeekPurchaseByBatch> seekPurchaseByBatchList = pageSeeks.getContent();
+        for (int i = 0;i < seekPurchaseByBatchList.size(); i++) {
+            if (!StringUtils.isEmpty(seekPurchaseByBatchList.get(i).getCode()) && !StringUtils.isEmpty(seekPurchaseByBatchList.get(i).getBrand())) {
+                List<Map<String, Object>> codeWord = searcherService.getSimilarComponents(seekPurchaseByBatchList.get(i).getCode());
+                if (codeWord != null && codeWord.size() > 0) {
+                    seekPurchaseByBatchList.get(i).setCodeWord(codeWord);
+                }
+                List<Map<String, Object>> brandWord = searcherService.getSimilarComponents(seekPurchaseByBatchList.get(i).getBrand());
+                if (codeWord != null && codeWord.size() > 0) {
+                    seekPurchaseByBatchList.get(i).setBrandWord(brandWord);
+                }
+            }
+        }
+        return new PageImpl<SeekPurchaseByBatch>(seekPurchaseByBatchList, pageInfo, pageSeeks.getTotalElements());
+    }
+
+    @Override
+    public ResultMap confirmBom(Long bomId, String spIds) {
+        SeekPurchaseBom seekPurchaseBom = seekPurchaseBomDao.findOne(bomId);
+        List<SeekPurchaseByBatch> seekPurchaseByBatchList = null;
+        if (!StringUtils.isEmpty(spIds)) {
+            // 保存选中
+            seekPurchaseByBatchList = seekPurchaseByBatchDao.findBySpids(Arrays.asList(spIds.split(",")));
+        } else {
+            // 保存所有
+            seekPurchaseByBatchList = seekPurchaseByBatchDao.findByBomId(bomId);
+        }
+        // 商城现货的数量
+        int haveGoodsCount = 0;
+        // 将临时表转换成正式表数据
+        List<SeekPurchase> seekPurchaseList = new ArrayList<>();
+        // 发布到正式表的临时数据
+        List<SeekPurchaseByBatch> deleteBatchList = new ArrayList<>();
+        for (SeekPurchaseByBatch batch : seekPurchaseByBatchList) {
+            SeekPurchase seekPurchase = new SeekPurchase();
+            if (!StringUtils.isEmpty(batch.getCode()) && !StringUtils.isEmpty(batch.getBrand()) && !StringUtils.isEmpty(batch.getDeadline()) && batch.getDeadline().compareTo(DateUtils.addTime(new Date(), 90, 23, 59 ,59))!= 1) {
+                //seekPurchase = (SeekPurchase) batch;
+                seekPurchase.setDeadline(batch.getDeadline());
+                seekPurchase.setCurrency(batch.getCurrency());
+                seekPurchase.setReleaseDate(batch.getReleaseDate());
+                seekPurchase.setCode(batch.getCode());
+                seekPurchase.setBrand(batch.getBrand());
+                seekPurchase.setAmount(batch.getAmount());
+                seekPurchase.setEncapsulation(batch.getEncapsulation());
+                seekPurchase.setUnitPrice(batch.getUnitPrice());
+                seekPurchase.setProduceDate(batch.getProduceDate());
+                seekPurchase.setBomId(batch.getBomId());
+                seekPurchase.setEnUu(seekPurchaseBom.getEnuu());
+                seekPurchase.setUu(seekPurchaseBom.getUu());
+                seekPurchase.setStatus(Status.NO_OFFER.getValue());
+                // 商城现货搜索
+                List<Goods> goods = goodsDao.getGoodsByCodeAndName(seekPurchase.getCode(), seekPurchase.getBrand());
+                if (goods != null && goods.size() > 0) {
+                    haveGoodsCount++;
+                }
+                deleteBatchList.add(batch);
+                seekPurchaseList.add(seekPurchase);
+            }
+        }
+        seekPurchaseList = seekPurchasedao.save(seekPurchaseList);
+        seekPurchaseBom.setAmount((seekPurchaseBom.getAmount() == null ? 0 : seekPurchaseBom.getAmount()) + seekPurchaseList.size());
+        seekPurchaseBom.setStatus(1);
+        seekPurchaseBomDao.save(seekPurchaseBom);
+        seekPurchaseByBatchDao.delete(deleteBatchList);
+        return ResultMap.success(haveGoodsCount);
+    }
+
+    @Override
+    public Page<SeekPurchaseBomList> getSeekPurchaseBomListPage(final PageInfo pageInfo, User user, String minReleaseDate, String maxReleaseDate, String name) {
+        if (user.getEnterprise() != null) {
+            pageInfo.filter("enUu", user.getEnterprise().getUu());
+        } else {
+            pageInfo.filter("uu", user.getUserUU());
+        }
+        // 发布时间
+        if (!StringUtils.isEmpty(minReleaseDate)) {
+            pageInfo.expression(
+                    PredicateUtils.gte("releaseDate", new Date(Long.valueOf(minReleaseDate)), false));
+        }
+        if (!StringUtils.isEmpty(maxReleaseDate)) {
+            pageInfo.expression(PredicateUtils.lte("releaseDate", new Date(Long.valueOf(maxReleaseDate)), false));
+        }
+        // Bom名称
+        if (!StringUtils.isEmpty(name)) {
+            pageInfo.filter("name", name);
+        }
+        pageInfo.sorting("releaseDate", Direction.DESC);
+        Page<SeekPurchaseBomList> pageSeeks = seekPurchaseBomListDao.findAll(new Specification<SeekPurchaseBomList>() {
+            public Predicate toPredicate(Root<SeekPurchaseBomList> root, CriteriaQuery<?> query,
+                    CriteriaBuilder builder) {
+                query.where(pageInfo.getPredicates(root, query, builder));
+                return null;
+            }
+        }, pageInfo);
+        return pageSeeks;
+    }
+
+    @Override
+    public Map<String, Object> getImportBomInfo(Long bomId) {
+        String sql = "select bom_id,count(bom_id) as successImport,(sum((IF(sp_brand is null,1,0)))+sum((IF(sp_code is null,1,0)))+sum((IF(sp_deadline is null,1,0)))) as nullField "
+                + "from trade$seek_purchase_by_batch where bom_id = ? group by bom_id";
+        try {
+            Map<String, Object> map = jdbcTemplate.queryForMap(sql, new Object[]{bomId});
+            return map;
+        } catch (DataAccessException e) {
+            return null;
+        }
+    }
+
+    @Override
+    public ResultMap updateSeekPurchaseByBatch(SeekPurchaseByBatch seekPurchaseByBatch) {
+        seekPurchaseByBatchDao.save(seekPurchaseByBatch);
+        return ResultMap.success(null);
+    }
+
+    @Override
+    public ResultMap deleteSeekPurchaseByBatch(String spIds) {
+        String sql = "delete from trade$seek_purchase_by_batch where sp_id in (:spIds)";
+        Map<String, Object> param = new HashMap<>();
+        param.put("spIds", spIds.contains(",") ? Arrays.asList(spIds.split(",")) : spIds);
+        namedParameterJdbcTemplate.update(sql, param);
+        return ResultMap.success(null);
+    }
+
+    @Override
+    public ResultMap updateSeekPurchaseBom(SeekPurchaseBom seekPurchaseBom) {
+        SeekPurchaseBom oldBom = seekPurchaseBomDao.findOne(seekPurchaseBom.getId());
+        String name = seekPurchaseBom.getName();
+        if (StringUtils.isEmpty(name)) {
+            throw new IllegalOperatorException("bom名称不符合要求");
+        }
+        oldBom.setName(seekPurchaseBom.getName());
+        seekPurchaseBomDao.save(oldBom);
+        return ResultMap.success(null);
+    }
+
+    @Override
+    public SeekPurchaseBomList findOneBom(Long bomId) {
+        return seekPurchaseBomListDao.findOne(bomId);
+    }
+
+}

+ 0 - 376
src/main/java/com/uas/platform/b2c/trade/seek/service/impl/SeekPurchaseServiceImpl.java

@@ -54,9 +54,7 @@ import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.DataAccessException;
 import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.Sort.Direction;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -312,378 +310,4 @@ public class SeekPurchaseServiceImpl implements SeekPurchaseService {
         return seekPurchasedao.save(seekPurchase);
     }
 
-    @Override
-    public ResultMap importBom(Workbook workbook, String bomName, User user) {
-        // 获取第一个工作表
-        Sheet sheet = workbook.getSheetAt(0);
-        int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
-        if (colNum != 8) {
-            return new ResultMap(CodeType.PARAMETER_ERROR, "表格模板不正确!请重新下载最新模板");
-        }
-        int rowNum = sheet.getLastRowNum();
-        if (rowNum > 500) {
-            return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息超过500条,请拆分成2000以再在上传");
-        }
-        // 插入Bom求购中
-        SeekPurchaseBom seekPurchaseBom = new SeekPurchaseBom();
-        seekPurchaseBom.setReleaseDate(new Date(System.currentTimeMillis()));
-        seekPurchaseBom.setEnuu(user.getEnterprise().getUu());
-        seekPurchaseBom.setUu(user.getUserUU());
-        seekPurchaseBom.setName(bomName);
-        seekPurchaseBom.setStatus(0);
-        seekPurchaseBom = seekPurchaseBomDao.save(seekPurchaseBom);
-        // 获取第一行的信息
-        Row headerRow = sheet.getRow(0);
-        int total = 0;
-        int blankNum = 0;
-        if (headerRow != null) {
-            // 验证是否为商城模板
-            Object codeCellObj = readWorkBookCell(headerRow.getCell(0), Cell.CELL_TYPE_STRING,
-                    0, 0);
-            if (!"产品型号".equals(StringUtilB2C.getStr(codeCellObj))) {
-                return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息列信息不正确,请与模板的列做比较");
-            }
-            Object brandCellObj = readWorkBookCell(headerRow.getCell(1), Cell.CELL_TYPE_STRING,
-                    0, 1);
-            if (!"品牌名称".equals(StringUtilB2C.getStr(brandCellObj))) {
-                return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息列信息不正确,请与模板的列做比较");
-            }
-            Object deadlineCellObj = readWorkBookCell(headerRow.getCell(2), Cell.CELL_TYPE_STRING,
-                    0, 2);
-            if (!"截止时间".equals(StringUtilB2C.getStr(deadlineCellObj))) {
-                return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息列信息不正确,请与模板的列做比较");
-            }
-            Object produceDateCellObj = readWorkBookCell(headerRow.getCell(7), Cell.CELL_TYPE_STRING,
-                    0, 7);
-            if (!"生产日期".equals(StringUtilB2C.getStr(produceDateCellObj))) {
-                return new ResultMap(CodeType.PARAMETER_ERROR, "您上传的信息列信息不正确,请与模板的列做比较");
-            }
-            List<SeekPurchaseByBatch> seekPurchaseByBatchList = new ArrayList<>();
-            for (int r = 3; r <= rowNum; r++) {
-                Row row = sheet.getRow(r);
-                if (row != null) {
-                    SeekPurchaseByBatch seekPurchaseByBatch = new SeekPurchaseByBatch();
-                    blankNum = convertValueToSeekPurchaseByBatch(row, seekPurchaseByBatch, r);
-                    seekPurchaseByBatch.setBomId(seekPurchaseBom.getId());
-                    seekPurchaseByBatch.setReleaseDate(new Date(System.currentTimeMillis()));
-
-                    seekPurchaseByBatchList.add(seekPurchaseByBatch);
-                }
-            }
-            seekPurchaseByBatchDao.save(seekPurchaseByBatchList);
-        }
-        return ResultMap.success(seekPurchaseBom.getId());
-    }
-
-    /**
-     * 将列信息注入到求购临时实体中
-     * @param row
-     * @param seekPurchaseByBatch
-     * @param rowNum
-     * @return
-     */
-    private int convertValueToSeekPurchaseByBatch(Row row, SeekPurchaseByBatch seekPurchaseByBatch, int rowNum) {
-        // 统计为空的个数
-        int result = 0;
-        // 型号
-        Object codeValue = readWorkBookCell(row.getCell(0), Cell.CELL_TYPE_STRING,
-                rowNum, 0);
-        if (StringUtils.isEmpty(codeValue)) {
-            result += 1;
-        } else {
-            seekPurchaseByBatch.setCode(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(codeValue)));
-        }
-
-        // 品牌
-        Object brandValue = readWorkBookCell(row.getCell(1), Cell.CELL_TYPE_STRING,
-                rowNum, 1);
-        if (StringUtils.isEmpty(brandValue)) {
-            result += 1;
-        } else {
-            seekPurchaseByBatch.setBrand(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(brandValue)));
-        }
-
-        // 截止日期
-        Object deadlineValue = readWorkBookCell(row.getCell(2), Cell.CELL_TYPE_STRING,
-                rowNum, 2);
-        if (StringUtils.isEmpty(deadlineValue)) {
-            result += 1;
-        } else {
-            String deadline = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(deadlineValue));
-            try {
-                deadline = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(deadline, 10);
-                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-                Date deadlineDate = sdf.parse(deadline);
-                seekPurchaseByBatch.setDeadline(addTime(deadlineDate));
-            } catch (Exception e) {
-                e.printStackTrace();
-                seekPurchaseByBatch.setDeadline(addTime(new Date(System.currentTimeMillis())));
-            }
-        }
-
-        // 求购数量
-        Object amountValue = readWorkBookCell(row.getCell(3), Cell.CELL_TYPE_STRING,
-                rowNum, 3);
-        if (!StringUtils.isEmpty(amountValue)) {
-            try {
-                Integer amount = Integer.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(amountValue)));
-                seekPurchaseByBatch.setAmount(amount);
-            } catch (NumberFormatException e) {
-                seekPurchaseByBatch.setAmount(null);
-            }
-        }
-
-        // 币别
-        Object currencyValue = readWorkBookCell(row.getCell(4), Cell.CELL_TYPE_STRING,
-                rowNum, 4);
-        if (!StringUtils.isEmpty(currencyValue)) {
-            try {
-                String currency = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(currencyValue));
-                seekPurchaseByBatch.setCurrency(currency);
-            } catch (Exception e) {
-                seekPurchaseByBatch.setCurrency("RMB");
-            }
-        }
-
-        // 单价
-        Object unitPriceValue = readWorkBookCell(row.getCell(5), Cell.CELL_TYPE_STRING,
-                rowNum, 5);
-        if (!StringUtils.isEmpty(unitPriceValue)) {
-            try {
-                Double unitPrice = Double.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(unitPriceValue)));
-                seekPurchaseByBatch.setUnitPrice(unitPrice);
-            } catch (NumberFormatException e) {
-                seekPurchaseByBatch.setUnitPrice(null);
-            }
-        }
-        // 如果填了单价又不选币种,导入的时候系统就默认人民币吧
-        if (!StringUtils.isEmpty(unitPriceValue) && StringUtils.isEmpty(currencyValue)) {
-            seekPurchaseByBatch.setCurrency("RMB");
-        }
-
-        // 封装
-        Object encapsulationValue = readWorkBookCell(row.getCell(6), Cell.CELL_TYPE_STRING,
-                rowNum, 6);
-        if (!StringUtils.isEmpty(encapsulationValue)) {
-            try {
-                String encapsulation = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(encapsulationValue));
-                seekPurchaseByBatch.setEncapsulation(encapsulation);
-            } catch (Exception e) {
-                seekPurchaseByBatch.setEncapsulation(null);
-            }
-        }
-
-
-        // 生产日期
-        Object produceDateValue = readWorkBookCell(row.getCell(7), Cell.CELL_TYPE_STRING,
-                rowNum, 7);
-        if (!StringUtils.isEmpty(produceDateValue)) {
-            try {
-                String produceDate = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(produceDateValue));
-                seekPurchaseByBatch.setProduceDate(produceDate);
-            } catch (Exception e) {
-                seekPurchaseByBatch.setProduceDate(null);
-            }
-        }
-        return result;
-    }
-
-    private Object readWorkBookCell(Cell cell, int cellType, int r, int n) {
-        Object obj = null;
-        try {
-            if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
-                switch (cellType) {
-                    case Cell.CELL_TYPE_STRING :
-                        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
-                        String str = cell.getStringCellValue().trim();
-                        if (str.indexOf("\u00A0") > 0) {
-                            str= str.replaceAll("\u00A0", "");
-                        }
-                        str = StringUtilB2C.replaceTabAndLineBreak(str);
-                        obj = str.trim();
-                        break;
-                    case Cell.CELL_TYPE_NUMERIC :
-                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
-                        obj = cell.getNumericCellValue();
-                        if (obj != null) {
-                            if (obj.toString().indexOf("E") > 0) {
-                                BigDecimal b = new BigDecimal(obj.toString());
-                                obj = b.toPlainString();
-                            }
-                        }
-                        break;
-                    default :
-                        if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
-                            String productTime = cell.getStringCellValue();
-                            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
-                            Matcher m = p.matcher(productTime);
-                            String time = m.replaceAll("");
-                            if (time.indexOf("\u00A0") > 0){
-                                time= time.replaceAll("\u00A0", "");
-                            }
-                            DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd");
-                            obj = format1.parse(time);
-                        } else if (HSSFDateUtil.isCellDateFormatted(cell)) {
-                            obj = cell.getDateCellValue();
-                        }
-                        break;
-                }
-            }
-        } catch (Exception e) {
-            throw new IllegalOperatorException("读取表格中" + r + "行" + (n + 1) + "列的内容错误,有可能是该单元格的格式不正确");
-        }
-        return obj;
-    }
-
-    @Override
-    public Page<SeekPurchaseByBatch> getSeekPurchaseByBatchPageInfo(final PageInfo pageInfo, Long bomId) {
-        if (bomId != null) {
-            pageInfo.filter("bomId", bomId);
-        }
-        Page<SeekPurchaseByBatch> pageSeeks = seekPurchaseByBatchDao.findAll(new Specification<SeekPurchaseByBatch>() {
-            public Predicate toPredicate(Root<SeekPurchaseByBatch> root, CriteriaQuery<?> query,
-                    CriteriaBuilder builder) {
-                query.where(pageInfo.getPredicates(root, query, builder));
-                return null;
-            }
-        }, pageInfo);
-        List<SeekPurchaseByBatch> seekPurchaseByBatchList = pageSeeks.getContent();
-        for (int i = 0;i < seekPurchaseByBatchList.size(); i++) {
-            if (!StringUtils.isEmpty(seekPurchaseByBatchList.get(i).getCode()) && !StringUtils.isEmpty(seekPurchaseByBatchList.get(i).getBrand())) {
-                List<Map<String, Object>> codeWord = searcherService.getSimilarComponents(seekPurchaseByBatchList.get(i).getCode());
-                if (codeWord != null && codeWord.size() > 0) {
-                    seekPurchaseByBatchList.get(i).setCodeWord(codeWord);
-                }
-                List<Map<String, Object>> brandWord = searcherService.getSimilarComponents(seekPurchaseByBatchList.get(i).getBrand());
-                if (codeWord != null && codeWord.size() > 0) {
-                    seekPurchaseByBatchList.get(i).setBrandWord(brandWord);
-                }
-            }
-        }
-        return new PageImpl<SeekPurchaseByBatch>(seekPurchaseByBatchList, pageInfo, pageSeeks.getTotalElements());
-    }
-
-    @Override
-    public ResultMap confirmBom(Long bomId, String spIds) {
-        SeekPurchaseBom seekPurchaseBom = seekPurchaseBomDao.findOne(bomId);
-        List<SeekPurchaseByBatch> seekPurchaseByBatchList = null;
-        if (!StringUtils.isEmpty(spIds)) {
-            // 保存选中
-            seekPurchaseByBatchList = seekPurchaseByBatchDao.findBySpids(Arrays.asList(spIds.split(",")));
-        } else {
-            // 保存所有
-            seekPurchaseByBatchList = seekPurchaseByBatchDao.findByBomId(bomId);
-        }
-        // 商城现货的数量
-        int haveGoodsCount = 0;
-        // 将临时表转换成正式表数据
-        List<SeekPurchase> seekPurchaseList = new ArrayList<>();
-        // 发布到正式表的临时数据
-        List<SeekPurchaseByBatch> deleteBatchList = new ArrayList<>();
-        for (SeekPurchaseByBatch batch : seekPurchaseByBatchList) {
-            SeekPurchase seekPurchase = new SeekPurchase();
-            if (!StringUtils.isEmpty(batch.getCode()) && !StringUtils.isEmpty(batch.getBrand()) && !StringUtils.isEmpty(batch.getDeadline())) {
-                //seekPurchase = (SeekPurchase) batch;
-                seekPurchase.setDeadline(batch.getDeadline());
-                seekPurchase.setCurrency(batch.getCurrency());
-                seekPurchase.setReleaseDate(batch.getReleaseDate());
-                seekPurchase.setCode(batch.getCode());
-                seekPurchase.setBrand(batch.getBrand());
-                seekPurchase.setAmount(batch.getAmount());
-                seekPurchase.setEncapsulation(batch.getEncapsulation());
-                seekPurchase.setUnitPrice(batch.getUnitPrice());
-                seekPurchase.setProduceDate(batch.getProduceDate());
-                seekPurchase.setBomId(batch.getBomId());
-                seekPurchase.setEnUu(seekPurchaseBom.getEnuu());
-                seekPurchase.setUu(seekPurchaseBom.getUu());
-                seekPurchase.setStatus(Status.NO_OFFER.getValue());
-                // 商城现货搜索
-                List<Goods> goods = goodsDao.getGoodsByCodeAndName(seekPurchase.getCode(), seekPurchase.getBrand());
-                if (goods != null && goods.size() > 0) {
-                    haveGoodsCount++;
-                }
-                deleteBatchList.add(batch);
-                seekPurchaseList.add(seekPurchase);
-            }
-        }
-        seekPurchaseList = seekPurchasedao.save(seekPurchaseList);
-        seekPurchaseBom.setAmount((seekPurchaseBom.getAmount() == null ? 0 : seekPurchaseBom.getAmount()) + seekPurchaseList.size());
-        seekPurchaseBom.setStatus(1);
-        seekPurchaseBomDao.save(seekPurchaseBom);
-        seekPurchaseByBatchDao.delete(deleteBatchList);
-        return ResultMap.success(haveGoodsCount);
-    }
-
-    @Override
-    public Page<SeekPurchaseBomList> getSeekPurchaseBomListPage(final PageInfo pageInfo, User user, String minReleaseDate, String maxReleaseDate, String name) {
-        if (user.getEnterprise() != null) {
-            pageInfo.filter("enUu", user.getEnterprise().getUu());
-        } else {
-            pageInfo.filter("uu", user.getUserUU());
-        }
-        // 发布时间
-        if (!StringUtils.isEmpty(minReleaseDate)) {
-            pageInfo.expression(PredicateUtils.gte("releaseDate", new Date(Long.valueOf(minReleaseDate)), false));
-        }
-        if (!StringUtils.isEmpty(maxReleaseDate)) {
-            pageInfo.expression(PredicateUtils.lte("releaseDate", new Date(Long.valueOf(maxReleaseDate)), false));
-        }
-        // Bom名称
-        if (!StringUtils.isEmpty(name)) {
-            pageInfo.filter("name", name);
-        }
-        pageInfo.sorting("releaseDate", Direction.DESC);
-        Page<SeekPurchaseBomList> pageSeeks = seekPurchaseBomListDao.findAll(new Specification<SeekPurchaseBomList>() {
-            public Predicate toPredicate(Root<SeekPurchaseBomList> root, CriteriaQuery<?> query,
-                    CriteriaBuilder builder) {
-                query.where(pageInfo.getPredicates(root, query, builder));
-                return null;
-            }
-        }, pageInfo);
-        return pageSeeks;
-    }
-
-    @Override
-    public Map<String, Object> getImportBomInfo(Long bomId) {
-        String sql = "select bom_id,count(bom_id) as successImport,(sum((IF(sp_brand is null,1,0)))+sum((IF(sp_code is null,1,0)))+sum((IF(sp_deadline is null,1,0)))) as nullField "
-                + "from trade$seek_purchase_by_batch where bom_id = ? group by bom_id";
-        try {
-            Map<String, Object> map = jdbcTemplate.queryForMap(sql, new Object[]{bomId});
-            return map;
-        } catch (DataAccessException e) {
-            return null;
-        }
-    }
-
-    @Override
-    public ResultMap updateSeekPurchaseByBatch(SeekPurchaseByBatch seekPurchaseByBatch) {
-        seekPurchaseByBatchDao.save(seekPurchaseByBatch);
-        return ResultMap.success(null);
-    }
-
-    @Override
-    public ResultMap deleteSeekPurchaseByBatch(String spIds) {
-        String sql = "delete from trade$seek_purchase_by_batch where sp_id in (:spIds)";
-        Map<String, Object> param = new HashMap<>();
-        param.put("spIds", spIds.contains(",") ? Arrays.asList(spIds.split(",")) : spIds);
-        namedParameterJdbcTemplate.update(sql, param);
-        return ResultMap.success(null);
-    }
-
-    @Override
-    public ResultMap updateSeekPurchaseBom(SeekPurchaseBom seekPurchaseBom) {
-        SeekPurchaseBom oldBom = seekPurchaseBomDao.findOne(seekPurchaseBom.getId());
-        String name = seekPurchaseBom.getName();
-        if (StringUtils.isEmpty(name)) {
-            throw new IllegalOperatorException("bom名称不符合要求");
-        }
-        oldBom.setName(seekPurchaseBom.getName());
-        seekPurchaseBomDao.save(oldBom);
-        return ResultMap.success(null);
-    }
-
-    @Override
-    public SeekPurchaseBomList findOneBom(Long bomId) {
-        return seekPurchaseBomListDao.findOne(bomId);
-    }
 }

+ 32 - 0
src/main/java/com/uas/platform/b2c/trade/seek/utils/DateUtils.java

@@ -0,0 +1,32 @@
+package com.uas.platform.b2c.trade.seek.utils;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * @author liusw
+ * @version 2018/1/19 15:10
+ */
+public class DateUtils {
+    /**
+     * 截止日期处理
+     * @param date
+     * @return
+     */
+    public static Date addTime(Date date) {
+        Long addTime = Long.valueOf(23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000);
+        Long deadline = date.getTime();
+        return new Date(addTime + deadline);
+    }
+
+    /**
+     * 当前时间增加几天
+     * @param date
+     * @param day
+     * @return
+     */
+    public static Date addTime(Date date, Integer day, Integer hour, Integer minute,Integer second){
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+        return new Date(date.getTime() + day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 100 + minute * 60 * 1000 + second * 1000);
+    }
+}

+ 1 - 0
src/main/webapp/resources/js/usercenter/controllers/forstore/seek_purchase_ctrl.js

@@ -217,6 +217,7 @@ define(['app/app'], function (app) {
                   : null;
               if ($scope.isSearch) {
                 param.page = 1;
+                params.page(1);
                 $scope.isSearch = false;
               }
               seekPurchase.getUserSeekPageInfo(param, function (data) {

+ 1 - 0
src/main/webapp/resources/js/vendor/controllers/forstore/seek_purchase_ctrl.js

@@ -26,6 +26,7 @@ define(['app/app'], function (app) {
                   : null;
               if ($scope.isSearch) {
                 param.page = 1;
+                params.page(1);
                 $scope.isSearch = false;
               }
               seekPurchase.getSeekPushGoodsPageInfo(param, function (data) {