Commit d64070fd authored by shangtx's avatar shangtx

feat: 服务管理

parent e45b4234
package com.onsiteservice.admin.controller.category;
import com.onsiteservice.admin.controller.category.dto.ServiceCategoryDTO;
import com.onsiteservice.admin.controller.category.vo.CategoryVO;
import com.onsiteservice.admin.service.category.ServiceCategoryService;
import com.onsiteservice.admin.service.category.ServiceSubclassService;
import com.onsiteservice.common.annotation.user.CurrentUserId;
import com.onsiteservice.core.result.Result;
import com.onsiteservice.entity.category.ServiceCategory;
import com.onsiteservice.entity.category.ServiceSubclass;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.validation.constraints.Positive;
import java.util.List;
import static com.onsiteservice.core.result.ResultGenerator.success;
/**
* @author 商天翔
* @date 2022-07-13 17:03
* @description ServiceCategoryController控制类
*/
@ApiIgnore
@Api(tags = "ServiceCategoryController")
@RestController
@RequestMapping("/service")
@Validated
@AllArgsConstructor(onConstructor_ = {@Autowired})
public class ServiceCategoryController {
private ServiceCategoryService serviceCategoryService;
private ServiceSubclassService serviceSubclassService;
@ApiOperation(value = "分类列表查询", notes = "作者: 商天翔")
@PostMapping("/category-list")
public Result<List<CategoryVO>> getCategoryList(@RequestBody ServiceCategoryDTO dto) {
return success(serviceCategoryService.getCategoryList(dto));
}
@ApiOperation(value = "根据id查询大类", notes = "作者: 商天翔")
@GetMapping("/{id}")
public Result<ServiceCategory> getDetails(@PathVariable @Positive Long id) {
return success(serviceCategoryService.selectByPrimaryKey(id), "根据id获取详情");
}
@ApiOperation(value = "根据id查询小类", notes = "作者: 商天翔")
@GetMapping("/sub-class/{id}")
public Result<ServiceSubclass> getSubDetails(@PathVariable @Positive Long id) {
return success(serviceSubclassService.selectByPrimaryKey(id), "根据id获取详情");
}
@ApiOperation(value = "修改大类信息", notes = "作者: 商天翔")
@PostMapping("/category")
public Result updateCategory(@RequestBody @NonNull @Validated ServiceCategory serviceCategory,
@CurrentUserId Long userId) {
return success(serviceCategoryService.saveOrUpdate(serviceCategory, userId));
}
@ApiOperation(value = "新增或修改小类信息", notes = "作者: 商天翔")
@PostMapping("/subclass")
public Result saveOrUpdateSubClass(@RequestBody @NonNull @Validated ServiceSubclass subclass,
@CurrentUserId Long userId) {
return success(serviceSubclassService.saveOrUpdate(subclass, userId));
}
}
package com.onsiteservice.admin.controller.category.dto;
import lombok.Data;
@Data
public class ServiceCategoryDTO {
private Boolean enabled;
}
package com.onsiteservice.admin.controller.category.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class CategoryVO {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("服务名称")
private String serviceName;
@ApiModelProperty("顺序")
private Integer sequence;
@ApiModelProperty("服务小类")
private List<ServiceItemVO> children;
private Integer type = 1;
private String key;
}
package com.onsiteservice.admin.controller.category.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ServiceItemVO {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("大类id")
private Integer categoryId;
@ApiModelProperty("服务名称")
private String serviceName;
@ApiModelProperty("顺序")
private Integer sequence;
@ApiModelProperty("大类图片")
private String img;
private Boolean enabled;
private Integer type = 2;
private String key;
}
package com.onsiteservice.admin.mapper.service;
import com.onsiteservice.admin.controller.category.vo.CategoryVO;
import java.util.List;
/**
* @author 商天翔
* @date 2022-07-13 17:03
* @description ServiceCategoryBizMapper业务接口
*/
public interface ServiceCategoryBizMapper {
List<CategoryVO> getAll();
}
package com.onsiteservice.admin.mapper.service;
import com.onsiteservice.admin.controller.category.dto.ServiceCategoryDTO;
import com.onsiteservice.admin.controller.category.vo.ServiceItemVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author 商天翔
* @date 2022-07-13 17:03
* @description ServiceSubclassBizMapper业务接口
*/
public interface ServiceSubclassBizMapper {
List<ServiceItemVO> getSubClasses(@Param("param")ServiceCategoryDTO dto);
}
package com.onsiteservice.admin.service.category;
import com.onsiteservice.admin.controller.category.dto.ServiceCategoryDTO;
import com.onsiteservice.admin.controller.category.vo.CategoryVO;
import com.onsiteservice.admin.controller.category.vo.ServiceItemVO;
import com.onsiteservice.admin.mapper.service.ServiceSubclassBizMapper;
import com.onsiteservice.common.annotation.user.CurrentUserId;
import com.onsiteservice.dao.common.AbstractMapper;
import com.onsiteservice.dao.mapper.service.ServiceCategoryMapper;
import com.onsiteservice.admin.mapper.service.ServiceCategoryBizMapper;
import com.onsiteservice.dao.common.page.PageParams;
import com.onsiteservice.dao.common.page.PageInfoVO;
import com.github.pagehelper.PageHelper;
import com.onsiteservice.dao.util.EntityUtils;
import com.onsiteservice.entity.category.ServiceCategory;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.swing.text.html.parser.Entity;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author 商天翔
* @date 2022-07-13 17:03
* @description ServiceCategoryService服务类
*/
@Service
@Transactional(rollbackFor = Exception.class)
@AllArgsConstructor(onConstructor_ = {@Autowired})
public class ServiceCategoryService extends AbstractMapper<ServiceCategory> {
private ServiceCategoryMapper serviceCategoryMapper;
private ServiceCategoryBizMapper serviceCategoryBizMapper;
private ServiceSubclassBizMapper serviceSubclassBizMapper;
/**
* 保存或更新方法
*/
public int saveOrUpdate(ServiceCategory serviceCategory, @CurrentUserId Long userId) {
EntityUtils.update(serviceCategory, userId);
return this.updateByPrimaryKeySelective(serviceCategory);
}
public List<CategoryVO> getCategoryList(ServiceCategoryDTO dto) {
List<CategoryVO> categories = serviceCategoryBizMapper.getAll();
// 获取服务小类
List<ServiceItemVO> subItems = serviceSubclassBizMapper.getSubClasses(dto);
Map<Integer, List<ServiceItemVO>> subMap = subItems.stream().collect(Collectors.groupingBy(ServiceItemVO::getCategoryId));
categories.forEach((category) -> category.setChildren(subMap.get(category.getId())));
return categories;
}
}
package com.onsiteservice.admin.service.category;
import com.onsiteservice.dao.common.AbstractMapper;
import com.onsiteservice.dao.util.EntityUtils;
import com.onsiteservice.entity.category.ServiceSubclass;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author 商天翔
* @date 2022-07-13 17:03
* @description ServiceSubclassService服务类
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ServiceSubclassService extends AbstractMapper<ServiceSubclass> {
/**
* 保存或更新方法
*/
public int saveOrUpdate(ServiceSubclass serviceSubclass, Long currentUserId) {
if (serviceSubclass.getId() == null) {
EntityUtils.insert(serviceSubclass, currentUserId);
return this.insertSelective(serviceSubclass);
} else {
EntityUtils.update(serviceSubclass, currentUserId);
return this.updateByPrimaryKeySelective(serviceSubclass);
}
}
}
<?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.onsiteservice.admin.mapper.service.ServiceCategoryBizMapper">
<select id="getAll" resultType="com.onsiteservice.admin.controller.category.vo.CategoryVO">
select t.id, service_name, sequence, img, t.id `key`
from service_category t
order by t.sequence
</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.onsiteservice.admin.mapper.service.ServiceSubclassBizMapper">
<select id="getSubClasses" resultType="com.onsiteservice.admin.controller.category.vo.ServiceItemVO">
select t.id,
t.category_id,
t.service_name,
t.sequence,
t.img,
t.enabled,
concat(t.category_id, '-', t.id) `key`
from service_subclass t
<where>
<if test="param.enabled != null">
and t.enabled = #{param.enabled}
</if>
</where>
</select>
</mapper>
package com.onsiteservice.admin.service.category;
import com.alibaba.fastjson.JSONObject;
import com.onsiteservice.admin.controller.category.dto.ServiceCategoryDTO;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class ServiceCategoryServiceTest {
@Resource
private ServiceCategoryService serviceCategoryService;
@Test
void getPage() {
}
@Test
void saveOrUpdate() {
}
@Test
void getCategoryList() {
System.out.println(JSONObject.toJSONString(serviceCategoryService.getCategoryList(new ServiceCategoryDTO())));
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import javax.persistence.*;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import tk.mybatis.mapper.annotation.LogicDelete;
@Getter
@Setter
......@@ -66,6 +67,9 @@ public class ServiceSubclass implements Serializable {
@ApiModelProperty("修改人")
private String modifyBy;
@ApiModelProperty("启用")
private Boolean enabled;
/**
* 修改时间
*/
......
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