Browse Source

wanghaicheng 2019.11.27-15.57

wanghaicheng 5 năm trước cách đây
mục cha
commit
a6f0c318eb

+ 165 - 0
lift-enterprise-service/src/main/java/cn/com/ty/lift/enterprise/custom/controller/PropertyCompanyController.java

@@ -0,0 +1,165 @@
+package cn.com.ty.lift.enterprise.custom.controller;
+
+import cn.com.ty.lift.enterprise.custom.entity.PropertyCompany;
+import cn.com.ty.lift.enterprise.custom.service.impl.PropertyCompanyServiceImpl;
+import cn.com.xwy.boot.web.dto.RestResponse;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/property-company")
+@AllArgsConstructor
+/**
+ * @author wang-hai-cheng
+ * @date 2019/11/27
+ * @description
+ * 客户接口(物业公司)(甲方公司) 前端控制器
+ */
+public class PropertyCompanyController {
+    private final PropertyCompanyServiceImpl propertyCompanyService;
+
+    @GetMapping("/page")
+    /**
+     * @description id顺序+分页客户列表
+     * @date 2019/11/27 11:33
+     * @param [current, size]
+     * @return cn.com.xwy.boot.web.dto.RestResponse
+     */
+    public RestResponse page(@RequestParam Integer current,@RequestParam Integer size) {
+        Page<PropertyCompany> page = new Page<>(current, size);
+        return RestResponse.ok(propertyCompanyService.page(page).getRecords(), "查询成功");
+    }
+
+    @GetMapping("/{id}")
+    /**
+     * @description 根据id获取客户详细信息
+     * @date 2019/11/27 11:36
+     * @param [id]
+     * @return cn.com.xwy.boot.web.dto.RestResponse
+     */
+    public RestResponse propertyCompany(@PathVariable int id) {
+        PropertyCompany byId = propertyCompanyService.getById(id);
+        if (byId != null) {
+            return RestResponse.ok(byId, "查询成功");
+        } else {
+            return RestResponse.ok(null,"无数据");
+        }
+    }
+
+    @GetMapping("/name")
+    /**
+     * @description 根据客户名称分页获取客户列表
+     * @date 2019/11/27 11:37
+     * @param [name, current, size]
+     * @return cn.com.xwy.boot.web.dto.RestResponse
+     */
+    public RestResponse propertyCompaniesFromName(@RequestParam String name,@RequestParam Integer current,@RequestParam Integer size) {
+        Page<PropertyCompany> page = new Page<>(current, size);
+        List<PropertyCompany> propertyCompanies = propertyCompanyService.page(page, new QueryWrapper<PropertyCompany>().like("name",name)).getRecords();
+        if (null != propertyCompanies) {
+            return RestResponse.ok(propertyCompanies, "查询成功");
+        } else {
+            return RestResponse.ok(null,"未搜索到客户");
+        }
+    }
+
+    @GetMapping("/address")
+    /**
+         * @description 根据客户地址分页获取客户列表
+         * @date 2019/11/27 11:38
+         * @param [address, current, size]
+         * @return cn.com.xwy.boot.web.dto.RestResponse
+         */
+    public RestResponse propertyCompaniesFromAddress(@RequestParam String address,@RequestParam Integer current,@RequestParam Integer size) {
+        Page<PropertyCompany> page = new Page<>(current, size);
+        List<PropertyCompany> propertyCompanies = propertyCompanyService.page(page, new QueryWrapper<PropertyCompany>().like("address",address)).getRecords();
+        if (null != propertyCompanies) {
+            return RestResponse.ok(propertyCompanies,"查询成功");
+        } else {
+            return RestResponse.ok(null,"未搜索到客户");
+        }
+    }
+
+    @GetMapping("/phone")
+    /**
+         * @description 根据客户电话分页获取客户列表
+         * @date 2019/11/27 11:39
+         * @param [phone, current, size]
+         * @return cn.com.xwy.boot.web.dto.RestResponse
+         */
+    public RestResponse propertyCompaniesFromPhone(@RequestParam String phone,@RequestParam Integer current,@RequestParam Integer size) {
+        Page<PropertyCompany> page = new Page<>(current, size);
+        List<PropertyCompany> propertyCompanies = propertyCompanyService.page(page, new QueryWrapper<PropertyCompany>().like("telephone",phone)).getRecords();
+        if (null != propertyCompanies) {
+            return RestResponse.ok(propertyCompanies,"查询成功");
+        } else {
+            return RestResponse.ok(null,"未搜索到客户");
+        }
+    }
+
+    @PostMapping("/add")
+    /**
+         * @description 新增客户
+         * @date 2019/11/27 11:45
+         * @param [propertyCompany]
+         * @return cn.com.xwy.boot.web.dto.RestResponse
+         */
+    public RestResponse add(@RequestBody PropertyCompany propertyCompany) {
+        String s = propertyCompanyService.savePropertyCompany(propertyCompany);
+        if (s.equals("新增客户成功")) {
+            return RestResponse.ok(null,"新增客户成功");
+        }else if (s.equals("新增客户失败")){
+            return RestResponse.ok(null,"新增客户失败");
+        }else {
+            return RestResponse.ok(null,"客户已存在");
+        }
+    }
+
+    @PostMapping("/update")
+    /**
+         * @description 更新客户信息
+         * @date 2019/11/27 11:45
+         * @param [propertyCompany]
+         * @return cn.com.xwy.boot.web.dto.RestResponse
+         */
+    public RestResponse update( PropertyCompany propertyCompany) {
+        if (propertyCompanyService.updateById(propertyCompany)) {
+            return RestResponse.ok(null,"更新成功");
+        } else {
+            return RestResponse.ok(null,"更新失败");
+        }
+    }
+
+    @GetMapping("/delete/{id}")
+    /**
+         * @description RestResponse
+         * @date 2019/11/27 11:46
+         * @param [id]
+         * @return cn.com.xwy.boot.web.dto.RestResponse
+         */
+    public RestResponse delete(@PathVariable int id) {
+
+        //判断维保电梯台数是否为0
+        //判断维保电梯台数是否为0
+        //判断维保电梯台数是否为0
+        //判断维保电梯台数是否为0
+        //判断维保电梯台数是否为0
+        //判断维保电梯台数是否为0
+        //判断维保电梯台数是否为0
+        //判断维保电梯台数是否为0
+        //判断维保电梯台数是否为0
+        //判断维保电梯台数是否为0
+        //判断维保电梯台数是否为0
+        //也就是客户公司创建的所有项目的总电梯的在保电梯是否为0
+
+        if (propertyCompanyService.delete(id)) {
+            return RestResponse.ok(null,"删除成功");
+        } else {
+            return RestResponse.ok(null,"删除失败");
+        }
+    }
+}

