Authored by mali

Merge branch 'master' of http://git.yoho.cn/ufo/ufo-platform

Conflicts:
	dal/src/main/java/com/yoho/ufo/dal/ProductMapper.java
	dal/src/main/resources/META-INF/mybatis/ProductMapper.xml
... ... @@ -3,43 +3,16 @@ package com.yoho.ufo.service.model;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by yoho on 2017/2/15.
*/
public class BaseBO implements Serializable {
public static final String NORMAL_FORMAT = "yyyy-MM-dd";
private static final long serialVersionUID = 1759153128139236954L;
private static final long serialVersionUID = 2713604434915399057L;
public BaseBO() {
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
public static String getDateFormatFromInt(long intTime, String... formats) {
if(intTime <= 0L) {
return null;
} else {
Date date = new Date(intTime * 1000L);
return getDateFormatFromDate(date, formats);
}
}
public static String getDateFormatFromDate(Date date, String... formats) {
if(date == null) {
return null;
} else {
String format = "yyyy-MM-dd";
if(null != formats && formats.length > 0) {
format = null == formats[0]?"yyyy-MM-dd":formats[0];
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(date);
}
}
}
\ No newline at end of file
... ...
... ... @@ -10,8 +10,7 @@ import org.apache.commons.lang3.StringUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
... ... @@ -175,31 +174,6 @@ public final class DateUtil {
}
}
public static Integer getTimeSeconds(String timeStr) {
String afterTime = "";
timeStr = timeStr.trim();
String[] hengStrs = timeStr.split("-");
String[] maoStrs = timeStr.split(":");
if(hengStrs.length == 2) {
afterTime = timeStr + "-01 00:00:00";
} else if(hengStrs.length == 3 && maoStrs.length == 1) {
afterTime = timeStr + " 00:00:00";
} else if(hengStrs.length == 3 && maoStrs.length == 3) {
afterTime = timeStr;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = sdf.parse(afterTime);
long e = date.getTime();
return Integer.valueOf((int)(e / 1000L));
} catch (ParseException var8) {
return null;
}
}
/**
* 获取当前时间,格式yyyy-MM-dd HH:mm:ss
* @return
... ... @@ -217,15 +191,17 @@ public final class DateUtil {
}
public static int getHour(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(11);
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalTime localTime = instant.atZone(zoneId).toLocalTime();
return localTime.getHour();
}
public static int getMinute(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(12);
public static int getMinute1(Date date) {
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalTime localTime = instant.atZone(zoneId).toLocalTime();
return localTime.getMinute();
}
public static int getAddOrMinusDay(Date date, int num) {
... ... @@ -237,63 +213,10 @@ public final class DateUtil {
}
public static Date getAddOrMinusDay2(Date date, int num) {
GregorianCalendar gc = (GregorianCalendar)Calendar.getInstance();
gc.setTime(date);
gc.add(5, num);
return gc.getTime();
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime().plusDays(num);
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}
public static int getMonthStart() {
Calendar cal = Calendar.getInstance();
int month = cal.get(2) + 1;
int year = cal.get(1);
return getTimeSeconds(year + "-" + month).intValue();
}
public static int getMonthEnd() {
Calendar cal = Calendar.getInstance();
cal.set(5, cal.getMaximum(5));
int month = cal.get(2) + 1;
int year = cal.get(1);
int day = cal.get(5);
if(month + 1 == 13) {
month = 1;
++year;
}
Integer time = Integer.valueOf(getTimeSeconds(year + "-" + month + "-" + day).intValue() + 86400);
return time.intValue();
}
public static boolean isValidDate(String s, String formats) {
try {
SimpleDateFormat e = new SimpleDateFormat(formats);
e.parse(s);
return true;
} catch (Exception var3) {
return false;
}
}
public static String getCronFromDateTime(String datetimeStr, String format) {
if(StringUtils.isBlank(datetimeStr)) {
return null;
} else {
LocalDateTime localDateTime = LocalDateTime.parse(datetimeStr, DateTimeFormatter.ofPattern(format));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ss mm HH dd MM ? yyyy");
return localDateTime.format(formatter);
}
}
public static int getWeekInterval(long dateInt) {
Calendar calendar = Calendar.getInstance();
int curWeekInt = calendar.get(3);
int curYearInt = calendar.get(1);
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(new Date(dateInt * 1000L));
int weekInt = calendar1.get(3);
int yearInt = calendar1.get(1);
return curYearInt == yearInt?curWeekInt - weekInt:52 * (curYearInt - yearInt) + curWeekInt - weekInt;
}
}
... ...
... ... @@ -64,4 +64,9 @@ public interface ProductMapper {
// 根据Id列表查询商品列表
List<Product> selectProductListByIds(@Param("productIdList")List<Integer> productIdList);
int updateStatusByPrimaryKey(@Param("id") Integer id,
@Param("shelveStatus") Integer shelveStatus);
}
\ No newline at end of file
... ...
... ... @@ -167,4 +167,16 @@
#{item}
</foreach>
</select>
<update id="updateStatusByPrimaryKey">
update product set
edit_time = unix_timestamp(),
update_time = unix_timestamp(),
shelve_status = #{shelveStatus,jdbcType=INTEGER}
<if test="shelveStatus != null and shelveStatus == 1">
,shelve_time = unix_timestamp()
</if>
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -84,7 +84,7 @@
select <include refid="queryColumns"/>
from size where sort_id = #{sortId}
</select>
<select id="selectAllSizeBySortId" resultMap="sizeMap">
<select id="selectByIdList" resultMap="sizeMap">
select id,size_name
from size where sort_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
... ...
... ... @@ -50,9 +50,22 @@ public class ProductController {
return productService.getSkuList(bo);
}
@RequestMapping(value = "/detailList")
public ApiResponse<PageResponseBO<ProductResponceBo>> detailList(ProductRequestBo bo) {
@RequestMapping(value = "/skupList")
public ApiResponse<PageResponseBO<ProductResponceBo>> skupList(ProductRequestBo bo) {
LOGGER.info("product.detailList param = {}", bo);
return productService.getSkupDetailList(bo);
}
@RequestMapping(value = "/changeProductShelfStatus")
public ApiResponse<Void> changeProductShelfStatus(ProductRequestBo bo) {
LOGGER.info("product.changeProductShelfStatus param = {}", bo);
return productService.changeProductStatus(bo);
}
@RequestMapping(value = "/cancelSaleSkup")
public ApiResponse<Void> cancelSaleSkup(ProductRequestBo bo) {
LOGGER.info("product.detailList param = {}", bo);
return productService.cancelSaleSkup(bo);
}
}
... ...
... ... @@ -18,5 +18,7 @@ public interface IProductService {
ApiResponse<PageResponseBO<ProductResponceBo>> getSkupDetailList(ProductRequestBo bo);
ApiResponse<PageResponseBO<ProductResponceBo>> cancelSaleSkup(ProductRequestBo bo);
ApiResponse<Void> cancelSaleSkup(ProductRequestBo bo);
ApiResponse<Void> changeProductStatus(ProductRequestBo bo);
}
... ...
... ... @@ -10,7 +10,6 @@ import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
... ... @@ -471,7 +470,7 @@ public static void main(String[] args) {
}
@Override
public ApiResponse<PageResponseBO<ProductResponceBo>> cancelSaleSkup(ProductRequestBo bo) {
public ApiResponse<Void> cancelSaleSkup(ProductRequestBo bo) {
StoragePrice sp = storagePriceMapper.selectBySkup(bo.getSkup());
if (sp == null) {
return new ApiResponse<>(400, "SKUP不存在");
... ... @@ -487,5 +486,25 @@ public static void main(String[] args) {
return new ApiResponse<>(400, "SKUP取消失败,状态已变更!");
}
@Override
public ApiResponse<Void> changeProductStatus(ProductRequestBo bo) {
Product product = productMapper.selectByPrimaryKey(bo.getId());
if (product == null) {
return new ApiResponse<>(400, "商品不存在");
}
if (product.getDelStatus() == null || product.getDelStatus() != 0) {
return new ApiResponse<>(400, "商品已删除");
}
if ((product.getShelveStatus() == null || product.getShelveStatus() == 1) && bo.getStatus()==1) {
return new ApiResponse<>(400, "商品不能上架");
}
if ((product.getShelveStatus() == null || product.getShelveStatus() != 1) && bo.getStatus()==0) {
return new ApiResponse<>(400, "商品不能下架");
}
int n = productMapper.updateStatusByPrimaryKey(bo.getId(), bo.getShelveStatus());
if (n == 1) {
return new ApiResponse<>(400, "操作成功");
}
return new ApiResponse<>(400, "操作失败!");
}
}
... ...