第一次接手电商项目在接口端学习到一个接口
代码如下:
package com.hgj.web.admin.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageInfo;
import com.hgj.common.web.RequestUtil;
import com.hgj.web.entity.SsProduct;
@Controller
@RequestMapping(value = "/base")
public class BaseController {
@Autowired
SqlSessionTemplate sqlSessionTemplate;
@RequestMapping(method = {RequestMethod.GET,RequestMethod.POST}, value = { "/jsp/{jspName}" })
public String toJsp(@PathVariable("jspName") String jspName) {
return jspName;
}
/**
* 动态查询接口
* @param request
* @param statement
* @return
*/
@RequestMapping(method = {RequestMethod.GET,RequestMethod.POST}, value = { "/quickQuery/{statement}" })
@ResponseBody
public Object quickQuery(HttpServletRequest request,
@PathVariable("statement") String statement ) {
List resultList=sqlSessionTemplate.selectList(statement, RequestUtil.parse(request));
String currentPage = request.getParameter("currentPage");
String pageSize = request.getParameter("pageSize");
if(StringUtils.isNumeric(currentPage)&&StringUtils.isNumeric(pageSize)) {
return new PageInfo(resultList);
}else {
Map<String, Object> map = new HashMap<String, Object>();
map.put("resultList", resultList);
return map;
}
}
}
这端代码重点在于
import org.mybatis.spring.SqlSessionTemplate;
此-处-为-分--------------------隔----------------------------------符
二丶service层灵活新写法
这里是接口层
package com.hgj.web.admin.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hgj.common.support.PromptException;
import com.hgj.common.web.In;
import com.hgj.web.config.StringUtils;
import com.hgj.web.dto.*;
import com.hgj.web.entity.ProductInfo;
import com.hgj.web.entity.SysRole;
import com.hgj.web.entity.SysUser;
import com.hgj.web.service.ProductInfoService;
import com.hgj.web.service.UserService;
import com.hgj.web.support.Constant;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.util.StringUtil;
import java.util.ArrayList;
import java.util.List;
/**
*
*
*/
@RestController
@RequestMapping("/product/")
@Validated
public class ProductInfoController {
@Autowired
private ProductInfoService productInfoService;
@Autowired
private UserService userService;
/**
* 审核不通过端口
* @param productInfoDto
* @param user
*/
@RequestMapping("noverifyProduct")
public void NoverifyProduct(ProductInfoDto productInfoDto,@In SysUser user) {
ResultDto result = new ResultDto();
UserDto userDto = new UserDto();
userDto.setId(user.getId());
userDto.setLoginName(user.getLoginName());
productInfoService.NoverifyProduct(productInfoDto,userDto);
}
/**
* 审核通过
*/
@RequestMapping("verifiedProduct")
public void verified(ProductInfoDto productInfoDto,@In SysUser user){
UserDto userDto = new UserDto();
userDto.setId(user.getId());
userDto.setLoginName(user.getLoginName());
userDto.setPassword(user.getPassword());
productInfoService.verifyProduct(productInfoDto,userDto);
}
/**
* 管理者上传产品
* @param productInfoDto
* @return
*/
@RequestMapping("uploadProductInfo")
public ResultDto uploadProductInfo(@RequestBody ProductInfoDto productInfoDto,@In SysUser user) {
ResultDto result = new ResultDto();
UserDto userDto = new UserDto();
userDto.setId(user.getId());
userDto.setLoginName(user.getLoginName());
ProductInfo productInfo = productInfoService.uploadProductInfo(productInfoDto,userDto);
productInfoDto.setId(productInfo.getId());
if(productInfoDto.getAddZone()==1){
productInfoService.addPreferentialForm(productInfoDto.getId(),userDto);
}
if(productInfoDto.getAddZone()==2){
productInfoService.addAppointment(productInfoDto,userDto);
}
/* if(productInfoDto.getAddZone()==3){
ProductSeckillDto productSeckillDto = productInfoService.getSeckillRelationDtoById(productInfoDto.getId());
if(productSeckillDto!=null){
throw new PromptException("重复添加!");
}
productInfoService.addUserRecommand(productInfoDto.getId(),userDto);
}
if(productInfoDto.getAddZone()==4){
productInfoService.addBoutiqueZone(productInfoDto.getId(),userDto);
}
*/
return result;
}
@RequestMapping("selectAllProductByWhere")
public List<ProductListDto> selectAllProductByWhere(ProductListDto productListDto,PageDto pageDto ,@In SysUser user) {
List<SysRole> sysRoles = userService.getSysRoleByUserId(user.getLoginName());
if(null!=sysRoles&&sysRoles.size()>0&&sysRoles.get(0).getRoleCode().equals("productManager")){
productListDto.setCreateUser(user.getId().toString());
}
if(null!=pageDto.getCurrentPage()&&null!=pageDto.getPageSize()){
PageHelper.startPage(pageDto.getCurrentPage(),pageDto.getPageSize());
}
if(productListDto.getAddZone()!=null&&productListDto.getAddZone()==6){
return productInfoService.selectAllProductByPtysixpeWhere(productListDto);
}
if(productListDto.getAddZone()!=null&&productListDto.getAddZone()!=1){
return productInfoService.selectAllProductByPtypeWhere(productListDto);
}
return productInfoService.selectAllProductByWhere(productListDto);
}
/**
*
修改审核产品信息端口
*/
@RequestMapping("updateVerifyProduct")
public void creaupdateVerifyProductteInfoImg(@RequestBody ProductInfoDto productInfoDto,@In SysUser user) {
UserDto userDto = new UserDto();
userDto.setId(user.getId());
userDto.setLoginName(user.getLoginName());
productInfoService.updateVerifyProduct(productInfoDto,userDto);
}
/**
* 下架产品
* @param ids
* @param user
* @return
*/
@RequestMapping("downProduct")
public void downProduct(@RequestBody List<Integer> ids,@In SysUser user) {
UserDto userDto = new UserDto();
userDto.setId(user.getId());
productInfoService.downProduct(ids,userDto);
}
/**
* 上传产品
*/
@RequestMapping("uploadProduct")
public void uploadProduct(@RequestBody List<Integer> ids) {
productInfoService.uploadProduct(ids);
}
/**
* 添加品牌
* @param productInfoDto
* @param user
*/
@RequestMapping("uploadProductByZone")
public void uploadProduct(@RequestBody ProductInfoDto productInfoDto,@In SysUser user) {
ResultDto result = new ResultDto();
UserDto userDto = new UserDto();
userDto.setId(user.getId());
userDto.setLoginName(user.getLoginName());
ProductSeckillDto dto = new ProductSeckillDto();
dto.setId(productInfoDto.getId());
ProductSeckillDto productSeckillDto = new ProductSeckillDto();
if(productInfoDto.getAddZone()!=null){
if(productInfoDto.getAddZone()==2||productInfoDto.getAddZone()==3
||productInfoDto.getAddZone()==4||productInfoDto.getAddZone()==5){
dto.setpType(productInfoDto.getAddZone());
productSeckillDto = productInfoService.getSeckillRelationDtoById(dto);
}
if(productInfoDto.getAddZone()==4){
if(productSeckillDto!=null&&productSeckillDto.getpType()==4){
throw new PromptException("重复添加!");
}
//是否放入特惠区
productInfoService.addPreferentialForm(productInfoDto.getId(), userDto );
}
if(productInfoDto.getAddZone()==6){
if(productSeckillDto!=null&&productSeckillDto.getpType()==6){
throw new PromptException("重复添加!");
}
productInfoService.addAppointment(productInfoDto,userDto);
}
if(productInfoDto.getAddZone()==2){
if(productSeckillDto!=null&&productSeckillDto.getpType()==2){
throw new PromptException("重复添加!");
}
productInfoService.addUserRecommand(productInfoDto.getId(),userDto);
}
if(productInfoDto.getAddZone()==5){
if(productSeckillDto!=null&&productSeckillDto.getpType()==5){
throw new PromptException("重复添加!");
}
if(productInfoDto.getAddProductIds().size()<1){
throw new PromptException("附赠产品最少为1件!");
}
if(productInfoDto.getAddProductIds().size()>2){
throw new PromptException("附赠产品最多为2件!");
}
productInfoService.addBoutiqueZone(productInfoDto,userDto);
}
if(productInfoDto.getAddZone()==3){
if(productSeckillDto!=null&&productSeckillDto.getpType()==3){
throw new PromptException("重复添加!");
}
productInfoService.updateGiftPoints(productInfoDto,userDto);
}
}
productInfoService.updateProductInfoTo(productInfoDto.getId());
}
/**
* 添加优惠
* @param id
* @param user
*/
@RequestMapping("addPreferentialForm")
public void addPreferentialForm(@RequestBody Integer id,@In SysUser user) {
ResultDto result = new ResultDto();
UserDto userDto = new UserDto();
userDto.setId(user.getId());
userDto.setLoginName(user.getLoginName());
productInfoService.addPreferentialForm(id,userDto);
}
//Appointment 约定,预约
@RequestMapping("addAppointment")
public void addAppointment(@RequestBody Integer id,@In SysUser user) {
UserDto userDto = new UserDto();
userDto.setId(user.getId());
ProductInfoDto productInfoDto = new ProductInfoDto();
productInfoDto.setId(id);
productInfoService.addAppointment(productInfoDto,userDto);
}
/**
* 用户推荐
* @param id
* @param user
*/
@RequestMapping("addUserRecommand")
public void addUserRecommand(@RequestBody Integer id,@In SysUser user) {
ProductSeckillDto dto = new ProductSeckillDto();
dto.setId(id);
dto.setpType(2);
ProductSeckillDto productSeckillDto = productInfoService.getSeckillRelationDtoById(dto);
if(productSeckillDto!=null){
throw new PromptException("重复添加!");
}
UserDto userDto = new UserDto();
userDto.setId(user.getId());
userDto.setLoginName(user.getLoginName());
productInfoService.addUserRecommand(id,userDto);
}
@RequestMapping("deleteUploadProductDetail")
public void deleteUploadProductDetail(@RequestBody ProductInfoImgInfo productInfoImgInfo) {
productInfoService.deleteUploadProductDetail(productInfoImgInfo);
}
@RequestMapping("deleteProductGraph")
public void deleteProductGraph(@RequestBody ProductGuidedGraphDto productGuidedGraphDto) {
productInfoService.deleteProductGraph(productGuidedGraphDto);
}
@RequestMapping("addShopProduct")
public void addShopProduct(@RequestBody ShopProductDto shopProductDto,@In SysUser user) {
productInfoService.addShopProduct(shopProductDto,user);
}
/**
* 根据用户查詢品牌
* @param user
* @return
*/
@RequestMapping("selectBrandNameByUser")
public List<ProductBrandDto> selectBrandNameByUser(@In SysUser user){
return productInfoService.selectBrandNameByUser(user);
}
/**
* 区域信息
* @param SsUserDto
* @param user
* @return
*/
@RequestMapping("areaInfoList")
public List<AreaManagerDto> areaInfoList(SsUserDto SsUserDto,@In SysUser user){
return productInfoService.areaInfoList(SsUserDto,user);
}
}
这里是service处理层
package com.hgj.web.service.impl;
import com.hgj.common.support.PromptException;
import com.hgj.web.dao.BaseDao;
import com.hgj.web.dto.*;
import com.hgj.common.util.HttpRequest;
import com.hgj.common.util.OtcHttpMsg;
import com.hgj.web.entity.*;
import com.hgj.web.service.ProductInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.util.StringUtil;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("productInfoService")
public class ProductInfoServiceImpl implements ProductInfoService {
@Autowired
private BaseDao baseDao;
@Value("${file.server.ip}")
private String fileIp;
/**
* 审核不通过
*/
@Override
public void NoverifyProduct(ProductInfoDto productInfoDto,UserDto userDto) {
// TODO Auto-generated method stub
ProductInfo productInfo = new ProductInfo();
productInfo.setId(productInfoDto.getId());
productInfo.setLastUpdateUser(userDto.getId());
productInfo.setIsDelete(3);
baseDao.update("productInfoMapper.noverifyProduct", productInfo);
}
//审核通过的
@Override
public void verifyProduct(ProductInfoDto productInfoDto,UserDto userDto) {
// TODO Auto-generated method stub
ProductInfo productInfo = new ProductInfo();
productInfo.setId(productInfoDto.getId());
productInfo.setLastUpdateUser(userDto.getId());
productInfo.setIsDelete(0);
baseDao.update("productInfoMapper.noverifyProduct", productInfo);
}
@Override
public void updateGiftPoints(ProductInfoDto productInfoDto,UserDto userDto) {
// TODO Auto-generated method stub
//计算积分
ProductInfoDto productInfo = baseDao.queryForObject("productInfoMapper.selectProductInfoById", productInfoDto.getId());
Double productPrice = productInfoDto.getProductPrice();
if(productPrice!=null){
String paramName ="gift_point_rate";
ParamEntity entity = baseDao.queryForObject("paramEntityMapper.selectParamByName", paramName);
double giftPoints = productPrice * entity.getParamValue();
productInfoDto.setGiftPoints(productPrice-giftPoints-productInfo.getCostPrice());
productInfoDto.setProductPrice(productPrice);
ProductSeckillDto productSeckillDto = new ProductSeckillDto();
productSeckillDto.setProductId(productInfoDto.getId());
productSeckillDto.setCreateDate(new Date());
productSeckillDto.setCreateUser(userDto.getId());
productSeckillDto.setIsState(1);
productSeckillDto.setpType(3);
int id =productInfoDto.getId();
ProductSeckillDto productSeckillDto2=baseDao.queryForObject("productInfoMapper.selectProductIdByProductId", id);
if(productSeckillDto2==null){
baseDao.insert("productInfoMapper.insertUserRecommand", productSeckillDto);
}
baseDao.update("productInfoMapper.updateVerifyProduct", productInfoDto);
}
}
@Override
public void addBoutiqueZone(ProductInfoDto productInfoDto, UserDto userDto) {
// TODO Auto-generated method stub
ProductSeckillDto productSeckillDto=new ProductSeckillDto();
productSeckillDto.setProductId(productInfoDto.getId());
productSeckillDto.setCreateDate(new Date());
productSeckillDto.setIsState(1);
productSeckillDto.setCreateUser(userDto.getId());
productSeckillDto.setpType(5);
for(Integer productId : productInfoDto.getAddProductIds()){
BonusProductDto bonusProductDto = new BonusProductDto();
bonusProductDto.setProductId(productInfoDto.getId());
bonusProductDto.setIsDelete(0);
bonusProductDto.setBonusProductId(productId);
bonusProductDto.setCreateUser(userDto.getId());
baseDao.insert("productInfoMapper.insertBonusProduct", bonusProductDto);
}
baseDao.insert("productInfoMapper.insertUserRecommand", productSeckillDto);
baseDao.update("productInfoMapper.updateUserRecommandPtype", productInfoDto);
}
/**
* 管理员上产品
*/
@Override
public ProductInfo uploadProductInfo(ProductInfoDto productInfoDto,UserDto userDto) {
// TODO Auto-generated method stub
// 添加属性到ss_product_attr
if (StringUtils.isNotEmpty(productInfoDto.getAttrIds())) {
String[] attrsId = productInfoDto.getAttrIds().split(",");
//4,7,10
for (int i = 0; i < attrsId.length; i++) {
String attr = attrsId[i].trim();
Map<String,Object> map = new HashMap<String,Object>();
map.put("attrId", attr);
map.put("productId", productInfoDto.getProductId());
List<ProductAttrDto> productAttrDto1 =baseDao.queryForList("productInfoMapper.selectProductAttrByProductId", map);
if(productAttrDto1==null || productAttrDto1.size()==0){
ProductAttrDto productAttrDto = new ProductAttrDto();
productAttrDto.setAttrId(Integer.parseInt(attr));
productAttrDto.setProductId(productInfoDto.getProductId());
productAttrDto.setCreateDate(new Date());
productAttrDto.setCreateUser(userDto.getId());
baseDao.insert("productInfoMapper.insertProductAttr", productAttrDto);
}
}
}
String url = "";
if(StringUtils.isNotEmpty(productInfoDto.getComparePrice())){
OtcHttpMsg result = HttpRequest.sendPost("http://"+fileIp+"/fileUpload/UploadQrCode", "qrCode=" + productInfoDto.getComparePrice());
if (result !=null) {
url = result.getJsonData().getString("url");
}
}
ProductInfo productInfo = new ProductInfo();
productInfo.setpId(productInfoDto.getProductId());
productInfo.setAttrs(productInfoDto.getAttrIds());
productInfo.setProductTitle(productInfoDto.getProductTitle());
productInfo.setProductPrice(productInfoDto.getProductPrice());
productInfo.setCostPrice(productInfoDto.getCostPrice());
productInfo.setTransportCost(productInfoDto.getTransportCost());
productInfo.setLeastPurchase(productInfoDto.getLeastPurchase());
productInfo.setOriginalPrice(productInfoDto.getProductPrice());
productInfo.setCreateUser(userDto.getId());
productInfo.setStock(productInfoDto.getStock());
productInfo.setIsDelete(2);
productInfo.setGiftPoints(0.0);
productInfo.setComparePrice(productInfoDto.getComparePrice());
productInfo.setIconUrl(productInfoDto.getIconUrl().replace("http://"+fileIp+"/", ""));
productInfo.setPurchaseAmount(productInfoDto.getPurchaseAmount());
productInfo.setMaxOrder(productInfoDto.getMaxOrder());
ProductInfo productInfoReturn = baseDao.insert("productInfoMapper.insertUploadProduct", productInfo);
ProductInfoExtendDto productInfoExtendDto = new ProductInfoExtendDto();
productInfoExtendDto.setProductStock(productInfoDto.getStock());
productInfoExtendDto.setProductId(productInfo.getId());
productInfoExtendDto.setCreateUser(userDto.getLoginName());
baseDao.insert("productInfoMapper.insertUploadProductExtend", productInfoExtendDto);
productInfo.setDetailPictrue(productInfoDto.getDetailPictrue());
productInfoDto.getImgDetail().setSort(2);
productInfoDto.getImgDetail().setCreateUser(userDto.getId());
productInfoDto.getImgDetail().setpId(productInfoExtendDto.getProductId());
if (!"".equals(productInfoDto.getImgDetail())) {
productInfoDto.getImgDetail().setImgUrl(productInfoDto.getImgDetail().getImgUrl().replace("http://"+fileIp+"/", ""));
}
baseDao.insert("productInfoMapper.insertUploadProductDetail", productInfoDto.getImgDetail());
if(StringUtils.isNotEmpty(url)){
ProductInfoImgInfo productInfoImgInfo = new ProductInfoImgInfo();
productInfoImgInfo.setCreateUser(userDto.getId());
productInfoImgInfo.setImgUrl(url);
productInfoImgInfo.setImgHeight(328);
productInfoImgInfo.setImgWidth(750);
productInfoImgInfo.setSort(1);
productInfoImgInfo.setpId(productInfoExtendDto.getProductId());
baseDao.insert("productInfoMapper.insertProductInfoDetail", productInfoImgInfo);
}
if (!"".equals(productInfoDto.getImgUrl())) {
String[] productGraph = productInfoDto.getImgUrl().split(",");
ProductGuidedGraphDto graphDto;
graphDto = new ProductGuidedGraphDto();
for (int i = 0; i < productGraph.length; i++) {
if (productGraph[i] != null && !"".equals(productGraph[i])) {
String productGuideGraph = productGraph[i].trim();
graphDto.setProductId(productInfo.getId());
graphDto.setImgUrl(productGuideGraph.replace("http://"+fileIp+"/", ""));
graphDto.setSort(i);
graphDto.setCreateUser(userDto.getId());
baseDao.insert("productInfoMapper.insertProductGraph", graphDto);
}
}
}
return productInfoReturn;
}
@Override
public void deleteUploadProductDetail(ProductInfoImgInfo productInfoImgInfo) {
baseDao.delete("productInfoMapper.deleteUploadProductDetail", productInfoImgInfo);
}
@Override
public void deleteProductGraph(ProductGuidedGraphDto productGuidedGraphDto) {
baseDao.delete("productInfoMapper.deleteProductGraph", productGuidedGraphDto);
}
@Override
public void addShopProduct(ShopProductDto shopProductDto, SysUser user) {
List<Integer> ids = shopProductDto.getIds();
List<Integer> cuont = baseDao.queryForList("shopMapper.selectShopProductByIds", shopProductDto);
if(cuont!=null&&cuont.size()>0){
Map paramMap1 = new HashMap();
paramMap1.put("ids", cuont);
baseDao.update("shopMapper.upShopProductByIds", paramMap1);
for (int i = 0; i < cuont.size(); i++) {
Map paramMap = new HashMap();
paramMap.put("id", cuont.get(i));
paramMap.put("createUser", user.getId());
ProductInfo productInfo = (ProductInfo) baseDao.queryForObject("productInfoMapper.selectpurByid", paramMap);
paramMap.put("productId", cuont.get(i));
paramMap.put("userId", shopProductDto.getUserId());
paramMap.put("orderAmount", productInfo.getPurchaseAmount());
}
}
ids.removeAll(cuont);
for (int i = 0; i < ids.size(); i++) {
Map paramMap = new HashMap();
paramMap.put("id", ids.get(i));
paramMap.put("createUser", user.getId());
ProductInfo productInfo = (ProductInfo) baseDao.queryForObject("productInfoMapper.selectpurByid", paramMap);
paramMap.put("productId", ids.get(i));
paramMap.put("userId", shopProductDto.getUserId());
paramMap.put("orderAmount", productInfo.getPurchaseAmount());
baseDao.insert("shopMapper.insertShopProduct", paramMap);
baseDao.insert("shopMapper.insertShopConsignment", paramMap);
}
}
@Override
public List<Integer> selectShopProductByIds(ShopProductDto shopProductDto) {
return baseDao.queryForObject("shopMapper.selectShopProductByIds", shopProductDto);
}
@Override
public int selectShopConsignment(ShopProductDto shopProductDto) {
return baseDao.queryForObject("shopMapper.selectShopConsignment", shopProductDto);
}
@Override
public List<ProductBrandDto> selectBrandNameByUser(SysUser user) {
Map paramMap = new HashMap();
paramMap.put("userId",user.getId());
List<Integer> userShopDto =baseDao.queryForList("productInfoMapper.selectShopByUserId", paramMap);
if(null!=userShopDto&&userShopDto.size()>0){
paramMap.put("shopIds",userShopDto);
return baseDao.queryForList("productInfoMapper.selectBrandNameByShopIds",paramMap);
}
return baseDao.queryForList("productInfoMapper.selectBrandNameAll");
}
@Override
public void downProduct(List<Integer> ids,UserDto userDto ) {
// TODO Auto-generated method stub
Map paramMap = new HashMap();
paramMap.put("isDelete",1);
paramMap.put("lastUpdateUser",userDto.getId());
paramMap.put("ids",ids);
ShopProductDto shopProductDto = new ShopProductDto();
shopProductDto.setIds(ids);
baseDao.delete("productInfoMapper.deleteSeckillRelationDtoByIds", shopProductDto);
List<Integer> count1 = baseDao.queryForList("shopMapper.selectShopProductByIds", shopProductDto);
if(count1.size()>0){
baseDao.queryForObject("shopMapper.dowtShopProductByIds", shopProductDto);
baseDao.delete("shopMapper.delShopProductByIds", shopProductDto);
}
baseDao.update("productInfoMapper.DownProudct", paramMap);
}
@Override
public void uploadProduct(List<Integer> ids) {
Map paramMap = new HashMap();
paramMap.put("ids",ids);
baseDao.update("productInfoMapper.updateProduct", paramMap);
}
@Override
public void addPreferentialForm(Integer id,UserDto userDto ) {
// TODO Auto-generated method stub
ProductInfoDto productInfo = baseDao.queryForObject("productInfoMapper.selectProductInfoById", id);
ParamEntity entity = baseDao.queryForObject("paramEntityMapper.selectParamByName", "gift_ticket");
productInfo.setUsedTicket(productInfo.getProductPrice()-productInfo.getCostPrice()*entity.getParamValue());
productInfo.setProductPrice(productInfo.getProductPrice()-productInfo.getUsedTicket());
productInfo.setId(id);
ProductSeckillDto productSeckillDto = new ProductSeckillDto();
productSeckillDto.setProductId(id);
productSeckillDto.setCreateDate(new Date());
productSeckillDto.setIsState(1);
productSeckillDto.setCreateUser(userDto.getId());
productSeckillDto.setpType(4);
ProductSeckillDto productSeckillDto2=baseDao.queryForObject("productInfoMapper.selectProductIdByProductId", id);
if(productSeckillDto2==null){
baseDao.insert("productInfoMapper.insertUserRecommand", productSeckillDto);
}
baseDao.update("productInfoMapper.updateVerifyProduct", productInfo);
}
@Override
public void addAppointment(ProductInfoDto productInfoDto,UserDto userDto) {
ProductOrderEntity productOrderEntity = new ProductOrderEntity();
productOrderEntity.setProductId(productInfoDto.getId());
productOrderEntity.setOrderTicket(productInfoDto.getOrderTicket());
productOrderEntity.setCreateDate(new Date());
productOrderEntity.setCreateUser(userDto.getId());
ProductSeckillDto productSeckillDto2=baseDao.queryForObject("productInfoMapper.selectProductIdByProductId", productInfoDto.getId());
if (productSeckillDto2 == null) {
baseDao.insert("productInfoMapper.insertAppointment", productOrderEntity);
}
}
@Override
public void addUserRecommand(Integer id, UserDto userDto) {
// TODO Auto-generated method stub
ProductSeckillDto productSeckillDto=new ProductSeckillDto();
productSeckillDto.setProductId(id);
productSeckillDto.setCreateDate(new Date());
productSeckillDto.setIsState(1);
productSeckillDto.setCreateUser(userDto.getId());
productSeckillDto.setpType(2);
baseDao.insert("productInfoMapper.insertUserRecommand", productSeckillDto);
}
@Override
public void updateProductInfoTo(Integer id) {
baseDao.update("productInfoMapper.updateUserRecommand", id);
}
@Override
public void updateVerifyProduct(ProductInfoDto productInfoDto,UserDto userDto) {
// TODO Auto-generated method stub
ProductInfoDto dto =new ProductInfoDto();
dto.setId(productInfoDto.getId());
dto.setProductId(productInfoDto.getProductId());
dto.setProductTitle(productInfoDto.getProductTitle());
dto.setProductPrice(productInfoDto.getProductPrice());
dto.setOriginalPrice(productInfoDto.getProductPrice());
dto.setCostPrice(productInfoDto.getCostPrice());
dto.setLeastPurchase(productInfoDto.getLeastPurchase());
dto.setTransportCost(productInfoDto.getTransportCost());
dto.setComparePrice(productInfoDto.getComparePrice());
dto.setIconUrl(productInfoDto.getIconUrl());
dto.setIsDelete(2);
baseDao.update("productInfoMapper.updateVerifyProduct", dto);
ProductInfoExtendDto extendDto =new ProductInfoExtendDto();
extendDto.setProductStock(productInfoDto.getStock());
extendDto.setProductId(productInfoDto.getId());
baseDao.update("productInfoMapper.updateProductExtendsById", extendDto);
if (!"".equals(productInfoDto.getImgDetail().getImgUrl())) {
dto.setDetailPictrue(productInfoDto.getDetailPictrue());
productInfoDto.getImgDetail().setSort(2);
productInfoDto.getImgDetail().setpId(productInfoDto.getId());
if (!"".equals(productInfoDto.getImgDetail())) {
productInfoDto.getImgDetail().setImgUrl(productInfoDto.getImgDetail().getImgUrl().replace(fileIp+"/", ""));
;
}
dto.setDetailPictrue(productInfoDto.getDetailPictrue());
productInfoDto.getImgDetail().setSort(1);
productInfoDto.getImgDetail().setCreateUser(userDto.getId());
productInfoDto.getImgDetail().setpId(productInfoDto.getId());
if (!"".equals(productInfoDto.getImgDetail())) {
productInfoDto.getImgDetail().setImgUrl(productInfoDto.getImgDetail().getImgUrl().replace(fileIp+"/", ""));
;
}
baseDao.insert("productInfoMapper.insertUploadProductDetail", productInfoDto.getImgDetail());
}
if (!"".equals(productInfoDto.getImgUrl())) {
String[] productGraph = productInfoDto.getImgUrl().split(",");
ProductGuidedGraphDto graphDto = new ProductGuidedGraphDto();
for (int i = 0; i < productGraph.length; i++) {
if (productGraph[i] != null && !"".equals(productGraph[i])) {
String productGuideGraph = productGraph[i].trim();
graphDto.setProductId(productInfoDto.getId());
graphDto.setImgUrl(productGuideGraph.replace(fileIp+"/", ""));
graphDto.setSort(i);
graphDto.setCreateUser(productInfoDto.getId());
List<ProductGuidedGraphDto> count = baseDao.queryForList("productInfoMapper.getProductGraph", graphDto);
if(count==null||count.size()==0){
baseDao.insert("productInfoMapper.insertProductGraph", graphDto);
}
}
}
}
}
@Override
public ProductSeckillDto getSeckillRelationDtoById(ProductSeckillDto roductSeckillDto) {
// TODO Auto-generated method stub
ProductSeckillDto seckillRelationDto=baseDao.queryForObject("productInfoMapper.selectSeckillRelationDtoById", roductSeckillDto);
return seckillRelationDto;
}
@Override
public List<ProductListDto> selectAllProductByWhere(ProductListDto productListDto) {
Map<String, Object> paramsMap = new HashMap<String, Object>();//翻页所需的参数
BeanUtils.copyProperties(productListDto,paramsMap);
return baseDao.queryForList("productInfoMapper.selectAllProductByWhere",productListDto);
}
@Override
public List<ProductListDto> selectAllProductByPtysixpeWhere(ProductListDto productListDto) {
Map<String, Object> paramsMap = new HashMap<String, Object>();//翻页所需的参数
BeanUtils.copyProperties(productListDto,paramsMap);
return baseDao.queryForList("productInfoMapper.selectAllProductByPtysixpeWhere",productListDto);
}
@Override
public List<ProductListDto> selectAllProductByPtypeWhere(ProductListDto productListDto) {
Map<String, Object> paramsMap = new HashMap<String, Object>();//翻页所需的参数
BeanUtils.copyProperties(productListDto,paramsMap);
return baseDao.queryForList("productInfoMapper.selectAllProductByPtypeWhere",productListDto);
}
/*
@Override
public void uploadProductGuidedGraph(ProductGuidedGraphDto productGuidedGraphDto) {
// TODO Auto-generated method stub
UserDto userDto = ShiroUtils.getCurrentUser();
if (!"".equals(productGuidedGraphDto.getImgUrl())) {
String[] productGuide = productGuidedGraphDto.getImgUrl().split(",");
for (int i = 0; i < productGuide.length; i++) {
if (i == 0) {
productGuidedGraphDto.setImgUrl(productGuide[i]);
baseDao.update("productInfoMapper.updateInfoImgUrl", productGuidedGraphDto);
}
String productGuideGraph = productGuide[i].trim();
ProductGuidedGraphDto graphDto = new ProductGuidedGraphDto();
graphDto.setProductId(productGuidedGraphDto.getId());
graphDto.setImgUrl(productGuideGraph);
graphDto.setSort(i);
graphDto.setCreateUser(userDto.getId());
baseDao.insert("productInfoMapper.insertProductGraph", graphDto);
}
}
}
@Override
public void downProduct(Integer id) {
// TODO Auto-generated method stub
UserDto userDto = ShiroUtils.getCurrentUser();
ProductInfo productInfo = new ProductInfo();
productInfo.setId(id);
productInfo.setIsDelete(1);
productInfo.setLastUpdateUser(userDto.getId());
baseDao.update("productInfoMapper.DownProudct", productInfo);
}
@Override
public GridData<ProductListDto> versifyProductByList(QueryParam queryParam) {
// TODO Auto-generated method stub
PageInfo<ProductListDto> pageInfo = baseDao.queryByPage("productInfoMapper.selectVerifyProductList",queryParam);
return bindGridData(pageInfo, ProductListDto.class);
}
*/
/*
@Override
public GridData<ProductInfoDto> getData(QueryParam queryParam) {
// TODO Auto-generated method stub
return null;
}
@Override
public GridData<ProductListDto> productShopUploadList(QueryParam queryParam) {
// TODO Auto-generated method stub
UserDto userDto = ShiroUtils.getCurrentUser();
PageInfo<ProductListDto> pageInfo = null;
String relate = "";
if ("".equals(queryParam.getParamsMap().get("relateShop"))
|| queryParam.getParamsMap().get("relateShop") == null) {
List<UserShopDto> userShopDto = baseDao.queryForList("productDetailMapper.selectProductShopById",
userDto.getId());
for (int i = 0; i < userShopDto.size(); i++) {
relate = relate + userShopDto.get(i).getShopId() + ",";
}
relate = relate.substring(0, relate.length() - 1);
String[] relateShopId=relate.split(",");
queryParam.getParamsMap().put("relate", relateShopId);
pageInfo = baseDao.queryByPage("productInfoMapper.selectSuppliedAllProductList", queryParam);
} else {
pageInfo = baseDao.queryByPage("productInfoMapper.selectSuppliedProductList", queryParam);
}
return bindGridData(pageInfo);
}
@Override
public GridData<ProductListDto> selectProductList(QueryParam queryParam) {
// TODO Auto-generated method stub
PageInfo<ProductListDto> pageInfo= baseDao.queryByPage("productInfoMapper.selectAllProductByMap",queryParam);
return bindGridData(pageInfo);
}
@Override
public ProductInfoDto selectProductInfoDtoById(Integer id) {
// TODO Auto-generated method stub
ProductInfoDto productInfoDto = baseDao.queryForObject("productInfoMapper.selectProductInfoById", id);
return productInfoDto;
}
@Override
public void ifRecommend(Integer id) {
// TODO Auto-generated method stub
baseDao.update("productInfoMapper.updateIfRecommend", id);
}
@Override
public void downIsRecommend(Integer id) {
// TODO Auto-generated method stub
baseDao.update("productInfoMapper.downIfRecommend", id);
}
@Override
public GridData<ProductSeckillDto> selectSeckillDate(QueryParam queryParam) {
// TODO Auto-generated method stub
PageInfo<ProductSeckillDto> pageInfo= baseDao.queryByPage("productInfoMapper.selectSeckillDate",queryParam);
return bindGridData(pageInfo);
}
@Override
public GridData<SeckillRelationDto> lookSeckillTimeList(QueryParam queryParam) {
// TODO Auto-generated method stub
PageInfo<SeckillRelationDto> pageInfo=baseDao.queryByPage("productInfoMapper.selectProductSeckillExtend",queryParam);
return bindGridData(pageInfo);
}
@Override
public void seckillRelationDto(SeckillRelationDto seckillRelationDto) {
// TODO Auto-generated method stub
seckillRelationDto.setCreateDate(new Date());
baseDao.insert("productInfoMapper.insertseckillRelationDto", seckillRelationDto);
}
@Override
public SeckillRelationDto selectExtendTimeById(Integer id) {
// TODO Auto-generated method stub
SeckillRelationDto seckillRelationDto=baseDao.queryForObject("productInfoMapper.selectExtendTimeById", id);
return seckillRelationDto;
}
@Override
public void modifyTimeSeckillRelationDto(SeckillRelationDto seckillRelationDto) {
// TODO Auto-generated method stub
SeckillRelationDto seckillRelationDto2=new SeckillRelationDto();
seckillRelationDto2.setSecKillStart(seckillRelationDto.getSecKillStart());
seckillRelationDto2.setSecKillEnd(seckillRelationDto.getSecKillEnd());
seckillRelationDto2.setTitle(seckillRelationDto.getTitle());
seckillRelationDto2.setId(seckillRelationDto.getId());
baseDao.update("productInfoMapper.modifyTimeSeckillRelationDto", seckillRelationDto);
}
@Override
public void deleteTimeById(Integer id) {
// TODO Auto-generated method stub
baseDao.delete("productInfoMapper.deleteTimeById", id);
}
@Override
public void addDate(SeckillRelationDto seckillRelationDto) {
// TODO Auto-generated method stub
seckillRelationDto.setCreateDate(new Date());
SeckillRelationDto relationDto = baseDao.insert("productInfoMapper.insertAddDate", seckillRelationDto);
Map<String, Object> hashMap=new HashMap<String, Object>();
List<SeckillRelationDto> list = baseDao.queryForList("productInfoMapper.selectAllTimeList");
if (!CollectionUtils.isEmpty(list)) {
for(SeckillRelationDto seckillRelationDto2:list){
hashMap.put("dateId", relationDto.getId());
hashMap.put("timeId", seckillRelationDto2.getId());
baseDao.insert("productInfoMapper.inserProductSeckillRelation", hashMap);
}
}
}
@Override
public GridData<ProductSeckillDto> getProductActivity(QueryParam queryParam) {
// TODO Auto-generated method stub
PageInfo<ProductSeckillDto> pageInfo = null;
if(queryParam.getParamsMap().get("type").toString().equals("productPoint")){
queryParam.getParamsMap().put("p_type", 3);
}else if (queryParam.getParamsMap().get("type").toString().equals("newUserList")) {
queryParam.getParamsMap().put("p_type", 2);
}
pageInfo=baseDao.queryByPage("productInfoMapper.selectProductActivity",queryParam);
return bindGridData(pageInfo);
}
@Override
public void deleteProductActivity(Integer id) {
// TODO Auto-generated method stub
baseDao.update("productInfoMapper.updateProductSetIsdelete", id);
baseDao.delete("productInfoMapper.deleteProductActivity", id);
}
@Override
public void addUserRecommand(Integer id) {
// TODO Auto-generated method stub
ProductSeckillDto productSeckillDto=new ProductSeckillDto();
productSeckillDto.setProductId(id);
productSeckillDto.setCreateDate(new Date());
productSeckillDto.setIsState(1);
productSeckillDto.setpType(2);
baseDao.insert("productInfoMapper.insertUserRecommand", productSeckillDto);
baseDao.update("productInfoMapper.updateUserRecommand", id);
}
@Override
public ProductSeckillDto getSeckillRelationDtoById(Integer id) {
// TODO Auto-generated method stub
ProductSeckillDto seckillRelationDto=baseDao.queryForObject("productInfoMapper.selectSeckillRelationDtoById", id);
return seckillRelationDto;
}
@Override
public void addSeckillArea(ProductSeckillDto seckillRelationDto) {
// TODO Auto-generated method stub
ProductSeckillDto productSeckillDto =new ProductSeckillDto();
productSeckillDto.setProductId(seckillRelationDto.getId());
productSeckillDto.setCreateDate(new Date());
productSeckillDto.setIsState(1);
productSeckillDto.setpType(1);
productSeckillDto.setSecKillStart(seckillRelationDto.getSecKillStart());
productSeckillDto.setSecKillEnd(seckillRelationDto.getSecKillEnd());
baseDao.insert("productInfoMapper.insertSeckillArea", productSeckillDto);
baseDao.update("productInfoMapper.updateUserRecommand", seckillRelationDto.getId());
}
@Override
public void deleteSeckillById(Integer id) {
// TODO Auto-generated method stub
ProductSeckillDto productSeckillDto=baseDao.queryForObject("productInfoMapper.selectProductIdById", id);
int num=baseDao.queryForObject("productInfoMapper.selectProductIdHaving", productSeckillDto.getProductId());
if (num <=1) {
baseDao.update("productInfoMapper.updateProductSetIsdelete", id);
baseDao.delete("productInfoMapper.deleteNewById", id);
}else{
baseDao.delete("productInfoMapper.deleteNewById", id);
}
}
@Override
public void uploadProduct(Integer id) {
// TODO Auto-generated method stub
baseDao.update("productInfoMapper.updateProduct", id);
}
@Override
public void addPreferentialForm(Integer id) {
// TODO Auto-generated method stub
ProductInfoDto productInfo = baseDao.queryForObject("productInfoMapper.selectProductInfoById", id);
ParamEntity entity = baseDao.queryForObject("paramEntityMapper.selectParamByName", "gift_ticket");
productInfo.setUsedTicket(productInfo.getProductPrice()-productInfo.getCostPrice()*entity.getParamValue());
productInfo.setProductPrice(productInfo.getProductPrice()-productInfo.getUsedTicket());
productInfo.setId(id);
ProductSeckillDto productSeckillDto = new ProductSeckillDto();
productSeckillDto.setProductId(id);
productSeckillDto.setCreateDate(new Date());
productSeckillDto.setIsState(1);
productSeckillDto.setpType(4);
ProductSeckillDto productSeckillDto2=baseDao.queryForObject("productInfoMapper.selectProductIdByProductId", id);
if(productSeckillDto2==null){
baseDao.insert("productInfoMapper.insertUserRecommand", productSeckillDto);
}
baseDao.update("productInfoMapper.updateVerifyProduct", productInfo);
}
*/
@Override
public List<AreaManagerDto> areaInfoList(SsUserDto ssUserDto,SysUser user) {
List<SysRole> sysRoles = baseDao.queryForList("com.hgj.web.mapper.SysPermissionMapper.selectRoleByUserId", user.getId());
Map map = new HashMap();
map.put("id",ssUserDto.getId());
for (SysRole sysRole : sysRoles) {
if(sysRole.getRoleCode().equals("RegionalAgent")){
return baseDao.queryForList("regionMapper.selectAreaInfoList",map);
}
}
return baseDao.queryForList("regionMapper.selectAreaInfo",map);
}
}
这里是《BaseDao》 映射层
package com.hgj.web.dao;
import com.github.pagehelper.PageInfo;
import com.hgj.common.util.query.QueryParam;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
public interface BaseDao {
/**
* 带条件查询,返回一条记录
* @param sqlId
* @param cond 实现了Serializable接口的类
* @return
*/
public <T> T queryForObject(String sqlId, Serializable cond);
/**
* 插入一条记录
* @param sqlId
* @param entity 返回插入的对象,可以返回主键
* @return
*/
public <T> T insert(String sqlId, T entity);
/**
* 插入一条记录
* @param sqlId
* @param paramMap
* @return
*/
public <T> void insert(String sqlId, Map<String, Object> paramMap);
/**
* 返回几个数据集
* @param sqlId
* @return
*/
public <T> List<T> queryForList(String sqlId);
/**
* 带条件查询,返回一个数据集
* @param sqlId
* @param cond 实现了Serializable接口的类
* @return
*/
public <T> List<T> queryForList(String sqlId, Serializable cond);
/**
* 带条件查询,返回一个数据集
* @param sqlId
* @param entity 实体参数
* @return
*/
public <T> List<T> queryForList(String sqlId, T entity);
/**
* 带条件查询,返回一个数据集
* @param sqlId
* @param paramMap Map参数
* @return
*/
public <T> List<T> queryForList(String sqlId, Map<String, Object> paramMap);
/**
* 带条件查询,返回一条记录
* @param sqlId
* @param entity 实体参数
* @return
*/
public <T> T queryForObject(String sqlId, T entity);
/**
* 带条件查询,返回一条记录
* @param sqlId
* @param paramMap Map参数
* @return
*/
public <T> T queryForObject(String sqlId, Map<String, Object> paramMap);
/**
* 带条件查询,返回一条记录
* @param sqlId
* @param entity 实体参数
* @return
*/
public <T> Map<String, Object> queryForMap(String sqlId, T entity);
/**
* 带条件查询,返回一条记录
* @param sqlId
* @param paramMap Map参数
* @return
*/
public Map<String, Object> queryForMap(String sqlId, Map<String, Object> paramMap);
/**
* 翻页查询
* @param sqlId
* @param params 查询参数
* @return
*/
public <T> PageInfo<T> queryByPage(String sqlId, QueryParam params);
/**
* 更新记录
* @param sqlId
* @param cond 实现了Serializable接口的类
* @return
*/
public <T> int update(String sqlId, Serializable cond);
/**
* 更新记录
* @param sqlId
* @param entity 实体参数
* @return
*/
public <T> int update(String sqlId, T entity);
/**
* 更新记录
* @param sqlId
* @param paramMap Map参数
* @return
*/
public int update(String sqlId, Map<String, Object> paramMap);
/**
* 删除记录,返回影响行数
* @param sqlId
* @param cond 实现了Serializable接口的类
* @return
*/
public int delete(String sqlId, Serializable cond);
/**
* 删除记录,返回影响行数
* @param sqlId
* @param entity 实体参数
* @return
*/
public <T> int delete(String sqlId, T entity);
/**
* 删除记录,返回影响行数
* @param sqlId
* @param paramMap Map参数
* @return
*/
public int delete(String sqlId, Map<String, Object> paramMap);
}
这里的重点就在于映射层 它可以灵活运动
baseDao.insert("shopMapper.insertShopProduct", paramMap);
baseDao.insert("shopMapper.insertShopConsignment", paramMap);
这里的shopMapper是映射文件,
而insertShopProduct是映射文件里的id 也就是执行的sql语句