diff --git a/build/classes/com/w1hd/zzhnc/controller/wx/WxMiniController.class b/build/classes/com/w1hd/zzhnc/controller/wx/WxMiniController.class index 36f5e58..75b6280 100644 Binary files a/build/classes/com/w1hd/zzhnc/controller/wx/WxMiniController.class and b/build/classes/com/w1hd/zzhnc/controller/wx/WxMiniController.class differ diff --git a/build/classes/com/w1hd/zzhnc/model/Goods.class b/build/classes/com/w1hd/zzhnc/model/Goods.class index 8b6e8a0..61fa23c 100644 Binary files a/build/classes/com/w1hd/zzhnc/model/Goods.class and b/build/classes/com/w1hd/zzhnc/model/Goods.class differ diff --git a/build/classes/com/w1hd/zzhnc/model/Saller.class b/build/classes/com/w1hd/zzhnc/model/Saller.class deleted file mode 100644 index 69edbea..0000000 Binary files a/build/classes/com/w1hd/zzhnc/model/Saller.class and /dev/null differ diff --git a/build/classes/com/w1hd/zzhnc/service/ArticleService.class b/build/classes/com/w1hd/zzhnc/service/ArticleService.class index 5a8ba2f..7267dfd 100644 Binary files a/build/classes/com/w1hd/zzhnc/service/ArticleService.class and b/build/classes/com/w1hd/zzhnc/service/ArticleService.class differ diff --git a/build/classes/com/w1hd/zzhnc/service/FansService.class b/build/classes/com/w1hd/zzhnc/service/FansService.class index 988a7ba..e986ecb 100644 Binary files a/build/classes/com/w1hd/zzhnc/service/FansService.class and b/build/classes/com/w1hd/zzhnc/service/FansService.class differ diff --git a/build/classes/com/w1hd/zzhnc/util/PageResults.class b/build/classes/com/w1hd/zzhnc/util/PageResults.class index 4c782cc..c7afb88 100644 Binary files a/build/classes/com/w1hd/zzhnc/util/PageResults.class and b/build/classes/com/w1hd/zzhnc/util/PageResults.class differ diff --git a/src/com/w1hd/zzhnc/controller/pc/GoodsController.java b/src/com/w1hd/zzhnc/controller/pc/GoodsController.java index 24be8bf..aeede86 100644 --- a/src/com/w1hd/zzhnc/controller/pc/GoodsController.java +++ b/src/com/w1hd/zzhnc/controller/pc/GoodsController.java @@ -1,15 +1,43 @@ package com.w1hd.zzhnc.controller.pc; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; +import com.w1hd.zzhnc.model.Goods; +import com.w1hd.zzhnc.service.GoodsService; +import com.w1hd.zzhnc.vo.Vo_msg; + @Controller @RequestMapping("/goods") public class GoodsController { + + @Autowired + GoodsService goodsService; + @RequestMapping("/goodsList") public ModelAndView goodsList() { return new ModelAndView("/pc/goods/goodsList"); } + + @ResponseBody + @RequestMapping("/update") + public Object update(@RequestBody Goods goods) { + return new Vo_msg(0,goodsService.update(goods)); + } + + @ResponseBody + @RequestMapping("/search") + public Object search(@RequestParam(value="key",required=false) String key, + @RequestParam(value="sellerId",required=false,defaultValue = "0")Integer sellerId, + @RequestParam(value="page",required=false,defaultValue = "1")Integer page, + @RequestParam(value="size",required=false,defaultValue = "10")Integer size) { + return new Vo_msg(0,goodsService.seacrh(key,sellerId,page,size)); + } + } diff --git a/src/com/w1hd/zzhnc/controller/pc/PrizeController.java b/src/com/w1hd/zzhnc/controller/pc/PrizeController.java index 20c77c1..f846e4f 100644 --- a/src/com/w1hd/zzhnc/controller/pc/PrizeController.java +++ b/src/com/w1hd/zzhnc/controller/pc/PrizeController.java @@ -1,16 +1,51 @@ package com.w1hd.zzhnc.controller.pc; +import java.util.Date; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; +import com.w1hd.zzhnc.model.Prize; +import com.w1hd.zzhnc.service.PrizeService; +import com.w1hd.zzhnc.vo.Vo_msg; + @Controller @RequestMapping("/prize") public class PrizeController { + @Autowired + PrizeService prizeService; @RequestMapping("/prizeList") public ModelAndView prizeList() { return new ModelAndView("/pc/prize/prizeList"); } + + @RequestMapping(value="/add",method=RequestMethod.POST) + @ResponseBody + public Object prizeList(String name ,Integer num) { + Prize p = new Prize(); + p.setName(name); + p.setNum(num); + p.setCreatetime(new Date()); + p.setDeleted(false); + boolean result = prizeService.add(p); + return new Vo_msg(0, result); + } + + @RequestMapping("/edit") + @ResponseBody + public Object edit(Integer id,String name ,Integer num) { + Prize p = new Prize(); + p.setName(name); + p.setNum(num); + p.setId(id); + boolean result = prizeService.update(p); + return new Vo_msg(0, result); + } } diff --git a/src/com/w1hd/zzhnc/controller/pc/SellerController.java b/src/com/w1hd/zzhnc/controller/pc/SellerController.java index 7098846..49cc54f 100644 --- a/src/com/w1hd/zzhnc/controller/pc/SellerController.java +++ b/src/com/w1hd/zzhnc/controller/pc/SellerController.java @@ -1,15 +1,30 @@ package com.w1hd.zzhnc.controller.pc; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; +import com.w1hd.zzhnc.model.Seller; +import com.w1hd.zzhnc.service.SellerService; +import com.w1hd.zzhnc.vo.Vo_msg; + @Controller @RequestMapping("/seller") public class SellerController { + @Autowired + SellerService sellerService; + @RequestMapping("/sellerList") public ModelAndView sellerList() { return new ModelAndView("/pc/seller/sellerList"); } + + @RequestMapping("/update") + public Object update( @RequestBody Seller s) { + boolean b = sellerService.update(s); + return new Vo_msg(0, true); + } } diff --git a/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java b/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java index b2b7300..15a3ec3 100644 --- a/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java +++ b/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java @@ -5,6 +5,7 @@ import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.servlet.ServletException; @@ -21,14 +22,19 @@ import org.theyeasy.weixin.model.WxMiniSessionInfo; import org.theyeasy.weixin.service.WxMiniService; import org.theyeasy.weixin.util.WxMiniUtil; +import com.beust.jcommander.internal.Maps; import com.w1hd.zzhnc.controller.pc.BaseController; import com.w1hd.zzhnc.dao.FansDao; import com.w1hd.zzhnc.model.Articles; +import com.w1hd.zzhnc.model.Banner; import com.w1hd.zzhnc.model.Fans; import com.w1hd.zzhnc.service.ActivityService; import com.w1hd.zzhnc.service.ArticleService; +import com.w1hd.zzhnc.service.BannerService; import com.w1hd.zzhnc.service.FansService; +import com.w1hd.zzhnc.service.GoodsService; import com.w1hd.zzhnc.util.RedisUtil; +import com.w1hd.zzhnc.vo.MiniHomeVO; import com.w1hd.zzhnc.vo.Vo_msg; @Controller @@ -40,16 +46,14 @@ public class WxMiniController extends BaseController { @Autowired WxMiniService wxMiniService; - @Autowired ArticleService articleService; - + @Autowired ActivityService activityService; - + @Autowired FansDao fansDao; - @RequestMapping("/wxmsg") public void WxMsg(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -91,21 +95,17 @@ public class WxMiniController extends BaseController { @RequestMapping("/login") // 购房助手登录 double lng,double lat public @ResponseBody Vo_msg login(@RequestParam(value = "code") String code, - @RequestParam(value = "shareFansId") Integer shareFansId, @RequestParam(value = "saleId") Integer saleId, - @RequestParam(value = "nickname") String nickname, @RequestParam(value = "logo") String logo, - @RequestParam(value = "lng") double lng, @RequestParam(value = "lat") double lat) { + @RequestParam(value = "shareId") Integer shareId, @RequestParam(value = "nickname") String nickname, + @RequestParam(value = "logo") String logo, @RequestParam(value = "lng") double lng, + @RequestParam(value = "lat") double lat) { logger.info("小程序登录:code=" + code); // 取openid WxMiniSessionInfo sessionInfo = WxMiniUtil.jscode2session(code); // 添加粉丝记录 - Fans fans = fansService.addFans(sessionInfo, shareFansId, nickname, logo, saleId, lng, lat); + Fans fans = fansService.addFans(sessionInfo, shareId, nickname, logo, lng, lat); if (fans != null) { - String salephone = "4008718710";// 默认电话 - Map map = new HashMap<>(); - map.put("fansid", fans.getId()); map.put("miniOpenId", sessionInfo.getOpenid()); - RedisUtil.setFansChatStatus(fans.getId(), 1); return new Vo_msg(0, map); } else { return new Vo_msg(-1, "登录失败,服务器异常"); @@ -147,7 +147,6 @@ public class WxMiniController extends BaseController { return WxMiniUtil.refreshToken(); } - // 文章列表 @RequestMapping(value = "/getArticlesList") @ResponseBody @@ -176,68 +175,99 @@ public class WxMiniController extends BaseController { } } -// //用户隐藏了小程序时调用此接口,将会向用户发送一个小程序卡片,一天只发送一次。 -// @RequestMapping(value = "/leave") -// @ResponseBody -// public String leaveMini(@RequestParam(value = "fansId") Integer fansId) { -// if (fansId<1) return "Failed: fansId < 1"; -// -// Activity activitySetting = activityService.getActivitySetting(); -// if (activitySetting != null && activitySetting.getStatus() == ActivityStatus.进行中.getIndex() ) //抽奖活动进行中 -// { -// Fans fans = fansDao.selectByPrimaryKey(fansId); -// if (null==fans) return "Failed:fans is null"; -// -// //一天最多发送一次 -// SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd"); -// Date last = fans.getLastSendProgram(); -// if(last!=null && fmt.format(last).equals(fmt.format(DateTime.now().toDate()))) return "faild: allowed send one time everyday."; -// -// //发送小程序卡片 -// String media_id = RedisUtil.get("zzhnc_leave_program_media_id"); -// String thumb_url = RedisUtil.get("zzhnc_leave_program_thumb_url"); -// -// if (null==media_id || media_id.length()<1 || null==thumb_url || thumb_url.length()<1) -// { -// //获取默认首页的海报 -// Example example = new Example(Postertemplet.class); -// example.createCriteria().andEqualTo("postertype", 2).andEqualTo("deleted",false); -// java.util.List posterList = postertempletDao.selectByExample(example); -// if (posterList.size() < 1) return "failed: Postertemplet Img not exists!"; -// thumb_url = posterList.get(0).getImgurl(); -// -// Vo_msg imgMsg = WxMiniUtil.uploadImage(thumb_url, false); -// if (imgMsg.code==0) -// { -// media_id = imgMsg.data.toString(); -// RedisUtil.set("zzhnc_leave_program_media_id",media_id,60*60); -// RedisUtil.set("zzhnc_leave_program_thumb_url",thumb_url,60*60); -// } -// else -// { -// return "failed: upload media img failed,errmsg=" + imgMsg.msg; -// } -// } -// -// -// String result = WxMiniUtil.sendCustoMiniprogrampage(fans.getMiniopenid(), "买房就找万小二","pages/openAnimation/openAnimation", thumb_url, media_id); -// System.out.println("粉丝离开小程序时发送小程序卡片:" + result); -// fans.setLastSendProgram(DateTime.now().toDate()); -// fansDao.updateByPrimaryKeySelective(fans); -// return result; -// } -// return "ok"; -// } -// - //清除小程序卡片的media_id的方法 + // //用户隐藏了小程序时调用此接口,将会向用户发送一个小程序卡片,一天只发送一次。 + // @RequestMapping(value = "/leave") + // @ResponseBody + // public String leaveMini(@RequestParam(value = "fansId") Integer fansId) { + // if (fansId<1) return "Failed: fansId < 1"; + // + // Activity activitySetting = activityService.getActivitySetting(); + // if (activitySetting != null && activitySetting.getStatus() == + // ActivityStatus.进行中.getIndex() ) //抽奖活动进行中 + // { + // Fans fans = fansDao.selectByPrimaryKey(fansId); + // if (null==fans) return "Failed:fans is null"; + // + // //一天最多发送一次 + // SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd"); + // Date last = fans.getLastSendProgram(); + // if(last!=null && + // fmt.format(last).equals(fmt.format(DateTime.now().toDate()))) return "faild: + // allowed send one time everyday."; + // + // //发送小程序卡片 + // String media_id = RedisUtil.get("zzhnc_leave_program_media_id"); + // String thumb_url = RedisUtil.get("zzhnc_leave_program_thumb_url"); + // + // if (null==media_id || media_id.length()<1 || null==thumb_url || + // thumb_url.length()<1) + // { + // //获取默认首页的海报 + // Example example = new Example(Postertemplet.class); + // example.createCriteria().andEqualTo("postertype", + // 2).andEqualTo("deleted",false); + // java.util.List posterList = + // postertempletDao.selectByExample(example); + // if (posterList.size() < 1) return "failed: Postertemplet Img not exists!"; + // thumb_url = posterList.get(0).getImgurl(); + // + // Vo_msg imgMsg = WxMiniUtil.uploadImage(thumb_url, false); + // if (imgMsg.code==0) + // { + // media_id = imgMsg.data.toString(); + // RedisUtil.set("zzhnc_leave_program_media_id",media_id,60*60); + // RedisUtil.set("zzhnc_leave_program_thumb_url",thumb_url,60*60); + // } + // else + // { + // return "failed: upload media img failed,errmsg=" + imgMsg.msg; + // } + // } + // + // + // String result = WxMiniUtil.sendCustoMiniprogrampage(fans.getMiniopenid(), + // "买房就找万小二","pages/openAnimation/openAnimation", thumb_url, media_id); + // System.out.println("粉丝离开小程序时发送小程序卡片:" + result); + // fans.setLastSendProgram(DateTime.now().toDate()); + // fansDao.updateByPrimaryKeySelective(fans); + // return result; + // } + // return "ok"; + // } + // + // 清除小程序卡片的media_id的方法 @RequestMapping(value = "/cleanProgramMedia") @ResponseBody public String cleanProgramMedia(@RequestParam(value = "code") String code) { - if (!code.equals("nmdzpsmhs")) return "error pwd"; + if (!code.equals("nmdzpsmhs")) + return "error pwd"; RedisUtil.remove("zzhnc_leave_program_media_id"); RedisUtil.remove("zzhnc_leave_program_thumb_url"); return "ok"; } - - + + @Autowired + BannerService bannerService; + + @Autowired + GoodsService goodsService; + + @RequestMapping(value = "/index") + @ResponseBody + public Object index(@RequestParam String openId) { + try { + Map result = Maps.newHashMap(); + List bannerList = bannerService.getAll(); + List homeData = articleService.getHomeData(); + goodsService.getHomeData(); + result.put("banner", bannerList); + MiniHomeVO.getData(homeData, goodsService.getHomeData()); + result.put("data", bannerList); + return new Vo_msg(0, result); + } catch (Exception e) { + return new Vo_msg(-1, "系统繁忙"); + } + + } + } diff --git a/src/com/w1hd/zzhnc/dao/SallerDao.java b/src/com/w1hd/zzhnc/dao/SellerDao.java index 76dc785..246c441 100644 --- a/src/com/w1hd/zzhnc/dao/SallerDao.java +++ b/src/com/w1hd/zzhnc/dao/SellerDao.java @@ -1,8 +1,8 @@ package com.w1hd.zzhnc.dao; -import com.w1hd.zzhnc.model.Saller; +import com.w1hd.zzhnc.model.Seller; import com.w1hd.zzhnc.util.MyMapper; -public interface SallerDao extends MyMapper{ +public interface SellerDao extends MyMapper{ } diff --git a/src/com/w1hd/zzhnc/model/Goods.java b/src/com/w1hd/zzhnc/model/Goods.java index 254f30c..39cdd8c 100644 --- a/src/com/w1hd/zzhnc/model/Goods.java +++ b/src/com/w1hd/zzhnc/model/Goods.java @@ -8,17 +8,18 @@ import javax.persistence.Id; public class Goods { @Id private Integer id; + private Integer sellerId; private String name; private String description; private BigDecimal primePrice; private BigDecimal price; private String imageUrl; - private String bannerUrl; - + private Boolean isHot; + private Boolean isHome; private Date createtime; - private Date updateTime; + private Boolean deleted; public Integer getId() { return id; @@ -227,4 +228,37 @@ public class Goods { public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } + + public Integer getSellerId() { + return sellerId; + } + + public void setSellerId(Integer sellerId) { + this.sellerId = sellerId; + } + + public Boolean getIsHot() { + return isHot; + } + + public void setIsHot(Boolean isHot) { + this.isHot = isHot; + } + + public Boolean getIsHome() { + return isHome; + } + + public void setIsHome(Boolean isHome) { + this.isHome = isHome; + } + + public Boolean getDeleted() { + return deleted; + } + + public void setDeleted(Boolean deleted) { + this.deleted = deleted; + } + } \ No newline at end of file diff --git a/src/com/w1hd/zzhnc/model/Saller.java b/src/com/w1hd/zzhnc/model/Seller.java index e958b31..c3ad9be 100644 --- a/src/com/w1hd/zzhnc/model/Saller.java +++ b/src/com/w1hd/zzhnc/model/Seller.java @@ -4,7 +4,7 @@ import java.util.Date; import javax.persistence.Id; -public class Saller { +public class Seller { @Id private Integer id; private String name; diff --git a/src/com/w1hd/zzhnc/service/ArticleService.java b/src/com/w1hd/zzhnc/service/ArticleService.java index 7001179..914b2d0 100644 --- a/src/com/w1hd/zzhnc/service/ArticleService.java +++ b/src/com/w1hd/zzhnc/service/ArticleService.java @@ -56,10 +56,6 @@ public class ArticleService{ @Autowired ArticlesDao articleDao; - /* (非 Javadoc) - * Description: - * @see com.w1hd.zzhnc.service.ArticleService#getArticlesList(java.lang.Integer, java.lang.Integer, java.lang.String) - */ public PageResults getArticlesList(Integer page, Integer pagesize, String keyword) { if(StringUtil.isZearoOrNull(pagesize))pagesize=10; @@ -79,11 +75,6 @@ public class ArticleService{ pageresult.setPageSize(pagesize); return pageresult; } - - /* (非 Javadoc) - * Description: - * @see com.w1hd.zzhnc.service.ArticleService#addArticle(java.lang.String, java.lang.String, java.lang.String) - */ public String addArticle(String title, String content, String imgurl) { // TODO Auto-generated method stub @@ -135,4 +126,13 @@ public class ArticleService{ } } + public List getHomeData() { + Example example = new Example(Articles.class); + example.createCriteria().andEqualTo("deleted", false); + RowBounds row = new RowBounds(0 , 5); + example.setOrderByClause(" id desc "); + List list = articleDao.selectByExampleAndRowBounds(example, row); + return list; + } + } diff --git a/src/com/w1hd/zzhnc/service/BannerService.java b/src/com/w1hd/zzhnc/service/BannerService.java index 678c989..179acd3 100644 --- a/src/com/w1hd/zzhnc/service/BannerService.java +++ b/src/com/w1hd/zzhnc/service/BannerService.java @@ -2,6 +2,7 @@ package com.w1hd.zzhnc.service; import java.util.List; +import org.apache.ibatis.session.RowBounds; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,4 +30,9 @@ public class BannerService { public List getAll() { return bannerDao.selectAll(); } + + public List getAll(int page, int size) { + List all = bannerDao.selectByRowBounds(new Banner(), new RowBounds(page, size)); + return all; + } } diff --git a/src/com/w1hd/zzhnc/service/FansService.java b/src/com/w1hd/zzhnc/service/FansService.java index 6c2f286..b0c07d4 100644 --- a/src/com/w1hd/zzhnc/service/FansService.java +++ b/src/com/w1hd/zzhnc/service/FansService.java @@ -60,8 +60,6 @@ public class FansService { @Autowired FansDao fansDao; - - public PageResults getFansList(Integer page, String keyword) { List list = fansDao.getFansList((page - 1) * 10, 10, keyword); int total = fansDao.getFansCount(keyword); @@ -72,7 +70,7 @@ public class FansService { pageResults.setTotal(total); return pageResults; } - + public Fans getFansByMiniOpenid(String miniOpenid) { Example example = new Example(Fans.class); example.createCriteria().andEqualTo("miniopenid", miniOpenid); @@ -83,16 +81,11 @@ public class FansService { return null; } - public Fans getFansById(Integer id) { return fansDao.selectByPrimaryKey(id); } - - - - public Fans addFans(String miniOpenid) { Fans fans = getFansByMiniOpenid(miniOpenid); if (null != fans) @@ -111,21 +104,14 @@ public class FansService { } - - public Fans addFans(WxMiniSessionInfo info, Integer shareFansId, String nickname, String logo, Integer salesid, - double lng, double lat) { + public Fans addFans(WxMiniSessionInfo info, Integer shareFansId, String nickname, String logo, double lng, + double lat) { if (info == null) return null; if (Strings.isNullOrEmpty(info.getOpenid())) return null; - // 通过转发进来,获取转发者的销售id - if (!StringUtil.isZearoOrNull(shareFansId)) { - Fans sharefans = getFansById(shareFansId); - - } - // 判断粉丝是否存在 System.out.println("miniopenid:" + info.getOpenid()); Fans myfans = getFansByMiniOpenid(info.getOpenid()); @@ -139,13 +125,13 @@ public class FansService { fans.setMiniopenid(info.getOpenid()); fans.setParentfansid(shareFansId); fans.setLogo(logo); + fans.setGoodsId(shareFansId); fans.setNickname(nickname); fans.setFanstype(1); fans.setLng(lng); fans.setLat(lat); JSONObject locationResult = CusAccessObjectUtil2.locationResult(lng, lat); - if (null!=locationResult) - { + if (null != locationResult) { fans.setProvince(CusAccessObjectUtil2.getProvince(locationResult)); fans.setCity(CusAccessObjectUtil2.getCity(locationResult)); fans.setDistrict(CusAccessObjectUtil2.getDistrict(locationResult)); @@ -178,7 +164,6 @@ public class FansService { return fans; } - public void updateFans(Fans fans) { fansDao.updateByPrimaryKeySelective(fans); } diff --git a/src/com/w1hd/zzhnc/service/GoodsService.java b/src/com/w1hd/zzhnc/service/GoodsService.java index 984bf34..79550fd 100644 --- a/src/com/w1hd/zzhnc/service/GoodsService.java +++ b/src/com/w1hd/zzhnc/service/GoodsService.java @@ -1,8 +1,58 @@ package com.w1hd.zzhnc.service; +import java.sql.Date; +import java.util.List; + +import org.apache.ibatis.session.RowBounds; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.testng.util.Strings; + +import com.w1hd.zzhnc.dao.GoodsDao; +import com.w1hd.zzhnc.model.Goods; +import com.w1hd.zzhnc.util.PageResults; + +import tk.mybatis.mapper.entity.Example; +import tk.mybatis.mapper.entity.Example.Criteria; @Service public class GoodsService { + @Autowired + GoodsDao goodsDao; + + public List getHomeData() { + Example ex = new Example(Goods.class); + ex.createCriteria().andEqualTo("deleted", false).andEqualTo("isHome", true); + RowBounds r = new RowBounds(0, 5); + return goodsDao.selectByExampleAndRowBounds(ex, r); + } + + public Goods update(Goods goods) { + goods.setUpdateTime(new Date(System.currentTimeMillis())); + if (goods.getId() == null || goods.getId() == 0) { + goods.setCreatetime(new Date(System.currentTimeMillis())); + goodsDao.insert(goods); + } else { + goodsDao.updateByPrimaryKey(goods); + } + return goods; + } + + public PageResults seacrh(String key, Integer sellerId, Integer page, Integer size) { + Example ex = new Example(Goods.class); + Criteria c = ex.createCriteria(); + if (!Strings.isNullOrEmpty(key)) { + c.andCondition(" (description like \"%" + key + "%\" or name like \"%" + key + "%\")"); + } + if (sellerId != null && sellerId > 0) { + c.andEqualTo("sellerId", sellerId); + } + c.andEqualTo("deleted", false); + RowBounds row = new RowBounds(page, size); + List list = goodsDao.selectByExampleAndRowBounds(ex, row); + PageResults pageResults = new PageResults<>(); + return pageResults; + } + } diff --git a/src/com/w1hd/zzhnc/service/PrizeService.java b/src/com/w1hd/zzhnc/service/PrizeService.java index d9ca3ed..ebe135f 100644 --- a/src/com/w1hd/zzhnc/service/PrizeService.java +++ b/src/com/w1hd/zzhnc/service/PrizeService.java @@ -1,8 +1,23 @@ package com.w1hd.zzhnc.service; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.w1hd.zzhnc.dao.PrizeDao; +import com.w1hd.zzhnc.model.Prize; + @Service public class PrizeService { + @Autowired + PrizeDao prizeDao; + + public boolean add(Prize prize) { + return prizeDao.insert(prize) > 0; + } + + public boolean update(Prize p) { + return prizeDao.updateByPrimaryKeySelective(p) > 0; + } + } diff --git a/src/com/w1hd/zzhnc/service/SallerService.java b/src/com/w1hd/zzhnc/service/SallerService.java deleted file mode 100644 index 99ac74f..0000000 --- a/src/com/w1hd/zzhnc/service/SallerService.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.w1hd.zzhnc.service; - -import org.springframework.stereotype.Service; - -@Service -public class SallerService { - -} diff --git a/src/com/w1hd/zzhnc/service/SellerService.java b/src/com/w1hd/zzhnc/service/SellerService.java new file mode 100644 index 0000000..32d1f9d --- /dev/null +++ b/src/com/w1hd/zzhnc/service/SellerService.java @@ -0,0 +1,22 @@ +package com.w1hd.zzhnc.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.w1hd.zzhnc.dao.SellerDao; +import com.w1hd.zzhnc.model.Seller; + +@Service +public class SellerService { + @Autowired + SellerDao sellerDao; + + public boolean update(Seller s) { + if (s.getId() == null) { + return sellerDao.insert(s) > 0; + } else { + return sellerDao.updateByPrimaryKey(s) > 0; + } + } + +} diff --git a/src/com/w1hd/zzhnc/util/PageResults.java b/src/com/w1hd/zzhnc/util/PageResults.java index 53b5462..d53b7f6 100644 --- a/src/com/w1hd/zzhnc/util/PageResults.java +++ b/src/com/w1hd/zzhnc/util/PageResults.java @@ -83,7 +83,6 @@ public class PageResults { } - public int getSum() { return sum; } diff --git a/src/com/w1hd/zzhnc/vo/MiniHomeVO.java b/src/com/w1hd/zzhnc/vo/MiniHomeVO.java new file mode 100644 index 0000000..c0a3afa --- /dev/null +++ b/src/com/w1hd/zzhnc/vo/MiniHomeVO.java @@ -0,0 +1,92 @@ +package com.w1hd.zzhnc.vo; + +import java.util.Date; +import java.util.List; + +import com.google.common.base.Strings; +import com.google.common.collect.Lists; +import com.w1hd.zzhnc.model.Articles; +import com.w1hd.zzhnc.model.Goods; + +public class MiniHomeVO { + + private Integer id; + private Integer type; + private String title; + private String subTitle; + private String imageUrl; + private Date createTime; + public Integer getId() { + return id; + } + public void setId(Integer id) { + this.id = id; + } + public Integer getType() { + return type; + } + public void setType(Integer type) { + this.type = type; + } + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public String getSubTitle() { + return subTitle; + } + public void setSubTitle(String subTitle) { + this.subTitle = subTitle; + } + public String getImageUrl() { + return imageUrl; + } + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + public Date getCreateTime() { + return createTime; + } + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public static List getData(List homeData,List goodsList){ + MiniHomeVO item = null; + List data = Lists.newArrayList(); + for(Articles a:homeData) { + item = new MiniHomeVO(); + item.setType(1); + item.setTitle(a.getTitle()); + item.setImageUrl(a.getImgurl()); + item.setCreateTime(a.getCreatedtime()); + String content = a.getContent(); + if(Strings.isNullOrEmpty(content)) { + if(content.length()>20) { + item.setSubTitle(content.substring(0, 15)+"..."); + } + } + data.add(item); + } + + for(Goods g :goodsList) { + item = new MiniHomeVO(); + item.setType(2); + item.setTitle(g.getName()); + item.setImageUrl(g.getBannerUrl()); + item.setCreateTime(g.getCreatetime()); + String content = g.getDescription(); + if(Strings.isNullOrEmpty(content)) { + if(content.length()>20) { + item.setSubTitle(content.substring(0, 15)+"..."); + } + } + data.add(item); + } + + return data; + } + +}