| | |
| | | package com.yuanchu.mom.controller; |
| | | |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.annotation.ValueAuth; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.dto.DataReportingPageDto; |
| | | import com.yuanchu.mom.dto.ProductCountDto; |
| | | import com.yuanchu.mom.dto.RegistrantCountDto; |
| | | import com.yuanchu.mom.pojo.DataReporting; |
| | | import com.yuanchu.mom.pojo.FansSubmit; |
| | | import com.yuanchu.mom.pojo.FinanceSubmit; |
| | | import com.yuanchu.mom.service.DataReportingService; |
| | | import com.yuanchu.mom.service.FansSubmitService; |
| | | import com.yuanchu.mom.utils.JackSonUtil; |
| | | import com.yuanchu.mom.service.FinanceSubmitService; |
| | | import com.yuanchu.mom.vo.Result; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Map; |
| | | |
| | | @RequestMapping("/dataReporting") |
| | |
| | | |
| | | private FansSubmitService fansSubmitService; |
| | | |
| | | private FinanceSubmitService financeSubmitService; |
| | | |
| | | @ApiOperation(value = "è·åæ°æ®ä¸æ¥å表") |
| | | @PostMapping("/selectDataReportingList") |
| | | public Result selectDataReportingList(@RequestBody Map<String, Object> data) { |
| | | Page page = JSON.parseObject(JSON.toJSONString(data.get("page")), Page.class); |
| | | DataReportingPageDto dataReportingPageDto = JSON.parseObject(JSON.toJSONString(data.get("entity")), DataReportingPageDto.class); |
| | | return Result.success(dataReportingService.selectUserList(page, dataReportingPageDto)); |
| | | return Result.success(dataReportingService.selectDataReportingList(page, dataReportingPageDto)); |
| | | } |
| | | |
| | | @ApiOperation(value = "ä¿®æ¹æ°æ®ä¸æ¥") |
| | |
| | | return Result.success(fansSubmitService.addFansSubmit(fansSubmit)); |
| | | } |
| | | |
| | | @ApiOperation(value = "è·åè´¢å¡ä¸æ¥å表") |
| | | @PostMapping("/selectFinanceSubmitList") |
| | | public Result selectFinanceSubmitList(@RequestBody Map<String, Object> data) { |
| | | Page page = JSON.parseObject(JSON.toJSONString(data.get("page")), Page.class); |
| | | FinanceSubmit financeSubmit = JSON.parseObject(JSON.toJSONString(data.get("entity")), FinanceSubmit.class); |
| | | return Result.success(financeSubmitService.selectFinanceSubmitList(page, financeSubmit)); |
| | | } |
| | | |
| | | @ApiOperation(value = "å é¤è´¢å¡ä¸æ¥å表") |
| | | @PostMapping("/delFinanceSubmit") |
| | | public Result delFinanceSubmit(Integer id){ |
| | | return Result.success(financeSubmitService.delFinanceSubmit(id)); |
| | | } |
| | | |
| | | @ApiOperation(value = "ä¿®æ¹è´¢å¡ä¸æ¥ä¿¡æ¯") |
| | | @PostMapping("/updateFinanceSubmit") |
| | | public Result<?> updateFinanceSubmit(@RequestBody FinanceSubmit financeSubmit) { |
| | | return Result.success(financeSubmitService.updateFinanceSubmit(financeSubmit)); |
| | | } |
| | | |
| | | @ApiOperation(value = "æ·»å è´¢å¡ä¸æ¥ä¿¡æ¯") |
| | | @PostMapping("/addFinanceSubmit") |
| | | public Result<?> addFinanceSubmit(@RequestBody FinanceSubmit financeSubmit) { |
| | | return Result.success(financeSubmitService.addFinanceSubmit(financeSubmit)); |
| | | } |
| | | |
| | | @ApiOperation(value = "è·åé¦é¡µæ°æ®") |
| | | @GetMapping("/getDataList") |
| | | @ValueAuth |
| | | public Result<?> getDataList() { |
| | | return Result.success(dataReportingService.getDataList()); |
| | | } |
| | | |
| | | } |
| | |
| | | @ApiModelProperty("å®¢æ·ææ¬") |
| | | private BigDecimal customerCosts; |
| | | |
| | | @ApiModelProperty("åå»ºç¨æ·") |
| | | private Integer createUser; |
| | | |
| | | } |
| | |
| | | @ValueTableShow(1) |
| | | private LocalDateTime updateTime; |
| | | |
| | | @ApiModelProperty("åå»ºç¨æ·") |
| | | private Integer createUser; |
| | | |
| | | } |
| | |
| | | import com.yuanchu.mom.pojo.DataReporting; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @description é对表ãdata_reporting(æ°æ®ä¸æ¥)ãçæ°æ®åºæä½Mapper |
| | |
| | | |
| | | IPage<RegistrantCountDto> selectRegistrantCountDtoPageList(IPage<RegistrantCountDto> page, QueryWrapper<RegistrantCountDto> ew); |
| | | |
| | | Map<String, BigDecimal> getDataFor1(); |
| | | |
| | | List<Map<String, String>> getDataFor2(); |
| | | |
| | | List<Map<String, String>> getDataFor3(); |
| | | |
| | | List<Map<String, String>> getDataFor4(); |
| | | |
| | | List<Map<String, String>> getDataFor5(); |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public interface DataReportingService extends IService<DataReporting> { |
| | | |
| | | Map<String, Object> selectUserList(IPage<DataReportingPageDto> page, DataReportingPageDto dataReportingPageDto); |
| | | Map<String, Object> selectDataReportingList(IPage<DataReportingPageDto> page, DataReportingPageDto dataReportingPageDto); |
| | | |
| | | int updateDataReporting(DataReporting dataReporting); |
| | | |
| | |
| | | |
| | | Map<String, Object> selectRegistrantCountDtoPageList(IPage<RegistrantCountDto> page, RegistrantCountDto registrantCountDto); |
| | | |
| | | Map<String, Object> getDataList(); |
| | | |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.DataReportingPageDto; |
| | | import com.yuanchu.mom.dto.ProductCountDto; |
| | |
| | | |
| | | private DataReportingMapper dataReportingMapper; |
| | | |
| | | private GetLook getLook; |
| | | |
| | | @Override |
| | | public Map<String, Object> selectUserList(IPage<DataReportingPageDto> page, DataReportingPageDto dataReportingPageDto) { |
| | | public Map<String, Object> selectDataReportingList(IPage<DataReportingPageDto> page, DataReportingPageDto dataReportingPageDto) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectDataReportingList"); |
| | | if(map1.get("look")==1) dataReportingPageDto.setCreateUser(map1.get("userId")); |
| | | map.put("head", PrintChina.printChina(DataReportingPageDto.class)); |
| | | map.put("body", dataReportingMapper.selectDataReportingDtoPageList(page, QueryWrappers.queryWrappers(dataReportingPageDto))); |
| | | return map; |
| | |
| | | public Map<String, Object> selectProductCountDtoPageList(IPage<ProductCountDto> page, ProductCountDto productCountDto) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(ProductCountDto.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectDataReportingList"); |
| | | if(map1.get("look")==1) productCountDto.setCreateUser(map1.get("userId")); |
| | | map.put("body", dataReportingMapper.selectProductCountDtoPageList(page, QueryWrappers.queryWrappers(productCountDto))); |
| | | return map; |
| | | } |
| | |
| | | public Map<String, Object> selectRegistrantCountDtoPageList(IPage<RegistrantCountDto> page, RegistrantCountDto registrantCountDto) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(RegistrantCountDto.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectDataReportingList"); |
| | | if(map1.get("look")==1) registrantCountDto.setCreateUser(map1.get("userId")); |
| | | map.put("body", dataReportingMapper.selectRegistrantCountDtoPageList(page, QueryWrappers.queryWrappers(registrantCountDto))); |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getDataList() { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("data1", dataReportingMapper.getDataFor1()); |
| | | map.put("data2", dataReportingMapper.getDataFor2()); |
| | | map.put("data3", dataReportingMapper.getDataFor3()); |
| | | map.put("data4", dataReportingMapper.getDataFor4()); |
| | | map.put("data5", dataReportingMapper.getDataFor5()); |
| | | return map; |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.DataReportingPageDto; |
| | | import com.yuanchu.mom.pojo.FansSubmit; |
| | |
| | | |
| | | private FansSubmitMapper fansSubmitMapper; |
| | | |
| | | private GetLook getLook; |
| | | |
| | | @Override |
| | | public Map<String, Object> selectFansSubmitList(IPage<FansSubmit> page, FansSubmit fansSubmit) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(FansSubmit.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectDataReportingList"); |
| | | if(map1.get("look")==1) fansSubmit.setCreateUser(map1.get("userId")); |
| | | map.put("body", fansSubmitMapper.selectFansSubmitPageList(page, QueryWrappers.queryWrappers(fansSubmit))); |
| | | return map; |
| | | } |
| | |
| | | </select> |
| | | <select id="selectProductCountDtoPageList" resultType="com.yuanchu.mom.dto.ProductCountDto"> |
| | | select * from ( |
| | | select update_time, create_time, product, sum(consumption) consumption, sum(fans_add) fans_add, sum(customer_costs) customer_costs |
| | | select update_time, create_time, product, sum(consumption) consumption, sum(fans_add) fans_add, sum(customer_costs) customer_costs, create_user |
| | | from data_reporting |
| | | group by product |
| | | ) a |
| | |
| | | </select> |
| | | <select id="selectRegistrantCountDtoPageList" resultType="com.yuanchu.mom.dto.RegistrantCountDto"> |
| | | select * from ( |
| | | select id, department, registrant, product, name, sum(`show`) `show`, sum(click) click, sum(account_consumption)account_consumption, sum(rebate_consumption) rebate_consumption,(sum(rebate_consumption)+sum(remark)) rebate_consumption2, sum(discounted_consumption) discounted_consumption, sum(fans_add) fans_add, sum(actual_cost) actual_cost, sum(customer_costs) customer_costs, sum(profit) profit, sum(agent_rebate) agent_rebate, sum(customer_rebate) customer_rebate, sum(remark) remark, create_time, update_time |
| | | select id, department, registrant, product, name, sum(`show`) `show`, sum(click) click, sum(account_consumption)account_consumption, sum(rebate_consumption) rebate_consumption,(sum(rebate_consumption)+sum(remark)) rebate_consumption2, sum(discounted_consumption) discounted_consumption, sum(fans_add) fans_add, sum(actual_cost) actual_cost, sum(customer_costs) customer_costs, sum(profit) profit, sum(agent_rebate) agent_rebate, sum(customer_rebate) customer_rebate, sum(remark) remark, create_time, update_time, create_user |
| | | from data_reporting |
| | | group by registrant |
| | | ) a |
| | |
| | | ${ew.customSqlSegment} |
| | | </if> |
| | | </select> |
| | | <select id="getDataFor1" resultType="java.util.Map"> |
| | | select COALESCE(sum(account_consumption), 0) data1, COALESCE(sum(consumption), 0) data2, COALESCE(sum(customer_costs),0) data3, COALESCE(sum(actual_cost), 0) data4 |
| | | from data_reporting |
| | | where date(create_time) like CURDATE() |
| | | </select> |
| | | <select id="getDataFor2" resultType="java.util.Map"> |
| | | SELECT sum(account_consumption) account_consumptions, DATE_FORMAT(create_time, '%m-%d') `date`, DATE_FORMAT(create_time, '%y-%m-%d') time |
| | | FROM data_reporting |
| | | group by DATE_FORMAT(create_time, '%y-%m-%d') |
| | | having DATE_SUB(CURDATE(), INTERVAL 7 DAY) < time |
| | | and time <= CURDATE() |
| | | </select> |
| | | <select id="getDataFor3" resultType="java.util.Map"> |
| | | SELECT sum(consumption) consumption, DATE_FORMAT(create_time, '%m-%d') `date`, DATE_FORMAT(create_time, '%y-%m-%d') time |
| | | FROM data_reporting |
| | | group by DATE_FORMAT(create_time, '%y-%m-%d') |
| | | having DATE_SUB(CURDATE(), INTERVAL 7 DAY) < time |
| | | and time <= CURDATE() |
| | | </select> |
| | | <select id="getDataFor4" resultType="java.util.Map"> |
| | | select product, sum(customer_costs) customerCosts |
| | | from data_reporting |
| | | group by product |
| | | order by customerCosts desc limit 7 |
| | | </select> |
| | | <select id="getDataFor5" resultType="java.util.Map"> |
| | | select product, sum(actual_cost) actualCost |
| | | from data_reporting |
| | | group by product |
| | | order by actualCost desc limit 7 |
| | | </select> |
| | | </mapper> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.annotation; |
| | | |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | public @interface ValueAuth { |
| | | |
| | | } |
| | |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | public @interface ValueTableShow { |
| | | |
| | | int value() default 0; |
| | | int value() default 1; |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.common; |
| | | |
| | | import com.yuanchu.mom.annotation.ValueAuth; |
| | | import com.yuanchu.mom.mapper.AuthMapper; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.context.WebApplicationContext; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | import org.springframework.web.servlet.mvc.method.RequestMappingInfo; |
| | | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | public class AllController { |
| | | @Resource |
| | | WebApplicationContext applicationContext; |
| | | |
| | | @Resource |
| | | private AuthMapper authMapper; |
| | | |
| | | public void addAllController() { |
| | | RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class); |
| | | Map<RequestMappingInfo, HandlerMethod> methodMap = mapping.getHandlerMethods(); |
| | | authMapper.deletePower(); |
| | | for (HandlerMethod value : methodMap.values()) { |
| | | ApiOperation annotation = value.getMethodAnnotation(ApiOperation.class); |
| | | ValueAuth valueAuth = value.getMethodAnnotation(ValueAuth.class); |
| | | if (valueAuth==null){ |
| | | if (annotation != null) { |
| | | String remark = annotation.value(); |
| | | String type = "ä¿®æ¹"; |
| | | if (remark.contains("è·å")||remark.contains("æ¥è¯¢")){ |
| | | type = "æ¥è¯¢"; |
| | | } else if(remark.contains("å é¤")){ |
| | | type = "å é¤"; |
| | | } else if(remark.contains("æ·»å ")||remark.contains("æ°å¢")){ |
| | | type = "æ·»å "; |
| | | } |
| | | try { |
| | | authMapper.insertPower(value.getMethod().getName(), remark, type); |
| | | }catch (Exception e){ |
| | | System.err.println(value.getMethod()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @PostConstruct |
| | | public void pingStart() { |
| | | addAllController(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.common; |
| | | |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.yuanchu.mom.mapper.AuthMapper; |
| | | import com.yuanchu.mom.utils.Jwt; |
| | | import com.yuanchu.mom.utils.ServletUtils; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | public class GetLook { |
| | | |
| | | @Resource |
| | | private AuthMapper authMapper; |
| | | |
| | | public Map<String, Integer> selectPowerByMethodAndUserId(String method){ |
| | | Integer id = Integer.parseInt(JSONUtil.parseObj(new Jwt().readJWT(ServletUtils.getRequest().getHeader("token")).get("data")).get("id")+""); |
| | | Map<String, Integer> map = new HashMap<>(); |
| | | map.put("userId", id); |
| | | map.put("look", authMapper.countPower(id, method)); |
| | | return map; |
| | | } |
| | | |
| | | } |
| | |
| | | @Value("${server.port}") |
| | | private String serverPort; |
| | | |
| | | private static ThreadLocal<String> threadLocal = new ThreadLocal<>(); |
| | | |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
| | | if (HttpMethod.OPTIONS.toString().equals(request.getMethod())) { |
| | |
| | | } |
| | | String[] strs = request.getRequestURL().toString().split(serverPort); |
| | | AtomicBoolean judge = new AtomicBoolean(false); |
| | | list.forEach(a -> { |
| | | if (strs[1].equals(a)) { |
| | | for (String s : list) { |
| | | if (strs[1].equals(s)) { |
| | | judge.set(true); |
| | | return; |
| | | } else if (a.indexOf("/**") > -1) { |
| | | if (strs[1].indexOf(a.replace("/**", "")) == 0) { |
| | | break; |
| | | } else if (s.indexOf("/**") > -1) { |
| | | if (strs[1].indexOf(s.replace("/**", "")) == 0) { |
| | | judge.set(true); |
| | | return; |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | if (judge.get()) return true; |
| | | response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
| | | response.setCharacterEncoding("UTF-8"); |
| | |
| | | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @Configuration |
| | | public class OpenFifer extends WebMvcConfigurationSupport { |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private FiferConfig fiferConfig; |
| | | |
| | | @Resource |
| | | private PowerConfig powerConfig; |
| | | |
| | | @Override |
| | | protected void addInterceptors(InterceptorRegistry registry) { |
| | | registry.addInterceptor(fiferConfig).addPathPatterns("/**"); |
| | | registry.addInterceptor(powerConfig).addPathPatterns("/**"); |
| | | super.addInterceptors(registry); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.config; |
| | | |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.yuanchu.mom.annotation.ValueAuth; |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.exception.MyFileException; |
| | | import com.yuanchu.mom.mapper.AuthMapper; |
| | | import com.yuanchu.mom.utils.JackSonUtil; |
| | | import com.yuanchu.mom.utils.Jwt; |
| | | import com.yuanchu.mom.utils.ServletUtils; |
| | | import org.apache.catalina.User; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | import org.springframework.web.servlet.HandlerInterceptor; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | public class PowerConfig implements HandlerInterceptor { |
| | | |
| | | @Resource |
| | | private AuthMapper authMapper; |
| | | |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
| | | if(handler instanceof HandlerMethod) { |
| | | HandlerMethod h = (HandlerMethod)handler; |
| | | ValueAuth annotation = h.getMethodAnnotation(ValueAuth.class); |
| | | if(annotation!=null){ |
| | | return HandlerInterceptor.super.preHandle(request, response, handler); |
| | | } |
| | | JSONObject obj = JSONUtil.parseObj(new Jwt().readJWT(request.getHeader("token")).get("data")); |
| | | Integer userId = Integer.parseInt(obj.get("id") + ""); |
| | | int i = authMapper.isPower(userId, h.getMethod().getName()); |
| | | |
| | | if (i == 0){ |
| | | throw new ErrorException(obj.get("name") + " æ æéè®¿é® " + h.getMethod().getName() + " æ¥å£"); |
| | | } |
| | | } |
| | | return HandlerInterceptor.super.preHandle(request, response, handler); |
| | | } |
| | | |
| | | @Override |
| | | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { |
| | | HandlerInterceptor.super.postHandle(request, response, handler, modelAndView); |
| | | } |
| | | |
| | | @Override |
| | | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { |
| | | HandlerInterceptor.super.afterCompletion(request, response, handler, ex); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.exception; |
| | | |
| | | public class ErrorException extends RuntimeException{ |
| | | |
| | | public ErrorException(String msg){ |
| | | super(msg); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.yuanchu.mom.handler; |
| | | |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.exception.MyFileException; |
| | | import com.yuanchu.mom.vo.Result; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | return Result.fail("æ±æä¸æ¯æã" + e.getMessage() +"ãåç¼çæä»¶ï¼"); |
| | | } |
| | | |
| | | @ExceptionHandler({ErrorException.class}) |
| | | public Result<?> errorException(Exception e) { |
| | | log.error(e.getMessage()); |
| | | return Result.fail(e.getMessage()); |
| | | } |
| | | |
| | | /** å
¶ä»é误 */ |
| | | /** |
| | | * å
¶ä»é误 |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.mapper; |
| | | |
| | | import org.apache.ibatis.annotations.Delete; |
| | | import org.apache.ibatis.annotations.Insert; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Select; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.util.Map; |
| | | |
| | | @Mapper |
| | | @Repository |
| | | public interface AuthMapper { |
| | | |
| | | @Insert("insert menu value (#{method}, #{remark}, #{type}, now())") |
| | | int insertPower(String method, String remark, String type); |
| | | |
| | | |
| | | @Delete("delete from menu") |
| | | int deletePower(); |
| | | |
| | | @Select("select COALESCE(count(*), 0) from power p left join user u on u.role_id = p.role_id where u.id = #{userId} and p.menu_method = #{method}") |
| | | int isPower(Integer userId, String method); |
| | | |
| | | @Select("select look from power p left join user u on u.role_id = p.role_id where u.id = #{userId} and p.menu_method = #{method}") |
| | | int countPower(Integer userId, String method); |
| | | |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | System.out.println(wrapper.getExpression().getSqlSegment()); |
| | | // System.out.println(wrapper.getExpression().getSqlSegment()); |
| | | return wrapper; |
| | | } |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.yuanchu.mom.mapper.AuthMapper"> |
| | | |
| | | </mapper> |
| | |
| | | package com.yuanchu.mom; |
| | | |
| | | import com.yuanchu.mom.common.AllController; |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.AutoConfiguration; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @SpringBootApplication |
| | | @MapperScan("com.yuanchu.mom.mapper")// æ«æMybatisä¸çmapperå
|
| | | public class SystemRunApplication { |
| | |
| | | * æ¯å¤©æä¸23ç¹0å10ç§æ§è¡ ã 0 0 4 1/1 * ? ã |
| | | * æµè¯ 20 ç§ä¸æ¬¡ã 0/20 * * * * ? ã |
| | | */ |
| | | @Scheduled(cron = "6 0 23 * * ?") |
| | | // @Scheduled(cron = "6 0 23 * * ?") |
| | | private void TimerDeleteFile(){ |
| | | Date date = new Date(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("d"); |
| | |
| | | |
| | | @ApiOperation(value = "å é¤å®¢æ·å表") |
| | | @PostMapping("/delCustomEnum") |
| | | public Result delRole(Integer id){ |
| | | public Result delCustomEnum(Integer id){ |
| | | return Result.success(customEnumService.delCustomEnum(id)); |
| | | } |
| | | |
| | | @ApiOperation(value = "ä¿®æ¹å®¢æ·ä¿¡æ¯") |
| | | @PostMapping("/updateCustomEnum") |
| | | public Result<?> updateUser(@RequestBody CustomEnum customEnum) { |
| | | public Result<?> updateCustomEnum(@RequestBody CustomEnum customEnum) { |
| | | return Result.success(customEnumService.updateCustomEnum(customEnum)); |
| | | } |
| | | |
| | |
| | | package com.yuanchu.mom.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.annotation.ValueAuth; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.dto.RolePowerDto; |
| | | import com.yuanchu.mom.dto.UserPageDto; |
| | | import com.yuanchu.mom.mapper.AuthMapper; |
| | | import com.yuanchu.mom.mapper.PowerMapper; |
| | | import com.yuanchu.mom.pojo.CustomEnum; |
| | | import com.yuanchu.mom.pojo.Power; |
| | | import com.yuanchu.mom.pojo.Role; |
| | | import com.yuanchu.mom.pojo.User; |
| | | import com.yuanchu.mom.service.PowerService; |
| | | import com.yuanchu.mom.service.RoleService; |
| | | import com.yuanchu.mom.service.UserService; |
| | | import com.yuanchu.mom.utils.JackSonUtil; |
| | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.ibatis.annotations.ResultType; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @RequestMapping("/role") |
| | |
| | | |
| | | private RoleService roleService; |
| | | |
| | | private PowerService powerService; |
| | | |
| | | @ApiOperation(value = "è·åè§è²å表æä¸¾") |
| | | @GetMapping("/selectRoleList") |
| | | public Result selectUserList(){ |
| | | public Result selectRoleList(){ |
| | | return Result.success(roleService.selectList()); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "è·åè§è²å表") |
| | | @PostMapping("/selectRoleLists") |
| | | public Result selectRoleList(@RequestBody Map<String, Object> data) throws Exception { |
| | | public Result selectRoleLists(@RequestBody Map<String, Object> data) throws Exception { |
| | | Page page = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("page")), Page.class); |
| | | Role role = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), Role.class); |
| | | return Result.success(roleService.selectUserList(page, role)); |
| | |
| | | return Result.success(roleService.delRole(id)); |
| | | } |
| | | |
| | | @ApiOperation(value = "æ·»å è§è²ä¿¡æ¯") |
| | | @ApiOperation(value = "éè¿è§è²idæ¥è¯¢æéå表") |
| | | @PostMapping("/selectPowerByRoleId") |
| | | public Result<?> selectPowerByRoleId(Integer id) { |
| | | return Result.success(powerService.selectPowerByRoleId(id)); |
| | | } |
| | | |
| | | @ApiOperation(value = "è·åèå") |
| | | @GetMapping("/selectMenuList") |
| | | @ValueAuth |
| | | public Result<?> selectMenuList() { |
| | | return Result.success(roleService.selectMenuList()); |
| | | } |
| | | |
| | | @ApiOperation(value = "æ·»å è§è²") |
| | | @PostMapping("/addRole") |
| | | public Result<?> addRole(@RequestBody Role role) { |
| | | return Result.success(roleService.addRole(role)); |
| | | public Result<?> addRole(String str) { |
| | | RolePowerDto powers = JSON.parseObject(str, RolePowerDto.class); |
| | | return Result.success(roleService.addRole(powers)); |
| | | } |
| | | |
| | | @ApiOperation(value = "ä¿®æ¹è§è²ä¿¡æ¯") |
| | | @PostMapping("/upRole") |
| | | public Result<?> upRole(String str) { |
| | | RolePowerDto powers = JSON.parseObject(str, RolePowerDto.class); |
| | | return Result.success(roleService.upRole(powers)); |
| | | } |
| | | } |
| | |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.annotation.ValueAuth; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.UserPageDto; |
| | | import com.yuanchu.mom.pojo.User; |
| | | import com.yuanchu.mom.service.PowerService; |
| | | import com.yuanchu.mom.service.UserService; |
| | | import com.yuanchu.mom.utils.JackSonUtil; |
| | | import com.yuanchu.mom.utils.Jwt; |
| | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.DigestUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | |
| | | @RequestMapping("/user") |
| | | @RestController |
| | | @Api(tags = "ç¨æ·æ¨¡å") |
| | | @AllArgsConstructor |
| | | public class UserController { |
| | | |
| | | @Autowired |
| | | UserService userService; |
| | | private UserService userService; |
| | | |
| | | @Autowired |
| | | private PowerService powerService; |
| | | |
| | | private Jwt jwt; |
| | | |
| | | @ApiOperation(value = "ç»å½") |
| | | @PostMapping("/enter") |
| | | @ValueAuth |
| | | public Result login(String account, String password) { |
| | | User user = userService.selectUserByPwd(account, password); |
| | | if (user == null) return Result.fail("ç»å½å¤±è´¥"); |
| | |
| | | String jwtReToken = jwt.createJwt(user.getName(), user.getId(), 24 * 60); |
| | | RedisUtil.set("" + user.getId(), jwtToken, 60); |
| | | RedisUtil.set(user.getId() + "Re", jwtReToken, 24 * 60); |
| | | Map<String, String> map = new HashMap<>(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("token", jwtToken); |
| | | map.put("reToken", jwtReToken); |
| | | map.put("name", user.getName()); |
| | | map.put("power", powerService.selectPowerByRoleId(user.getRoleId())); |
| | | return Result.success("ç»å½æå", map); |
| | | } |
| | | |
| | | @ApiOperation(value = "tokenå·æ°") |
| | | @PostMapping("/refresh") |
| | | @ValueAuth |
| | | public Result refresh(String reToken) throws Exception { |
| | | Map<String, String> map = new Jwt().readJWT(reToken); |
| | | Map<String, String> maps = JackSonUtil.unmarshal(map.get("data"), Map.class); |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.dto; |
| | | |
| | | import com.yuanchu.mom.pojo.Power; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | @AllArgsConstructor |
| | | @NoArgsConstructor |
| | | public class RolePowerDto implements Serializable { |
| | | |
| | | private Integer roleId2; |
| | | |
| | | private String roleName; |
| | | |
| | | private List<Power> powers; |
| | | |
| | | } |
| | |
| | | package com.yuanchu.mom.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.yuanchu.mom.pojo.Menu; |
| | | import com.yuanchu.mom.pojo.Power; |
| | | import com.yuanchu.mom.pojo.Role; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Mapper |
| | | @Repository |
| | | public interface RoleMapper extends BaseMapper<Role> { |
| | | |
| | | List<Menu> selectMenuList(); |
| | | |
| | | int addPower(Power power); |
| | | |
| | | } |
| | |
| | | package com.yuanchu.mom.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.yuanchu.mom.dto.RolePowerDto; |
| | | import com.yuanchu.mom.dto.UserPageDto; |
| | | import com.yuanchu.mom.pojo.Menu; |
| | | import com.yuanchu.mom.pojo.Role; |
| | | import com.yuanchu.mom.pojo.User; |
| | | |
| | |
| | | |
| | | int delRole(Integer id); |
| | | |
| | | int addRole(Role role); |
| | | int addRole(RolePowerDto rolePowerDto); |
| | | |
| | | List<Menu> selectMenuList(); |
| | | |
| | | int upRole(RolePowerDto rolePowerDto); |
| | | |
| | | } |
| | |
| | | package com.yuanchu.mom.service.imp; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.mapper.CustomEnumMapper; |
| | | import com.yuanchu.mom.pojo.CustomEnum; |
| | |
| | | |
| | | private CustomEnumMapper customEnumMapper; |
| | | |
| | | private GetLook getLook; |
| | | |
| | | @Override |
| | | public Map<String, Object> selectCustomEnumList(IPage<CustomEnum> page, CustomEnum customEnum) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(CustomEnum.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectDataReportingList"); |
| | | if(map1.get("look")==1) customEnum.setCreateUser(map1.get("userId")); |
| | | map.put("body", customEnumMapper.selectPage(page, QueryWrappers.queryWrappers(customEnum))); |
| | | return map; |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.mapper.ProductEnumMapper; |
| | | import com.yuanchu.mom.pojo.ProductEnum; |
| | |
| | | |
| | | private ProductEnumMapper productEnumMapper; |
| | | |
| | | private GetLook getLook; |
| | | |
| | | @Override |
| | | public Map<String, Object> selectProductEnumList(IPage<ProductEnum> page, ProductEnum productEnum) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(ProductEnum.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectDataReportingList"); |
| | | if(map1.get("look")==1) productEnum.setCreateUser(map1.get("userId")); |
| | | map.put("body", productEnumMapper.selectPage(page, QueryWrappers.queryWrappers(productEnum))); |
| | | return map; |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.RolePowerDto; |
| | | import com.yuanchu.mom.dto.UserPageDto; |
| | | import com.yuanchu.mom.mapper.PowerMapper; |
| | | import com.yuanchu.mom.mapper.RoleMapper; |
| | | import com.yuanchu.mom.mapper.UserMapper; |
| | | import com.yuanchu.mom.pojo.Menu; |
| | | import com.yuanchu.mom.pojo.Power; |
| | | import com.yuanchu.mom.pojo.Role; |
| | | import com.yuanchu.mom.pojo.User; |
| | | import com.yuanchu.mom.service.RoleService; |
| | |
| | | import com.yuanchu.mom.utils.QueryWrappers; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.DigestUtils; |
| | | |
| | | import java.util.HashMap; |
| | |
| | | |
| | | private RoleMapper roleMapper; |
| | | |
| | | private PowerMapper powerMapper; |
| | | |
| | | private GetLook getLook; |
| | | |
| | | @Override |
| | | public List<Role> selectList() { |
| | | return roleMapper.selectList(null); |
| | |
| | | public Map<String, Object> selectUserList(IPage<Role> page, Role role) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(Role.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectDataReportingList"); |
| | | if(map1.get("look")==1) role.setCreateUser(map1.get("userId")); |
| | | map.put("body", roleMapper.selectPage(page, QueryWrappers.queryWrappers(role))); |
| | | return map; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int addRole(Role role) { |
| | | return roleMapper.insert(role); |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int addRole(RolePowerDto rolePowerDto) { |
| | | Role role = new Role(); |
| | | role.setName(rolePowerDto.getRoleName()); |
| | | int insert = roleMapper.insert(role); |
| | | if (insert == 1){ |
| | | rolePowerDto.getPowers().forEach(a->{ |
| | | a.setRoleId(role.getId()); |
| | | powerMapper.insert(a); |
| | | }); |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | @Override |
| | | public List<Menu> selectMenuList() { |
| | | return roleMapper.selectMenuList(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int upRole(RolePowerDto rolePowerDto) { |
| | | Role role = new Role(); |
| | | role.setName(rolePowerDto.getRoleName()); |
| | | role.setId(rolePowerDto.getRoleId2()); |
| | | int up = roleMapper.updateById(role); |
| | | if (up == 1){ |
| | | powerMapper.delete(Wrappers.<Power>lambdaUpdate().eq(Power::getRoleId, role.getId())); |
| | | rolePowerDto.getPowers().forEach(a->{ |
| | | a.setRoleId(role.getId()); |
| | | powerMapper.insert(a); |
| | | }); |
| | | } |
| | | return 1; |
| | | } |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.UserPageDto; |
| | | import com.yuanchu.mom.mapper.UserMapper; |
| | |
| | | |
| | | Jwt jwt; |
| | | |
| | | private GetLook getLook; |
| | | |
| | | @Override |
| | | public User selectUserByPwd(String account, String password) { |
| | | QueryWrapper<User> wrapper = new QueryWrapper<>(); |
| | |
| | | public Map<String, Object> selectUserList(IPage<UserPageDto> page, UserPageDto user) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(UserPageDto.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectDataReportingList"); |
| | | if(map1.get("look")==1) user.setCreateUser(map1.get("userId")); |
| | | map.put("body", userMapper.selectUserDtoPageList(page, QueryWrappers.queryWrappers(user))); |
| | | return map; |
| | | } |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.yuanchu.mom.mapper.RoleMapper"> |
| | | <insert id="addPower"> |
| | | |
| | | </insert> |
| | | <select id="selectMenuList" resultType="com.yuanchu.mom.pojo.Menu"> |
| | | select method,remark,type from menu |
| | | </select> |
| | | </mapper> |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.yuanchu.mom.mapper.UserMapper"> |
| | | |
| | | <select id="selectUserDtoPageList" resultType="com.yuanchu.mom.dto.UserPageDto"> |
| | | select * from ( |
| | | select u1.id, u1.account, u1.name, u1.state, u1.create_time, u1.update_time, u1.create_user, u1.update_user, u1.age, u1.email, u1.phone, u1.department, u1.company, u1.role_id, u2.name create_user_name, u3.name update_user_name, r.name role_name |