Browse Source

报修类型改为从后台查询

leihy 2 years ago
parent
commit
3e5a113feb

+ 34 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/program/controller/WorkerMiniController.java

@@ -6,6 +6,7 @@ import com.example.nngkxxdp.entity.SEvaluation;
 import com.example.nngkxxdp.program.constant.MiniConstant;
 import com.example.nngkxxdp.program.entity.SRepair;
 import com.example.nngkxxdp.program.service.CanteenMiniService;
+import com.example.nngkxxdp.program.service.SDictService;
 import com.example.nngkxxdp.program.service.SRepairService;
 import com.example.nngkxxdp.program.service.SWorkerService;
 import com.example.nngkxxdp.program.util.MiniTokenUtil;
@@ -21,6 +22,9 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.Map;
 
 @RestController
@@ -29,6 +33,7 @@ import java.util.Map;
 @RequiredArgsConstructor
 public class WorkerMiniController {
     private final SRepairService service;
+    private final SDictService dictService;
 
 
     @PostMapping("/addOrder")
@@ -92,5 +97,34 @@ public class WorkerMiniController {
 
 
 
+    @GetMapping("/getDictByType")
+    public Map<String, Object> getDictByType(String types, String codes) {
+        try {
+            List<String> typeList =  new ArrayList<>();
+            List<String> codeList =  new ArrayList<>();
+            if(StrUtil.isNotEmpty(types)) {
+                String[] typeArray = types.split(",");
+                Collections.addAll(codeList, typeArray);
+            }
+            if(StrUtil.isNotEmpty(codes)) {
+                String[] codeArray = codes.split(",");
+                Collections.addAll(codeList, codeArray);
+            }
+            return SendUtil.send(true, ConstStr.RESULT_SUCCESS, dictService.getDictByType(typeList, codeList));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return SendUtil.send(false, ConstStr.ADD_FAILED);
+    }
 
+    @GetMapping("/getUserType")
+    public Map<String, Object> getUserType(String userId) {
+        try {
+            //普通用户 1 维修人员 2
+            return SendUtil.send(true, ConstStr.RESULT_SUCCESS, 1);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return SendUtil.send(false, ConstStr.ADD_FAILED);
+    }
 }

+ 86 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/program/dao/SDictDao.java

@@ -0,0 +1,86 @@
+package com.example.nngkxxdp.program.dao;
+
+
+import com.example.nngkxxdp.program.entity.SDict;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+
+/**
+ * (SRepair)表数据库访问层
+ *
+ */
+ @Mapper
+public interface SDictDao {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    SDict queryById(Integer id);
+
+    /**
+     * 查询指定行数据
+     *
+     * @param sDict 查询条件
+     * @param pageable         分页对象
+     * @return 对象列表
+     */
+    List<SDict> queryAllByLimit(SDict sDict, @Param("pageable") Pageable pageable);
+
+    /**
+     * 统计总行数
+     *
+     * @param sDict 查询条件
+     * @return 总行数
+     */
+    long count(SDict sDict);
+
+    /**
+     * 新增数据
+     *
+     * @param sDict 实例对象
+     * @return 影响行数
+     */
+    int insert(SDict sDict);
+
+    /**
+     * 批量新增数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<SDict> 实例对象列表
+     * @return 影响行数
+     */
+    int insertBatch(@Param("entities") List<SDict> entities);
+
+    /**
+     * 批量新增或按主键更新数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<SDict> 实例对象列表
+     * @return 影响行数
+     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
+     */
+    int insertOrUpdateBatch(@Param("entities") List<SDict> entities);
+
+    /**
+     * 修改数据
+     *
+     * @param sDict 实例对象
+     * @return 影响行数
+     */
+    int update(SDict sDict);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+    List<SDict> getDictByType(@Param("types") List<String> types, @Param("codes") List<String> codes);
+}
+

+ 31 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/program/entity/SDict.java

@@ -0,0 +1,31 @@
+package com.example.nngkxxdp.program.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * TODO
+ *
+ * @Description
+ * @Author leihy
+ * @Date 2023/3/24 10:57
+ **/
+@Data
+public class SDict implements Serializable {
+
+    private static final long serialVersionUID = -1L;
+
+    private int id;
+
+    private String type;
+
+    private String typeName;
+
+    private String code;
+
+    private String codeValue;
+
+    private int status;
+
+}

+ 104 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/program/service/Impl/SDictServiceImpl.java

@@ -0,0 +1,104 @@
+package com.example.nngkxxdp.program.service.Impl;
+
+
+import cn.hutool.core.io.FileTypeUtil;
+import cn.hutool.core.lang.UUID;
+import com.example.nngkxxdp.dao.FileDao;
+import com.example.nngkxxdp.entity.SFile;
+import com.example.nngkxxdp.program.dao.SDictDao;
+import com.example.nngkxxdp.program.entity.SDict;
+import com.example.nngkxxdp.program.service.SDictService;
+import com.example.nngkxxdp.util.Blank;
+import com.example.nngkxxdp.util.ConstStr;
+import com.example.nngkxxdp.util.SendUtil;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * (SDict)表服务实现类
+ *
+ */
+@Service("sDictService")
+public class SDictServiceImpl implements SDictService {
+    
+    private final SDictDao sDictDao;
+    
+    public SDictServiceImpl(SDictDao sDictDao) {
+        this.sDictDao = sDictDao;
+    }
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    @Override
+    public SDict queryById(Integer id) {
+        return this.sDictDao.queryById(id);
+    }
+
+    /**
+     * 分页查询
+     *
+     * @param sDict 筛选条件
+     * @param pageRequest      分页对象
+     * @return 查询结果
+     */
+    @Override
+    public Page<SDict> queryByPage(SDict sDict, PageRequest pageRequest) {
+        long total = this.sDictDao.count(sDict);
+        return new PageImpl<>(this.sDictDao.queryAllByLimit(sDict, pageRequest), pageRequest, total);
+    }
+
+    /**
+     * 新增数据
+     *
+     * @param sDict 实例对象
+     * @return 实例对象
+     */
+    @Override
+    public SDict insert(SDict sDict) {
+        this.sDictDao.insert(sDict);
+        return sDict;
+    }
+
+    /**
+     * 修改数据
+     *
+     * @param sDict 实例对象
+     * @return 实例对象
+     */
+    @Override
+    public SDict update(SDict sDict) {
+        this.sDictDao.update(sDict);
+        return this.queryById(sDict.getId());
+    }
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 是否成功
+     */
+    @Override
+    public boolean deleteById(Integer id) {
+        return this.sDictDao.deleteById(id) > 0;
+    }
+
+
+    @Override
+    public List<SDict> getDictByType(List<String> types, List<String> codes) {
+        return sDictDao.getDictByType(types, codes);
+    }
+}

+ 66 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/program/service/SDictService.java

@@ -0,0 +1,66 @@
+package com.example.nngkxxdp.program.service;
+
+
+import com.example.nngkxxdp.program.entity.SDict;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * (SDict)表服务接口
+ *
+ */
+public interface SDictService {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    SDict queryById(Integer id);
+
+    /**
+     * 分页查询
+     *
+     * @param sDict 筛选条件
+     * @param pageRequest      分页对象
+     * @return 查询结果
+     */
+    Page<SDict> queryByPage(SDict sDict, PageRequest pageRequest);
+
+    /**
+     * 新增数据
+     *
+     * @param sDict 实例对象
+     * @return 实例对象
+     */
+    SDict insert(SDict sDict);
+
+    /**
+     * 修改数据
+     *
+     * @param sDict 实例对象
+     * @return 实例对象
+     */
+    SDict update(SDict sDict);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 是否成功
+     */
+    boolean deleteById(Integer id);
+
+
+
+    List<SDict> getDictByType(List<String> types, List<String> codes);
+
+
+}

+ 154 - 0
nngkxxdp/src/main/resources/mapper/SDictDao.xml

@@ -0,0 +1,154 @@
+<?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.example.nngkxxdp.program.dao.SRepairDao">
+
+    <resultMap type="com.example.nngkxxdp.program.entity.SDict" id="SDictMap">
+        <result property="id" column="id" jdbcType="INTEGER"/>
+        <result property="type" column="type" jdbcType="VARCHAR"/>
+        <result property="typeName" column="type_name" jdbcType="VARCHAR"/>
+        <result property="code" column="code" jdbcType="VARCHAR"/>
+        <result property="codeValue" column="code_value" jdbcType="VARCHAR"/>
+        <result property="status" column="status" jdbcType="INTEGER"/>
+
+    </resultMap>
+
+    <!--查询单个-->
+    <select id="queryById" resultMap="SDictMap">
+        select
+            id, type, type_name, code, code_value, status
+        from s_dict
+        where id = #{id}
+    </select>
+
+    <!--查询指定行数据-->
+    <select id="queryAllByLimit" resultMap="SDictMap">
+        select
+            id, type, type_name, code, code_value, status
+        from s_dict
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="type != null and type != ''">
+                and type = #{type}
+            </if>
+            <if test="typeName != null and typeName != ''">
+                and type_name = #{typeName}
+            </if>
+            <if test="code != null and code != ''">
+                and code = #{code}
+            </if>
+            <if test="codeValue != null and codeValue != ''">
+                and code_value = #{codeValue}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+        </where>
+        limit #{pageable.offset}, #{pageable.pageSize}
+    </select>
+
+    <!--统计总行数-->
+    <select id="count" resultType="java.lang.Long">
+        select count(1)
+        from s_dict
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="type != null and type != ''">
+                and type = #{type}
+            </if>
+            <if test="typeName != null and typeName != ''">
+                and type_name = #{typeName}
+            </if>
+            <if test="code != null and code != ''">
+                and code = #{code}
+            </if>
+            <if test="codeValue != null and codeValue != ''">
+                and code_value = #{codeValue}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+        </where>
+    </select>
+
+    <!--新增所有列-->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        INSERT INTO s_dict(type, type_name, code, code_value, status)
+        VALUES (#{type}, #{typeName}, #{code}, #{codeValue}, #{status})
+    </insert>
+
+    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
+        INSERT INTO s_dict(type, type_name, code, code_value, status)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{type}, #{typeName}, #{code}, #{codeValue}, #{status})
+        </foreach>
+    </insert>
+
+    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
+        INSERT INTO s_dict(type, type_name, code, code_value, status)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{type}, #{typeName}, #{code}, #{codeValue}, #{status})
+        </foreach>
+        on duplicate key update
+        type = values(type),
+        type_name = values(type_name),
+        code = values(code),
+        code_value = values(code_value),
+        status = values(status)
+    </insert>
+
+    <!--通过主键修改数据-->
+    <update id="update">
+        update s_dict
+        <set>
+            <if test="type != null and type != ''">
+                type = #{type},
+            </if>
+            <if test="typeName != null and typeName != ''">
+                type_name = #{typeName},
+            </if>
+            <if test="code != null and code != ''">
+                code = #{code},
+            </if>
+            <if test="codeValue != null and codeValue != ''">
+                code_value = #{codeValue},
+            </if>
+            <if test="status != null">
+               status = #{status},
+            </if>
+        </set>
+        where id = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete from s_dict where id = #{id}
+    </delete>
+
+
+    <select id="getDictByType" resultMap="SDictMap">
+        select
+            type, type_name, code, code_value
+        from s_dict
+        where status = 1
+        <if test="types != null and types.size > 0">
+            AND type_name in
+            <foreach collection="types" item="s" index="index" open="(" close=")" separator=",">
+                #{s}
+            </foreach>
+        </if>
+        <if test="codes != null and codes.size > 0">
+            AND type_name in
+            <foreach collection="codes" item="s" index="index" open="(" close=")" separator=",">
+                #{s}
+            </foreach>
+        </if>
+    </select>
+
+</mapper>
+

+ 63 - 9
nnzwminiapp/pagesPublic/pages/work-order/work-order.js

@@ -25,7 +25,7 @@ Page({
         dateTime: null,
         startYear: 2000,
         endYear: 2250,
-        typeList: ['报修类型一', '报修类型二', '报修类型三'],
+        typeList: [],
         list: [],
         repairList: [],
         completeList: [],
@@ -50,15 +50,45 @@ Page({
             dateTimeArray: obj.dateTimeArray
         });
 
-        // 查询所有报修类型
+        // 设置所有报修类型
+        this.setRepairType();
+        let that = this;
+        request({
+          url: '/mini/worker/getUserType',
+          method: 'GET',
+          data: {
+            userId: wx.getStorageSync('userid')
+          }
+        }).then(res => {
+          if (res.result) {
 
-        let isUser = this.data.isUser;
-        if (!isUser) {
-            // 初始化待维修工单
-            this.loadTobeRepair();
-            // 初始化已完成工单
-            // this.loadComplete();
-        }
+            let userType = res.data;
+            if ("1" == userType) {
+                // 普通用户
+                this.setData({
+                  isUser: true
+                });
+                // 初始化待维修工单
+                that.loadTobeRepair();
+                // 初始化已完成工单
+                // this.loadComplete();
+            }else{
+              this.setData({
+                isUser: false
+              });
+            }
+          
+          }else{
+          }
+        });
+
+        // let isUser = this.data.isUser;
+        // if (!isUser) {
+        //     // 初始化待维修工单
+        //     this.loadTobeRepair();
+        //     // 初始化已完成工单
+        //     // this.loadComplete();
+        // }
     },
 
     /**
@@ -488,6 +518,30 @@ Page({
             }
             wx.hideLoading();
         });
+    },
+    /**
+     * 设置报修类型
+     */
+    setRepairType() {
+      // this.setData({
+      //          typeList: [{"code": 1, "codeValue": "报修类型一"},{"code": 2, "codeValue": "报修类型二"},{"code": 3, "codeValue": "报修类型三"}]
+      //        });
+        request({
+            url: '/mini/worker/getDictByType',
+            method: 'GET',
+            data: {
+                types: 'repair_type',
+                codes: ''
+            }
+        }).then(res => {
+            console.info(res)
+            if (res.result) {
+              let data = res.data;
+              this.setData({
+                typeList: data
+              });
+            }
+        });
     }
 
 })

+ 3 - 3
nnzwminiapp/pagesPublic/pages/work-order/work-order.wxml

@@ -16,9 +16,9 @@
                 <view class="formBox">
                     <view class="form-item">
                         <label for="" class="form-item-label">报修类型:</label>
-                        <picker mode="selector" class="form-item-picker" range="{{typeList}}" value="{{index}}" bindchange="typePickerChange">
-                            <input type="text" class="form-input" style="width: 100%;" disabled="true" value="{{typeList[index]}}" placeholder="请选择报修类型" placeholder-style="color:#999999" />
-                            <input type="text" style="display: none;" name="type" value="{{index}}" />
+                        <picker mode="selector" class="form-item-picker" range="{{typeList}}" range-key="{{'codeValue'}}" value="{{index}}" bindchange="typePickerChange">
+                            <input type="text" class="form-input" style="width: 100%;" disabled="true" value="{{typeList[index].codeValue}}" placeholder="请选择报修类型" placeholder-style="color:#999999" />
+                            <input type="text" style="display: none;" name="type" value="{{typeList[index].code}}" />
                         </picker>
                         <image class="form-icon" src="/pages/images/arrow.png" alt=""></image>
                     </view>