Authored by caoyan

自助上架

package com.yoho.product.dal;
import com.yoho.product.model.ProductSelfShelves;
import java.util.List;
public interface ProductSelfShelvesMapper {
int deleteByPrimaryKey(Integer id);
import org.apache.ibatis.annotations.Param;
int insert(ProductSelfShelves record);
import com.yoho.product.model.ProductSelfShelves;
import com.yoho.product.model.SelfShelvesReq;
int insertSelective(ProductSelfShelves record);
public interface ProductSelfShelvesMapper {
int selectTotalByCondition(@Param("selfShelvesReq")SelfShelvesReq selfShelvesReq);
ProductSelfShelves selectByPrimaryKey(Integer id);
List<ProductSelfShelves> selectByCondition(@Param("selfShelvesReq")SelfShelvesReq selfShelvesReq);
int updateByPrimaryKeySelective(ProductSelfShelves record);
ProductSelfShelves selectById(@Param("id") Integer id);
int updateByPrimaryKey(ProductSelfShelves record);
int upadteAuditResult(@Param("id") Integer id, @Param("status") Integer status);
}
\ No newline at end of file
... ...
package com.yoho.product.dal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yoho.product.model.ProductSelfShelvesPic;
public interface ProductSelfShelvesPicMapper {
int deleteByPrimaryKey(Integer id);
int insert(ProductSelfShelvesPic record);
ProductSelfShelvesPic selectByPrimaryKey(Integer id);
List<String> selectPicUrlBySelfShelvesId(@Param("selfShelvesId") Integer selfShelvesId);
}
\ No newline at end of file
... ...
package com.yoho.product.model;
import com.yoho.ufo.service.model.PageRequestBO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
/**
* Created by caoyan.
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SelfShelvesReq extends PageRequestBO{
/**
*
*/
private static final long serialVersionUID = 1620427808531296022L;
private Integer id;
private String productName;
private String productCode;
private Integer status;
}
... ...
package com.yoho.product.model;
import java.util.List;
import com.yoho.ufo.service.model.PageRequestBO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
/**
* Created by caoyan.
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SelfShelvesRsp extends PageRequestBO{
/**
*
*/
private static final long serialVersionUID = 1620427808531296022L;
private Integer id;
private Integer uid;
private String brand;
private String productName;
private String price;
private String saleTime;
private String productCode;
private Integer status;
private String statusStr;
private List<String> imageList;
}
... ...
... ... @@ -27,127 +27,47 @@
delete from product_self_shelves
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.product.model.ProductSelfShelves" >
insert into product_self_shelves (id, brand, product_name,
price, sale_time, product_code,
status, uid, create_time,
update_time)
values (#{id,jdbcType=INTEGER}, #{brand,jdbcType=VARCHAR}, #{productName,jdbcType=VARCHAR},
#{price,jdbcType=DECIMAL}, #{saleTime,jdbcType=INTEGER}, #{productCode,jdbcType=VARCHAR},
#{status,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER},
#{updateTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.product.model.ProductSelfShelves" >
insert into product_self_shelves
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
<sql id="Query_Sql" >
<if test="selfShelvesReq.productName != null and selfShelvesReq.productName != '' ">
<bind name="pattern" value="'%' + selfShelvesReq.productName + '%'" />
and product_name like #{pattern}
</if>
<if test="brand != null" >
brand,
<if test="selfShelvesReq.productCode != null and selfShelvesReq.productName != '' ">
and product_code=#{selfShelvesReq.productCode}
</if>
<if test="productName != null" >
product_name,
<if test="selfShelvesReq.status != null">
and status=#{selfShelvesReq.status}
</if>
<if test="price != null" >
price,
</if>
<if test="saleTime != null" >
sale_time,
</if>
<if test="productCode != null" >
product_code,
</if>
<if test="status != null" >
status,
</if>
<if test="uid != null" >
uid,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="brand != null" >
#{brand,jdbcType=VARCHAR},
</if>
<if test="productName != null" >
#{productName,jdbcType=VARCHAR},
</if>
<if test="price != null" >
#{price,jdbcType=DECIMAL},
</if>
<if test="saleTime != null" >
#{saleTime,jdbcType=INTEGER},
</if>
<if test="productCode != null" >
#{productCode,jdbcType=VARCHAR},
</if>
<if test="status != null" >
#{status,jdbcType=INTEGER},
</if>
<if test="uid != null" >
#{uid,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.product.model.ProductSelfShelves" >
update product_self_shelves
<set >
<if test="brand != null" >
brand = #{brand,jdbcType=VARCHAR},
</if>
<if test="productName != null" >
product_name = #{productName,jdbcType=VARCHAR},
</if>
<if test="price != null" >
price = #{price,jdbcType=DECIMAL},
</if>
<if test="saleTime != null" >
sale_time = #{saleTime,jdbcType=INTEGER},
</if>
<if test="productCode != null" >
product_code = #{productCode,jdbcType=VARCHAR},
</if>
<if test="status != null" >
status = #{status,jdbcType=INTEGER},
</if>
<if test="uid != null" >
uid = #{uid,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=INTEGER},
</sql>
<select id="selectTotalByCondition" resultType="java.lang.Integer" parameterType="com.yoho.product.model.SelfShelvesReq">
select count(1)
from product_self_shelves
where 1=1
<include refid="Query_Sql"></include>
</select>
<select id="selectByCondition" resultMap="BaseResultMap" parameterType="com.yoho.product.model.SelfShelvesReq">
select <include refid="Base_Column_List"></include>
from product_self_shelves
where 1=1
<include refid="Query_Sql"></include>
order by update_time desc
<if test="selfShelvesReq.start!=null and selfShelvesReq.size != null">
limit #{selfShelvesReq.start},#{selfShelvesReq.size}
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.product.model.ProductSelfShelves" >
update product_self_shelves
set brand = #{brand,jdbcType=VARCHAR},
product_name = #{productName,jdbcType=VARCHAR},
price = #{price,jdbcType=DECIMAL},
sale_time = #{saleTime,jdbcType=INTEGER},
product_code = #{productCode,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
uid = #{uid,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectById" resultMap="BaseResultMap">
select <include refid="Base_Column_List"></include>
from product_self_shelves
where id=#{id}
</select>
<update id="upadteAuditResult">
update product_self_shelves set status=#{status}, update_time=unix_timestamp()
where id=#{id}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -15,14 +15,10 @@
from product_self_shelves_pic
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from product_self_shelves_pic
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.product.model.ProductSelfShelvesPic" >
insert into product_self_shelves_pic (id, self_shelves_id, picture_url
)
values (#{id,jdbcType=INTEGER}, #{selfShelvesId,jdbcType=INTEGER}, #{pictureUrl,jdbcType=VARCHAR}
)
</insert>
<select id="selectPicUrlBySelfShelvesId" resultType="java.lang.String" parameterType="java.lang.Integer" >
select picture_url
from product_self_shelves_pic
where self_shelves_id = #{selfShelvesId,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
... ...
package com.yoho.ufo.controller.product;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yoho.product.model.SelfShelvesReq;
import com.yoho.product.model.SelfShelvesRsp;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.service.ISelfShelvesService;
import com.yoho.ufo.service.model.ApiResponse;
import com.yoho.ufo.service.model.PageResponseBO;
@RestController
@RequestMapping(value = "/selfShelves")
public class SelfShelvesController {
private static final Logger LOGGER = LoggerFactory.getLogger(SelfShelvesController.class);
@Autowired
private ISelfShelvesService selfShelvesService;
@RequestMapping(value = "/queryList")
public ApiResponse queryList(SelfShelvesReq req) {
LOGGER.info("queryList in. req is {}", req);
PageResponseBO<SelfShelvesRsp> result = selfShelvesService.queryList(req);
return new ApiResponse.ApiResponseBuilder().code(200).message("查询成功").data(result).build();
}
@RequestMapping(value = "/getDetailById")
public ApiResponse getDetailById(SelfShelvesReq req) {
LOGGER.info("save in. req is {}", req);
SelfShelvesRsp result = selfShelvesService.getDetail(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(result).message("保存成功").build();
}
@RequestMapping(value = "/updateAuditInfoById")
public ApiResponse updateAuditInfoById(SelfShelvesReq req) {
LOGGER.info("save in. req is {}", req);
int result;
try {
result = selfShelvesService.updateAuditResult(req);
} catch (PlatformException e) {
return new ApiResponse.ApiResponseBuilder().code(500).message(e.getMessage()).build();
}
if(result>0) {
return new ApiResponse.ApiResponseBuilder().code(200).data(result).message("保存成功").build();
}else {
return new ApiResponse.ApiResponseBuilder().code(500).data(result).message("保存失败").build();
}
}
}
... ...
package com.yoho.ufo.service;
import com.yoho.product.model.SelfShelvesReq;
import com.yoho.product.model.SelfShelvesRsp;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.service.model.PageResponseBO;
public interface ISelfShelvesService {
PageResponseBO<SelfShelvesRsp> queryList(SelfShelvesReq req);
SelfShelvesRsp getDetail(SelfShelvesReq req);
int updateAuditResult(SelfShelvesReq req) throws PlatformException;
}
... ...
package com.yoho.ufo.service.impl;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.common.collect.Lists;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.product.dal.ProductSelfShelvesMapper;
import com.yoho.product.dal.ProductSelfShelvesPicMapper;
import com.yoho.product.model.ProductSelfShelves;
import com.yoho.product.model.SelfShelvesReq;
import com.yoho.product.model.SelfShelvesRsp;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.service.ISelfShelvesService;
import com.yoho.ufo.service.model.PageResponseBO;
/**
* @author caoyan
* @date 2019/3/19
*/
@Service
public class SelfShelvesServiceImpl implements ISelfShelvesService {
private static final Logger LOGGER = LoggerFactory.getLogger(SelfShelvesServiceImpl.class);
@Autowired
private ProductSelfShelvesMapper selfShelvesMapper;
@Autowired
private ProductSelfShelvesPicMapper productSelfShelvesPicMapper;
@Override
public PageResponseBO<SelfShelvesRsp> queryList(SelfShelvesReq req){
int total = selfShelvesMapper.selectTotalByCondition(req);
if(total == 0) {
return null;
}
List<ProductSelfShelves> list = selfShelvesMapper.selectByCondition(req);
if(CollectionUtils.isEmpty(list)) {
return null;
}
List<SelfShelvesRsp> rspList = Lists.newArrayList();
for(ProductSelfShelves item : list) {
SelfShelvesRsp rsp = new SelfShelvesRsp();
rsp.setId(item.getId());
rsp.setUid(item.getUid());
rsp.setBrand(item.getBrand());
rsp.setProductName(item.getProductName());
rsp.setPrice(null == item.getPrice() ? "/" : String.valueOf(item.getPrice()));
rsp.setSaleTime(DateUtil.getDateStrBySecond(item.getSaleTime(), "yyyy年MM月dd日"));
rsp.setProductCode(item.getProductCode());
rsp.setStatus(item.getStatus());
rsp.setStatusStr(getAuditStatusStr(item.getStatus()));
rspList.add(rsp);
}
PageResponseBO<SelfShelvesRsp> result=new PageResponseBO<>();
result.setList(rspList);
result.setPage(req.getPage());
result.setSize(req.getSize());
result.setTotal(total);
return result;
}
@Override
public SelfShelvesRsp getDetail(SelfShelvesReq req) {
ProductSelfShelves pss = selfShelvesMapper.selectById(req.getId());
if(null == pss) {
return null;
}
SelfShelvesRsp rsp = new SelfShelvesRsp();
BeanUtils.copyProperties(pss, rsp, SelfShelvesRsp.class);
rsp.setPrice(String.valueOf(pss.getPrice()));
rsp.setSaleTime(DateUtil.getDateStrBySecond(pss.getSaleTime(), "yyyy.MM.dd"));
//获取图片
List<String> imageList = productSelfShelvesPicMapper.selectPicUrlBySelfShelvesId(pss.getId());
rsp.setImageList(imageList);
return rsp;
}
@Override
public int updateAuditResult(SelfShelvesReq req) throws PlatformException {
ProductSelfShelves pss = selfShelvesMapper.selectById(req.getId());
if(null == pss) {
throw new PlatformException("记录不存在", 400);
}
return selfShelvesMapper.upadteAuditResult(req.getId(), req.getStatus());
}
private String getAuditStatusStr(int status) {
if(status == 0) {
return "待审核";
}else if(status == 1) {
return "已通过";
}else if(status == 2) {
return "不通过";
}
return "";
}
}
... ...
... ... @@ -8,6 +8,8 @@ datasources:
maxTotal: 100
daos:
- com.yohobuy.platform.dal.product.IProductSortMapper
- com.yoho.product.dal.ProductSelfShelvesMapper
- com.yoho.product.dal.ProductSelfShelvesPicMapper
ufo_order:
servers:
... ...
... ... @@ -8,6 +8,8 @@ datasources:
maxTotal: 100
daos:
- com.yohobuy.platform.dal.product.IBrandDao
- com.yoho.product.dal.ProductSelfShelvesMapper
- com.yoho.product.dal.ProductSelfShelvesPicMapper
ufo_order:
servers:
... ...