SupplierStaffController.java 9.0 KB
Newer Older
苗卫卫 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
package com.boco.nbd.wios.manage.controller;

import cn.hutool.core.lang.Assert;
import com.boco.nbd.cams.core.constant.CamsConstant;
import com.boco.nbd.wios.manage.contants.WiosConstant;
import com.boco.nbd.wios.manage.entity.bo.SupplierStaffBo;
import com.boco.nbd.wios.manage.entity.bo.SupplierStaffVo;
import com.boco.nbd.wios.manage.service.impl.SupplierStaffService;
import com.boco.nbd.wios.manage.util.CommonUtils;
import com.ihidea.component.api.v2.BaseResponse;
import com.ihidea.core.support.exception.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 服务商员工管理接口
 *
 * @author xgl
 * @version [版本号, 2020年9月28日]
 */
@RestController
@RequestMapping("api")
@Api(tags = "服务商员工管理接口")
@ApiIgnore
public class SupplierStaffController {
    @Autowired
    private SupplierStaffService supplierStaffService;

    /**
     * 添加服务商员工
     *
     * @param supplierStaffBo
     * @return
     */
    @PostMapping(value = "supplierStaff/add")
    @ApiOperation(value = "添加服务商员工")
    @ApiImplicitParams({@ApiImplicitParam(name = "roleIds", value = "角色id", dataType = "String", paramType = "query", required = true),})
    public BaseResponse<Object> add(SupplierStaffBo supplierStaffBo) {
        Assert.notNull(supplierStaffBo.getName(), "姓名不能为空");
        Assert.notNull(supplierStaffBo.getSupplierId(), "服务商不能为空");
        Assert.notNull(supplierStaffBo.getPhone(), "电话不能为空");
        Assert.notNull(supplierStaffBo.getIsInsure(), "是否投保不能为空");
        Assert.notNull(supplierStaffBo.getDataAuth(), "数据权限不能为空");
        if (!StringUtils.isEmpty(supplierStaffBo.getCertFiles())) {
            String[] arr = supplierStaffBo.getCertFiles().split(CamsConstant.COMMA);
            List<String> list = new ArrayList<String>();
            for (String s : arr) {
                list.add(CommonUtils.urlHandle(s));
            }
            supplierStaffBo.setCertFiles(StringUtils.collectionToCommaDelimitedString(list));
        }
        //电工保险单据
        if (!StringUtils.isEmpty(supplierStaffBo.getInsureFiles())) {
            String[] insureArr = supplierStaffBo.getInsureFiles().split(CamsConstant.COMMA);
            List<String> insureFileList = new ArrayList<>();
            for (String str : insureArr) {
                insureFileList.add(CommonUtils.urlHandle(str));
            }
            supplierStaffBo.setInsureFiles(StringUtils.collectionToCommaDelimitedString(insureFileList));
        }
        //电工身份证
        if (!StringUtils.isEmpty(supplierStaffBo.getIdcardFiles())) {
            String[] idcardArr = supplierStaffBo.getIdcardFiles().split(CamsConstant.COMMA);
            List<String> idcardFileList = new ArrayList<>();
            for (String str : idcardArr) {
                idcardFileList.add(CommonUtils.urlHandle(str));
            }
            supplierStaffBo.setIdcardFiles(StringUtils.collectionToCommaDelimitedString(idcardFileList));
        }
        if (!StringUtils.isEmpty(supplierStaffBo.getCertExpireStr())) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = sdf.parse(supplierStaffBo.getCertExpireStr());
                supplierStaffBo.setCertExpire(date);
            } catch (ParseException e) {
                throw new ServiceException("日期格式错误");
            }
        }
        supplierStaffService.add(supplierStaffBo);
        return new BaseResponse<>();
    }

    /**
     * 更新服务商员工信息
     *
     * @param staff
     * @return
     */
    @PostMapping(value = "supplierStaff/update")
    @ApiOperation(value = "更新服务商员工")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "int", paramType = "query", required = true),
        @ApiImplicitParam(name = "name", value = "员工姓名", dataType = "String", paramType = "query", required = false),
        @ApiImplicitParam(name = "phone", value = "员工手机", dataType = "String", paramType = "query", required = false),
        @ApiImplicitParam(name = "certExpireStr", value = "电工证有效期", dataType = "String", paramType = "query", required = false),
        @ApiImplicitParam(name = "isInsure", value = "是否投保 0-未投保 1-已投保", dataType = "int", paramType = "query", required = false),
        @ApiImplicitParam(name = "dataAuth", value = "数据权限 1:个人 2:全部", dataType = "int", paramType = "query", required = false),
        @ApiImplicitParam(name = "certFiles", value = "电工证图片", dataType = "String", paramType = "query", required = false),
        @ApiImplicitParam(name = "insureFiles", value = "电工保险", dataType = "String", paramType = "query", required = false),
        @ApiImplicitParam(name = "idcardFiles", value = "电工身份证", dataType = "String", paramType = "query", required = false),
        @ApiImplicitParam(name = "status", value = "状态 0禁用 1启用", dataType = "int", paramType = "query", required = false),
    })
    public BaseResponse<Object> update(SupplierStaffBo staff) {
        if (!StringUtils.isEmpty(staff.getCertFiles())) {
            String[] arr = staff.getCertFiles().split(CamsConstant.COMMA);
            List<String> list = new ArrayList<>();
            for (String s : arr) {
                list.add(CommonUtils.urlHandle(s));
            }
            staff.setCertFiles(StringUtils.collectionToCommaDelimitedString(list));
        }
        //电工保险单据
        if (!StringUtils.isEmpty(staff.getInsureFiles())) {
            String[] insureArr = staff.getInsureFiles().split(CamsConstant.COMMA);
            List<String> insureFileList = new ArrayList<>();
            for (String str : insureArr) {
                insureFileList.add(CommonUtils.urlHandle(str));
            }
            staff.setInsureFiles(StringUtils.collectionToCommaDelimitedString(insureFileList));
        }
        //电工身份证
        if (!StringUtils.isEmpty(staff.getIdcardFiles())) {
            String[] idcardArr = staff.getIdcardFiles().split(CamsConstant.COMMA);
            List<String> idcardFileList = new ArrayList<>();
            for (String str : idcardArr) {
                idcardFileList.add(CommonUtils.urlHandle(str));
            }
            staff.setIdcardFiles(StringUtils.collectionToCommaDelimitedString(idcardFileList));
        }
        if (!StringUtils.isEmpty(staff.getCertExpireStr())) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = sdf.parse(staff.getCertExpireStr());
                staff.setCertExpire(date);
            } catch (ParseException e) {
                throw new ServiceException("日期格式错误");
            }
        }
        supplierStaffService.update(staff.getId(), staff);
        return new BaseResponse<>();
    }

    /**
     * 查询服务商员工列表
     *
     * @param account
     * @param name
     * @return
     */
    @GetMapping(value = "supplierStaff/list")
    @ApiOperation(value = "查询服务商员工列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "一页显示数量", dataType = "int", paramType = "query", required = false),
        @ApiImplicitParam(name = "pagecount", value = "页码", dataType = "int", paramType = "query", required = false),
        @ApiImplicitParam(name = "account", value = "账号", dataType = "String", paramType = "query", required = false),
        @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = false),
        @ApiImplicitParam(name = "supplierId", value = "安装服务商id", dataType = "int", paramType = "query", required = false),
        @ApiImplicitParam(name = "showCertExpired", value = "显示电工证过期的数据 0:否 1:是", dataType = "int", paramType = "query", required = false),

    })
    public BaseResponse<List<SupplierStaffVo>> getList(String account, String name, Integer supplierId, Integer showCertExpired) {
        SupplierStaffBo condition = new SupplierStaffBo();
        condition.setAccount(account);
        condition.setName(name);
        condition.setSupplierId(supplierId);
        condition.setShowCertExpired(showCertExpired);
        return new BaseResponse<>(supplierStaffService.getList(condition));
    }
}