Showing
5 changed files
with
142 additions
and
0 deletions
1 | +package com.yohoufo.product.controller; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | + | ||
5 | +import org.apache.commons.collections.CollectionUtils; | ||
6 | +import org.apache.commons.lang3.StringUtils; | ||
7 | +import org.slf4j.Logger; | ||
8 | +import org.slf4j.LoggerFactory; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
10 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
11 | +import org.springframework.web.bind.annotation.RequestParam; | ||
12 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
13 | +import org.springframework.web.bind.annotation.RestController; | ||
14 | + | ||
15 | +import com.yohoufo.common.ApiResponse; | ||
16 | +import com.yohoufo.dal.product.model.ProductSelfShelves; | ||
17 | +import com.yohoufo.product.service.SelfShelvesService; | ||
18 | + | ||
19 | +@RestController | ||
20 | +public class SelfShelvesController { | ||
21 | + | ||
22 | + private static final Logger LOGGER = LoggerFactory.getLogger(SelfShelvesController.class); | ||
23 | + | ||
24 | + @Autowired | ||
25 | + private SelfShelvesService selfShelvesService; | ||
26 | + | ||
27 | + @RequestMapping(params = "method=ufo.selfShelves.save") | ||
28 | + @ResponseBody | ||
29 | + public ApiResponse save(@RequestParam(value = "uid", required = true) Integer uid, | ||
30 | + @RequestParam(value = "brand", required = true) String brand, | ||
31 | + @RequestParam(value = "product_name", required = true) String productName, | ||
32 | + @RequestParam(value = "price", required = true) String price, | ||
33 | + @RequestParam(value = "sale_time", required = true) String saleTime, | ||
34 | + @RequestParam(value = "product_code", required = true) String productCode, | ||
35 | + @RequestParam(value = "imageList", required = true) List<String> imageList) { | ||
36 | + LOGGER.info("ufo.selfShelves.save in. uid is {}, brand is {}, productName is {}, price is {}, " | ||
37 | + + "saleTime is {}, productCode is {}, imageList is {}", uid, brand, productName, price, saleTime, productCode, imageList); | ||
38 | + if(StringUtils.isEmpty(brand) || StringUtils.isEmpty(productName) || StringUtils.isEmpty(price) | ||
39 | + || StringUtils.isEmpty(saleTime) || StringUtils.isEmpty(productCode) || CollectionUtils.isEmpty(imageList)) { | ||
40 | + return new ApiResponse.ApiResponseBuilder().code(500).message("有参数为空").build(); | ||
41 | + } | ||
42 | + if(null == uid || 0 == uid.intValue()) { | ||
43 | + return new ApiResponse.ApiResponseBuilder().code(401).message("uid为空,请登录").build(); | ||
44 | + } | ||
45 | + ProductSelfShelves pss = new ProductSelfShelves(); | ||
46 | + pss.setUid(uid); | ||
47 | + pss.setBrand(brand); | ||
48 | + pss.setProductName(productName); | ||
49 | + pss.setProductCode(productCode); | ||
50 | + int result = selfShelvesService.save(pss, price, saleTime, imageList); | ||
51 | + if(result>0) { | ||
52 | + return new ApiResponse.ApiResponseBuilder().code(200).message("保存成功").build(); | ||
53 | + }else { | ||
54 | + return new ApiResponse.ApiResponseBuilder().code(500).message("保存失败").build(); | ||
55 | + } | ||
56 | + } | ||
57 | + | ||
58 | +} |
1 | +package com.yohoufo.product.service.impl; | ||
2 | + | ||
3 | +import java.math.BigDecimal; | ||
4 | +import java.text.ParseException; | ||
5 | +import java.text.SimpleDateFormat; | ||
6 | +import java.util.Date; | ||
7 | +import java.util.List; | ||
8 | + | ||
9 | +import org.slf4j.Logger; | ||
10 | +import org.slf4j.LoggerFactory; | ||
11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
12 | +import org.springframework.stereotype.Service; | ||
13 | + | ||
14 | +import com.yohoufo.common.exception.UfoServiceException; | ||
15 | +import com.yohoufo.common.utils.DateUtil; | ||
16 | +import com.yohoufo.dal.product.ProductSelfShelvesMapper; | ||
17 | +import com.yohoufo.dal.product.ProductSelfShelvesPicMapper; | ||
18 | +import com.yohoufo.dal.product.model.ProductSelfShelves; | ||
19 | +import com.yohoufo.product.service.SelfShelvesService; | ||
20 | + | ||
21 | +/** | ||
22 | + * @author caoyan | ||
23 | + * @date 2019/3/19 | ||
24 | + */ | ||
25 | +@Service | ||
26 | +public class SelfShelvesServiceImpl implements SelfShelvesService { | ||
27 | + | ||
28 | + private static final Logger LOGGER = LoggerFactory.getLogger(SelfShelvesServiceImpl.class); | ||
29 | + | ||
30 | + @Autowired | ||
31 | + private ProductSelfShelvesMapper productSelfShelvesMapper; | ||
32 | + | ||
33 | + @Autowired | ||
34 | + private ProductSelfShelvesPicMapper productSelfShelvesPicMapper; | ||
35 | + | ||
36 | + @Override | ||
37 | + public int save(ProductSelfShelves pss, String price, String saleTime, List<String> imageList) { | ||
38 | + pss.setPrice(BigDecimal.valueOf(Long.parseLong(price))); | ||
39 | + pss.setSaleTime((int)convertDateToLong(saleTime)); | ||
40 | + pss.setCreateTime(DateUtil.getCurrentTimeSecond()); | ||
41 | + pss.setUpdateTime(DateUtil.getCurrentTimeSecond()); | ||
42 | + | ||
43 | + LOGGER.info("insert data is {}", pss); | ||
44 | + int num = productSelfShelvesMapper.insert(pss); | ||
45 | + | ||
46 | + Integer selfShelvesId = pss.getId(); | ||
47 | + if(null == selfShelvesId) { | ||
48 | + return 0; | ||
49 | + } | ||
50 | + //插入图片 | ||
51 | + productSelfShelvesPicMapper.insertBatch(selfShelvesId, imageList); | ||
52 | + | ||
53 | + return num; | ||
54 | + } | ||
55 | + | ||
56 | + private long convertDateToLong(String date) { | ||
57 | + if(date.equals("0")) { | ||
58 | + return 0; | ||
59 | + } | ||
60 | + SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); | ||
61 | + Date dateDate = new Date(); | ||
62 | + try { | ||
63 | + dateDate = formatter.parse(date + " 00:00:00"); | ||
64 | + } catch (ParseException e) { | ||
65 | + throw new UfoServiceException(500, "时间格式有误"); | ||
66 | + } | ||
67 | + return dateDate.getTime() / 1000; | ||
68 | + } | ||
69 | + | ||
70 | +} |
@@ -40,6 +40,8 @@ datasources: | @@ -40,6 +40,8 @@ datasources: | ||
40 | - com.yohoufo.dal.product.TransferRecordsHistoryMapper | 40 | - com.yohoufo.dal.product.TransferRecordsHistoryMapper |
41 | - com.yohoufo.dal.product.ProductSalesMapper | 41 | - com.yohoufo.dal.product.ProductSalesMapper |
42 | - com.yohoufo.dal.product.ProductLimitSaleMapper | 42 | - com.yohoufo.dal.product.ProductLimitSaleMapper |
43 | + - com.yohoufo.dal.product.ProductSelfShelvesMapper | ||
44 | + - com.yohoufo.dal.product.ProductSelfShelvesPicMapper | ||
43 | 45 | ||
44 | 46 | ||
45 | ufo_order: | 47 | ufo_order: |
@@ -40,6 +40,8 @@ datasources: | @@ -40,6 +40,8 @@ datasources: | ||
40 | - com.yohoufo.dal.product.TransferRecordsHistoryMapper | 40 | - com.yohoufo.dal.product.TransferRecordsHistoryMapper |
41 | - com.yohoufo.dal.product.ProductLimitSaleMapper | 41 | - com.yohoufo.dal.product.ProductLimitSaleMapper |
42 | - com.yohoufo.dal.product.ProductSalesMapper | 42 | - com.yohoufo.dal.product.ProductSalesMapper |
43 | + - com.yohoufo.dal.product.ProductSelfShelvesMapper | ||
44 | + - com.yohoufo.dal.product.ProductSelfShelvesPicMapper | ||
43 | 45 | ||
44 | ufo_order: | 46 | ufo_order: |
45 | servers: | 47 | servers: |
-
Please register or login to post a comment