+ 157 - 2
lift-system-service/src/main/java/cn/com/ty/lift/system/faq/controller/FaqController.java

@@ -1,8 +1,163 @@
 package cn.com.ty.lift.system.faq.controller;
 
 
-import org.springframework.web.bind.annotation.RestController;
+import cn.com.ty.lift.system.faq.entity.Faq;
+import cn.com.ty.lift.system.faq.mapper.FaqMapper;
+import cn.com.ty.lift.system.faq.service.impl.FaqServiceImpl;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 
+import lombok.AllArgsConstructor;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @author wang-hai-cheng
+ * @date 2019/11/27
+ * @description 常见问题级常见问题分类表 前端控制器
+ */
 @RestController
+@RequestMapping("/faq")
+@AllArgsConstructor
 public class FaqController {
-}
+    private final FaqServiceImpl faqService;
+    private final FaqMapper faqMapper;
+
+    @GetMapping("/one")
+    /**
+     * @description 查询一级分类
+     * @date 2019/11/27 10:19
+     * @param []
+     * @return java.util.List<cn.com.ty.lift.system.faq.entity.Faq>
+     */
+    public List<Faq> one() {
+        return faqService.list(new QueryWrapper<Faq>().eq("type", 1).eq("parent_id", 0).orderByAsc("serial"));
+    }
+
+    @GetMapping("/child")
+    /**
+     * @description 根据父分类id查询子分类
+     * @date 2019/11/27 10:19
+     * @param [parentId]
+     * @return java.util.List<cn.com.ty.lift.system.faq.entity.Faq>
+     */
+    public List<Faq> child(int parentId) {
+        return faqService.list(new QueryWrapper<Faq>().eq("type", 1).eq("parent_id", parentId).orderByAsc("serial"));
+    }
+
+    @GetMapping("/question")
+    /**
+     * @description 根据分类id查询问题标题列表
+     * @date 2019/11/27 10:25
+     * @param [parentId]
+     * @return java.util.List<cn.com.ty.lift.system.faq.entity.Faq>
+     */
+    public List<Faq> question(int parentId) {
+        return faqService.list(new QueryWrapper<Faq>().eq("type", 2).eq("parent_id", parentId).orderByAsc("serial"));
+    }
+
+    @GetMapping("/answer")
+    /**
+     * @description 根据问题id查询答案
+     * @date 2019/11/27 10:31
+     * @param [parentId]
+     * @return cn.com.ty.lift.system.faq.entity.Faq
+     */
+    public Faq answer(int parentId) {
+        return faqService.getOne(new QueryWrapper<Faq>().eq("type", 3).eq("parent_id", parentId).orderByAsc("serial"));
+    }
+
+    @PostMapping("/add/one")
+    /**
+     * @description 新增一级分类
+     * @date 2019/11/27 10:47
+     * @param [faq]
+     * @return org.springframework.http.ResponseEntity
+     */
+    public ResponseEntity addOne(Faq faq) {
+        //@RequestParam String title, @RequestParam String description
+        return faqService.addOne(faq.getContent(), faq.getDescription());
+    }
+
+    @PostMapping("/add/child")
+    /**
+     * @description 新增子分类
+     * @date 2019/11/27 10:47
+     * @param [faq]
+     * @return org.springframework.http.ResponseEntity
+     */
+    public ResponseEntity addChild(Faq faq) {
+        //@RequestParam int parentId, @RequestParam String title, @RequestParam String description
+        return faqService.addChild(faq.getParentId(), faq.getContent(), faq.getDescription());
+    }
+
+    @PostMapping("/add/question")
+    /**
+         * @description 根据分类id新增问题
+         * @date 2019/11/27 10:51
+         * @param [faq]
+         * @return org.springframework.http.ResponseEntity
+         */
+    public ResponseEntity addQuestion(Faq faq) {
+        //@RequestParam int parentId, @RequestParam String title, @RequestParam String description
+        return faqService.addQuestion(faq.getParentId(), faq.getContent(), faq.getDescription());
+    }
+
+    @PostMapping("/add/answer")
+    /**
+         * @description 根据问题id新增答案
+         * @date 2019/11/27 10:51
+         * @param [faq]
+         * @return org.springframework.http.ResponseEntity
+         */
+    public ResponseEntity addAnswer(Faq faq) {
+        //@RequestParam int parentId, @RequestParam String content, @RequestParam String description
+        return faqService.addAnswer(faq.getParentId(), faq.getContent(), faq.getDescription());
+    }
+
+    @PostMapping("/update")
+    /**
+         * @description 更新分类名或问题标题或答案内容,都是title参数,description是对此id信息的描述
+         * @date 2019/11/27 10:51
+         * @param [faq]
+         * @return org.springframework.http.ResponseEntity
+         */
+    public ResponseEntity updateOne(Faq faq) {
+        return faqService.up(faq.getId(), faq.getContent(), faq.getDescription());
+    }
+
+    @PostMapping("/delete")
+    /**
+         * @description 根据id删除此id下的分类和问答
+         * @date 2019/11/27 10:51
+         * @param [id]
+         * @return org.springframework.http.ResponseEntity
+         */
+    public ResponseEntity deleteAll(int id) {
+        return faqService.delete(id);
+    }
+
+    @GetMapping("/up")
+    /** 排序上移一位
+         * @description
+         * @date 2019/11/27 10:52
+         * @param [id]
+         * @return org.springframework.http.ResponseEntity
+         */
+    public ResponseEntity up(int id) {
+        return faqService.up(id);
+    }
+
+    @GetMapping("/down")
+    /**
+         * @description 排序下移一位
+         * @date 2019/11/27 10:52
+         * @param [id]
+         * @return org.springframework.http.ResponseEntity
+         */
+    public ResponseEntity down(int id) {
+        return faqService.down(id);
+    }
+}

