Commit 652b4e9c by 张新旗

代码修改

parent d83dc360
package com.ruoyi.web.controller.coffee; package com.ruoyi.web.controller.coffee;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.uuid.UUID; import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.domain.Machine; import com.ruoyi.system.domain.Machine;
import com.ruoyi.system.domain.vo.PushBean; import com.ruoyi.system.domain.vo.PushBean;
...@@ -60,11 +61,10 @@ public class ApplicationController { ...@@ -60,11 +61,10 @@ public class ApplicationController {
@RequestMapping("/jgRegister") @RequestMapping("/jgRegister")
public AjaxResult jgRegister(@RequestParam String machineCode,@RequestParam String registerId){ public AjaxResult jgRegister(@RequestParam String machineCode,@RequestParam String registerId){
Machine machine = new Machine();
machine.setId(machineCode); Machine machine = machineService.selectMachineById(machineCode);
List<Machine> machines = machineService.selectMachineList(machine); if(machine==null ){
if(machines==null ||machines.isEmpty()){ throw new ServiceException("该机器未绑定店铺,请先绑定店铺");
return AjaxResult.error("该机器未绑定店铺,请先绑定店铺");
} }
machine.setRegister(registerId); machine.setRegister(registerId);
......
...@@ -102,7 +102,7 @@ public class ShopController extends BaseController ...@@ -102,7 +102,7 @@ public class ShopController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('system:shop:addGoods')") @PreAuthorize("@ss.hasPermi('system:shop:addGoods')")
@GetMapping(value = "/addGoods") @GetMapping(value = "/addGoods")
public AjaxResult addGoods(long shopId,String goodsIds) public AjaxResult addGoods(Long shopId,String goodsIds)
{ {
return AjaxResult.success(shopService.addGoods(shopId,goodsIds)); return AjaxResult.success(shopService.addGoods(shopId,goodsIds));
} }
......
...@@ -38,7 +38,7 @@ public class ShopRecommendController extends BaseController ...@@ -38,7 +38,7 @@ public class ShopRecommendController extends BaseController
/** /**
* 查询推荐和今日特惠列表 * 查询推荐和今日特惠列表
*/ */
@PreAuthorize("@ss.hasPermi('system:recommend:list')") // @PreAuthorize("@ss.hasPermi('system:recommend:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(ShopRecommend shopRecommend) public TableDataInfo list(ShopRecommend shopRecommend)
{ {
......
...@@ -82,7 +82,7 @@ public class SpecController extends BaseController ...@@ -82,7 +82,7 @@ public class SpecController extends BaseController
/** /**
* 删除规格 * 删除规格
*/ */
@PreAuthorize("@ss.hasPermi('system:spec:remove')") //@PreAuthorize("@ss.hasPermi('system:spec:remove')")
@Log(title = "规格", businessType = BusinessType.DELETE) @Log(title = "规格", businessType = BusinessType.DELETE)
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public AjaxResult remove(@PathVariable String id) public AjaxResult remove(@PathVariable String id)
......
package com.ruoyi.framework.config; package com.ruoyi.framework.config;
import com.ruoyi.framework.interceptor.GlobalExceptionHandlerFilter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
...@@ -11,6 +12,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur ...@@ -11,6 +12,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.access.channel.ChannelProcessingFilter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter; import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.web.filter.CorsFilter; import org.springframework.web.filter.CorsFilter;
...@@ -55,6 +57,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter ...@@ -55,6 +57,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
*/ */
@Autowired @Autowired
private CorsFilter corsFilter; private CorsFilter corsFilter;
@Autowired
private GlobalExceptionHandlerFilter globalExceptionHandlerFilter;
/** /**
* 解决 无法直接注入 AuthenticationManager * 解决 无法直接注入 AuthenticationManager
...@@ -122,6 +126,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter ...@@ -122,6 +126,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 添加CORS filter // 添加CORS filter
httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class); httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class);
httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class); httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class);
httpSecurity.addFilterBefore(globalExceptionHandlerFilter, ChannelProcessingFilter.class);
} }
/** /**
......
package com.ruoyi.framework.interceptor;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Component;
import org.springframework.web.util.NestedServletException;
import javax.servlet.*;
import java.io.IOException;
import java.sql.SQLIntegrityConstraintViolationException;
@Component
public class GlobalExceptionHandlerFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
try {
filterChain.doFilter(servletRequest,servletResponse);
}catch (Exception e){
/**
* 捕捉出现的异常,根据自己的需求进行处理
* ResultEntity 自定义的响应结果封装类
* SCSException 自定义异常
*/
servletResponse.setCharacterEncoding("UTF-8");
AjaxResult ajaxResult = null;
Throwable throwable;
if(e instanceof NestedServletException){
throwable = e.getCause();
}else{
throwable = e;
}
/**
* 重复数据异常
*/
if(throwable instanceof DuplicateKeyException){
ajaxResult = AjaxResult.error("该数据已经存在");
}else if(throwable instanceof SQLIntegrityConstraintViolationException){
ajaxResult = AjaxResult.error("该数据已经存在");
}else if(throwable instanceof ServiceException){
ajaxResult = AjaxResult.error(e.getMessage());
}else{
throw e;
}
servletResponse.getWriter().write(JSONObject.toJSONString(ajaxResult));
}
}
}
...@@ -147,6 +147,7 @@ public class WeixinServiceImpl { ...@@ -147,6 +147,7 @@ public class WeixinServiceImpl {
customer.setId(cutomerId); customer.setId(cutomerId);
customer.setHeadSculpturePath(encDataInf.getString("avatarUrl")); customer.setHeadSculpturePath(encDataInf.getString("avatarUrl"));
customer.setUserName(encDataInf.getString("nickName")); customer.setUserName(encDataInf.getString("nickName"));
customer.setPhone(encDataInf.getString("phoneNumber"));
customer.setCreateTime(new Date()); customer.setCreateTime(new Date());
if(StringUtils.isNotEmpty(source)){ if(StringUtils.isNotEmpty(source)){
customer.setSoucre(source); customer.setSoucre(source);
......
...@@ -110,14 +110,14 @@ public class Goods extends BaseEntity ...@@ -110,14 +110,14 @@ public class Goods extends BaseEntity
@Excel(name = "商品编码") @Excel(name = "商品编码")
private String code; private String code;
private List<GoodsTag> goodsTagList; private List<String> goodsTagList;
public List<GoodsTag> getGoodsTagList() { public List<String> getGoodsTagList() {
return goodsTagList; return goodsTagList;
} }
public void setGoodsTagList(List<GoodsTag> goodsTagList) { public void setGoodsTagList(List<String> goodsTagList) {
this.goodsTagList = goodsTagList; this.goodsTagList = goodsTagList;
} }
public void setId(long id) public void setId(long id)
......
...@@ -18,7 +18,7 @@ public class SpecRuleMaterial extends BaseEntity ...@@ -18,7 +18,7 @@ public class SpecRuleMaterial extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 主键 */ /** 主键 */
private long id; private Long id;
/** 规则名称 */ /** 规则名称 */
@Excel(name = "规则名称") @Excel(name = "规则名称")
...@@ -26,15 +26,15 @@ public class SpecRuleMaterial extends BaseEntity ...@@ -26,15 +26,15 @@ public class SpecRuleMaterial extends BaseEntity
/** 规格ID */ /** 规格ID */
@Excel(name = "规格ID") @Excel(name = "规格ID")
private long specId; private Long specId;
/** 选项ID */ /** 选项ID */
@Excel(name = "选项ID") @Excel(name = "选项ID")
private long ruleId; private Long ruleId;
/** 原料ID */ /** 原料ID */
@Excel(name = "原料ID") @Excel(name = "原料ID")
private long materialId; private Long materialId;
/** 原料名称 */ /** 原料名称 */
@Excel(name = "原料名称") @Excel(name = "原料名称")
...@@ -62,12 +62,12 @@ public class SpecRuleMaterial extends BaseEntity ...@@ -62,12 +62,12 @@ public class SpecRuleMaterial extends BaseEntity
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date updatedAt; private Date updatedAt;
public void setId(long id) public void setId(Long id)
{ {
this.id = id; this.id = id;
} }
public long getId() public Long getId()
{ {
return id; return id;
} }
...@@ -80,12 +80,12 @@ public class SpecRuleMaterial extends BaseEntity ...@@ -80,12 +80,12 @@ public class SpecRuleMaterial extends BaseEntity
{ {
return name; return name;
} }
public void setSpecId(long specId) public void setSpecId(Long specId)
{ {
this.specId = specId; this.specId = specId;
} }
public long getSpecId() public Long getSpecId()
{ {
return specId; return specId;
} }
...@@ -94,16 +94,16 @@ public class SpecRuleMaterial extends BaseEntity ...@@ -94,16 +94,16 @@ public class SpecRuleMaterial extends BaseEntity
this.ruleId = ruleId; this.ruleId = ruleId;
} }
public long getRuleId() public Long getRuleId()
{ {
return ruleId; return ruleId;
} }
public void setMaterialId(long materialId) public void setMaterialId(Long materialId)
{ {
this.materialId = materialId; this.materialId = materialId;
} }
public long getMaterialId() public Long getMaterialId()
{ {
return materialId; return materialId;
} }
......
...@@ -61,4 +61,6 @@ public interface GoodsSkuMapper ...@@ -61,4 +61,6 @@ public interface GoodsSkuMapper
public int deleteGoodsSkuByIds(String[] ids); public int deleteGoodsSkuByIds(String[] ids);
void deleteGoodsSkuByGoodsId(@Param("goodsId") String id); void deleteGoodsSkuByGoodsId(@Param("goodsId") String id);
List<GoodsSku> selectSpec(String query);
} }
...@@ -4,6 +4,7 @@ import java.math.BigDecimal; ...@@ -4,6 +4,7 @@ import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
...@@ -52,7 +53,7 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -52,7 +53,7 @@ public class GoodsServiceImpl implements IGoodsService
Goods goods = goodsMapper.selectGoodsById(id); Goods goods = goodsMapper.selectGoodsById(id);
GoodsTag goodsTag = new GoodsTag(); GoodsTag goodsTag = new GoodsTag();
goodsTag.setGoodsId(goods.getId()); goodsTag.setGoodsId(goods.getId());
goods.setGoodsTagList(goodsTagMapper.selectGoodsTagList(goodsTag)); goods.setGoodsTagList(goodsTagMapper.selectGoodsTagList(goodsTag).stream().map(GoodsTag::getTag).collect(Collectors.toList()));
return goods; return goods;
} }
...@@ -124,12 +125,14 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -124,12 +125,14 @@ public class GoodsServiceImpl implements IGoodsService
} }
createSku(ruleNodeList,goodsId,goods.getDiscount(),goods.getPrice()); createSku(ruleNodeList,goodsId,goods.getDiscount(),goods.getPrice());
} }
List<GoodsTag> goodsTagList = goods.getGoodsTagList(); List<String> goodsTagList = goods.getGoodsTagList();
if(goodsTagList!=null &&!goodsTagList.isEmpty()){ if(goodsTagList!=null &&!goodsTagList.isEmpty()){
for (GoodsTag goodsTag : goodsTagList) { for (String tagName : goodsTagList) {
GoodsTag goodsTag = new GoodsTag();
goodsTag.setGoodsId(goodsId); goodsTag.setGoodsId(goodsId);
goodsTag.setState("1"); goodsTag.setState("1");
goodsTag.setCreatedAt(new Date()); goodsTag.setCreatedAt(new Date());
goodsTag.setTag(tagName);
goodsTagMapper.insertGoodsTag(goodsTag); goodsTagMapper.insertGoodsTag(goodsTag);
} }
} }
......
...@@ -3,6 +3,7 @@ package com.ruoyi.system.service.impl; ...@@ -3,6 +3,7 @@ package com.ruoyi.system.service.impl;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.service.IMachineService; import com.ruoyi.system.service.IMachineService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -95,10 +96,21 @@ public class MachineServiceImpl implements IMachineService ...@@ -95,10 +96,21 @@ public class MachineServiceImpl implements IMachineService
@Override @Override
public String bindMachine(String code, Long shopId) { public String bindMachine(String code, Long shopId) {
Machine machine1 = machineMapper.selectMachineById(code);
if(machine1!=null){
throw new ServiceException("该机器已经被绑定,请先解绑再绑定");
}
Machine machine = new Machine(); Machine machine = new Machine();
machine.setShopId(shopId);
List<Machine> machines = machineMapper.selectMachineList(machine);
if(!machines.isEmpty()){
throw new ServiceException("目前只允许一个店铺绑定一台机器");
}
machine.setId(code); machine.setId(code);
machine.setCode(code); machine.setCode(code);
machine.setShopId(shopId);
machine.setBindTime(new Date()); machine.setBindTime(new Date());
machine.setCreatedAt(new Date()); machine.setCreatedAt(new Date());
machine.setUpdatedAt(new Date()); machine.setUpdatedAt(new Date());
......
...@@ -3,9 +3,12 @@ package com.ruoyi.system.service.impl; ...@@ -3,9 +3,12 @@ package com.ruoyi.system.service.impl;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.GenerateCode; import com.ruoyi.common.utils.GenerateCode;
import com.ruoyi.system.domain.GoodsSku;
import com.ruoyi.system.domain.SpecRule; import com.ruoyi.system.domain.SpecRule;
import com.ruoyi.system.domain.SpecRuleMaterial; import com.ruoyi.system.domain.SpecRuleMaterial;
import com.ruoyi.system.mapper.GoodsSkuMapper;
import com.ruoyi.system.service.ISpecService; import com.ruoyi.system.service.ISpecService;
import com.ruoyi.system.mapper.SpecRuleMapper; import com.ruoyi.system.mapper.SpecRuleMapper;
import com.ruoyi.system.mapper.SpecRuleMaterialMapper; import com.ruoyi.system.mapper.SpecRuleMaterialMapper;
...@@ -30,6 +33,8 @@ public class SpecServiceImpl implements ISpecService ...@@ -30,6 +33,8 @@ public class SpecServiceImpl implements ISpecService
private SpecRuleMapper specRuleMapper; private SpecRuleMapper specRuleMapper;
@Autowired @Autowired
private SpecRuleMaterialMapper specRuleMaterialMapper; private SpecRuleMaterialMapper specRuleMaterialMapper;
@Autowired
private GoodsSkuMapper goodsSkuMapper;
/** /**
* 查询规格 * 查询规格
...@@ -190,6 +195,11 @@ public class SpecServiceImpl implements ISpecService ...@@ -190,6 +195,11 @@ public class SpecServiceImpl implements ISpecService
@Override @Override
public int deleteSpecById(String id) public int deleteSpecById(String id)
{ {
String query ="\"specId\": "+id;
List<GoodsSku> goodsSkus = goodsSkuMapper.selectSpec(query);
if(!goodsSkus.isEmpty()){
throw new ServiceException("当前还有商品使用,请先删除商品");
}
long specId = Long.parseLong(id); long specId = Long.parseLong(id);
specRuleMapper.deleteSpecRuleBySpecId(specId); specRuleMapper.deleteSpecRuleBySpecId(specId);
specRuleMaterialMapper.deleteSpecRuleMaterialBySpecId(specId); specRuleMaterialMapper.deleteSpecRuleMaterialBySpecId(specId);
......
...@@ -87,4 +87,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -87,4 +87,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="deleteGoodsSkuByGoodsId"> <update id="deleteGoodsSkuByGoodsId">
update goods_sku set is_deleted ='1' where goods_id=#{goodsId} update goods_sku set is_deleted ='1' where goods_id=#{goodsId}
</update> </update>
<select id="selectSpec" resultMap="GoodsSkuResult">
<include refid="selectGoodsSkuVo"/>
where rule_list like concat('%',#{query},'%')
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -144,16 +144,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -144,16 +144,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sg.state, sg.state,
g.code g.code
from from
shop s ,
shop_recommend sr, shop_recommend sr,
shop_goods sg,
goods g goods g
where where
sr.goods_id = sg.goods_id sr.shop_id = #{shopId}
and g.id = sg.goods_id and type = #{type}
and g.state = '3' and sr.shop_id = s.id
and g.is_deleted = 0 and g.is_deleted = 0
and sr.`type` = #{type} and g.id = sr.goods_id
and sr.shop_id = #{shopId}
order by order by
sr.turn sr.turn
</select> </select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment