UserAPIService.java 3.21 KB
package com.huaheng.api.U8.Service;

import com.huaheng.api.U8.domain.ICSPersonModel;
import com.huaheng.api.general.Controller.BasicDataApi;
import com.huaheng.api.general.service.BasicDataApiService;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.general.company.domain.CompanyWu;
import com.huaheng.pc.general.company.domain.WarehouseCompany;
import com.huaheng.pc.general.company.mapper.WarehouseCompanyMapperAuto;
import com.huaheng.pc.general.company.service.ICompanyService;
import com.huaheng.pc.system.dept.service.IDeptService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class UserAPIService {

    @Autowired
    IUserService iUserService;

    @Autowired
    IDeptService iDeptService;
    @Resource
    private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto;

    @Autowired
    BasicDataApiService basicDataApiService;
    @Autowired
    private ICompanyService companyService;


    /**
     * 人员档案service
     * @param ICSPerson
     * @return
     */
    @Transactional
    public AjaxResult ICSPerson(ICSPersonModel ICSPerson) {
        WarehouseCompany warehouseCompany = new WarehouseCompany();
        CompanyWu companyWu=new CompanyWu();
        companyWu.setuCompanyCode(ICSPerson.getCompanyCode());
        companyWu=companyService.selectCompanyWu(companyWu);
        if (companyWu == null) {
            return AjaxResult.error("货主不存在");
        }
        warehouseCompany.setCompanyCode(companyWu.getCompanyCode());
        List<WarehouseCompany> list = warehouseCompanyMapperAuto.selectListEntityByEqual(warehouseCompany);
        if (list == null || list.size() == 0) {
            return AjaxResult.error("系统中没有该货主:" + warehouseCompany.toString() + "  信息,请先录入货主信息!");
        }
        List<Integer> idlist=new ArrayList<>();
        for(WarehouseCompany wc : list){
            idlist.add(wc.getCompanyId());
        }

        User user = new User();
        user.setLoginName(ICSPerson.getcPersonCode());
        user.setUserName(ICSPerson.getcPersonName());
        try {
            //根据部门编码获取部门ID
            user.setDeptId(iDeptService.selectDeptId(ICSPerson.getcDepCode()));
        }catch (Exception e){
            return AjaxResult.error("部门编码错误,找不到该部门");
        }
        user.setCreateBy(ShiroUtils.getLoginName());
        user.setUpdateBy(ShiroUtils.getLoginName());
        user.setUpdateTime(new Date());
        user.setCompanyIdList(idlist);
//        PersonApi personApi = new PersonApi();
        AjaxResult ajaxResult = basicDataApiService.user(user);
//        CompanyWu companyWu=companyService.selectCompanyWu(ICSPerson.getCompanyCode());
//        if(companyWu==null){
//            return AjaxResult.error("货主不存在");
//        }
        return ajaxResult;
    }
}