+ 64 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/faq/entity/Faq.java

@@ -0,0 +1,64 @@
+package cn.com.ty.lift.system.faq.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 常见问题级常见问题分类表
+ * </p>
+ *
+ * @author wang-hai-cheng
+ * @since 2019-11-21
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class Faq implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * (分类 问题标题 答案) 的id
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 内容
+     */
+    @TableField("content")
+    private String content;
+
+    /**
+     * 1分类 2问题标题 3答案
+     */
+    @TableField("type")
+    private Integer type;
+
+    /**
+     * 父id
+     */
+    @TableField("parent_id")
+    private Integer parentId;
+
+    /**
+     * 序号
+     */
+    @TableField("serial")
+    private Integer serial;
+
+    /**
+     * 描述
+     */
+    @TableField("description")
+    private String description;
+
+
+}

+ 23 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/faq/mapper/FaqMapper.java

@@ -0,0 +1,23 @@
+package cn.com.ty.lift.system.faq.mapper;
+
+import cn.com.ty.lift.system.faq.entity.Faq;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+
+/**
+ * <p>
+ * 常见问题级常见问题分类表 Mapper 接口
+ * </p>
+ *
+ * @author wang-hai-cheng
+ * @since 2019-11-21
+ */
+@Mapper
+@Repository
+public interface FaqMapper extends BaseMapper<Faq> {
+}

