|
|
@@ -1,12 +1,26 @@
|
|
|
package com.hssx.pcbms.service.impl;
|
|
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import com.hssx.pcbms.entity.Goods;
|
|
|
+import com.hssx.pcbms.entity.GoodsNo;
|
|
|
import com.hssx.pcbms.entity.vo.GoodsVO;
|
|
|
import com.hssx.pcbms.mapper.GoodsMapper;
|
|
|
+import com.hssx.pcbms.mapper.GoodsNoMapper;
|
|
|
+import com.hssx.pcbms.service.GoodsNoService;
|
|
|
import com.hssx.pcbms.service.GoodsService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.hssx.pcbms.util.HttpRespMsg;
|
|
|
+import com.hssx.pcbms.util.PageUtil;
|
|
|
+import com.hssx.pcbms.util.UploadFileToFileNameUtil;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -18,9 +32,61 @@ import org.springframework.stereotype.Service;
|
|
|
*/
|
|
|
@Service
|
|
|
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {
|
|
|
+ @Resource
|
|
|
+ private GoodsMapper goodsMapper;
|
|
|
+ @Resource
|
|
|
+ private GoodsNoMapper goodsNoMapper;
|
|
|
+ @Resource
|
|
|
+ private GoodsNoService goodsNoService;
|
|
|
+ @Value("${upload.path}")
|
|
|
+ private String path;
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg add(GoodsVO goodsVO) {
|
|
|
- return null;
|
|
|
+ public HttpRespMsg add(GoodsVO goodsVO,MultipartFile file) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ if(null != file){
|
|
|
+ goodsVO.setPic(UploadFileToFileNameUtil.uploadFile(file, path));
|
|
|
+ }
|
|
|
+ Goods goods = new Goods();
|
|
|
+ BeanUtils.copyProperties(goodsVO,goods);
|
|
|
+ List<GoodsNo> list = new ArrayList<>();
|
|
|
+ goodsMapper.insert(goods);
|
|
|
+ if(0 != goodsVO.getNumber()){
|
|
|
+ for(int i=0;i<goodsVO.getNumber();i++){
|
|
|
+ GoodsNo goodsNo = new GoodsNo();
|
|
|
+ goodsNo.setGoodsId(goods.getId());
|
|
|
+ goodsNo.setModelNo(goodsVO.getDeptStr()+goodsVO.getGoodStr()+String.format("%04d", i));
|
|
|
+ list.add(goodsNo);
|
|
|
+ }
|
|
|
+ goodsNoService.saveBatch(list);
|
|
|
+ }else{
|
|
|
+ msg.setError("资产数量必须大于零");
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg updateInfo(Goods goods, MultipartFile file) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ if(null != file){
|
|
|
+ goods.setPic(UploadFileToFileNameUtil.uploadFile(file, path));
|
|
|
+ }
|
|
|
+ goodsMapper.updateById(goods);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getList(PageUtil page, String keyName, Integer tagId) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ PageHelper.startPage(page.getPageNum(),page.getPageSize());
|
|
|
+ List<GoodsVO> list = goodsMapper.getListBycondition(keyName,tagId);
|
|
|
+ PageInfo<GoodsVO> info = new PageInfo<>(list);
|
|
|
+ msg.data = info;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String format = String.format("%04d", 0);
|
|
|
+ System.out.println(format);
|
|
|
}
|
|
|
}
|