diff --git a/README.md b/README.md index 93ad7ee182dda9188ff34aa0e6558994fce11364..a1894d5d7e2f977c9545392fcfb2808f50aae84e 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,9 @@ shop_category comment1字段用作当前分类的路径 shop_carouse comment字段用作当前轮播图绑定的商品spu 123231231412 ``` +##### 2019/12/3 16:42 by yonyong +``` +shop_category 主键改为int,自增 +shop_address 表comment1字段用作收货地址联系人,comment2字段用作收货地址联系电话 +shop_address weight字段用作判断收货地址是否为默认收货地址,1为是,其他则不是 +``` diff --git a/src/main/java/com/hxtec/polaris/commons/constant/Code.java b/src/main/java/com/hxtec/polaris/commons/constant/Code.java index 348653c4f548721762f7a5653f6f392f33440b5d..07d10d510d826a40b619c2cb4500b979f6629081 100644 --- a/src/main/java/com/hxtec/polaris/commons/constant/Code.java +++ b/src/main/java/com/hxtec/polaris/commons/constant/Code.java @@ -20,4 +20,6 @@ public final class Code { public final static Integer FAIL_4301 = 4301; //浏览历史相关失败返回 public final static Integer FAIL_4401 = 4401; + //地址相关失败返回 + public final static Integer FAIL_4501 = 4501; } diff --git a/src/main/java/com/hxtec/polaris/commons/constant/Msg.java b/src/main/java/com/hxtec/polaris/commons/constant/Msg.java index 3af11bb8085148b7b65e7c32e1349f59ec69343f..9c81cfeeca45ca64ebb79bf1cd41eca52a72052b 100644 --- a/src/main/java/com/hxtec/polaris/commons/constant/Msg.java +++ b/src/main/java/com/hxtec/polaris/commons/constant/Msg.java @@ -69,4 +69,12 @@ public final class Msg { public static final String HISTORY_DELETE_NULL = "删除指定记录成功,影响条数为0"; public static final String HISTORY_TRUNK_FAIL = "清空全部浏览浏览记录失败"; public static final String HISTORY_TRUNK_NULL = "清空全部浏览记录成功,影响条数为0"; + + /** + * 通用 + */ + public static final String COMMON_FAIL = "操作失败"; + public static final String COMMON_QUERY_NULL = "查询结果为空"; + public static final String COMMON_OK = "操作成功"; + } diff --git a/src/main/java/com/hxtec/polaris/commons/thread/HistoryRunable.java b/src/main/java/com/hxtec/polaris/commons/thread/HistoryRunable.java index 9ab68665c2d38b131d2bc7eae1eebd2032953228..223eaad1644eb0121eb5f83488646a305d615180 100644 --- a/src/main/java/com/hxtec/polaris/commons/thread/HistoryRunable.java +++ b/src/main/java/com/hxtec/polaris/commons/thread/HistoryRunable.java @@ -3,6 +3,7 @@ package com.hxtec.polaris.commons.thread; import com.hxtec.polaris.commons.api.vo.Result; import com.hxtec.polaris.commons.constant.GlobalVar; import com.hxtec.polaris.commons.constant.Log; +import com.hxtec.polaris.commons.constant.Msg; import com.hxtec.polaris.commons.exception.MyException; import com.hxtec.polaris.entity.ShopHistory; import com.hxtec.polaris.mapper.ShopHistoryMapper; @@ -15,7 +16,6 @@ import org.springframework.web.context.support.WebApplicationContextUtils; import javax.servlet.ServletContext; import java.text.MessageFormat; import java.util.Date; -import java.util.List; import java.util.concurrent.CountDownLatch; /** @@ -54,7 +54,7 @@ public class HistoryRunable implements Runnable { } doneSignal.await(); }catch (Exception e){ - throw new MyException(Result.error(MessageFormat.format(Log.PATTERN_HISTORY,history.toString()))); + throw new MyException(Result.error(Msg.COMMON_FAIL),MessageFormat.format(Log.PATTERN_HISTORY,history.toString())); } } diff --git a/src/main/java/com/hxtec/polaris/controller/LocationController.java b/src/main/java/com/hxtec/polaris/controller/LocationController.java new file mode 100644 index 0000000000000000000000000000000000000000..fe113ec0a055848c73f60fc0fb381d3d1c23eebb --- /dev/null +++ b/src/main/java/com/hxtec/polaris/controller/LocationController.java @@ -0,0 +1,50 @@ +package com.hxtec.polaris.controller; + +import com.hxtec.polaris.entity.ShopAddress; +import com.hxtec.polaris.service.LocationService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @Describtion 地址相关 + * @Author yonyong + * @Date 2019/12/3 15:25 + * @Version 1.0.0 + **/ +@RestController +@RequestMapping(value = "location",produces = "application/json;charset=utf-8") +@CrossOrigin +@Api(value = "/location", tags = "地址相关") +public class LocationController { + + @Autowired + private LocationService locationService; + + @GetMapping("get") + public Object getLoaction(){ + return locationService.getLoaction(); + } + + @PostMapping("add") + public Object addLoaction(ShopAddress shopAddress){ + return locationService.addLoaction(shopAddress); + } + + @PutMapping("update") + public Object updateLoaction(ShopAddress shopAddress){ + return locationService.updateLoaction(shopAddress); + } + + @ApiImplicitParams({ + @ApiImplicitParam(name = "ids[]", value = "删除的地址集合",allowMultiple=true, dataType = "String") + }) + @DeleteMapping("delete") + public Object deleteLoaction(@RequestParam("ids[]") List ids){ + return locationService.deleteLoaction(ids); + } +} diff --git a/src/main/java/com/hxtec/polaris/controller/OrderController.java b/src/main/java/com/hxtec/polaris/controller/OrderController.java index 492990a573c14dc051c91f30dd876859d71ef72a..f1369f7166921c8a1fff7a297adcddc90def86af 100644 --- a/src/main/java/com/hxtec/polaris/controller/OrderController.java +++ b/src/main/java/com/hxtec/polaris/controller/OrderController.java @@ -1,6 +1,8 @@ package com.hxtec.polaris.controller; +import com.hxtec.polaris.service.OrderService; import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; /** @@ -15,29 +17,32 @@ import org.springframework.web.bind.annotation.*; @Api(value = "/order", tags = "订单相关") public class OrderController { + @Autowired + private OrderService orderService; + @GetMapping("getAll") public Object getAll(){ - return null; + return orderService.getAll(); } @GetMapping("getToPay") public Object getToPay(){ - return null; + return orderService.getToPay(); } @GetMapping("getToTransport") public Object getToTransport(){ - return null; + return orderService.getToTransport(); } @GetMapping("getToRate") public Object getToRate(){ - return null; + return orderService.getToRate(); } @GetMapping("getAfterSale") public Object getAfterSale(){ - return null; + return orderService.getAfterSale(); } @PostMapping("cancel") diff --git a/src/main/java/com/hxtec/polaris/entity/ShopAddress.java b/src/main/java/com/hxtec/polaris/entity/ShopAddress.java index 0668cf6d907f920d4e38d53a743698e876cac412..090d777a99bc15902a2151ef3aaf7586d0bc3ff7 100644 --- a/src/main/java/com/hxtec/polaris/entity/ShopAddress.java +++ b/src/main/java/com/hxtec/polaris/entity/ShopAddress.java @@ -285,4 +285,22 @@ public class ShopAddress { public void setComment3(String comment3) { this.comment3 = comment3; } + + @Override + public String toString() { + return "ShopAddress{" + + "id=" + id + + ", userId='" + userId + '\'' + + ", province='" + province + '\'' + + ", city='" + city + '\'' + + ", region='" + region + '\'' + + ", detail='" + detail + '\'' + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", weight=" + weight + + ", comment1='" + comment1 + '\'' + + ", comment2='" + comment2 + '\'' + + ", comment3='" + comment3 + '\'' + + '}'; + } } \ No newline at end of file diff --git a/src/main/java/com/hxtec/polaris/mapper/ShopAddressMapper.java b/src/main/java/com/hxtec/polaris/mapper/ShopAddressMapper.java index 0885a8570a6d7195d617b45459a423dd4ca7a537..08df527f830957da7f0681cbd6e22458b9b545a1 100644 --- a/src/main/java/com/hxtec/polaris/mapper/ShopAddressMapper.java +++ b/src/main/java/com/hxtec/polaris/mapper/ShopAddressMapper.java @@ -1,7 +1,87 @@ package com.hxtec.polaris.mapper; import com.hxtec.polaris.entity.ShopAddress; +import org.apache.ibatis.annotations.Param; import tk.mybatis.mapper.MyMapper; +import java.util.List; +import java.util.Map; +/** + * @Author yonyong + * @Description //TODO + * @Date 2019/12/3 16:30 + * @Param + * @return + **/ public interface ShopAddressMapper extends MyMapper { + + /** + * 根据手机号获取用户的所有收获地址 + * @param username + * @return + */ + List> getLocationByUsername(@Param("username") String username); + + /** + * 根据手机号获取用户的userid + * @param username + * @return + */ + String getUserIdByUsername(@Param("username") String username); + + /** + * 添加收货地址 + * @param shopAddress + * @return + */ + int insertLocation(ShopAddress shopAddress); + + /** + * 更新收货地址 + * @param shopAddress + * @return + */ + int updateLocation(ShopAddress shopAddress); + + /** + * 删除一条收货地址 + * @param id + * @return + */ + int deleteLocation(@Param("id") String id); + + /** + * 将当前用户的其他的收货地址改为非默认状态 + * @param username + * @param id + */ + void updateDefaultLocation(@Param("username")String username, @Param("id")Integer id); + + /** + * 根据手机号获取用户的所有收获地址的个数 + * @param username + * @return + */ + int selectCountByUsername(@Param("username")String username); + + /** + * 根据手机号获取用户的默认收获地址的个数 + * @param username + * @return + */ + int selectDefaultCountByUsername(@Param("username")String username); + + /** + * 根据手机号获取用户最新的收货地址 + * @param username + * @return + */ + ShopAddress getFrstLocationByUsername(@Param("username")String username); + + /** + * 更新指定id的收货地址的默认状态 1 为默认其他为非默认收货地址 + * @param shopAddress + * @return + */ + int updateDefaultState(ShopAddress shopAddress); } \ No newline at end of file diff --git a/src/main/java/com/hxtec/polaris/service/LocationService.java b/src/main/java/com/hxtec/polaris/service/LocationService.java new file mode 100644 index 0000000000000000000000000000000000000000..427dba768ff624f0a499b9f79d476b9e5e0babd2 --- /dev/null +++ b/src/main/java/com/hxtec/polaris/service/LocationService.java @@ -0,0 +1,38 @@ +package com.hxtec.polaris.service; + +import com.hxtec.polaris.entity.ShopAddress; + +import java.util.List; + +/** + * @Author yonyong + * @Description //地址相关service + * @Date 2019/12/3 15:33 + * @Param + * @return + **/ +public interface LocationService { + /** + * 获取对应用户的配置地址 + * @return + */ + Object getLoaction(); + + /** + * 添加对应用户的配置地址 + * @return + */ + Object addLoaction(ShopAddress shopAddress); + + /** + * 更新对应用户的配置地址 + * @return + */ + Object updateLoaction(ShopAddress shopAddress); + + /** + * 删除对应用户的配置地址 + * @return + */ + Object deleteLoaction(List ids); +} diff --git a/src/main/java/com/hxtec/polaris/service/OrderService.java b/src/main/java/com/hxtec/polaris/service/OrderService.java new file mode 100644 index 0000000000000000000000000000000000000000..547dddee220e1f0277667e94f02a20fd581ab86c --- /dev/null +++ b/src/main/java/com/hxtec/polaris/service/OrderService.java @@ -0,0 +1,40 @@ +package com.hxtec.polaris.service; + +/** + * @Author yonyong + * @Description //订单相关service + * @Date 2019/12/3 14:49 + * @Param + * @return + **/ +public interface OrderService { + /** + * 获取所有订单 + * @return + */ + Object getAll(); + + /** + * 获取待付款订单 + * @return + */ + Object getToPay(); + + /** + * 获取待收获订单 + * @return + */ + Object getToTransport(); + + /** + * 获取待评价订单 + * @return + */ + Object getToRate(); + + /** + * 获取售后订单 + * @return + */ + Object getAfterSale(); +} diff --git a/src/main/java/com/hxtec/polaris/service/impl/LocationServiceImpl.java b/src/main/java/com/hxtec/polaris/service/impl/LocationServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..45d239cf735857c9b71a3816199e78cbea03eda8 --- /dev/null +++ b/src/main/java/com/hxtec/polaris/service/impl/LocationServiceImpl.java @@ -0,0 +1,160 @@ +package com.hxtec.polaris.service.impl; + +import com.hxtec.polaris.commons.api.vo.Result; +import com.hxtec.polaris.commons.constant.Code; +import com.hxtec.polaris.commons.constant.Log; +import com.hxtec.polaris.commons.constant.Msg; +import com.hxtec.polaris.commons.exception.MyException; +import com.hxtec.polaris.entity.ShopAddress; +import com.hxtec.polaris.mapper.ShopAddressMapper; +import com.hxtec.polaris.service.LocationService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.text.MessageFormat; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * @Describtion 地址相关service + * @Author yonyong + * @Date 2019/12/3 15:32 + * @Version 1.0.0 + **/ +@Service +@Transactional +public class LocationServiceImpl implements LocationService { + + private final static Logger logger = LoggerFactory.getLogger(LocationServiceImpl.class); + private final static String LOG_CLASS_NAME = "LocationServiceImpl"; + private final static String LOG_METHOD_ADD_LOCATION = "addLoaction"; + private final static String LOG_METHOD_DEL_LOCATION = "deleteLoaction"; + private final static String LOG_METHOD_UPDATE_LOCATION ="updateLoaction"; + + @Resource + private ShopAddressMapper shopAddressMapper; + @Resource + private AddressServiceImpl addressService; + + @Override + public Object getLoaction() { + List> mapList = shopAddressMapper.getLocationByUsername( addressService.getUser()); + if (mapList.size()>0){ + return Result.ok(mapList); + }else { + throw new MyException(Result.error(Code.FAIL_4501, Msg.COMMON_QUERY_NULL)); + } + } + + @Override + public Object addLoaction(ShopAddress shopAddress) { + try { + doInsert(shopAddress); + }catch (Exception e){ + String params = "shopAddress="+shopAddress.toString(); + String LOG_MSG = MessageFormat.format(Log.PATTERN_LOG,Log.INSERT,LOG_CLASS_NAME,LOG_METHOD_ADD_LOCATION,params); + throw new MyException(Result.error(Code.FAIL_4501,Msg.COMMON_FAIL),LOG_MSG); + } + return Result.ok(Msg.COMMON_OK); + } + + @Override + public Object updateLoaction(ShopAddress shopAddress) { + try { + doUpdate(shopAddress); + }catch (Exception e){ + String params = "shopAddress="+shopAddress.toString(); + String LOG_MSG = MessageFormat.format(Log.PATTERN_LOG,Log.UPDATE,LOG_CLASS_NAME,LOG_METHOD_UPDATE_LOCATION,params); + throw new MyException(Result.error(Code.FAIL_4501,Msg.COMMON_FAIL),LOG_MSG); + } + return Result.ok(Msg.COMMON_OK); + } + + @Override + public Object deleteLoaction(List ids) { + try { + doDelete(ids); + }catch (Exception e){ + String params = "ids="+ids; + String LOG_MSG = MessageFormat.format(Log.PATTERN_LOG,Log.DELETE,LOG_CLASS_NAME,LOG_METHOD_DEL_LOCATION,params); + throw new MyException(Result.error(Code.FAIL_4501,Msg.COMMON_FAIL),LOG_MSG); + } + return Result.ok(Msg.COMMON_OK); + } + + /** + * 执行添加收货地址业务 + * @param shopAddress + */ + private void doInsert(ShopAddress shopAddress) { + //查询数据库中当前用户设置了几条收货地址,如果是第一次添加收货地址,则该地址为默认收货地址 + int count = shopAddressMapper.selectCountByUsername(addressService.getUser()); + if (count == 0){ + shopAddress.setWeight(1.0); + } + String userId = shopAddressMapper.getUserIdByUsername(addressService.getUser()); + shopAddress.setUserId(userId); + shopAddress.setCreateTime(new Date()); + shopAddress.setUpdateTime(new Date()); + shopAddressMapper.insertLocation(shopAddress); + + if (count > 0){ + //修正默认状态 + updateDefaultAddress(shopAddress); + } + } + + /** + * 执行更新收货地址业务 + * @param shopAddress + */ + private void doUpdate(ShopAddress shopAddress) { + //查询数据库中当前用户设置了几条收货地址,如果是第一次添加收货地址,即使用户取消修改了默认地址,该地址仍然为默认收货地址 + int count = shopAddressMapper.selectCountByUsername(addressService.getUser()); + if (count == 1){ + shopAddress.setWeight(1.0); + } + shopAddress.setUpdateTime(new Date()); + shopAddressMapper.updateLocation(shopAddress); + + if (count > 1){ + //修正默认状态 + updateDefaultAddress(shopAddress); + } + } + + /** + * 执行删除收货地址业务 + * @param ids + */ + private void doDelete(List ids) { + for (String id: ids) { + shopAddressMapper.deleteLocation(id); + } + //如果把默认地址删除掉了,则默认第一条为默认收货地址 + int count = shopAddressMapper.selectDefaultCountByUsername(addressService.getUser()); + if (count !=1){ + ShopAddress shopAddress = shopAddressMapper.getFrstLocationByUsername(addressService.getUser()); + //如果shopAddress不为空,则表明数据库中还有当前用户的收货地址,将查询出的这个地址设置为默认收货地址 + if (null != shopAddress){ + shopAddress.setWeight(1.0); + shopAddressMapper.updateDefaultState(shopAddress); + } + } + } + + /** + * 如果当前操作的的收货地址状态为默认的,则将当前用户的其他地址状态改为非默认,改为0 + * @param shopAddress + */ + private void updateDefaultAddress(ShopAddress shopAddress){ + String username =addressService.getUser(); + if (null != shopAddress.getWeight() && shopAddress.getWeight() == 1){ + shopAddressMapper.updateDefaultLocation(username,shopAddress.getId()); + } + } +} diff --git a/src/main/java/com/hxtec/polaris/service/impl/OrderServiceImpl.java b/src/main/java/com/hxtec/polaris/service/impl/OrderServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..2e6c1471b40a35b9591c2497eddc46a0ce129981 --- /dev/null +++ b/src/main/java/com/hxtec/polaris/service/impl/OrderServiceImpl.java @@ -0,0 +1,40 @@ +package com.hxtec.polaris.service.impl; + +import com.hxtec.polaris.service.OrderService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * @Describtion 订单相关service + * @Author yonyong + * @Date 2019/12/3 14:48 + * @Version 1.0.0 + **/ +@Service +@Transactional +public class OrderServiceImpl implements OrderService{ + @Override + public Object getAll() { + return null; + } + + @Override + public Object getToPay() { + return null; + } + + @Override + public Object getToTransport() { + return null; + } + + @Override + public Object getToRate() { + return null; + } + + @Override + public Object getAfterSale() { + return null; + } +} diff --git a/src/main/resources/mapper/ShopAddressMapper.xml b/src/main/resources/mapper/ShopAddressMapper.xml index 32fa12e87ddadcb9bb1361e64e69d4557da13d24..10b0c3795b651eae792dc581ef12e0009578bac1 100644 --- a/src/main/resources/mapper/ShopAddressMapper.xml +++ b/src/main/resources/mapper/ShopAddressMapper.xml @@ -18,4 +18,74 @@ + + a.id, a.user_id,a.region, a.detail,a.weight,a.comment1,a.comment2 + + + + + + + + + + + + insert into shop_address (user_id, region, detail,create_time, update_time, weight,comment1,comment2) + values (#{userId,jdbcType=VARCHAR}, #{region,jdbcType=VARCHAR}, #{detail,jdbcType=VARCHAR}, + #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{weight,jdbcType=VARCHAR}, + #{comment1,jdbcType=VARCHAR},#{comment2,jdbcType=VARCHAR} + ) + + + + update shop_address set comment1=#{comment1,jdbcType=VARCHAR}, comment2=#{comment2,jdbcType=VARCHAR},region =#{region,jdbcType=VARCHAR}, + detail = #{detail,jdbcType=VARCHAR},update_time = #{updateTime,jdbcType=TIMESTAMP},weight = #{weight,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + + + UPDATE shop_address set weight = 0 + WHERE id != #{id} and user_id in ( + select id from shop_user where mobile = #{username} + ) + + + + delete from shop_address where id = #{id} + + + + + + UPDATE set weight = #{weight,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + \ No newline at end of file diff --git a/src/main/resources/mapper/ShopCategoryMapper.xml b/src/main/resources/mapper/ShopCategoryMapper.xml index d988283a4e4ef4fd4355b8d725ccf2548a44d8f2..f0deae71364b9797a52662363f6cfad5b006dcc5 100644 --- a/src/main/resources/mapper/ShopCategoryMapper.xml +++ b/src/main/resources/mapper/ShopCategoryMapper.xml @@ -40,13 +40,13 @@ - insert into shop_category (id, parent_id, is_parent, + insert into shop_category (parent_id, is_parent, name, decriptsion, image, weight, goods_count, state, is_delete, create_time, update_time, comment1, comment2, comment3 ) - values (#{id,jdbcType=VARCHAR}, #{parentId,jdbcType=VARCHAR}, #{isParent,jdbcType=VARCHAR}, + values (#{parentId,jdbcType=VARCHAR}, #{isParent,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{decriptsion,jdbcType=VARCHAR}, #{image,jdbcType=VARCHAR}, #{weight,jdbcType=DOUBLE}, #{goodsCount,jdbcType=INTEGER}, #{state,jdbcType=VARCHAR}, #{isDelete,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},