Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / River / OfficialClassificationController.java
package com.newfiber.api.pc.controller.River;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.newfiber.api.core.bean.ReqBodyObj;
import com.newfiber.api.core.bean.RespBodyObj;
import com.newfiber.api.pc.dao.RiverManage.OfficialClassificationDao;
import com.newfiber.api.pc.model.River.OfficialClassification;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author wmj
 * @Date: 2017/12/16 14:32
 * @description 业务管理--文案管理--文案分类
 */
@Controller
public class OfficialClassificationController {

    @Autowired
    private OfficialClassificationDao officialClassificationDao;

    /**
     * 业务管理--文案管理--文案分类查询
     *
     * @return
     */
    @PostMapping(value = "river/selectOfficialClassificationList", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj selectOfficialClassificationList(@RequestBody ReqBodyObj<Map<String, String>> param) {

        String officialTypeZn = param.getData().get("officialTypeZn");
        Integer page = param.getCurrent();
        Integer rows = param.getSize();
        try {
            Integer pageNo = null;
            Integer pageSize = rows;
            if (officialTypeZn != null && officialTypeZn.equals("") != true) {
                officialTypeZn = URLDecoder.decode(officialTypeZn, "UTF-8");
            }
            if (page != null && page != 0) {
                pageNo = (page - 1) * pageSize;
            }else{
                pageNo = null;
                pageSize = null;
            }
            List<OfficialClassification> officialClassificationList = officialClassificationDao.selectOfficialClassificationList(pageNo, pageSize, officialTypeZn);

            Page page1 = new Page();
            page1.setRecords(officialClassificationList);
            page1.setTotal(officialClassificationList.size());
            return RespBodyObj.ok(page1);
        } catch (Exception e) {
            e.printStackTrace();
            return RespBodyObj.error();
        }
    }

    /**
     * 业务管理--文案管理--新增文案分类
     *
     * @param request
     * @return
     */
    @PostMapping(value = "river/addOfficialClassification", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj addOfficialClassification(HttpServletRequest request, @RequestBody ReqBodyObj<Map<String, String>>param) {


        String officialTypeZn = param.getData().get("officialTypeZn");
        String remark = param.getData().get("remark");
        String createUserNo = param.getData().get("createUserNo");
        try {
            if (createUserNo == null || createUserNo == "") {
                createUserNo = request.getHeader("userNo");
            }
            if (officialTypeZn != null && officialTypeZn.equals("") != true) {
                officialTypeZn = URLDecoder.decode(officialTypeZn, "UTF-8");
            }
            int c = officialClassificationDao.selectMaxOfficialType() + 1;
            int a = officialClassificationDao.addOfficialClassification(c, officialTypeZn, createUserNo, remark);
            if (a > 0) {
                boolean result = true;
                return RespBodyObj.ok("新增成功");
            } else {
                return RespBodyObj.ok("新增失败");
            }
        } catch (Exception e) {
            e.printStackTrace();

            return RespBodyObj.error();
        }
    }

    /**
     * 业务管理--文案管理--修改文案分类
     *
     * @return
     */
    @PostMapping(value = "river/updateOfficialClassification", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj updateOfficialClassification(HttpServletRequest request, @RequestBody ReqBodyObj<Map<String, Object>> param) {
        String updateUserNo = (String) param.getData().get("updateUserNo");
        String officialTypeZn = (String) param.getData().get("officialTypeZn");
        String remark = (String) param.getData().get("remark");
        Integer serial = (Integer) param.getData().get("serial");
        try {
            if (updateUserNo == null || updateUserNo == "") {
                updateUserNo = request.getHeader("userNo");
            }
            Date updateTime = new Date();
            officialTypeZn = URLDecoder.decode(officialTypeZn, "UTF-8");
            int a = officialClassificationDao.updateOfficialClassification(officialTypeZn, updateUserNo, updateTime, remark, serial);
            if (a > 0) {
                boolean result = true;

                return RespBodyObj.ok("修改成功");
            } else {
                boolean result = false;
                return RespBodyObj.ok("修改失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RespBodyObj.error();
        }
    }

    /**
     * 业务管理--文案管理--删除文案分类
     *
     * @return
     */
    @PostMapping(value = "river/deleteOfficialClassification", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj deleteOfficialClassification(@RequestBody ReqBodyObj<Map<String, long[]>> param) {


        long[] serial = param.getData().get("serial");

        try {
            int a = officialClassificationDao.deleteOfficialClassification(serial);
            if (a > 0) {
                return RespBodyObj.ok("删除成功");
            } else {
                return RespBodyObj.ok("删除失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RespBodyObj.error();
        }
    }

    /**
     * 业务管理--文案管理--文案分类下拉框
     *
     * @return
     */
    @PostMapping(value = "river/selectOfficialClassTotal", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj selectOfficialClassTotal() {
        JSONObject json = new JSONObject();
        List<Object> list = new ArrayList<Object>();
        try {
            List<OfficialClassification> officialClassificationList = officialClassificationDao.selectOfficialClassTotal();
            if (officialClassificationList != null && officialClassificationList.size() > 0) {
                for (OfficialClassification officialClassification : officialClassificationList) {
                    Map<String, Object> map = new HashMap<String, Object>();
                    Integer officialType = officialClassification.getOfficialType();
                    String officialTypeZn = officialClassification.getOfficialTypeZn();
                    map.put("officialType", officialType);
                    map.put("officialTypeZn", officialTypeZn);
                    list.add(map);
                }
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("officialType", -1);
                map.put("officialTypeZn", "---全部---");
                list.add(map);
            }
            return RespBodyObj.ok(list);
        } catch (Exception e) {
            e.printStackTrace();
            return RespBodyObj.error();
        }
    }

    /**
     * 业务管理--文案管理--文案分类下拉框
     *
     * @return
     */
    @PostMapping(value = "river/selectOfficialClassTotalo", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj selectOfficialClassTotalo() {
        JSONObject json = new JSONObject();
        List<Object> list = new ArrayList<Object>();
        try {
            List<OfficialClassification> officialClassificationList = officialClassificationDao.selectOfficialClassTotal();
            if (officialClassificationList != null && officialClassificationList.size() > 0) {
                for (OfficialClassification officialClassification : officialClassificationList) {
                    Map<String, Object> map = new HashMap<String, Object>();
                    Integer officialType = officialClassification.getOfficialType();
                    String officialTypeZn = officialClassification.getOfficialTypeZn();
                    map.put("officialType", officialType);
                    map.put("officialTypeZn", officialTypeZn);
                    list.add(map);
                }
            }
            return RespBodyObj.ok(list);
        } catch (Exception e) {
            e.printStackTrace();
            return RespBodyObj.error();
        }
    }
}