+ 12 - 3
lift-system-service/src/main/java/cn/com/ty/lift/system/faq/service/FaqService.java

@@ -1,7 +1,16 @@
 package cn.com.ty.lift.system.faq.service;
 
-import org.springframework.stereotype.Service;
+import cn.com.ty.lift.system.faq.entity.Faq;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ * 常见问题级常见问题分类表 服务类
+ * </p>
+ *
+ * @author wang-hai-cheng
+ * @since 2019-11-21
+ */
+public interface FaqService extends IService<Faq> {
 
-@Service
-public class FaqService {
 }

+ 151 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/faq/service/impl/FaqServiceImpl.java

@@ -0,0 +1,151 @@
+package cn.com.ty.lift.system.faq.service.impl;
+
+import cn.com.ty.lift.system.faq.entity.Faq;
+import cn.com.ty.lift.system.faq.mapper.FaqMapper;
+import cn.com.ty.lift.system.faq.service.FaqService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.AllArgsConstructor;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 常见问题级常见问题分类表 服务实现类
+ * </p>
+ *
+ * @author wang-hai-cheng
+ * @since 2019-11-21
+ */
+@Transactional
+@Service
+@AllArgsConstructor
+public class FaqServiceImpl extends ServiceImpl<FaqMapper, Faq> implements FaqService {
+
+    public ResponseEntity addOne(String title, String description) {
+        Faq faq = new Faq();
+        faq.setContent(title).setType(1).setParentId(0).setDescription(description);
+        faq.setSerial(this.list(new QueryWrapper<Faq>().eq("type", 1).eq("parent_id", 0)).size() + 1);
+        if (this.save(faq)) {
+            return ResponseEntity.status(HttpStatus.OK).body("新增一级分类成功");
+        } else {
+            return ResponseEntity.status(HttpStatus.OK).body("新增一级分类失败");
+        }
+    }
+
+    public ResponseEntity addChild(int parentId, String title, String description) {
+        Faq faq = new Faq();
+        faq.setContent(title).setType(1).setParentId(parentId).setDescription(description);
+        faq.setSerial(this.list(new QueryWrapper<Faq>().eq("type", 1).eq("parent_id", parentId)).size() + 1);
+        if (this.save(faq)) {
+            return ResponseEntity.status(HttpStatus.OK).body("新增一级分类成功");
+        } else {
+            return ResponseEntity.status(HttpStatus.OK).body("新增一级分类失败");
+        }
+    }
+
+    public ResponseEntity addQuestion(int parentId, String title, String description) {
+        Faq faq = new Faq();
+        faq.setContent(title).setType(2).setParentId(parentId).setDescription(description);
+        faq.setSerial(this.list(new QueryWrapper<Faq>().eq("type", 2).eq("parent_id", parentId)).size() + 1);
+        if (this.save(faq)) {
+            return ResponseEntity.status(HttpStatus.OK).body("新增问题成功");
+        } else {
+            return ResponseEntity.status(HttpStatus.OK).body("新增问题失败");
+        }
+    }
+
+    public ResponseEntity addAnswer(int parentId, String content, String description) {
+        Faq faq = new Faq();
+        faq.setContent(content).setType(3).setParentId(parentId).setDescription(description);
+        faq.setSerial(this.list(new QueryWrapper<Faq>().eq("type", 3).eq("parent_id", parentId)).size() + 1);
+        if (this.save(faq)) {
+            return ResponseEntity.status(HttpStatus.OK).body("新增答案成功");
+        } else {
+            return ResponseEntity.status(HttpStatus.OK).body("新增答案失败");
+        }
+    }
+
+    public ResponseEntity up(int id, String title, String description) {
+        Faq byId = this.getById(id);
+        byId.setContent(title).setDescription(description);
+        if (this.updateById(byId)) {
+            return ResponseEntity.status(HttpStatus.OK).body("更新成功");
+        } else {
+            return ResponseEntity.status(HttpStatus.OK).body("更新失败");
+        }
+    }
+
+    public ResponseEntity delete(int id) {
+        if (deleteAll(id)) {
+            return ResponseEntity.status(HttpStatus.OK).body("删除成功");
+        } else {
+            return ResponseEntity.status(HttpStatus.OK).body("删除失败");
+        }
+    }
+
+    //递归删除id及它下面所有分类,问答
+    private boolean deleteAll(int id) {
+        //获取父id下的所有子分类或问答
+        List<Faq> faqs = this.list(new QueryWrapper<Faq>().eq("parent_id", id));
+        //删除父id下的所有子分类或问答
+        this.remove(new QueryWrapper<Faq>().eq("parent_id", id));
+        //删除自己
+        this.remove(new QueryWrapper<Faq>().eq("id", id));
+        //如果父id下还有子分类或问答
+        if (faqs.size() != 0) {
+            //遍历删除自己及删除自己下的所有子分类或问答
+            faqs.forEach(faq -> {
+                this.remove(new QueryWrapper<Faq>().eq("parent_id", id));
+                this.remove(new QueryWrapper<Faq>().eq("id", id));
+                //递归删除
+                deleteAll(faq.getParentId());
+            });
+            //删除完毕返回true
+            return true;
+        } else {
+            //如果没有子分类或问答就直接返回了
+            return true;
+        }
+    }
+
+    public ResponseEntity up(int id) {
+        Faq up = this.getById(id);
+        if (up != null) {
+            if (up.getSerial() > 1) {
+                Faq one = this.getOne(new QueryWrapper<Faq>().eq("type", up.getType()).eq("parent_id", up.getParentId()).eq("serial", up.getSerial() - 1));
+                one.setSerial(one.getSerial() + 1);
+                up.setSerial(up.getSerial() - 1);
+                this.updateById(one);
+                this.updateById(up);
+                return ResponseEntity.status(HttpStatus.OK).body("上移一位");
+            } else {
+                return ResponseEntity.status(HttpStatus.OK).body("已经到顶了");
+            }
+        } else {
+            return ResponseEntity.status(HttpStatus.OK).body("此id不存在");
+        }
+    }
+
+    public ResponseEntity down(int id) {
+        Faq up = this.getById(id);
+        if (up != null) {
+            if (this.count(new QueryWrapper<Faq>().eq("type", up.getType()).eq("parent_id", up.getParentId()).eq("serial", up.getSerial())) > up.getSerial()) {
+                Faq one = this.getOne(new QueryWrapper<Faq>().eq("type", up.getType()).eq("parent_id", up.getParentId()).eq("serial", up.getSerial() + 1));
+                one.setSerial(one.getSerial() - 1);
+                up.setSerial(one.getSerial() + 1);
+                this.updateById(one);
+                this.updateById(up);
+                return ResponseEntity.status(HttpStatus.OK).body("下移一位");
+            } else {
+                return ResponseEntity.status(HttpStatus.OK).body("已经到顶了");
+            }
+        } else {
+            return ResponseEntity.status(HttpStatus.OK).body("此id不存在");
+        }
+    }
+}